OOBE: Restart app after onboarding to renew permission scopes [1/2]

This commit is contained in:
Rahul Patel
2024-06-25 22:02:31 +05:30
parent 3615c39163
commit 8857353029
3 changed files with 28 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ import com.aurora.gplayapi.data.models.App
import com.aurora.store.R
import com.aurora.store.util.Log
import com.aurora.store.util.Preferences
import kotlin.system.exitProcess
val Context.inflater: LayoutInflater
get() = LayoutInflater.from(this)
@@ -135,3 +136,15 @@ fun Context.isIgnoringBatteryOptimizations(): Boolean {
true
}
}
fun Context.restartApp() {
val intent = packageManager.getLaunchIntentForPackage(packageName)
val componentName = intent?.component
val newIntent = Intent.makeRestartActivityTask(componentName)
newIntent.setPackage(packageName)
startActivity(newIntent)
exitProcess(0)
}

View File

@@ -37,6 +37,7 @@ object Preferences {
const val PREFERENCE_DEFAULT_SELECTED_TAB = "PREFERENCE_DEFAULT_SELECTED_TAB"
const val PREFERENCE_SIMILAR = "PREFERENCE_SIMILAR"
const val PREFERENCE_INTRO = "PREFERENCE_INTRO"
const val PREFERENCE_SCOPED_RESTART = "PREFERENCE_SCOPED_RESTART"
const val PREFERENCE_FILTER_GOOGLE = "PREFERENCE_FILTER_GOOGLE"
const val PREFERENCE_FILTER_FDROID = "PREFERENCE_FILTER_FDROID"
@@ -98,6 +99,10 @@ object Preferences {
getPrefs(context).edit().putBoolean(key, value).apply()
}
fun putBooleanNow(context: Context, key: String, value: Boolean) {
getPrefs(context).edit().putBoolean(key, value).commit()
}
fun getString(context: Context, key: String, default: String = ""): String {
return getPrefs(context).getString(key, default).toString()
}

View File

@@ -27,6 +27,7 @@ import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.aurora.extensions.hide
import com.aurora.extensions.isValidPackageName
import com.aurora.extensions.restartApp
import com.aurora.extensions.show
import com.aurora.store.R
import com.aurora.store.data.AuthState
@@ -34,6 +35,7 @@ import com.aurora.store.databinding.FragmentSplashBinding
import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB
import com.aurora.store.util.Preferences.PREFERENCE_INTRO
import com.aurora.store.util.Preferences.PREFERENCE_SCOPED_RESTART
import com.aurora.store.viewmodel.auth.AuthViewModel
import dagger.hilt.android.AndroidEntryPoint
@@ -56,6 +58,14 @@ class SplashFragment : Fragment(R.layout.fragment_splash) {
return
}
if (!Preferences.getBoolean(requireContext(), PREFERENCE_SCOPED_RESTART)) {
// DO NOT REPLACE THIS WITH Context.save()
Preferences.putBooleanNow(requireContext(), PREFERENCE_SCOPED_RESTART, true)
requireContext().restartApp()
return
}
// Toolbar
binding.layoutToolbarAction.toolbar.apply {
elevation = 0f