Skip to content
Snippets Groups Projects
Unverified Commit b3f27483 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

settings: do not saveSettings if already refreshing

If a settings is set when mIsRefreshingViewFromPresenter is true,
the modified settings can blink, causing an infinite loop which
cause a crash.

Change-Id: I4f64f6c36ec626a81a9b1f3d341e6e2c792282ce
Gitlab: #624
parent 50273c71
No related branches found
No related tags found
No related merge requests found
...@@ -61,10 +61,6 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp ...@@ -61,10 +61,6 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp
ViewGroup mGroupPushNotifications; ViewGroup mGroupPushNotifications;
@BindView(R.id.settings_push_notifications) @BindView(R.id.settings_push_notifications)
Switch mViewPushNotifications; Switch mViewPushNotifications;
/*@BindView(R.id.settings_contacts)
Switch mViewContacts;
@BindView(R.id.settings_place_call)
Switch mViewPlaceCall;*/
@BindView(R.id.settings_startup) @BindView(R.id.settings_startup)
Switch mViewStartup; Switch mViewStartup;
@BindView(R.id.settings_persistNotification) @BindView(R.id.settings_persistNotification)
...@@ -116,57 +112,17 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp ...@@ -116,57 +112,17 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp
@OnCheckedChanged({ @OnCheckedChanged({
R.id.settings_push_notifications, R.id.settings_push_notifications,
/*R.id.settings_contacts,
R.id.settings_place_call,*/
R.id.settings_startup, R.id.settings_startup,
R.id.settings_persistNotification R.id.settings_persistNotification
}) })
public void onSettingsCheckedChanged(CompoundButton button, boolean isChecked) { public void onSettingsCheckedChanged(CompoundButton button, boolean isChecked) {
saveSettings(); if (!mIsRefreshingViewFromPresenter)
/*String neededPermission = null;
if (isChecked) {
switch (button.getId()) {
case R.id.settings_contacts:
neededPermission = Manifest.permission.READ_CONTACTS;
break;
case R.id.settings_place_call:
neededPermission = Manifest.permission.WRITE_CALL_LOG;
break;
default:
neededPermission = null;
break;
}
}
// No specific permission needed but we known that user as triggered un settings change
if (TextUtils.isEmpty(neededPermission) && !mIsRefreshingViewFromPresenter) {
saveSettings(); saveSettings();
return;
}
// Some specific permissions are required, we must check for them
if (!TextUtils.isEmpty(neededPermission)) {
if (ContextCompat.checkSelfPermission(getActivity(), neededPermission) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//~ Ask permission to use the contacts of the device
if (((RingApplication) getActivity().getApplication()).canAskForPermission(neededPermission)) {
requestPermissions(new String[]{neededPermission}, RingApplication.PERMISSIONS_REQUEST);
}
}
} else if (!mIsRefreshingViewFromPresenter) {
// permission is already granted
saveSettings();
}
}*/
} }
private void saveSettings() { private void saveSettings() {
Settings newSettings = new Settings(); Settings newSettings = new Settings();
/*newSettings.setAllowSystemContacts(mViewContacts.isChecked());
newSettings.setAllowPlaceSystemCalls(mViewPlaceCall.isChecked());*/
newSettings.setAllowRingOnStartup(mViewStartup.isChecked()); newSettings.setAllowRingOnStartup(mViewStartup.isChecked());
newSettings.setAllowPushNotifications(mViewPushNotifications.isChecked()); newSettings.setAllowPushNotifications(mViewPushNotifications.isChecked());
newSettings.setAllowPersistentNotification(mViewPersistNotif.isChecked()); newSettings.setAllowPersistentNotification(mViewPersistNotif.isChecked());
...@@ -189,10 +145,8 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp ...@@ -189,10 +145,8 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp
.setTitle(getString(R.string.clear_history_dialog_title)) .setTitle(getString(R.string.clear_history_dialog_title))
.setMessage(getString(R.string.clear_history_dialog_message)) .setMessage(getString(R.string.clear_history_dialog_message))
.setPositiveButton(android.R.string.ok, (dialog, id) -> { .setPositiveButton(android.R.string.ok, (dialog, id) -> {
// ask the presenter to clear history // ask the presenter to clear history
presenter.clearHistory(); presenter.clearHistory();
Snackbar.make(getView(), Snackbar.make(getView(),
getString(R.string.clear_history_completed), getString(R.string.clear_history_completed),
Snackbar.LENGTH_SHORT).show(); Snackbar.LENGTH_SHORT).show();
...@@ -203,33 +157,6 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp ...@@ -203,33 +157,6 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp
.show(); .show();
} }
/*
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[],
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
for (int i = 0, n = permissions.length; i < n; ++i) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
String permission = permissions[i];
((RingApplication) getActivity().getApplication()).permissionHasBeenAsked(permission);
switch (permission) {
case Manifest.permission.READ_CONTACTS:
mViewContacts.setChecked(false);
presentReadContactPermissionExplanationToast();
break;
case Manifest.permission.WRITE_CALL_LOG:
mViewPlaceCall.setChecked(false);
presentWriteCallLogPermissionExplanationToast();
break;
}
}
}
saveSettings();
}
*/
/** /**
* Presents a Toast explaining why the Read Contacts permission is required to display the devi- * Presents a Toast explaining why the Read Contacts permission is required to display the devi-
* ces contacts in Ring. * ces contacts in Ring.
...@@ -259,8 +186,6 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp ...@@ -259,8 +186,6 @@ public class SettingsFragment extends BaseSupportFragment<SettingsPresenter> imp
mIsRefreshingViewFromPresenter = true; mIsRefreshingViewFromPresenter = true;
mViewPushNotifications.setChecked(viewModel.isAllowPushNotifications()); mViewPushNotifications.setChecked(viewModel.isAllowPushNotifications());
mViewPersistNotif.setChecked(viewModel.isAllowPersistentNotification()); mViewPersistNotif.setChecked(viewModel.isAllowPersistentNotification());
/*mViewContacts.setChecked(viewModel.isAllowSystemContacts());
mViewPlaceCall.setChecked(viewModel.isAllowPlaceSystemCalls());*/
mViewStartup.setChecked(viewModel.isAllowRingOnStartup()); mViewStartup.setChecked(viewModel.isAllowRingOnStartup());
mIsRefreshingViewFromPresenter = false; mIsRefreshingViewFromPresenter = false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment