-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
SettingsActivityPresenter.java
191 lines (163 loc) · 4.32 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package org.dolphinemu.dolphinemu.ui.settings;
import android.os.Bundle;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.settings.SettingSection;
import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.SettingsFile;
import java.util.HashMap;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
public final class SettingsActivityPresenter
{
private static final String SHOULD_SAVE = BuildConfig.APPLICATION_ID + ".should_save";
private SettingsActivityView mView;
private String mFileName;
private HashMap<String, SettingSection> mSettingsBySection;
private int mStackCount;
private boolean mShouldSave;
public SettingsActivityPresenter(SettingsActivityView view)
{
mView = view;
}
public void onCreate(Bundle savedInstanceState, final String filename)
{
mFileName = filename;
if (savedInstanceState == null)
{
// TODO DI should be able to get rid of this hack
if (filename.equals(SettingsFile.FILE_NAME_GCPAD))
{
// Psyche! Don't actually load that file (yet).
mFileName = SettingsFile.FILE_NAME_DOLPHIN;
// But do display its fragment, as if we had.
mView.showSettingsFragment(SettingsFile.FILE_NAME_GCPAD, false);
}
else
{
mFileName = filename;
mView.showSettingsFragment(mFileName, false);
}
SettingsFile.readFile(mFileName)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<HashMap<String, SettingSection>>()
{
@Override
public void call(HashMap<String, SettingSection> settingsBySection)
{
mSettingsBySection = settingsBySection;
mView.onSettingsFileLoaded(settingsBySection);
}
},
new Action1<Throwable>()
{
@Override
public void call(Throwable throwable)
{
Log.error("[SettingsActivityPresenter] Error reading file " + filename + ".ini: "+ throwable.getMessage());
mView.onSettingsFileNotFound();
}
});
}
else
{
mShouldSave = savedInstanceState.getBoolean(SHOULD_SAVE);
}
}
public void setSettings(HashMap<String, SettingSection> settings)
{
mSettingsBySection = settings;
}
public HashMap<String, SettingSection> getSettings()
{
return mSettingsBySection;
}
public void onStop(boolean finishing)
{
if (mSettingsBySection != null && finishing && mShouldSave)
{
Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...");
SettingsFile.saveFile(mFileName, mSettingsBySection)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
new Action1<Boolean>()
{
@Override
public void call(Boolean aBoolean)
{
mView.showToastMessage("Saved successfully to " + mFileName + ".ini");
}
},
new Action1<Throwable>()
{
@Override
public void call(Throwable throwable)
{
mView.showToastMessage("Error saving " + mFileName + ".ini: " + throwable.getMessage());
}
});
}
}
public void addToStack()
{
mStackCount++;
}
public void onBackPressed()
{
if (mStackCount > 0)
{
mView.popBackStack();
mStackCount--;
}
else
{
mView.finish();
}
}
public boolean handleOptionsItem(int itemId)
{
switch (itemId)
{
case R.id.menu_exit_no_save:
mShouldSave = false;
mView.finish();
return true;
}
return false;
}
public void onSettingChanged()
{
mShouldSave = true;
}
public void saveState(Bundle outState)
{
outState.putBoolean(SHOULD_SAVE, mShouldSave);
}
public void onGcPadSettingChanged(String key, int value)
{
switch (value)
{
case 6:
mView.showToastMessage("Configuration coming soon. Settings from old versions will still work.");
break;
case 12:
mView.showSettingsFragment(key, true);
break;
}
}
public void onWiimoteSettingChanged(String section, int value)
{
switch (value)
{
case 1:
mView.showToastMessage("Configuration coming soon. Settings from old versions will still work.");
break;
case 2:
mView.showToastMessage("Please make sure Continuous Scanning is enabled in Core Settings.");
break;
}
}
}