Fix issue with settings forcing an app restart
This commit is contained in:
parent
e6aa9adabf
commit
b4c08a3225
|
@ -80,6 +80,7 @@ public class SettingsFragment extends Fragment {
|
|||
private static final int ACTIVITY_CHOOSE_FILE = 411;
|
||||
private TextView set_folder;
|
||||
private EditText your_api_key;
|
||||
private int count1, count2, count3, count4;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -103,7 +104,10 @@ public class SettingsFragment extends Fragment {
|
|||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
count1 = 0;
|
||||
count2 = 0;
|
||||
count3 = 0;
|
||||
count4 = 0;
|
||||
|
||||
boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
|
||||
|
||||
|
@ -579,8 +583,10 @@ public class SettingsFragment extends Fragment {
|
|||
set_night_mode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if( count1 > 0 ) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
switch (position){
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
editor.putInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
editor.apply();
|
||||
|
@ -594,12 +600,14 @@ public class SettingsFragment extends Fragment {
|
|||
editor.apply();
|
||||
break;
|
||||
}
|
||||
if( getActivity() != null)
|
||||
if (getActivity() != null)
|
||||
getActivity().recreate();
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
|
||||
startActivity(intent);
|
||||
}
|
||||
count1++;
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
|
@ -618,8 +626,9 @@ public class SettingsFragment extends Fragment {
|
|||
set_change_locale.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if( count2 > 0 ) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
switch (position){
|
||||
switch (position) {
|
||||
case 0:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.getDefault()));
|
||||
editor.commit();
|
||||
|
@ -693,6 +702,7 @@ public class SettingsFragment extends Fragment {
|
|||
editor.commit();
|
||||
break;
|
||||
}
|
||||
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
Intent intent = packageManager.getLaunchIntentForPackage(context.getPackageName());
|
||||
assert intent != null;
|
||||
|
@ -701,6 +711,8 @@ public class SettingsFragment extends Fragment {
|
|||
context.startActivity(mainIntent);
|
||||
Runtime.getRuntime().exit(0);
|
||||
}
|
||||
count2++;
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
|
@ -889,20 +901,21 @@ public class SettingsFragment extends Fragment {
|
|||
translation_layout_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if( count3 > 0 ) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
switch (position){
|
||||
switch (position) {
|
||||
case 0:
|
||||
your_api_key.setVisibility(View.VISIBLE);
|
||||
editor.putInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
||||
editor.apply();
|
||||
if( sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, null) != null)
|
||||
if (sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, null) != null)
|
||||
your_api_key.setText(sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, ""));
|
||||
break;
|
||||
case 1:
|
||||
your_api_key.setVisibility(View.VISIBLE);
|
||||
editor.putInt(Helper.SET_TRANSLATOR, Helper.TRANS_DEEPL);
|
||||
editor.apply();
|
||||
if( sharedpreferences.getString(SET_YANDEX_API_KEY, null) != null)
|
||||
if (sharedpreferences.getString(SET_YANDEX_API_KEY, null) != null)
|
||||
your_api_key.setText(sharedpreferences.getString(SET_YANDEX_API_KEY, null));
|
||||
break;
|
||||
case 2:
|
||||
|
@ -919,6 +932,8 @@ public class SettingsFragment extends Fragment {
|
|||
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
|
||||
startActivity(intent);
|
||||
}
|
||||
count3++;
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
|
@ -935,10 +950,13 @@ public class SettingsFragment extends Fragment {
|
|||
resize_layout_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if( count4 > 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putInt(Helper.SET_PICTURE_RESIZE, position);
|
||||
editor.apply();
|
||||
}
|
||||
count4++;
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue