Skip to content

Commit

Permalink
Add observer for new version
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Jun 28, 2023
1 parent be84593 commit ea7320a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.qhy040404.libraryonetap.constant

import androidx.core.content.edit
import androidx.lifecycle.MutableLiveData
import com.qhy040404.libraryonetap.BuildConfig
import com.qhy040404.libraryonetap.R
import com.qhy040404.libraryonetap.utils.PackageUtils
Expand Down Expand Up @@ -76,6 +77,7 @@ object GlobalValues {
)
}
var newVersion: String? = null
var newVersionLiveData: MutableLiveData<String?> = MutableLiveData()
var latestApkName: String by SPDelegates(Constants.LATEST_APK_NAME, "")

// Edu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
}

findPreference<Preference>(Constants.PREF_UPDATE)?.apply {
if (GlobalValues.newVersion != null) {
summary =
R.string.upd_available.getStringAndFormat(GlobalValues.newVersion)
GlobalValues.newVersionLiveData.observe(viewLifecycleOwner) {
if (it.isNullOrEmpty().not()) {
summary =
R.string.upd_available.getStringAndFormat(GlobalValues.newVersion)
}
}
setOnPreferenceClickListener {
lifecycleScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ object UpdateUtils {
.split("\r\n")

GlobalValues.newVersion = versionName
GlobalValues.newVersionLiveData.postValue(versionName)

val dialogBody = buildSpannedString {
inSpans(
Expand Down

0 comments on commit ea7320a

Please sign in to comment.