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
@AndroidEntryPoint | |
class MovieDetailActivity : AppCompatActivity() { | |
val viewmodel: MovieViewModel by viewModels() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
// viewmodel = Injector.detailViewModel(this) remove this line | |
...// viewModle is ready to be used... |
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
// Source : https://chetangupta.net/viewbinding/ | |
// file name : profile_layout.xml | |
<FrameLayout ... > | |
<TextView android:id="@+id/text_name" ... /> | |
<TextView android:id="@+id/text_twitter" ... /> | |
<TextView android:id="@+id/text_blog" ... /> | |
</FrameLayout> | |
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
// Source : https://chetangupta.net/viewbinding/ | |
// Author : ChetanGupta.net @Androidbites | |
abstract class ViewBindingFragment<VB : ViewBinding> : Fragment() { | |
private var _binding: ViewBinding? = null | |
abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB | |
@Suppress("UNCHECKED_CAST") | |
protected val binding: VB |
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
// Source : https://chetangupta.net/viewbinding/ | |
// file name : profile_layout.xml | |
<FrameLayout ... > | |
<TextView android:id="@+id/text_name" ... /> | |
<TextView android:id="@+id/text_twitter" ... /> | |
<TextView android:id="@+id/text_blog" ... /> | |
</FrameLayout> | |
// controller fragment class |
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
// Author : ChetanGupta.net @Androidbites | |
abstract class ViewBindingActivity<VB : ViewBinding> : AppCompatActivity() { | |
private var _binding: ViewBinding? = null | |
abstract val bindingInflater: (LayoutInflater) -> VB | |
@Suppress("UNCHECKED_CAST") | |
protected val binding: VB | |
get() = _binding as VB |
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
// Directly use the 4th constructor example | |
val contact = mapOf("chetan" to "[email protected]") | |
val linkedMapOfContact = LinkedHashMap(contact) | |
// Or create and add all entries | |
val linkedMapOfContact = LinkedHashMap<String,Int>() | |
linkedMapOfContact.putAll(contact) |
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
val linkedHashMap = LinkedHashMap<String,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
fun <K, V> linkedMapOf(vararg pairs: Pair<K, V>): LinkedHashMap<K, V> | |
= pairs.toMap(LinkedHashMap(mapCapacity(pairs.size))) | |
// this factory function takes pair and uses LinkedHashMap's second constructor which | |
// start off with the object capacity as the number of pairs passed |
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
fun <K, V> linkedMapOf(): LinkedHashMap<K, V> = LinkedHashMap<K, V>() | |
// linkedMapOf directly create LinkedHashMap object default constructor | |
// Java LinkedHashMap default constructor create LinkedHashMap with | |
// * inital capacity 16 and * LoadFactor 0.75 |
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
// Kotlin Standard Library function | |
fun <K, V> linkedMapOf(): LinkedHashMap<K, V> | |
fun <K, V> linkedMapOf(vararg pairs: Pair<K, V>): LinkedHashMap<K, V> |