Fix back button closing settings from submenu (#313)

* Prevent back button from closing the activity.

* Remove redundant overrides

* Do not close the settings after resetting the themes.

Closes #290
This commit is contained in:
davidoskky 2020-12-08 15:36:12 +01:00 committed by GitHub
parent a1e4f89cd1
commit 00c8eed034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -195,16 +195,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}); });
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -245,16 +235,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
}); });
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
} }
/** /**
@ -298,16 +278,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
}); });
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -322,10 +292,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();
if (id == android.R.id.home) { if (id == R.id.clear) {
getActivity().finish();
return true;
} else if (id == R.id.clear) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = pref.edit(); SharedPreferences.Editor editor = pref.edit();
editor.remove("color_primary"); editor.remove("color_primary");
@ -334,7 +301,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
editor.remove("color_accent_dark"); editor.remove("color_accent_dark");
editor.remove("dark_theme"); editor.remove("dark_theme");
editor.apply(); editor.apply();
getActivity().finish(); getActivity().recreate();
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -353,16 +320,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
addPreferencesFromResource(R.xml.pref_offline); addPreferencesFromResource(R.xml.pref_offline);
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -373,16 +330,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
addPreferencesFromResource(R.xml.pref_experimental); addPreferencesFromResource(R.xml.pref_experimental);
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
} }
@ -390,7 +337,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();
if (id == android.R.id.home) { if (id == android.R.id.home) {
finish(); super.onBackPressed();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);