Example from Android Jetpack: LiveData
MutableLiveData Example |
---|
![]() |
import android.content.Context | |
import android.net.ConnectivityManager | |
import android.net.NetworkCapabilities | |
import android.os.Build | |
val Context.isConnected: Boolean | |
get() { | |
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
return when { | |
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> { |
// Result is a superpowered enum that can be Success or Failure | |
// and the basis for a railway junction | |
sealed class Result<T> | |
data class Success<T>(val value: T): Result<T>() | |
data class Failure<T>(val errorMessage: String): Result<T>() | |
// Composition: apply a function f to Success results | |
infix fun <T,U> Result<T>.then(f: (T) -> Result<U>) = | |
when (this) { | |
is Success -> f(this.value) |
MutableLiveData Example |
---|
![]() |
package com.example.util | |
import android.support.v7.widget.LinearLayoutManager | |
import android.support.v7.widget.RecyclerView | |
/** | |
* Call listener when the current page is changed. | |
* Use this with LinearLayoutManager and PagerSnapHelper. | |
* | |
* Whether the listener is called at first might depend on the version of RecyclerView. |
Simple helper file for standard text sizes in material design. The sizes are provided by the material design documentation https://www.google.com/design/spec/style/typography.html#typography-roboto
Too many type sizes and styles at once can wreck any layout. A typographic scale is a limited set of type sizes that work well together, along with the layout grid. The basic set of styles are based on a typographic scale of 12, 14, 16, 20, and 34.
Disclaimer: This is dumb. If anybody knows a better way, I'm all ears.
You have two Android projects. One is a library and one is an app that depends on that library. Both are on your local machine.
Now, say you want to test the library in the app before you publish it. Here's what you do.
You have an app and a lib: