AndroidX KIT leverages your coding with the AndroidX libraries. This library provides features for easier use of the standard library components.
The library is published to Maven Central. Add the Maven Central repository if it is not already there.
repositories {
mavenCentral()
}
To use the library in a single-platform project, add a dependency.
dependencies {
implementation("app.moviebase:androidx-kit:2.0.5")
}
Creating a RecyclerView adapter with the builder:
private val itemsAdapter = recyclerViewAdapter<TextItem> {
viewHolderHeader { adapter, parent -> HeaderViewHolder(adapter, parent) }
viewHolder { adapter, parent -> TextViewHolder(adapter, parent) }
onItemId { it.id }
onClick {
Toast.makeText(this@MainActivity, "Click on ${it.text}", Toast.LENGTH_SHORT).show()
}
onLongClick {
Toast.makeText(this@MainActivity, "Long click on ${it.text}", Toast.LENGTH_SHORT).show()
}
}
Send your actions and messages from the ViewModel to the Activity via LiveData.
For example, start a new Activity or Fragment:
// in the Activity or Fragment
viewModel.action.bindTo(this)
viewModel.message.bindTo(this)
// send from the ViewModel
val action = SingleLiveEvent<Action>()
action.value = StartActivityActio(MainActivity::class)
action.value = ShowDialogFragmentAction(MyDialogFragment::clas)
For example, send a Snackbar message:
// in the Activity or Fragment
viewModel.message.bindTo(this)
// send from the ViewModel
val message = SingleLiveEvent<SnackbarMessage>()
message.value = SuccessSnackbarMessage(context, R.string.message)
Open a CustomTab:
CustomTabHelper.openCustomTab(activity, uri, ContextCompatColors.colorSurface(activity), Logger::e)
Coming soon
Coming soon