mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-22 16:30:57 +01:00
android: Convert MainPresenter to Kotlin
This commit is contained in:
parent
42b3e72e96
commit
0f742b3464
2 changed files with 66 additions and 81 deletions
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue