MainActivity: Restrict self-updates check to non-fdroid builds

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
ThIsLinked
2023-11-16 05:19:56 +02:00
committed by Aayush Gupta
parent 11302915d2
commit 63460f8629
6 changed files with 47 additions and 8 deletions

View File

@@ -60,9 +60,11 @@ import com.aurora.store.data.model.NetworkStatus
import com.aurora.store.data.model.SelfUpdate
import com.aurora.store.data.providers.NetworkProvider
import com.aurora.store.databinding.ActivityMainBinding
import com.aurora.store.util.CertUtil
import com.aurora.store.util.Log
import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB
import com.aurora.store.util.Preferences.PREFERENCE_SELF_UPDATE
import com.aurora.store.view.ui.sheets.NetworkDialogSheet
import com.aurora.store.view.ui.sheets.SelfUpdateSheet
import com.aurora.store.viewmodel.MainViewModel
@@ -150,13 +152,15 @@ class MainActivity : AppCompatActivity() {
}
/* Check self update only for stable release, skip debug & nightlies*/
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) viewModel.checkSelfUpdate(this)
this.lifecycleScope.launch {
viewModel.selfUpdateAvailable.collect {
if (it != null) {
showUpdatesSheet(it)
} else {
Log.i("No self-update available")
if (Preferences.getBoolean(this, PREFERENCE_SELF_UPDATE)) {
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) viewModel.checkSelfUpdate(this)
this.lifecycleScope.launch {
viewModel.selfUpdateAvailable.collect {
if (it != null) {
showUpdatesSheet(it)
} else {
Log.i("No self-update available")
}
}
}
}

View File

@@ -66,6 +66,8 @@ object Preferences {
const val PREFERENCE_UNIQUE_GROUP_IDS = "PREFERENCE_UNIQUE_GROUP_IDS"
const val PREFERENCE_SELF_UPDATE = "PREFERENCE_SELF_UPDATE"
private var prefs: SharedPreferences? = null
fun getPrefs(context: Context): SharedPreferences {

View File

@@ -28,9 +28,11 @@ import androidx.navigation.fragment.findNavController
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.aurora.extensions.isSAndAbove
import com.aurora.store.BuildConfig
import com.aurora.store.R
import com.aurora.store.data.work.UpdateWorker
import com.aurora.store.databinding.FragmentOnboardingBinding
import com.aurora.store.util.CertUtil
import com.aurora.store.util.PathUtil
import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_AUTO_DELETE
@@ -51,6 +53,7 @@ import com.aurora.store.util.Preferences.PREFERENCE_INTRO
import com.aurora.store.util.Preferences.PREFERENCE_PROXY_ENABLED
import com.aurora.store.util.Preferences.PREFERENCE_PROXY_INFO
import com.aurora.store.util.Preferences.PREFERENCE_PROXY_URL
import com.aurora.store.util.Preferences.PREFERENCE_SELF_UPDATE
import com.aurora.store.util.Preferences.PREFERENCE_SIMILAR
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
@@ -187,5 +190,9 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
save(PREFERENCE_UPDATES_EXTENDED, false)
save(PREFERENCE_UPDATES_CHECK, true)
save(PREFERENCE_UPDATES_CHECK_INTERVAL, 3)
save(
PREFERENCE_SELF_UPDATE,
CertUtil.isFDroidApp(requireContext(), BuildConfig.APPLICATION_ID)
)
}
}

View File

@@ -25,15 +25,30 @@ import androidx.appcompat.widget.Toolbar
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.aurora.store.BuildConfig
import com.aurora.store.R
import com.aurora.store.data.work.UpdateWorker
import com.aurora.store.util.CertUtil
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_CHECK
import com.aurora.store.util.Preferences.PREFERENCE_SELF_UPDATE
import com.aurora.store.util.save
class UpdatesPreference : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences_updates, rootKey)
findPreference<SwitchPreferenceCompat>(PREFERENCE_SELF_UPDATE)?.let {
if (CertUtil.isFDroidApp(requireContext(), BuildConfig.APPLICATION_ID)) {
it.isVisible = false
}
it.setOnPreferenceChangeListener { _, newValue ->
save(PREFERENCE_SELF_UPDATE, newValue.toString().toBoolean())
true
}
}
findPreference<SwitchPreferenceCompat>(PREFERENCE_UPDATES_CHECK)
?.setOnPreferenceChangeListener { _, newValue ->
if (newValue.toString().toBoolean()) {
@@ -52,4 +67,4 @@ class UpdatesPreference : PreferenceFragmentCompat() {
setNavigationOnClickListener { findNavController().navigateUp() }
}
}
}
}

View File

@@ -393,4 +393,7 @@
<string name="android_market_desc">Android Market was an online store offering software applications designed for Android devices, retired in 2017.</string>
<string name="app_link_amazon_appstore" translatable="false">www.amazon.com</string>
<string name="amazon_appstore_desc">Amazon Appstore is an app store for Android-compatible platforms operated by Amazon.</string>
<string name="pref_self_update_title">Self-updates</string>
<string name="pref_self_update_summary">Check and notify if a new stable version of Aurora Store is available</string>
</resources>

View File

@@ -20,6 +20,14 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="PREFERENCE_SELF_UPDATE"
app:singleLineTitle="false"
app:summary="@string/pref_self_update_summary"
app:title="@string/pref_self_update_title" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"