class FooViewModel: ViewModel() {
/* repository is provided here */
init {
launch { fetchData() }
}
internal suspend fun fetchData() {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
companion object { | |
@JvmStatic | |
fun printStaticHello() { | |
println("Static Hello World!") | |
} | |
fun printNonStaticHello() { | |
println("Non-Static Hello World!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MyObject { | |
@JvmStatic | |
fun printStaticHello() { | |
println("Static Hello World!") | |
} | |
fun printNonStaticHello() { | |
println("Non-Static Hello World!") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
// some implementations | |
companion object { | |
val SOME_STATIC_VARIABLE = "some_static_variable" | |
fun someStaticFunction() { | |
// static function implementation | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MyObject { | |
// further implementation | |
fun printHello() { | |
println("Hello World!") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"user": { | |
"name": "Foo Bar", | |
"address1": "Moon", | |
"address2": "Mars" | |
}, | |
"books": [ | |
{ | |
"isbn": "asdf4f234m02454ac3", | |
"author": "Alien 1", |
NewerOlder