mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-12-16 04:09:39 +00:00
Android: Add Reset Dolphin Settings functionality
This commit is contained in:
parent
b920182c97
commit
f718a6b72f
@ -308,6 +308,8 @@ public final class NativeLibrary
|
|||||||
|
|
||||||
public static native void ReloadConfig();
|
public static native void ReloadConfig();
|
||||||
|
|
||||||
|
public static native void ResetDolphinSettings();
|
||||||
|
|
||||||
public static native void UpdateGCAdapterScanThread();
|
public static native void UpdateGCAdapterScanThread();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -15,6 +15,8 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.dolphinemu.dolphinemu.NativeLibrary
|
||||||
import org.dolphinemu.dolphinemu.R
|
import org.dolphinemu.dolphinemu.R
|
||||||
import org.dolphinemu.dolphinemu.databinding.ActivityUserDataBinding
|
import org.dolphinemu.dolphinemu.databinding.ActivityUserDataBinding
|
||||||
import org.dolphinemu.dolphinemu.dialogs.NotificationDialog
|
import org.dolphinemu.dolphinemu.dialogs.NotificationDialog
|
||||||
@ -22,8 +24,11 @@ import org.dolphinemu.dolphinemu.dialogs.TaskDialog
|
|||||||
import org.dolphinemu.dolphinemu.dialogs.UserDataImportWarningDialog
|
import org.dolphinemu.dolphinemu.dialogs.UserDataImportWarningDialog
|
||||||
import org.dolphinemu.dolphinemu.features.DocumentProvider
|
import org.dolphinemu.dolphinemu.features.DocumentProvider
|
||||||
import org.dolphinemu.dolphinemu.model.TaskViewModel
|
import org.dolphinemu.dolphinemu.model.TaskViewModel
|
||||||
|
import org.dolphinemu.dolphinemu.ui.main.ThemeProvider
|
||||||
import org.dolphinemu.dolphinemu.utils.*
|
import org.dolphinemu.dolphinemu.utils.*
|
||||||
|
import org.dolphinemu.dolphinemu.utils.ThemeHelper
|
||||||
import org.dolphinemu.dolphinemu.utils.ThemeHelper.enableScrollTint
|
import org.dolphinemu.dolphinemu.utils.ThemeHelper.enableScrollTint
|
||||||
|
import org.dolphinemu.dolphinemu.utils.ThemeHelper.setCorrectTheme
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
@ -33,11 +38,13 @@ import java.util.zip.ZipInputStream
|
|||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
class UserDataActivity : AppCompatActivity() {
|
class UserDataActivity : AppCompatActivity(), ThemeProvider {
|
||||||
private lateinit var taskViewModel: TaskViewModel
|
private lateinit var taskViewModel: TaskViewModel
|
||||||
|
|
||||||
private lateinit var mBinding: ActivityUserDataBinding
|
private lateinit var mBinding: ActivityUserDataBinding
|
||||||
|
|
||||||
|
override var themeId: Int = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
|
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
|
||||||
|
|
||||||
@ -73,11 +80,17 @@ class UserDataActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
mBinding.buttonExportUserData.setOnClickListener { exportUserData() }
|
mBinding.buttonExportUserData.setOnClickListener { exportUserData() }
|
||||||
|
|
||||||
|
mBinding.buttonResetSettings.setOnClickListener { confirmResetSettings() }
|
||||||
|
|
||||||
setSupportActionBar(mBinding.toolbarUserData)
|
setSupportActionBar(mBinding.toolbarUserData)
|
||||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
setInsets()
|
setInsets()
|
||||||
enableScrollTint(this, mBinding.toolbarUserData, mBinding.appbarUserData)
|
enableScrollTint(this, mBinding.toolbarUserData, mBinding.appbarUserData)
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
Analytics.checkAnalyticsInit(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
@ -85,6 +98,16 @@ class UserDataActivity : AppCompatActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
setCorrectTheme(this)
|
||||||
|
super.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTheme(themeId: Int) {
|
||||||
|
super.setTheme(themeId)
|
||||||
|
this.themeId = themeId
|
||||||
|
}
|
||||||
|
|
||||||
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
|
||||||
@ -113,6 +136,28 @@ class UserDataActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun confirmResetSettings() {
|
||||||
|
MaterialAlertDialogBuilder(this)
|
||||||
|
.setTitle(R.string.reset_dolphin_settings)
|
||||||
|
.setMessage(R.string.reset_dolphin_settings_confirmation)
|
||||||
|
.setPositiveButton(R.string.yes) { _, _ -> resetSettings() }
|
||||||
|
.setNegativeButton(R.string.no, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resetSettings() {
|
||||||
|
NativeLibrary.ResetDolphinSettings()
|
||||||
|
ThemeHelper.resetThemePreferences(this, false)
|
||||||
|
|
||||||
|
val restartIntent = Intent(this, UserDataActivity::class.java)
|
||||||
|
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||||
|
|
||||||
|
finish()
|
||||||
|
overridePendingTransition(0, 0)
|
||||||
|
startActivity(restartIntent)
|
||||||
|
overridePendingTransition(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
private fun openFileManager() {
|
private fun openFileManager() {
|
||||||
// First, try to open the user data folder directly
|
// First, try to open the user data folder directly
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -32,18 +32,21 @@ import org.dolphinemu.dolphinemu.features.input.model.ControllerInterface
|
|||||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings
|
import org.dolphinemu.dolphinemu.features.settings.model.Settings
|
||||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsFragment.Companion.newInstance
|
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsFragment.Companion.newInstance
|
||||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter
|
import org.dolphinemu.dolphinemu.ui.main.MainPresenter
|
||||||
|
import org.dolphinemu.dolphinemu.ui.main.ThemeProvider
|
||||||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper
|
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper
|
||||||
import org.dolphinemu.dolphinemu.utils.InsetsHelper
|
import org.dolphinemu.dolphinemu.utils.InsetsHelper
|
||||||
import org.dolphinemu.dolphinemu.utils.SerializableHelper.serializable
|
import org.dolphinemu.dolphinemu.utils.SerializableHelper.serializable
|
||||||
import org.dolphinemu.dolphinemu.utils.ThemeHelper.enableScrollTint
|
import org.dolphinemu.dolphinemu.utils.ThemeHelper.enableScrollTint
|
||||||
|
import org.dolphinemu.dolphinemu.utils.ThemeHelper.setCorrectTheme
|
||||||
import org.dolphinemu.dolphinemu.utils.ThemeHelper.setTheme
|
import org.dolphinemu.dolphinemu.utils.ThemeHelper.setTheme
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity(), SettingsActivityView {
|
class SettingsActivity : AppCompatActivity(), SettingsActivityView, ThemeProvider {
|
||||||
private var presenter: SettingsActivityPresenter? = null
|
private var presenter: SettingsActivityPresenter? = null
|
||||||
private var dialog: AlertDialog? = null
|
private var dialog: AlertDialog? = null
|
||||||
private var toolbarLayout: CollapsingToolbarLayout? = null
|
private var toolbarLayout: CollapsingToolbarLayout? = null
|
||||||
private var binding: ActivitySettingsBinding? = null
|
private var binding: ActivitySettingsBinding? = null
|
||||||
|
|
||||||
|
override var themeId: Int = 0
|
||||||
override var isMappingAllDevices = false
|
override var isMappingAllDevices = false
|
||||||
|
|
||||||
override val settings: Settings
|
override val settings: Settings
|
||||||
@ -107,6 +110,16 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
|
|||||||
presenter!!.onStart()
|
presenter!!.onStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
setCorrectTheme(this)
|
||||||
|
super.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTheme(themeId: Int) {
|
||||||
|
super.setTheme(themeId)
|
||||||
|
this.themeId = themeId
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this is called, the user has left the settings screen (potentially through the
|
* If this is called, the user has left the settings screen (potentially through the
|
||||||
* home button) and will expect their changes to be persisted.
|
* home button) and will expect their changes to be persisted.
|
||||||
|
|||||||
@ -141,11 +141,27 @@ object ThemeHelper {
|
|||||||
activity.recreate()
|
activity.recreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun resetThemePreferences(activity: AppCompatActivity, applyImmediately: Boolean = false) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(activity.applicationContext)
|
||||||
|
.edit()
|
||||||
|
.remove(CURRENT_THEME)
|
||||||
|
.remove(CURRENT_THEME_MODE)
|
||||||
|
.remove(USE_BLACK_BACKGROUNDS)
|
||||||
|
.apply()
|
||||||
|
activity.delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
|
activity.delegate.applyDayNight()
|
||||||
|
if (applyImmediately) {
|
||||||
|
activity.recreate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setCorrectTheme(activity: AppCompatActivity) {
|
fun setCorrectTheme(activity: AppCompatActivity) {
|
||||||
val currentTheme = (activity as ThemeProvider).themeId
|
val provider = activity as? ThemeProvider ?: return
|
||||||
|
val currentTheme = provider.themeId
|
||||||
setTheme(activity)
|
setTheme(activity)
|
||||||
if (currentTheme != (activity as ThemeProvider).themeId) {
|
if (currentTheme != provider.themeId) {
|
||||||
activity.recreate()
|
activity.recreate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,7 +107,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:barrierDirection="start"
|
app:barrierDirection="start"
|
||||||
app:constraint_referenced_ids="button_open_system_file_manager,button_import_user_data,button_export_user_data" />
|
app:constraint_referenced_ids="button_open_system_file_manager,button_import_user_data,button_export_user_data,button_reset_settings" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button_open_system_file_manager"
|
android:id="@+id/button_open_system_file_manager"
|
||||||
@ -141,6 +141,17 @@
|
|||||||
app:layout_constraintStart_toEndOf="@id/barrier_text"
|
app:layout_constraintStart_toEndOf="@id/barrier_text"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/button_import_user_data"
|
app:layout_constraintTop_toBottomOf="@id/button_import_user_data"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/button_reset_settings" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_reset_settings"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/spacing_small"
|
||||||
|
android:text="@string/reset_all_settings"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/barrier_text"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/button_export_user_data"
|
||||||
app:layout_constraintBottom_toBottomOf="parent" />
|
app:layout_constraintBottom_toBottomOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@ -118,6 +118,17 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/button_import_user_data"
|
app:layout_constraintTop_toBottomOf="@id/button_import_user_data"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/button_reset_settings" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_reset_settings"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="@string/reset_all_settings"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/button_export_user_data"
|
||||||
app:layout_constraintBottom_toBottomOf="parent" />
|
app:layout_constraintBottom_toBottomOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@ -456,6 +456,9 @@
|
|||||||
<string name="user_data_import_failure">Failed to import user data.</string>
|
<string name="user_data_import_failure">Failed to import user data.</string>
|
||||||
<string name="user_data_export_success">Your user data has been exported.</string>
|
<string name="user_data_export_success">Your user data has been exported.</string>
|
||||||
<string name="user_data_export_failure">Failed to export user data.</string>
|
<string name="user_data_export_failure">Failed to export user data.</string>
|
||||||
|
<string name="reset_dolphin_settings">Reset Dolphin Settings</string>
|
||||||
|
<string name="reset_all_settings">Reset All Settings</string>
|
||||||
|
<string name="reset_dolphin_settings_confirmation">Are you sure you want to restore all Dolphin settings to their default values? This action cannot be undone!\nAll customizations or changes you have made will be lost.\n\nDo you want to proceed?</string>
|
||||||
|
|
||||||
<!-- Miscellaneous -->
|
<!-- Miscellaneous -->
|
||||||
<string name="yes">Yes</string>
|
<string name="yes">Yes</string>
|
||||||
|
|||||||
@ -545,6 +545,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadConfig
|
|||||||
SConfig::GetInstance().LoadSettings();
|
SConfig::GetInstance().LoadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ResetDolphinSettings(JNIEnv*,
|
||||||
|
jclass)
|
||||||
|
{
|
||||||
|
HostThreadLock guard;
|
||||||
|
SConfig::ResetAllSettings();
|
||||||
|
UICommon::SetUserDirectory(File::GetUserPath(D_USER_IDX));
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateGCAdapterScanThread(JNIEnv*, jclass)
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateGCAdapterScanThread(JNIEnv*, jclass)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user