ChrisKruegerDev / androidx-kit

🛠️ AndroidX KIT leverages your coding with the AndroidX libraries. It helps you to use standard components easily.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AndroidX KIT

Maven Central Kotlin Gradle GitHub License

AndroidX KIT leverages your coding with the AndroidX libraries. This library provides features for easier use of the standard library components.

Setup

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")
}

Usage

RecyclerView builder

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()
    }
}

ViewModel event communication

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 CustomTab

Open a CustomTab:

CustomTabHelper.openCustomTab(activity, uri, ContextCompatColors.colorSurface(activity), Logger::e)

View extensions

Coming soon

AppBar change handling

Coming soon

About

🛠️ AndroidX KIT leverages your coding with the AndroidX libraries. It helps you to use standard components easily.

License:Apache License 2.0


Languages

Language:Kotlin 75.5%Language:Java 24.5%