Added in a preference button for selecting the default home app

This commit is contained in:
ottoptj 2024-08-12 01:10:43 +03:00
commit b05d26aa66
2 changed files with 22 additions and 0 deletions

View file

@ -1,6 +1,9 @@
package eu.ottop.yamlauncher
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.widget.Toast
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
@ -23,6 +26,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
rightSwipePref = findPreference("rightSwipeApp")
val aboutPref = findPreference<Preference?>("aboutPage")
val hiddenPref = findPreference<Preference?>("hiddenApps")
val homePref = findPreference<Preference?>("defaultHome")
// Only enable manual location when gps location is disabled
if (gpsLocationPref != null && manualLocationPref != null) {
@ -81,6 +85,16 @@ class SettingsFragment : PreferenceFragmentCompat() {
.addToBackStack(null)
.commit()
true }
homePref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
val intent = Intent(Settings.ACTION_HOME_SETTINGS)
if (intent.resolveActivity(requireContext().packageManager) != null) {
startActivity(intent)
} else {
Toast.makeText(requireContext(), "Unable to launch settings", Toast.LENGTH_SHORT).show()
}
true }
}
override fun onResume() {

View file

@ -1,6 +1,14 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:key="defaultHome"
app:selectable="true"
app:title="Set Default Home" />
<PreferenceCategory
android:layout_width="wrap_content"
android:layout_height="wrap_content"