MainActivity: Restrict self-updates check to non-fdroid builds
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -60,9 +60,11 @@ import com.aurora.store.data.model.NetworkStatus
|
|||||||
import com.aurora.store.data.model.SelfUpdate
|
import com.aurora.store.data.model.SelfUpdate
|
||||||
import com.aurora.store.data.providers.NetworkProvider
|
import com.aurora.store.data.providers.NetworkProvider
|
||||||
import com.aurora.store.databinding.ActivityMainBinding
|
import com.aurora.store.databinding.ActivityMainBinding
|
||||||
|
import com.aurora.store.util.CertUtil
|
||||||
import com.aurora.store.util.Log
|
import com.aurora.store.util.Log
|
||||||
import com.aurora.store.util.Preferences
|
import com.aurora.store.util.Preferences
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB
|
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.NetworkDialogSheet
|
||||||
import com.aurora.store.view.ui.sheets.SelfUpdateSheet
|
import com.aurora.store.view.ui.sheets.SelfUpdateSheet
|
||||||
import com.aurora.store.viewmodel.MainViewModel
|
import com.aurora.store.viewmodel.MainViewModel
|
||||||
@@ -150,13 +152,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check self update only for stable release, skip debug & nightlies*/
|
/* Check self update only for stable release, skip debug & nightlies*/
|
||||||
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) viewModel.checkSelfUpdate(this)
|
if (Preferences.getBoolean(this, PREFERENCE_SELF_UPDATE)) {
|
||||||
this.lifecycleScope.launch {
|
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) viewModel.checkSelfUpdate(this)
|
||||||
viewModel.selfUpdateAvailable.collect {
|
this.lifecycleScope.launch {
|
||||||
if (it != null) {
|
viewModel.selfUpdateAvailable.collect {
|
||||||
showUpdatesSheet(it)
|
if (it != null) {
|
||||||
} else {
|
showUpdatesSheet(it)
|
||||||
Log.i("No self-update available")
|
} else {
|
||||||
|
Log.i("No self-update available")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ object Preferences {
|
|||||||
|
|
||||||
const val PREFERENCE_UNIQUE_GROUP_IDS = "PREFERENCE_UNIQUE_GROUP_IDS"
|
const val PREFERENCE_UNIQUE_GROUP_IDS = "PREFERENCE_UNIQUE_GROUP_IDS"
|
||||||
|
|
||||||
|
const val PREFERENCE_SELF_UPDATE = "PREFERENCE_SELF_UPDATE"
|
||||||
|
|
||||||
private var prefs: SharedPreferences? = null
|
private var prefs: SharedPreferences? = null
|
||||||
|
|
||||||
fun getPrefs(context: Context): SharedPreferences {
|
fun getPrefs(context: Context): SharedPreferences {
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ import androidx.navigation.fragment.findNavController
|
|||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||||
import com.aurora.extensions.isSAndAbove
|
import com.aurora.extensions.isSAndAbove
|
||||||
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.aurora.store.data.work.UpdateWorker
|
import com.aurora.store.data.work.UpdateWorker
|
||||||
import com.aurora.store.databinding.FragmentOnboardingBinding
|
import com.aurora.store.databinding.FragmentOnboardingBinding
|
||||||
|
import com.aurora.store.util.CertUtil
|
||||||
import com.aurora.store.util.PathUtil
|
import com.aurora.store.util.PathUtil
|
||||||
import com.aurora.store.util.Preferences
|
import com.aurora.store.util.Preferences
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_AUTO_DELETE
|
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_ENABLED
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_PROXY_INFO
|
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_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_SIMILAR
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
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_EXTENDED, false)
|
||||||
save(PREFERENCE_UPDATES_CHECK, true)
|
save(PREFERENCE_UPDATES_CHECK, true)
|
||||||
save(PREFERENCE_UPDATES_CHECK_INTERVAL, 3)
|
save(PREFERENCE_UPDATES_CHECK_INTERVAL, 3)
|
||||||
|
save(
|
||||||
|
PREFERENCE_SELF_UPDATE,
|
||||||
|
CertUtil.isFDroidApp(requireContext(), BuildConfig.APPLICATION_ID)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,30 @@ import androidx.appcompat.widget.Toolbar
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.aurora.store.data.work.UpdateWorker
|
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_UPDATES_CHECK
|
||||||
|
import com.aurora.store.util.Preferences.PREFERENCE_SELF_UPDATE
|
||||||
|
import com.aurora.store.util.save
|
||||||
|
|
||||||
class UpdatesPreference : PreferenceFragmentCompat() {
|
class UpdatesPreference : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.preferences_updates, rootKey)
|
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)
|
findPreference<SwitchPreferenceCompat>(PREFERENCE_UPDATES_CHECK)
|
||||||
?.setOnPreferenceChangeListener { _, newValue ->
|
?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
if (newValue.toString().toBoolean()) {
|
if (newValue.toString().toBoolean()) {
|
||||||
|
|||||||
@@ -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="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="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="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>
|
</resources>
|
||||||
|
|||||||
@@ -20,6 +20,14 @@
|
|||||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
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
|
<SwitchPreferenceCompat
|
||||||
app:defaultValue="false"
|
app:defaultValue="false"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
|
|||||||
Reference in New Issue
Block a user