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
| @Composable | |
| fun ExpressiveButtonAnimation() { | |
| var selectedIndex by remember { mutableIntStateOf(-1) } | |
| val checkedColor = Color(0xFF554F6E) | |
| val uncheckedColor = Color(0xFFEAE5FF) | |
| val icons = listOf(Icons.Outlined.Alarm, Icons.Outlined.LinkOff, Icons.Outlined.Wifi) | |
| var weights = remember { mutableStateListOf(0.85f, 0.65f, 1.5f) } | |
| Box( |
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 TokenInterceptor( | |
| private val preferencesService: PreferencesService, // shared prefs or data store | |
| private val retrofit: Retrofit, | |
| ) : Interceptor { | |
| override fun intercept(chain: Interceptor.Chain): Response = runBlocking { | |
| val request: Request = chain.request() | |
| val response = chain.proceed(request = request) | |
| if (!response.isSuccessful && response.code == 401) { |
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.robertlevonyan.demo.progressbar | |
| import android.animation.AnimatorSet | |
| import android.animation.ValueAnimator | |
| import android.content.Context | |
| import android.graphics.Canvas | |
| import android.graphics.Color | |
| import android.graphics.Paint | |
| import android.util.AttributeSet | |
| import android.view.View |
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
| Name | Support by Google | Caching | RxJava | Coroutines | Additional files | Write* | Read* | |
|---|---|---|---|---|---|---|---|---|
| Room | Yes | SQLite | Yes | Yes | No | 247** | 181** | |
| Realm | No | C++ core | Yes | Partial | No | 18 | 12 | |
| ObjectBox | No | JSON | Yes | No | No | 4 | 4 | |
| SqlDelight | No | SQLite | Yes | Yes | Yes | 127 | 14 |
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 SqlDelightDao() { | |
| /** | |
| * Create a SqlDriver instance, which will maintain connections to an underlying SQL database and provide APIs | |
| * for managing transactions and executing SQL statements. | |
| * Params are a Schema of the generated database, an application context and a name of db | |
| */ | |
| private val driver: SqlDriver = AndroidSqliteDriver(Database.Schema, context, "caching.db") | |
| // Instance of the generated database instance with adapter. Movie is a generated entoty | |
| private val database = Database(driver, Movie.Adapter(DateAdapter())) | |
| // Instance of generated MoviesQueries interface |
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 DateAdapter : ColumnAdapter<Date, String> { | |
| companion object { | |
| private val format = SimpleDateFormat("yyyy-MM-dd", Locale.US) | |
| } | |
| override fun decode(databaseValue: String): Date = format.parse(databaseValue) ?: Date() | |
| override fun encode(value: Date): String = format.format(value) | |
| } |
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
| import java.util.Date; | |
| CREATE TABLE Movie( | |
| id INTEGER PRIMARY KEY, | |
| backdropPath TEXT, | |
| posterPath TEXT, | |
| title TEXT, | |
| overview TEXT, | |
| releaseDate TEXT as Date | |
| ); |
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 ObjectBoxDao() : DbRepository { | |
| // create a Box instance for Movie type | |
| private val moviesBox: Box<Movie> = ObjectBox.boxStore.boxFor(ObMovie::class.java) | |
| override suspend fun save(movies: List<Movie>) { | |
| moviesBox.put(movies) | |
| } | |
| override fun getMovies(): Flow<List<Movie>> = callbackFlow { // wrap response in a callback flow | |
| val subscription = moviesBox.query().build().subscribe() |
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
| object ObjectBox { | |
| lateinit var boxStore: BoxStore | |
| private set | |
| fun init(context: Context) { | |
| boxStore = MyObjectBox.builder() | |
| .androidContext(context.applicationContext) | |
| .build() | |
| } | |
| } |
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 RealmDao() { | |
| private val realm: Realm = Realm.getDefaultInstance() | |
| suspend fun save(movies: List<Movie>) { | |
| realm.executeTransactionAwait { r -> // open a realm transaction | |
| for (movie in movies) { | |
| if (r.where(RealmMovie::class.java).equalTo("id", movie.id).findFirst() != null) { | |
| continue | |
| } |
NewerOlder