diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-03-08 03:14:06 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:37 +0200 |
commit | 34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1 (patch) | |
tree | 1faaaba70106f9a92fd300250a2cef12ffbdcd9b /src | |
parent | android: Convert SettingsActivity to Kotlin (diff) | |
download | yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.tar yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.tar.gz yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.tar.bz2 yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.tar.lz yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.tar.xz yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.tar.zst yuzu-34ce4877bd69f9bdb7dc8f370a5f94afb2ed7da1.zip |
Diffstat (limited to 'src')
2 files changed, 99 insertions, 122 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.java deleted file mode 100644 index 25b7758a9..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.yuzu.yuzu_emu.features.settings.ui; - -import android.content.IntentFilter; -import android.os.Bundle; -import android.text.TextUtils; - -import org.yuzu.yuzu_emu.NativeLibrary; -import org.yuzu.yuzu_emu.features.settings.model.Settings; -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile; -import org.yuzu.yuzu_emu.utils.DirectoryInitialization; -import org.yuzu.yuzu_emu.utils.DirectoryInitialization.DirectoryInitializationState; -import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver; -import org.yuzu.yuzu_emu.utils.Log; -import org.yuzu.yuzu_emu.utils.ThemeUtil; - -import java.io.File; - -public final class SettingsActivityPresenter { - private static final String KEY_SHOULD_SAVE = "should_save"; - - private SettingsActivityView mView; - - private Settings mSettings = new Settings(); - - private boolean mShouldSave; - - private DirectoryStateReceiver directoryStateReceiver; - - private String menuTag; - private String gameId; - - public SettingsActivityPresenter(SettingsActivityView view) { - mView = view; - } - - public void onCreate(Bundle savedInstanceState, String menuTag, String gameId) { - if (savedInstanceState == null) { - this.menuTag = menuTag; - this.gameId = gameId; - } else { - mShouldSave = savedInstanceState.getBoolean(KEY_SHOULD_SAVE); - } - } - - public void onStart() { - prepareDirectoriesIfNeeded(); - } - - void loadSettingsUI() { - if (mSettings.isEmpty()) { - if (!TextUtils.isEmpty(gameId)) { - mSettings.loadSettings(gameId, mView); - } else { - mSettings.loadSettings(mView); - } - } - - mView.showSettingsFragment(menuTag, false, gameId); - mView.onSettingsFileLoaded(mSettings); - } - - private void prepareDirectoriesIfNeeded() { - File configFile = new File(DirectoryInitialization.getUserDirectory() + "/config/" + SettingsFile.FILE_NAME_CONFIG + ".ini"); - if (!configFile.exists()) { - Log.error(DirectoryInitialization.getUserDirectory() + "/config/" + SettingsFile.FILE_NAME_CONFIG + ".ini"); - Log.error("yuzu config file could not be found!"); - } - if (DirectoryInitialization.areDirectoriesReady()) { - loadSettingsUI(); - } else { - mView.showLoading(); - IntentFilter statusIntentFilter = new IntentFilter( - DirectoryInitialization.BROADCAST_ACTION); - - directoryStateReceiver = - new DirectoryStateReceiver(directoryInitializationState -> - { - if (directoryInitializationState == DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED) { - mView.hideLoading(); - loadSettingsUI(); - } else if (directoryInitializationState == DirectoryInitializationState.CANT_FIND_EXTERNAL_STORAGE) { - mView.showExternalStorageNotMountedHint(); - mView.hideLoading(); - } - }); - - mView.startDirectoryInitializationService(directoryStateReceiver, statusIntentFilter); - } - } - - public void setSettings(Settings settings) { - mSettings = settings; - } - - public Settings getSettings() { - return mSettings; - } - - public void onStop(boolean finishing) { - if (directoryStateReceiver != null) { - mView.stopListeningToDirectoryInitializationService(directoryStateReceiver); - directoryStateReceiver = null; - } - - if (mSettings != null && finishing && mShouldSave) { - Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI..."); - mSettings.saveSettings(mView); - } - - ThemeUtil.applyTheme(); - - NativeLibrary.ReloadSettings(); - } - - public void onSettingChanged() { - mShouldSave = true; - } - - public void saveState(Bundle outState) { - outState.putBoolean(KEY_SHOULD_SAVE, mShouldSave); - } -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt new file mode 100644 index 000000000..4b24d6108 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivityPresenter.kt @@ -0,0 +1,99 @@ +package org.yuzu.yuzu_emu.features.settings.ui + +import android.content.IntentFilter +import android.os.Bundle +import android.text.TextUtils +import org.yuzu.yuzu_emu.NativeLibrary +import org.yuzu.yuzu_emu.features.settings.model.Settings +import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile +import org.yuzu.yuzu_emu.utils.DirectoryInitialization +import org.yuzu.yuzu_emu.utils.DirectoryInitialization.DirectoryInitializationState +import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver +import org.yuzu.yuzu_emu.utils.Log +import java.io.File + +class SettingsActivityPresenter(private val activityView: SettingsActivityView) { + var settings: Settings? = Settings() + private var shouldSave = false + private var directoryStateReceiver: DirectoryStateReceiver? = null + private lateinit var menuTag: String + private lateinit var gameId: String + + fun onCreate(savedInstanceState: Bundle?, menuTag: String, gameId: String) { + if (savedInstanceState == null) { + this.menuTag = menuTag + this.gameId = gameId + } else { + shouldSave = savedInstanceState.getBoolean(KEY_SHOULD_SAVE) + } + } + + fun onStart() { + prepareDirectoriesIfNeeded() + } + + private fun loadSettingsUI() { + if (settings!!.isEmpty) { + if (!TextUtils.isEmpty(gameId)) { + settings!!.loadSettings(gameId, activityView) + } else { + settings!!.loadSettings(activityView) + } + } + activityView.showSettingsFragment(menuTag, false, gameId) + activityView.onSettingsFileLoaded(settings) + } + + private fun prepareDirectoriesIfNeeded() { + val configFile = + File(DirectoryInitialization.userDirectory + "/config/" + SettingsFile.FILE_NAME_CONFIG + ".ini") + if (!configFile.exists()) { + Log.error(DirectoryInitialization.userDirectory + "/config/" + SettingsFile.FILE_NAME_CONFIG + ".ini") + Log.error("yuzu config file could not be found!") + } + if (DirectoryInitialization.areDirectoriesReady()) { + loadSettingsUI() + } else { + activityView.showLoading() + val statusIntentFilter = IntentFilter(DirectoryInitialization.BROADCAST_ACTION) + directoryStateReceiver = + DirectoryStateReceiver { directoryInitializationState: DirectoryInitializationState -> + if (directoryInitializationState == DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED) { + activityView.hideLoading() + loadSettingsUI() + } else if (directoryInitializationState == DirectoryInitializationState.CANT_FIND_EXTERNAL_STORAGE) { + activityView.showExternalStorageNotMountedHint() + activityView.hideLoading() + } + } + activityView.startDirectoryInitializationService( + directoryStateReceiver, + statusIntentFilter + ) + } + } + + fun onStop(finishing: Boolean) { + if (directoryStateReceiver != null) { + activityView.stopListeningToDirectoryInitializationService(directoryStateReceiver!!) + directoryStateReceiver = null + } + if (settings != null && finishing && shouldSave) { + Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...") + settings!!.saveSettings(activityView) + } + NativeLibrary.ReloadSettings() + } + + fun onSettingChanged() { + shouldSave = true + } + + fun saveState(outState: Bundle) { + outState.putBoolean(KEY_SHOULD_SAVE, shouldSave) + } + + companion object { + private const val KEY_SHOULD_SAVE = "should_save" + } +} |