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
// Declaralion and find SharedPreference from device | |
shPr = PreferenceManager.getDefaultSharedPreferences(this /* Activity context */) | |
// If you save values between sessions - then false (if there are none, then it will create) | |
// Если сохранять значения между сеансами, то false (если их нет, то создаст) | |
if (shPr.getBoolean("preference_remember", true)) | |
preferencesReset(false) // if not reset at startup to Default | |
else | |
preferencesReset(true) // if reset at startup to Default |
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
// Declaralion and find SharedPreference from device | |
shPr = PreferenceManager.getDefaultSharedPreferences(this /* Activity context */) | |
// If you save values between sessions - then false (if there are none, then it will create) |
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
viewModel.starClicked.observeEvent(viewLifecycleOwner) { | |
Toast.makeText(activity, it, Toast.LENGTH_LONG).show() | |
} | |
viewModel.keyBoard.observeEvent(viewLifecycleOwner) { | |
it?.let { | |
if (it) showKeyboard() | |
else hideKeyboard() | |
} | |
} |
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 _starClicked = MutableLiveData<Event<String?>>() | |
val starClicked: LiveData<Event<String?>> | |
get() = _starClicked | |
fun onStarClick() { | |
_starClicked.value = Event("on Star ONCE Clicked") | |
} |
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
open class Event<out T>(private val content: T? = null) { | |
@Suppress("MemberVisibilityCanBePrivate") | |
var hasBeenHandled = false | |
private set | |
// Returns the content and prevents its use again. | |
fun getContentIfNotHandled(): T? = if (hasBeenHandled) null else content.also { hasBeenHandled = true } | |
// Returns the content, even if it's already been handled. | |
fun peekContent(): T? = content | |
} |