Skip to content

Commit

Permalink
Fixes crash when opening 'preferences' after upgrading from old version
Browse files Browse the repository at this point in the history
Fixes #475
Closes #476
  • Loading branch information
twaik committed Oct 2, 2023
1 parent 18b5751 commit 4acf4b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/src/main/java/com/termux/x11/LoriePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
public static class LoriePreferenceFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
SharedPreferences p = getPreferenceManager().getSharedPreferences();
int modeValue = p == null ? 0 : Integer.parseInt(p.getString("touchMode", "1")) - 1;
if (modeValue > 2) {
SharedPreferences.Editor e = Objects.requireNonNull(p).edit();
e.putString("touchMode", "1");
e.apply();
}

addPreferencesFromResource(R.xml.preferences);
}

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int modeValue = Integer.parseInt(preferences.getString("touchMode", "1")) - 1;
if (modeValue > 2) {
SharedPreferences.Editor e = Objects.requireNonNull(preferences).edit();
e.putString("touchMode", "1");
e.apply();
}

preferences.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> onPreferencesChanged(key));

getWindow().setFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | FLAG_KEEP_SCREEN_ON | FLAG_TRANSLUCENT_STATUS, 0);
Expand Down

0 comments on commit 4acf4b2

Please sign in to comment.