Fixes to the custom preference and fixes to about page scaling

This commit is contained in:
ottoptj 2024-09-02 15:48:17 +03:00
commit 063135c9b1
5 changed files with 176 additions and 184 deletions

View file

@ -5,6 +5,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.UIUtils
class HomeSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
@ -18,74 +19,55 @@ class HomeSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.home_preferences, rootKey)
val uiUtils = UIUtils(requireContext())
sharedPreferenceManager = SharedPreferenceManager(requireContext())
sharedPreferenceManager = SharedPreferenceManager(requireContext())
clockApp = findPreference("clockSwipeApp")
dateApp = findPreference("dateSwipeApp")
clockApp = findPreference("clockSwipeApp")
dateApp = findPreference("dateSwipeApp")
val gpsLocationPref = findPreference<SwitchPreference?>("gpsLocation")
manualLocationPref = findPreference("manualLocation")
leftSwipePref = findPreference("leftSwipeApp")
rightSwipePref = findPreference("rightSwipeApp")
val gpsLocationPref = findPreference<SwitchPreference?>("gpsLocation")
manualLocationPref = findPreference("manualLocation")
leftSwipePref = findPreference("leftSwipeApp")
rightSwipePref = findPreference("rightSwipeApp")
// Only enable manual location when gps location is disabled
if (gpsLocationPref != null && manualLocationPref != null) {
manualLocationPref?.isEnabled = !gpsLocationPref.isChecked
// Only enable manual location when gps location is disabled
if (gpsLocationPref != null && manualLocationPref != null) {
manualLocationPref?.isEnabled = !gpsLocationPref.isChecked
gpsLocationPref.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
val isGpsEnabled = newValue as Boolean
manualLocationPref?.isEnabled = !isGpsEnabled
true
}
gpsLocationPref.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
val isGpsEnabled = newValue as Boolean
manualLocationPref?.isEnabled = !isGpsEnabled
true
}
manualLocationPref?.onPreferenceClickListener =
manualLocationPref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
uiUtils.switchFragment(requireActivity(), LocationFragment())
true
}
}
leftSwipePref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, LocationFragment())
.addToBackStack(null)
.commit()
true
}
}
uiUtils.switchFragment(requireActivity(), GestureAppsFragment("left"))
true }
leftSwipePref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, GestureAppsFragment("left"))
.addToBackStack(null)
.commit()
true }
rightSwipePref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
uiUtils.switchFragment(requireActivity(), GestureAppsFragment("right"))
true }
rightSwipePref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, GestureAppsFragment("right"))
.addToBackStack(null)
.commit()
true }
clockApp?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
uiUtils.switchFragment(requireActivity(), GestureAppsFragment("clock"))
true }
clockApp?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, GestureAppsFragment("clock"))
.addToBackStack(null)
.commit()
true }
dateApp?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, GestureAppsFragment("date"))
.addToBackStack(null)
.commit()
true }
dateApp?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
uiUtils.switchFragment(requireActivity(), GestureAppsFragment("date"))
true }
}
override fun onResume() {

View file

@ -2,11 +2,16 @@ package eu.ottop.yamlauncher.settings
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.UIUtils
class SettingsFragment : PreferenceFragmentCompat(), TitleProvider {
@ -15,6 +20,8 @@ class SettingsFragment : PreferenceFragmentCompat(), TitleProvider {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
val uiUtils = UIUtils(requireContext())
sharedPreferenceManager = SharedPreferenceManager(requireContext())
val homePref = findPreference<Preference>("defaultHome")
@ -39,47 +46,27 @@ class SettingsFragment : PreferenceFragmentCompat(), TitleProvider {
uiSettings?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, UISettingsFragment())
.addToBackStack(null)
.commit()
uiUtils.switchFragment(requireActivity(), UISettingsFragment())
true }
homeSettings?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, HomeSettingsFragment())
.addToBackStack(null)
.commit()
uiUtils.switchFragment(requireActivity(), HomeSettingsFragment())
true }
appMenuSettings?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, AppMenuSettingsFragment())
.addToBackStack(null)
.commit()
uiUtils.switchFragment(requireActivity(), AppMenuSettingsFragment())
true }
hiddenPref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, HiddenAppsFragment())
.addToBackStack(null)
.commit()
uiUtils.switchFragment(requireActivity(), HiddenAppsFragment())
true }
aboutPref?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, AboutFragment())
.addToBackStack(null)
.commit()
uiUtils.switchFragment(requireActivity(), AboutFragment())
true }
resetPref?.onPreferenceClickListener =
@ -92,4 +79,6 @@ class SettingsFragment : PreferenceFragmentCompat(), TitleProvider {
return "Launcher Settings"
}
}

View file

@ -1,6 +1,7 @@
package eu.ottop.yamlauncher.settings
import android.content.Context
import android.content.res.TypedArray
import android.os.Handler
import android.os.Looper
import android.util.AttributeSet
@ -46,7 +47,7 @@ class SpinnerPreference (context: Context, attrs: AttributeSet? = null): Prefere
spinner?.adapter = adapter
}
val selectedIndex = entryValues?.indexOf(currentValue as? CharSequence) ?: 0
val selectedIndex = entryValues?.indexOf(currentValue as? CharSequence) ?: entryValues?.indexOf(defaultNo as CharSequence) ?: 0
spinner?.setSelection(selectedIndex)
// Somehow prevents an error :D
@ -76,13 +77,9 @@ class SpinnerPreference (context: Context, attrs: AttributeSet? = null): Prefere
spinner?.performClick()
}
override fun onSetInitialValue(defaultValue: Any?) {
currentValue = getPersistedString(defaultValue as? String)
}
// This is required to ensure that default values are stored (needed for full settings reset)
override fun onAttached() {
super.onAttached()
currentValue = getPersistedString(defaultNo)
persistString(getPersistedString(defaultNo))
}
}

View file

@ -4,6 +4,8 @@ import android.content.Context
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Color
import android.os.Handler
import android.os.Looper
import android.util.TypedValue
import android.view.Gravity
import android.view.View
@ -18,8 +20,12 @@ import android.widget.TextClock
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.children
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import eu.ottop.yamlauncher.settings.UISettingsFragment
class UIUtils(private val context: Context) {
@ -411,4 +417,12 @@ class UIUtils(private val context: Context) {
}
}
}
fun switchFragment(activity: FragmentActivity, fragment: Fragment) {
activity.supportFragmentManager
.beginTransaction()
.replace(R.id.settingsLayout, fragment)
.addToBackStack(null)
.commit()
}
}

View file

@ -1,151 +1,161 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/aboutLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".settings.AboutFragment">
<ImageView
android:id="@+id/iconView"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5.5"
android:contentDescription="@string/app_icon"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:src="@drawable/ic_launcher_foreground" />
<TextView
android:id="@+id/appNameView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:text="@string/app_name"
android:textAlignment="center"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/iconView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iconView" />
android:textStyle="bold" />
<TextView
android:id="@+id/creditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:gravity="center_horizontal"
android:text="@string/creditName"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/appNameView"
app:layout_constraintTop_toBottomOf="@+id/appNameView" />
android:textSize="17sp" />
<TextView
android:id="@+id/sourceTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="30dp"
android:layout_weight="1.3"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:text="@string/source_code"
android:textAlignment="center"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/creditText" />
android:textSize="24sp" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="?android:attr/listDivider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sourceTitle" />
android:background="?android:attr/listDivider" />
<TextView
android:id="@+id/codebergLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:linksClickable="true"
android:text="@string/codeberg"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toStartOf="@+id/githubLink"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider" />
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/githubLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:linksClickable="true"
android:text="@string/github"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/codebergLink"
app:layout_constraintTop_toBottomOf="@+id/divider" />
<TextView
android:id="@+id/codebergLink"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:linksClickable="true"
android:text="@string/codeberg"
android:textAlignment="center"
android:textSize="20sp" />
<TextView
android:id="@+id/githubLink"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:linksClickable="true"
android:text="@string/github"
android:textAlignment="center"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="@+id/donationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="40dp"
android:layout_weight="1.3"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:text="@string/donate"
android:textAlignment="center"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/codebergLink" />
android:textSize="24sp" />
<View
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="?android:attr/listDivider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/donationTitle" />
android:background="?android:attr/listDivider" />
<TextView
android:id="@+id/stripeLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:linksClickable="true"
android:text="@string/stripe"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/liberaLink"
app:layout_constraintTop_toBottomOf="@+id/divider2" />
android:layout_weight="2"
android:orientation="horizontal">
<TextView
android:id="@+id/liberaLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:linksClickable="true"
android:text="@string/liberapay"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toStartOf="@+id/stripeLink"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider2" />
<TextView
android:id="@+id/stripeLink"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:linksClickable="true"
android:text="@string/stripe"
android:textAlignment="center"
android:textSize="20sp" />
<TextView
android:id="@+id/liberaLink"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:linksClickable="true"
android:text="@string/liberapay"
android:textAlignment="center"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="@+id/weatherLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="150dp"
android:layout_marginBottom="20dp"
android:layout_weight="1.5"
android:autoSizeMinTextSize="5sp"
android:autoSizeTextType="uniform"
android:gravity="bottom|center_horizontal"
android:linksClickable="true"
android:text="@string/weather_data_credit"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
android:textSize="16sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>