Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix: commit all shared pref changes before restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Apr 6, 2024
1 parent eda7e56 commit 7e44bec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
32 changes: 5 additions & 27 deletions app/src/main/java/gm/tieba/tabswitch/dao/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
public class Preferences {
private static SharedPreferences sTsPreferences;
private static SharedPreferences sTsConfig;
private static SharedPreferences sTsNotes;

public static void init(final Context context) {
sTsPreferences = context.getSharedPreferences("TS_preferences", Context.MODE_PRIVATE);
sTsConfig = context.getSharedPreferences("TS_config", Context.MODE_PRIVATE);
sTsNotes = context.getSharedPreferences("TS_notes", Context.MODE_PRIVATE);
}

// Preferences
Expand Down Expand Up @@ -81,13 +79,7 @@ public static boolean getIsEULAAccepted() {
public static void putAutoSignEnabled() {
final SharedPreferences.Editor editor = sTsConfig.edit();
editor.putBoolean("auto_sign", true);
editor.commit();
}

public static void putAutoSignDisabled() {
final SharedPreferences.Editor editor = sTsConfig.edit();
editor.putBoolean("auto_sign", false);
editor.commit();
editor.apply();
}

public static boolean getIsAutoSignEnabled() {
Expand All @@ -101,13 +93,6 @@ public static void putPurgeEnabled() {
editor.commit();
}

@SuppressLint("ApplySharedPref")
public static void putPurgeDisabled() {
final SharedPreferences.Editor editor = sTsConfig.edit();
editor.putBoolean("ze", false);
editor.commit();
}

public static boolean getIsPurgeEnabled() {
return sTsConfig.getBoolean("ze", false);
}
Expand Down Expand Up @@ -143,16 +128,9 @@ public static boolean getIsSigned() {
return Calendar.getInstance().get(Calendar.DAY_OF_YEAR) == sTsConfig.getInt("sign_date", 0);
}

// Notes
public static Map<String, ?> getNotes() {
return sTsNotes.getAll();
}

public static String getNote(final String name) {
return sTsNotes.getString(name, null);
}

public static SharedPreferences.Editor getTsNotesEditor() {
return sTsNotes.edit();
@SuppressLint("ApplySharedPref")
public static void commit() {
sTsConfig.edit().commit();
sTsPreferences.edit().commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ private void proxyPage(final Activity activity, final NavigationBar navigationBa
final LinearLayout preferenceLayout) throws Throwable {
navigationBar.setTitleText(title);
navigationBar.setCenterTextTitle("");
navigationBar.addTextButton("重启", v -> DisplayUtils.restart(activity));
navigationBar.addTextButton("重启", v -> {
Preferences.commit();
DisplayUtils.restart(activity);
});
final var contentView = (ViewGroup) activity.findViewById(android.R.id.content);
final var parent = (LinearLayout) contentView.getChildAt(0);
final var mainScroll = (ScrollView) parent.getChildAt(1);
Expand Down

0 comments on commit 7e44bec

Please sign in to comment.