From 0f742b3464d596fdb55162c2d0cd5aff14405b34 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 11 Mar 2023 00:34:24 -0500 Subject: [PATCH] android: Convert MainPresenter to Kotlin --- .../yuzu/yuzu_emu/ui/main/MainPresenter.java | 81 ------------------- .../yuzu/yuzu_emu/ui/main/MainPresenter.kt | 66 +++++++++++++++ 2 files changed, 66 insertions(+), 81 deletions(-) delete mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.java create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.kt diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.java deleted file mode 100644 index d2ef753bc..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.yuzu.yuzu_emu.ui.main; - -import android.os.SystemClock; - -import org.yuzu.yuzu_emu.BuildConfig; -import org.yuzu.yuzu_emu.YuzuApplication; -import org.yuzu.yuzu_emu.R; -import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile; -import org.yuzu.yuzu_emu.model.GameDatabase; -import org.yuzu.yuzu_emu.utils.AddDirectoryHelper; - -public final class MainPresenter { - public static final int REQUEST_ADD_DIRECTORY = 1; - public static final int REQUEST_INSTALL_KEYS = 2; - public static final int REQUEST_SELECT_GPU_DRIVER = 3; - private final MainView mView; - private String mDirToAdd; - private long mLastClickTime = 0; - - public MainPresenter(MainView view) { - mView = view; - } - - public void onCreate() { - String versionName = BuildConfig.VERSION_NAME; - mView.setVersionString(versionName); - refreshGameList(); - } - - public void launchFileListActivity(int request) { - if (mView != null) { - mView.launchFileListActivity(request); - } - } - - public boolean handleOptionSelection(int itemId) { - // Double-click prevention, using threshold of 500 ms - if (SystemClock.elapsedRealtime() - mLastClickTime < 500) { - return false; - } - mLastClickTime = SystemClock.elapsedRealtime(); - - switch (itemId) { - case R.id.menu_settings_core: - mView.launchSettingsActivity(SettingsFile.FILE_NAME_CONFIG); - return true; - - case R.id.button_add_directory: - launchFileListActivity(REQUEST_ADD_DIRECTORY); - return true; - - case R.id.button_install_keys: - launchFileListActivity(REQUEST_INSTALL_KEYS); - return true; - - case R.id.button_select_gpu_driver: - launchFileListActivity(REQUEST_SELECT_GPU_DRIVER); - return true; - } - - return false; - } - - public void addDirIfNeeded(AddDirectoryHelper helper) { - if (mDirToAdd != null) { - helper.addDirectory(mDirToAdd, mView::refresh); - - mDirToAdd = null; - } - } - - public void onDirectorySelected(String dir) { - mDirToAdd = dir; - } - - public void refreshGameList() { - GameDatabase databaseHelper = YuzuApplication.databaseHelper; - databaseHelper.scanLibrary(databaseHelper.getWritableDatabase()); - mView.refresh(); - } -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.kt new file mode 100644 index 000000000..b2d731494 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.kt @@ -0,0 +1,66 @@ +package org.yuzu.yuzu_emu.ui.main + +import org.yuzu.yuzu_emu.BuildConfig +import org.yuzu.yuzu_emu.R +import org.yuzu.yuzu_emu.YuzuApplication +import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile +import org.yuzu.yuzu_emu.utils.AddDirectoryHelper + +class MainPresenter(private val view: MainView) { + private var dirToAdd: String? = null + + fun onCreate() { + val versionName = BuildConfig.VERSION_NAME + view.setVersionString(versionName) + refreshGameList() + } + + private fun launchFileListActivity(request: Int) { + view.launchFileListActivity(request) + } + + fun handleOptionSelection(itemId: Int): Boolean { + when (itemId) { + R.id.menu_settings_core -> { + view.launchSettingsActivity(SettingsFile.FILE_NAME_CONFIG) + return true + } + R.id.button_add_directory -> { + launchFileListActivity(REQUEST_ADD_DIRECTORY) + return true + } + R.id.button_install_keys -> { + launchFileListActivity(REQUEST_INSTALL_KEYS) + return true + } + R.id.button_select_gpu_driver -> { + launchFileListActivity(REQUEST_SELECT_GPU_DRIVER) + return true + } + } + return false + } + + fun addDirIfNeeded(helper: AddDirectoryHelper) { + if (dirToAdd != null) { + helper.addDirectory(dirToAdd) { view.refresh() } + dirToAdd = null + } + } + + fun onDirectorySelected(dir: String?) { + dirToAdd = dir + } + + private fun refreshGameList() { + val databaseHelper = YuzuApplication.databaseHelper + databaseHelper!!.scanLibrary(databaseHelper.writableDatabase) + view.refresh() + } + + companion object { + const val REQUEST_ADD_DIRECTORY = 1 + const val REQUEST_INSTALL_KEYS = 2 + const val REQUEST_SELECT_GPU_DRIVER = 3 + } +}