Improve update channel settings

Fix #446
This commit is contained in:
topjohnwu 2018-08-07 15:48:43 +08:00
parent c38533e0f8
commit 7fb4777c1c
4 changed files with 15 additions and 10 deletions

View File

@ -123,19 +123,23 @@ public class SettingsActivity extends BaseActivity implements Topic.Subscriber {
SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH); SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH);
SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT); SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT);
updateChannel.setOnPreferenceChangeListener((pref, o) -> { updateChannel.setOnPreferenceChangeListener((p, o) -> {
Data.updateChannel = Integer.parseInt((String) o); String prev =String.valueOf(Data.updateChannel);
if (Data.updateChannel == Const.Value.CUSTOM_CHANNEL) { int channel = Integer.parseInt((String) o);
if (channel == Const.Value.CUSTOM_CHANNEL) {
View v = LayoutInflater.from(requireActivity()).inflate(R.layout.custom_channel_dialog, null); View v = LayoutInflater.from(requireActivity()).inflate(R.layout.custom_channel_dialog, null);
EditText url = v.findViewById(R.id.custom_url); EditText url = v.findViewById(R.id.custom_url);
url.setText(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, "")); url.setText(prefs.getString(Const.Key.CUSTOM_CHANNEL, ""));
new AlertDialog.Builder(requireActivity()) new AlertDialog.Builder(requireActivity())
.setTitle(R.string.settings_update_custom) .setTitle(R.string.settings_update_custom)
.setView(v) .setView(v)
.setPositiveButton(R.string.ok, (d, i) -> .setPositiveButton(R.string.ok, (d, i) ->
prefs.edit().putString(Const.Key.CUSTOM_CHANNEL, prefs.edit().putString(Const.Key.CUSTOM_CHANNEL,
url.getText().toString()).apply()) url.getText().toString()).apply())
.setNegativeButton(R.string.close, null) .setNegativeButton(R.string.close, (d, i) ->
prefs.edit().putString(Const.Key.UPDATE_CHANNEL, prev).apply())
.setOnCancelListener(d ->
prefs.edit().putString(Const.Key.UPDATE_CHANNEL, prev).apply())
.show(); .show();
} }
return true; return true;
@ -287,6 +291,7 @@ public class SettingsActivity extends BaseActivity implements Topic.Subscriber {
Topic.publish(false, Topic.RELOAD_ACTIVITY); Topic.publish(false, Topic.RELOAD_ACTIVITY);
break; break;
case Const.Key.UPDATE_CHANNEL: case Const.Key.UPDATE_CHANNEL:
case Const.Key.CUSTOM_CHANNEL:
CheckUpdates.check(); CheckUpdates.check();
break; break;
case Const.Key.CHECK_UPDATES: case Const.Key.CHECK_UPDATES:
@ -321,7 +326,7 @@ public class SettingsActivity extends BaseActivity implements Topic.Subscriber {
@Override @Override
public int[] getSubscribedTopics() { public int[] getSubscribedTopics() {
return new int[] {Topic.LOCAL_FETCH_DONE}; return new int[] {Topic.LOCALE_FETCH_DONE};
} }
} }

View File

@ -70,7 +70,7 @@ public class LocaleManager {
} }
Collections.sort(locales, (a, b) -> a.getDisplayName(a).compareTo(b.getDisplayName(b))); Collections.sort(locales, (a, b) -> a.getDisplayName(a).compareTo(b.getDisplayName(b)));
Topic.publish(Topic.LOCAL_FETCH_DONE); Topic.publish(Topic.LOCALE_FETCH_DONE);
}); });
} }
} }

View File

@ -17,10 +17,10 @@ public class Topic {
public static final int REPO_LOAD_DONE = 3; public static final int REPO_LOAD_DONE = 3;
public static final int UPDATE_CHECK_DONE = 4; public static final int UPDATE_CHECK_DONE = 4;
public static final int SNET_CHECK_DONE = 5; public static final int SNET_CHECK_DONE = 5;
public static final int LOCAL_FETCH_DONE = 6; public static final int LOCALE_FETCH_DONE = 6;
@IntDef({MAGISK_HIDE_DONE, RELOAD_ACTIVITY, MODULE_LOAD_DONE, REPO_LOAD_DONE, @IntDef({MAGISK_HIDE_DONE, RELOAD_ACTIVITY, MODULE_LOAD_DONE, REPO_LOAD_DONE,
UPDATE_CHECK_DONE, SNET_CHECK_DONE, LOCAL_FETCH_DONE}) UPDATE_CHECK_DONE, SNET_CHECK_DONE, LOCALE_FETCH_DONE})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface TopicID {} public @interface TopicID {}

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong