This file contains 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 boxModule = module { | |
single { ObjectBox.init(androidContext()) } | |
} |
This file contains 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
inline fun <reified T: Any> saveToDatabase(data: List<T>) { | |
CoroutineScope(Dispatchers.IO).launch { | |
boxStore.boxFor<T>().put(data) | |
} | |
} |
This file contains 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
internal class DarkModeHelper(private val context: Context) { | |
internal fun onModeChanged(newMode: Boolean, delegate: AppCompatDelegate) { | |
if (newMode) { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) | |
} else { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | |
} | |
delegate.applyDayNight() | |
} | |
} |
This file contains 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
private val darkModeHelper: DarkModeHelper by inject() | |
// ... | |
override fun onOptionsItemSelected(item: MenuItem?): Boolean { | |
return when (item?.itemId) { | |
R.id.mnu_set_theme -> { | |
darkMode = !darkMode | |
sharedPref.edit { | |
putBoolean("darkMode", darkMode) |
This file contains 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
override fun onResume() { | |
super.onResume() | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | |
configureAutoDarkMode() | |
} else { | |
darkModeHelper.onModeChanged(darkMode, delegate) | |
} | |
} | |
private fun configureAutoDarkMode() { |
This file contains 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
[versions] | |
hilt = "2.50" | |
kotlin = "1.9.22" | |
kotlin-coroutines = "1.7.3" | |
retrofit = "2.9.0" | |
room = "2.6.1" | |
(...) | |
[plugins] |
This file contains 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 RocketApi { | |
@GET("rockets") | |
suspend fun getRockets(): List<RocketResponse> | |
} |
This file contains 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
@Serializable | |
data class RocketResponse( | |
@SerialName("id") | |
val id: String = "", | |
@SerialName("name") | |
val name: String = "", | |
@SerialName("cost_per_launch") | |
val costPerLaunch: Int = 0, |
This file contains 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
private const val DATABASE_VERSION = 1 | |
@Database( | |
entities = [RocketCached::class], | |
version = DATABASE_VERSION | |
) | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun rocketDao(): RocketDao | |
} |
This file contains 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
@Dao | |
interface RocketDao { | |
@Query("SELECT * FROM RocketCached") | |
fun getRockets(): Flow<List<RocketCached>> | |
@Upsert | |
suspend fun saveRockets(rockets: List<RocketCached>) | |
} |