summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainPresenter.java
blob: d2ef753bc41c60c369525af0ebee3960d77f3eb8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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();
    }
}