diff options
| author | 2023-03-11 00:34:24 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:39 -0700 | |
| commit | 0f742b3464d596fdb55162c2d0cd5aff14405b34 (patch) | |
| tree | 17f92433ad094a5a5948503547431818955b7868 /src/android | |
| parent | android: Convert InputOverlayDrawableJoystick to Kotlin (diff) | |
| download | yuzu-0f742b3464d596fdb55162c2d0cd5aff14405b34.tar.gz yuzu-0f742b3464d596fdb55162c2d0cd5aff14405b34.tar.xz yuzu-0f742b3464d596fdb55162c2d0cd5aff14405b34.zip | |
android: Convert MainPresenter to Kotlin
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.java | 81 | ||||
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.kt | 66 |
2 files changed, 66 insertions, 81 deletions
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.ui.main; | ||
| 2 | |||
| 3 | import android.os.SystemClock; | ||
| 4 | |||
| 5 | import org.yuzu.yuzu_emu.BuildConfig; | ||
| 6 | import org.yuzu.yuzu_emu.YuzuApplication; | ||
| 7 | import org.yuzu.yuzu_emu.R; | ||
| 8 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile; | ||
| 9 | import org.yuzu.yuzu_emu.model.GameDatabase; | ||
| 10 | import org.yuzu.yuzu_emu.utils.AddDirectoryHelper; | ||
| 11 | |||
| 12 | public final class MainPresenter { | ||
| 13 | public static final int REQUEST_ADD_DIRECTORY = 1; | ||
| 14 | public static final int REQUEST_INSTALL_KEYS = 2; | ||
| 15 | public static final int REQUEST_SELECT_GPU_DRIVER = 3; | ||
| 16 | private final MainView mView; | ||
| 17 | private String mDirToAdd; | ||
| 18 | private long mLastClickTime = 0; | ||
| 19 | |||
| 20 | public MainPresenter(MainView view) { | ||
| 21 | mView = view; | ||
| 22 | } | ||
| 23 | |||
| 24 | public void onCreate() { | ||
| 25 | String versionName = BuildConfig.VERSION_NAME; | ||
| 26 | mView.setVersionString(versionName); | ||
| 27 | refreshGameList(); | ||
| 28 | } | ||
| 29 | |||
| 30 | public void launchFileListActivity(int request) { | ||
| 31 | if (mView != null) { | ||
| 32 | mView.launchFileListActivity(request); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | public boolean handleOptionSelection(int itemId) { | ||
| 37 | // Double-click prevention, using threshold of 500 ms | ||
| 38 | if (SystemClock.elapsedRealtime() - mLastClickTime < 500) { | ||
| 39 | return false; | ||
| 40 | } | ||
| 41 | mLastClickTime = SystemClock.elapsedRealtime(); | ||
| 42 | |||
| 43 | switch (itemId) { | ||
| 44 | case R.id.menu_settings_core: | ||
| 45 | mView.launchSettingsActivity(SettingsFile.FILE_NAME_CONFIG); | ||
| 46 | return true; | ||
| 47 | |||
| 48 | case R.id.button_add_directory: | ||
| 49 | launchFileListActivity(REQUEST_ADD_DIRECTORY); | ||
| 50 | return true; | ||
| 51 | |||
| 52 | case R.id.button_install_keys: | ||
| 53 | launchFileListActivity(REQUEST_INSTALL_KEYS); | ||
| 54 | return true; | ||
| 55 | |||
| 56 | case R.id.button_select_gpu_driver: | ||
| 57 | launchFileListActivity(REQUEST_SELECT_GPU_DRIVER); | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | |||
| 61 | return false; | ||
| 62 | } | ||
| 63 | |||
| 64 | public void addDirIfNeeded(AddDirectoryHelper helper) { | ||
| 65 | if (mDirToAdd != null) { | ||
| 66 | helper.addDirectory(mDirToAdd, mView::refresh); | ||
| 67 | |||
| 68 | mDirToAdd = null; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | public void onDirectorySelected(String dir) { | ||
| 73 | mDirToAdd = dir; | ||
| 74 | } | ||
| 75 | |||
| 76 | public void refreshGameList() { | ||
| 77 | GameDatabase databaseHelper = YuzuApplication.databaseHelper; | ||
| 78 | databaseHelper.scanLibrary(databaseHelper.getWritableDatabase()); | ||
| 79 | mView.refresh(); | ||
| 80 | } | ||
| 81 | } | ||
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.ui.main | ||
| 2 | |||
| 3 | import org.yuzu.yuzu_emu.BuildConfig | ||
| 4 | import org.yuzu.yuzu_emu.R | ||
| 5 | import org.yuzu.yuzu_emu.YuzuApplication | ||
| 6 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile | ||
| 7 | import org.yuzu.yuzu_emu.utils.AddDirectoryHelper | ||
| 8 | |||
| 9 | class MainPresenter(private val view: MainView) { | ||
| 10 | private var dirToAdd: String? = null | ||
| 11 | |||
| 12 | fun onCreate() { | ||
| 13 | val versionName = BuildConfig.VERSION_NAME | ||
| 14 | view.setVersionString(versionName) | ||
| 15 | refreshGameList() | ||
| 16 | } | ||
| 17 | |||
| 18 | private fun launchFileListActivity(request: Int) { | ||
| 19 | view.launchFileListActivity(request) | ||
| 20 | } | ||
| 21 | |||
| 22 | fun handleOptionSelection(itemId: Int): Boolean { | ||
| 23 | when (itemId) { | ||
| 24 | R.id.menu_settings_core -> { | ||
| 25 | view.launchSettingsActivity(SettingsFile.FILE_NAME_CONFIG) | ||
| 26 | return true | ||
| 27 | } | ||
| 28 | R.id.button_add_directory -> { | ||
| 29 | launchFileListActivity(REQUEST_ADD_DIRECTORY) | ||
| 30 | return true | ||
| 31 | } | ||
| 32 | R.id.button_install_keys -> { | ||
| 33 | launchFileListActivity(REQUEST_INSTALL_KEYS) | ||
| 34 | return true | ||
| 35 | } | ||
| 36 | R.id.button_select_gpu_driver -> { | ||
| 37 | launchFileListActivity(REQUEST_SELECT_GPU_DRIVER) | ||
| 38 | return true | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return false | ||
| 42 | } | ||
| 43 | |||
| 44 | fun addDirIfNeeded(helper: AddDirectoryHelper) { | ||
| 45 | if (dirToAdd != null) { | ||
| 46 | helper.addDirectory(dirToAdd) { view.refresh() } | ||
| 47 | dirToAdd = null | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | fun onDirectorySelected(dir: String?) { | ||
| 52 | dirToAdd = dir | ||
| 53 | } | ||
| 54 | |||
| 55 | private fun refreshGameList() { | ||
| 56 | val databaseHelper = YuzuApplication.databaseHelper | ||
| 57 | databaseHelper!!.scanLibrary(databaseHelper.writableDatabase) | ||
| 58 | view.refresh() | ||
| 59 | } | ||
| 60 | |||
| 61 | companion object { | ||
| 62 | const val REQUEST_ADD_DIRECTORY = 1 | ||
| 63 | const val REQUEST_INSTALL_KEYS = 2 | ||
| 64 | const val REQUEST_SELECT_GPU_DRIVER = 3 | ||
| 65 | } | ||
| 66 | } | ||