Kotlin Tools for Android ViewModel, LiveData, Data Binding, Dependency injection, Async operations, Repository pattern, Retrofit, Form Validation, Cloud Firestore, etc.
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
| package com.uncommon.model.smartlock | |
| import android.app.Activity | |
| import android.content.Intent | |
| import android.content.IntentSender | |
| import com.google.android.gms.auth.api.credentials.Credential | |
| import com.google.android.gms.auth.api.credentials.CredentialPickerConfig | |
| import com.google.android.gms.auth.api.credentials.CredentialRequest | |
| import com.google.android.gms.auth.api.credentials.Credentials | |
| import com.google.android.gms.auth.api.credentials.HintRequest |
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
| open class DataBoundAdapter<T>(val lifecycleOwner: LifecycleOwner, val itemLayoutIdProvider: (T) -> Int, val bindingVariableId: Int, diffCallback: DiffUtil.ItemCallback<T>) : ListAdapter<T, DataBoundViewHolder>(diffCallback) { | |
| constructor(lifecycleOwner: LifecycleOwner, @LayoutRes itemLayoutId: Int, bindingVariableId: Int, diffCallback: DiffUtil.ItemCallback<T>) : this(lifecycleOwner, { itemLayoutId }, bindingVariableId, diffCallback) | |
| private val extras = hashMapOf<Int, Any>() | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataBoundViewHolder { | |
| val layoutInflater = LayoutInflater.from(parent.context) | |
| val binding = DataBindingUtil.inflate<ViewDataBinding>(layoutInflater, viewType, parent, false) | |
| binding.setLifecycleOwner(lifecycleOwner) | |
| return DataBoundViewHolder(binding) |
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
| interface SignInView { | |
| //... | |
| } | |
| class SignInFragment : Fragment(), SignInView { | |
| val vmb by vmb<SignInViewModel, FragmentSignInBinding>(R.layout.fragment_sign_in) | |
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
| return vmb.rootView | |
| } |
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
| <LinearLayout | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:orientation="vertical"> | |
| <EditText | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:hint="@string/global_email" | |
| android:inputType="textEmailAddress" | |
| android:text="@={viewModel.email}" /> |
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 formValid = MediatorLiveData<Boolean>() | |
| .addValueSource(email, { validateForm(email, password) }) | |
| .addValueSource(password, { validateForm(email, password) }) |
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 email = mutableLiveDataOf(defaultEmail) | |
| val password = mutableLiveDataOf(defaultPassword) | |
| val formValid = MediatorLiveData<Boolean>().apply { | |
| addSource(email, {value = validateForm(email.value, password.value)}) | |
| addSource(password, {value = validateForm(email.value, password.value)}) | |
| } | |
| private fun validateForm(email: String, password: String): Boolean | |
| = validateEmail(email) && validatePassword(password, config.MIN_PASSWORD_LENGTH) |
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 MainViewModel : ViewModel(){ | |
| // val email = ObservableField<String>("@") | |
| val email = mutableLiveDataOf("@") | |
| } |
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 MainActivity : AppCompatActivity(){ | |
| val viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java) | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| val titleView = findViewById<TextView>(R.id.title) | |
| viewModel.myliveData.observe(this, Observer { | |
| titleView.setText(it.title) | |
| }) |
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
| <layout> | |
| <data> | |
| <variable | |
| name="viewModel" | |
| type="com.strv.dundee.ui.main.MainViewModel" /> | |
| <variable | |
| name="view" | |
| type="com.strv.dundee.ui.main.MainView" /> | |
| </data> |
NewerOlder