mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Added a setting to restart the launcher
This commit is contained in:
parent
98dcd5810d
commit
0ca4dbef2e
3 changed files with 25 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ package eu.ottop.yamlauncher.settings
|
|||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
|
|
@ -13,6 +14,7 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import eu.ottop.yamlauncher.MainActivity
|
||||
import eu.ottop.yamlauncher.R
|
||||
import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding
|
||||
import eu.ottop.yamlauncher.utils.PermissionUtils
|
||||
|
|
@ -30,7 +32,6 @@ class SettingsActivity : AppCompatActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
sharedPreferenceManager = SharedPreferenceManager(this@SettingsActivity)
|
||||
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(this@SettingsActivity)
|
||||
|
|
@ -198,6 +199,17 @@ class SettingsActivity : AppCompatActivity() {
|
|||
} catch(_: Exception) {}
|
||||
}
|
||||
|
||||
fun restartApp() {
|
||||
val restartIntent = Intent(applicationContext, MainActivity::class.java)
|
||||
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
applicationContext, 0, restartIntent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
pendingIntent.send()
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class SettingsFragment : PreferenceFragmentCompat(), TitleProvider {
|
|||
val backupPref = findPreference<Preference>("backup")
|
||||
val restorePref = findPreference<Preference>("restore")
|
||||
val aboutPref = findPreference<Preference>("aboutPage")
|
||||
val restartPref = findPreference<Preference>("restartLauncher")
|
||||
val resetPref = findPreference<Preference>("resetAll")
|
||||
|
||||
homePref?.onPreferenceClickListener =
|
||||
|
|
@ -77,6 +78,11 @@ class SettingsFragment : PreferenceFragmentCompat(), TitleProvider {
|
|||
uiUtils.switchFragment(requireActivity(), AboutFragment())
|
||||
true }
|
||||
|
||||
restartPref?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
(requireActivity() as SettingsActivity).restartApp()
|
||||
true }
|
||||
|
||||
resetPref?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
sharedPreferenceManager.resetAllPreferences()
|
||||
|
|
|
|||
|
|
@ -86,6 +86,12 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:allowDividerAbove="false"
|
||||
app:title="Reset">
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:key="restartLauncher"
|
||||
app:selectable="true"
|
||||
app:title="Restart YAM Launcher" />
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue