Skip to content

Instantly share code, notes, and snippets.

View bigyanthapa's full-sized avatar
👀

Bigyan Thapa bigyanthapa

👀
View GitHub Profile
@bigyanthapa
bigyanthapa / VerticalTextView.kt
Created January 22, 2021 21:29
Vertical text view
private const val VERTICAL_ROTATION = 270f
class VerticalTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
AppCompatTextView(context, attrs, defStyle) {
private var _measuredWidth: Int = 0
private var _measuredHeight: Int = 0
private val _bounds = Rect()
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
class UserFragment : Fragment() {
private lateinit binding: FragmentUserBinding
private lateinit viewModel: UserViewModel
private val adapter: UserAdapter = UserAdapter()
override onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_user, container, false)
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
class UserAdapter : RecyclerView.Adapter<UserAdapter.UserViewHolder> {
var users: List<User> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
// This keeps track of the currently selected position
var selectedPosition by Delegates.observable(-1) { property, oldPos, newPos ->
class MyClass {
companion object {
@JvmStatic
fun printStaticHello() {
println("Static Hello World!")
}
fun printNonStaticHello() {
println("Non-Static Hello World!")
object MyObject {
@JvmStatic
fun printStaticHello() {
println("Static Hello World!")
}
fun printNonStaticHello() {
println("Non-Static Hello World!")
}
class MyClass {
// some implementations
companion object {
val SOME_STATIC_VARIABLE = "some_static_variable"
fun someStaticFunction() {
// static function implementation
}
}
object MyObject {
// further implementation
fun printHello() {
println("Hello World!")
}
}
{
"user": {
"name": "Foo Bar",
"address1": "Moon",
"address2": "Mars"
},
"books": [
{
"isbn": "asdf4f234m02454ac3",
"author": "Alien 1",
class FooViewModel: ViewModel() {

   /* repository is provided here */

   init {
      launch { fetchData() }
   }

 internal suspend fun fetchData() {