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
# QuotaShop | |
Protocol: https | |
Host: quotashop.ml | |
Title: QuotaShop | |
# Eevee Save Project | |
Protocol: https | |
Host: tiny.cc | |
Path: eeveesaveproject | |
Title: Eevee Save Project |
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
suspend fun setUiMode(uiMode: UiMode) { | |
dataStore.edit { preferences -> | |
preferences[IS_DARK_MODE] = when (uiMode) { | |
UiMode.LIGHT -> false | |
UiMode.DARK -> true | |
} | |
} | |
} |
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
companion object { | |
val IS_DARK_MODE = preferencesKey<Boolean>("dark_mode") | |
} |
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
class SettingsManager(context: Context) { | |
private val dataStore = context.createDataStore(name = "settings_pref") | |
... |
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
dependencies { | |
// Preferences DataStore | |
implementation "androidx.datastore:datastore-preferences:1.0.0-alpha01" | |
} |
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 fun initCountObserver() { | |
lifecycleScope.launch { | |
viewModel.countState.collect { value -> | |
textview_count.text = "$value" | |
} | |
} | |
} |
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 fun initView() { | |
button_plus.setOnClickListener(::incrementCounter) | |
button_minus.setOnClickListener(::decrementCounter) | |
} | |
private fun incrementCounter(view: View) { | |
viewModel.incrementCount() | |
} | |
private fun decrementCounter(view: View) { |
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
class MainActivity : AppCompatActivity() { | |
private val viewModel by lazy { | |
ViewModelProvider(this)[MainViewModel::class.java] | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
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
import kotlinx.coroutines.* | |
import kotlinx.coroutines.flow.* | |
fun main() = runBlocking { | |
val stateFlow = MutableStateFlow<Int>(0) | |
// Observe values | |
val job = launch { | |
stateFlow.collect { | |
print("$it ") |
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
@ExperimentalCoroutinesApi | |
class MainViewModel : ViewModel() { | |
private val _countState = MutableStateFlow(0) | |
val countState: StateFlow<Int> = _countState | |
fun incrementCount() { | |
_countState.value++ | |
} |
NewerOlder