Without property delegationclass UserSettings( private val prefs: SharedPreferences) { var name: String get() = prefs.getString("name", "") ?: "" set(value) { prefs.edit { putString("name", value) } } var age: Int get() = prefs.getInt("age", 0) ?:0 set(value) { prefs.edit { putInt("name", value) } } } Using del..
Use case When we have filter/search functionality in our app, we often want to trigger an operation whenver user enters query in an EditText and we want to reduce network calls by using debouncing. Kotlin Flow supports debouce operation but it's still preview until 1.6. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/debounce.html debounce debounce com..
import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; /** * This pattern has the following benefits: * * - Date formats are referenced as a strong type * - Code completion on patterns * - Patterns can be javadoc'ed */ public enum Dates { /** * Format: yyyy-MM-dd * Example: 2022-03-30 */ yyyy_MM_dd("yyyy-MM-dd"), /** * Format: MMM d..