mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Fix circular not downloaded after first start
This commit is contained in:
@@ -31,16 +31,10 @@ class CircularLetterViewModel internal constructor(
|
|||||||
private val circularRepository: CircularRepository,
|
private val circularRepository: CircularRepository,
|
||||||
application: Application
|
application: Application
|
||||||
) : AndroidViewModel(application), SharedPreferences.OnSharedPreferenceChangeListener {
|
) : AndroidViewModel(application), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private val preferenceManager = PreferenceManager.getDefaultSharedPreferences(application)
|
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(application)
|
||||||
|
|
||||||
private val schoolID =
|
private val schoolID =
|
||||||
MutableLiveData(preferenceManager.getString("school", "0")?.toInt() ?: 0)
|
MutableLiveData(sharedPreferences.getString("school", "0")?.toInt() ?: 0)
|
||||||
|
|
||||||
init {
|
|
||||||
updateCirculars()
|
|
||||||
|
|
||||||
preferenceManager.registerOnSharedPreferenceChangeListener(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
val query = MutableLiveData("")
|
val query = MutableLiveData("")
|
||||||
val circulars: LiveData<List<Circular>> =
|
val circulars: LiveData<List<Circular>> =
|
||||||
@@ -59,6 +53,13 @@ class CircularLetterViewModel internal constructor(
|
|||||||
val circularsUpdated = MutableLiveData<Boolean>().apply { value = false }
|
val circularsUpdated = MutableLiveData<Boolean>().apply { value = false }
|
||||||
private var isNotUpdating = true
|
private var isNotUpdating = true
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (!sharedPreferences.getBoolean("first_start", true))
|
||||||
|
updateCirculars()
|
||||||
|
|
||||||
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
fun updateCirculars() {
|
fun updateCirculars() {
|
||||||
if (isNotUpdating) {
|
if (isNotUpdating) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@@ -75,7 +76,12 @@ class CircularLetterViewModel internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
if (key == "school")
|
val firstStart = sharedPreferences?.getBoolean("first_start", true) ?: true
|
||||||
schoolID.postValue(preferenceManager.getString("school", "0")?.toInt() ?: 0)
|
|
||||||
|
if (!firstStart && key == "school" || key == "first_start") {
|
||||||
|
schoolID.postValue(sharedPreferences?.getString("school", "0")?.toInt() ?: 0)
|
||||||
|
|
||||||
|
updateCirculars()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user