-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
SettingsActivityPresenter.java
171 lines (142 loc) · 3.92 KB
/
SettingsActivityPresenter.java
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.ui;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.core.app.ComponentActivity;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.Log;
public final class SettingsActivityPresenter
{
private static final String KEY_SHOULD_SAVE = "should_save";
private SettingsActivityView mView;
private Settings mSettings;
private boolean mShouldSave;
private MenuTag mMenuTag;
private String mGameId;
private int mRevision;
private boolean mIsWii;
private ComponentActivity mActivity;
SettingsActivityPresenter(SettingsActivityView view, Settings settings)
{
mView = view;
mSettings = settings;
}
public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId, int revision,
boolean isWii, ComponentActivity activity)
{
this.mMenuTag = menuTag;
this.mGameId = gameId;
this.mRevision = revision;
this.mIsWii = isWii;
this.mActivity = activity;
mShouldSave = savedInstanceState != null && savedInstanceState.getBoolean(KEY_SHOULD_SAVE);
}
public void onDestroy()
{
if (mSettings != null)
{
mSettings.close();
mSettings = null;
}
}
public void onStart()
{
prepareDolphinDirectoriesIfNeeded();
}
private void loadSettingsUI()
{
if (mSettings.isEmpty())
{
if (!TextUtils.isEmpty(mGameId))
{
mSettings.loadSettings(mView, mGameId, mRevision, mIsWii);
if (mSettings.gameIniContainsJunk())
{
mView.showGameIniJunkDeletionQuestion();
}
}
else
{
mSettings.loadSettings(mView, mIsWii);
}
}
mView.showSettingsFragment(mMenuTag, null, false, mGameId);
mView.onSettingsFileLoaded(mSettings);
}
private void prepareDolphinDirectoriesIfNeeded()
{
if (DirectoryInitialization.areDolphinDirectoriesReady())
{
loadSettingsUI();
}
else
{
mView.showLoading();
new AfterDirectoryInitializationRunner()
.setFinishedCallback(mView::hideLoading)
.runWithLifecycle(mActivity, true, this::loadSettingsUI);
}
}
public Settings getSettings()
{
return mSettings;
}
public void clearSettings()
{
mSettings.clearSettings();
onSettingChanged();
}
public void onStop(boolean finishing)
{
if (mSettings != null && finishing && mShouldSave)
{
Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...");
mSettings.saveSettings(mView, mActivity);
}
}
public void onSettingChanged()
{
mShouldSave = true;
}
public void saveState(Bundle outState)
{
outState.putBoolean(KEY_SHOULD_SAVE, mShouldSave);
}
public boolean shouldSave()
{
return mShouldSave;
}
public void onGcPadSettingChanged(MenuTag key, int value)
{
if (value != 0) // Not disabled
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(key, bundle, true, mGameId);
}
}
public void onWiimoteSettingChanged(MenuTag menuTag, int value)
{
switch (value)
{
case 1:
mView.showSettingsFragment(menuTag, null, true, mGameId);
break;
case 2:
mView.showToastMessage(mActivity.getString(R.string.make_sure_continuous_scan_enabled));
break;
}
}
public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
if (value != 0) // None
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
}
}
}