mirror of
https://github.com/mandarine3ds/mandarine.git
synced 2024-11-23 06:09:46 +00:00
Android: Remove popup theme settings setup
This commit is contained in:
parent
14bcd43dcb
commit
451d96ca6e
@ -14,8 +14,6 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -30,7 +28,6 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.transition.MaterialFadeThrough
|
||||
import io.github.mandarine3ds.mandarine.MandarineApplication
|
||||
@ -42,21 +39,17 @@ import io.github.mandarine3ds.mandarine.model.SetupCallback
|
||||
import io.github.mandarine3ds.mandarine.model.SetupPage
|
||||
import io.github.mandarine3ds.mandarine.model.StepState
|
||||
import io.github.mandarine3ds.mandarine.ui.main.MainActivity
|
||||
import io.github.mandarine3ds.mandarine.utils.MandarineDirectoryHelper
|
||||
import io.github.mandarine3ds.mandarine.utils.GameHelper
|
||||
import io.github.mandarine3ds.mandarine.utils.MandarineDirectoryHelper
|
||||
import io.github.mandarine3ds.mandarine.utils.PermissionsHandler
|
||||
import io.github.mandarine3ds.mandarine.utils.ViewUtils
|
||||
import io.github.mandarine3ds.mandarine.viewmodel.GamesViewModel
|
||||
import io.github.mandarine3ds.mandarine.viewmodel.HomeViewModel
|
||||
import io.github.mandarine3ds.mandarine.utils.ThemeUtil
|
||||
import com.google.android.material.materialswitch.MaterialSwitch
|
||||
|
||||
class SetupFragment : Fragment() {
|
||||
private var _binding: FragmentSetupBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val homeViewModel: HomeViewModel by activityViewModels()
|
||||
private val gamesViewModel: GamesViewModel by activityViewModels()
|
||||
|
||||
private lateinit var mainActivity: MainActivity
|
||||
|
||||
@ -263,30 +256,6 @@ class SetupFragment : Fragment() {
|
||||
R.string.add_games_warning_help
|
||||
)
|
||||
)
|
||||
add(
|
||||
SetupPage(
|
||||
R.drawable.ic_palette,
|
||||
R.string.set_up_theme_settings,
|
||||
R.string.setup_theme_settings_description,
|
||||
0,
|
||||
true,
|
||||
R.string.setup_set_theme,
|
||||
{
|
||||
ThemeUtil.isDuringSetup = true
|
||||
showStaticThemeSelectionDialog()
|
||||
},
|
||||
false,
|
||||
false,
|
||||
{
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
if (preferences.getBoolean("ThemeSetupCompleted", false)) {
|
||||
StepState.STEP_COMPLETE
|
||||
} else {
|
||||
StepState.STEP_INCOMPLETE
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
add(
|
||||
SetupPage(
|
||||
R.drawable.ic_check,
|
||||
@ -399,71 +368,6 @@ class SetupFragment : Fragment() {
|
||||
private lateinit var microphoneCallback: SetupCallback
|
||||
private lateinit var cameraCallback: SetupCallback
|
||||
|
||||
private fun showStaticThemeSelectionDialog() {
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val themeColors = resources.getStringArray(R.array.staticThemeNames)
|
||||
val currentThemeColor = preferences.getInt(Settings.PREF_STATIC_THEME_COLOR, 0)
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.set_up_theme_settings)
|
||||
.setSingleChoiceItems(themeColors, currentThemeColor) { _, which ->
|
||||
preferences.edit().putInt(Settings.PREF_STATIC_THEME_COLOR, which).apply()
|
||||
}
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
showMaterialYouAndBlackThemeDialog()
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun showMaterialYouAndBlackThemeDialog() {
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val switchContainer = LinearLayout(requireContext()).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
setPadding(64, 16, 64, 32)
|
||||
}
|
||||
|
||||
val blackThemeSwitch = MaterialSwitch(requireContext()).apply {
|
||||
text = getString(R.string.use_black_backgrounds)
|
||||
isChecked = preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false)
|
||||
}
|
||||
val blackThemeDescription = TextView(requireContext()).apply {
|
||||
text = getString(R.string.use_black_backgrounds_description)
|
||||
}
|
||||
switchContainer.addView(blackThemeSwitch)
|
||||
switchContainer.addView(blackThemeDescription)
|
||||
|
||||
val materialYouSwitch = MaterialSwitch(requireContext()).apply {
|
||||
text = getString(R.string.material_you)
|
||||
isChecked = preferences.getBoolean(Settings.PREF_MATERIAL_YOU, false)
|
||||
}
|
||||
val materialYouDescription = TextView(requireContext()).apply {
|
||||
text = getString(R.string.material_you_description)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
switchContainer.addView(materialYouSwitch)
|
||||
switchContainer.addView(materialYouDescription)
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.set_up_theme_settings)
|
||||
.setView(switchContainer)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
preferences.edit().apply {
|
||||
putBoolean(Settings.PREF_BLACK_BACKGROUNDS, blackThemeSwitch.isChecked)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
putBoolean(Settings.PREF_MATERIAL_YOU, materialYouSwitch.isChecked)
|
||||
}
|
||||
apply()
|
||||
}
|
||||
preferences.edit().putBoolean("ThemeSetupCompleted", true).apply()
|
||||
requireActivity().recreate()
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private val permissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
|
||||
if (isGranted) {
|
||||
@ -528,7 +432,6 @@ class SetupFragment : Fragment() {
|
||||
preferences.edit()
|
||||
.putBoolean(Settings.PREF_FIRST_APP_LAUNCH, false)
|
||||
.apply()
|
||||
ThemeUtil.isDuringSetup = false
|
||||
mainActivity.finishSetup(binding.root.findNavController())
|
||||
}
|
||||
|
||||
|
@ -116,18 +116,13 @@ object ThemeUtil {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
var isDuringSetup = false //Track setup status in order to enable / disbale listener
|
||||
|
||||
// Listener that detects if the theme is being changed from the initial setup or from normal settings
|
||||
// Without this the dual popup on the setup was getting cut off becuase the activity was being recreated
|
||||
// Listener that detects if the theme keys are being changed from the setting menu and recreates the activity
|
||||
private var listener: SharedPreferences.OnSharedPreferenceChangeListener? = null
|
||||
|
||||
fun themeChangeListener(activity: AppCompatActivity) {
|
||||
listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||
val relevantKeys = listOf(Settings.PREF_STATIC_THEME_COLOR, Settings.PREF_MATERIAL_YOU, Settings.PREF_BLACK_BACKGROUNDS)
|
||||
if (key in relevantKeys && !isDuringSetup) {
|
||||
if (key in relevantKeys) {
|
||||
activity.recreate()
|
||||
}
|
||||
}
|
||||
|
@ -93,9 +93,6 @@
|
||||
<string name="cannot_skip">You can\'t skip this step</string>
|
||||
<string name="cannot_skip_directory_description">This step is required to allow Mandarine to work. Please select a directory and then you can continue.</string>
|
||||
<string name="cannot_skip_directory_help">https://github.com/citra-emu/citra/wiki/Citra-Android-user-data-and-storage</string>
|
||||
<string name="set_up_theme_settings">Theme Settings</string>
|
||||
<string name="setup_theme_settings_description">Configure your theme preferences for Mandarine.</string>
|
||||
<string name="setup_set_theme">Set Theme</string>
|
||||
|
||||
<!-- Search Strings -->
|
||||
<string name="search_and_filter_games">Search and Filter Games</string>
|
||||
@ -521,18 +518,18 @@
|
||||
<string name="memory_exabyte">EB</string>
|
||||
|
||||
<!-- System theme -->
|
||||
<string name="change_theme_mode">Change Theme Mode</string>
|
||||
<string name="change_theme_mode">Theme Mode</string>
|
||||
<string name="theme_mode_follow_system">Follow System</string>
|
||||
<string name="theme_mode_light">Light</string>
|
||||
<string name="theme_mode_dark">Dark</string>
|
||||
|
||||
<!-- Material You theme -->
|
||||
<string name="material_you">Material You</string>
|
||||
<string name="material_you_description">Use system colors across the app. Overrides static theme color option.</string>
|
||||
<string name="material_you_description">Use the operating system\'s color theme across the app (Overrides the "Theme Color" setting when enabled)</string>
|
||||
|
||||
<!-- Static theme color -->
|
||||
<string name="static_theme_color">Change Theme Color</string>
|
||||
<string name="static_theme_color_description">Change the main theme color of the app without the use of Material You (Requires Material You to be disabled)</string>
|
||||
<string name="static_theme_color">Theme Color</string>
|
||||
<string name="static_theme_color_description">Change the color theme of the app\'s menus</string>
|
||||
|
||||
<!-- Black backgrounds theme -->
|
||||
<string name="use_black_backgrounds">Black Backgrounds</string>
|
||||
|
Loading…
Reference in New Issue
Block a user