OOBE: Restart app after onboarding to renew permission scopes [1/2]
This commit is contained in:
@@ -37,6 +37,7 @@ import com.aurora.gplayapi.data.models.App
|
|||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
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 kotlin.system.exitProcess
|
||||||
|
|
||||||
val Context.inflater: LayoutInflater
|
val Context.inflater: LayoutInflater
|
||||||
get() = LayoutInflater.from(this)
|
get() = LayoutInflater.from(this)
|
||||||
@@ -135,3 +136,15 @@ fun Context.isIgnoringBatteryOptimizations(): Boolean {
|
|||||||
true
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ object Preferences {
|
|||||||
const val PREFERENCE_DEFAULT_SELECTED_TAB = "PREFERENCE_DEFAULT_SELECTED_TAB"
|
const val PREFERENCE_DEFAULT_SELECTED_TAB = "PREFERENCE_DEFAULT_SELECTED_TAB"
|
||||||
const val PREFERENCE_SIMILAR = "PREFERENCE_SIMILAR"
|
const val PREFERENCE_SIMILAR = "PREFERENCE_SIMILAR"
|
||||||
const val PREFERENCE_INTRO = "PREFERENCE_INTRO"
|
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_GOOGLE = "PREFERENCE_FILTER_GOOGLE"
|
||||||
const val PREFERENCE_FILTER_FDROID = "PREFERENCE_FILTER_FDROID"
|
const val PREFERENCE_FILTER_FDROID = "PREFERENCE_FILTER_FDROID"
|
||||||
@@ -98,6 +99,10 @@ object Preferences {
|
|||||||
getPrefs(context).edit().putBoolean(key, value).apply()
|
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 {
|
fun getString(context: Context, key: String, default: String = ""): String {
|
||||||
return getPrefs(context).getString(key, default).toString()
|
return getPrefs(context).getString(key, default).toString()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.aurora.extensions.hide
|
import com.aurora.extensions.hide
|
||||||
import com.aurora.extensions.isValidPackageName
|
import com.aurora.extensions.isValidPackageName
|
||||||
|
import com.aurora.extensions.restartApp
|
||||||
import com.aurora.extensions.show
|
import com.aurora.extensions.show
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.aurora.store.data.AuthState
|
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
|
||||||
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_INTRO
|
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 com.aurora.store.viewmodel.auth.AuthViewModel
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
@@ -56,6 +58,14 @@ class SplashFragment : Fragment(R.layout.fragment_splash) {
|
|||||||
return
|
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
|
// Toolbar
|
||||||
binding.layoutToolbarAction.toolbar.apply {
|
binding.layoutToolbarAction.toolbar.apply {
|
||||||
elevation = 0f
|
elevation = 0f
|
||||||
|
|||||||
Reference in New Issue
Block a user