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 android.content.SharedPreferences | |
import kotlin.properties.ReadWriteProperty | |
import kotlin.reflect.KProperty | |
class DelegatedPreference<T>( | |
private val sharedPrefs: SharedPreferences, | |
private val key: String, | |
private val defValue: T | |
) : ReadWriteProperty<Any?, T> { |
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 android.content.SharedPreferences | |
import androidx.lifecycle.LiveData | |
class LivePreference<T>( | |
private val sharedPrefs: SharedPreferences, | |
private val key: String, | |
private val defValue: T | |
) : LiveData<T?>() { | |
private val preferenceChangeListener = |
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
sealed class ResponseMessage { | |
class Success(val message: String?) : ResponseMessage() | |
class Error(val message: String?, val throwable: Throwable?) : ResponseMessage() | |
fun getErrorMessage(): String? { | |
return when (this) { | |
is Success -> { | |
null | |
} | |
is Error -> { |
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 LoginViewModel(context: Application) : AndroidViewModel(context) { | |
... | |
fun isUserExists(id: Int) = viewModelScope.async { | |
usersRepository.isUserExists(id) | |
} | |
// But you can also write this way: | |
suspend fun isUserExists(id: String): Int { |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_login) | |
progress_auth.visibility = View.VISIBLE | |
button_auth.setOnClickListener { | |
val actionBar = supportActionBar | |
GlobalScope.launch(Dispatchers.Main) { |