1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-09 11:41:29 +00:00

Properly dismiss usage reporting dialog on orientation change (fixes #184) (#186)

* Add RestApi#isUsageReportingAccepted (fixes #184)

* Add verbose log when usage report question dialog triggers (fixes #184)

* Remove asynchronous requests to determine if user opted-in to usage reporting (fixes #184)

* Check if the config is loaded before evaluating current ur user wish

* Properly dismiss mUsageReportingDialog on orientation change (fixes #184)

- Consolidate createRestartDialog into showRestartDialog
- Remove unused var mBatteryOptimizationsDialog
This commit is contained in:
Catfriend1 2019-01-03 18:37:01 +01:00 committed by GitHub
parent 27e98b675b
commit 8a2fe3ceec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 16 deletions

View file

@ -83,8 +83,8 @@ public class MainActivity extends SyncthingActivity
*/ */
private static final long USAGE_REPORTING_DIALOG_DELAY = TimeUnit.DAYS.toMillis(3); private static final long USAGE_REPORTING_DIALOG_DELAY = TimeUnit.DAYS.toMillis(3);
private AlertDialog mBatteryOptimizationsDialog;
private AlertDialog mQrCodeDialog; private AlertDialog mQrCodeDialog;
private AlertDialog mUsageReportingDialog;
private Dialog mRestartDialog; private Dialog mRestartDialog;
private SyncthingService.State mSyncthingServiceState = SyncthingService.State.INIT; private SyncthingService.State mSyncthingServiceState = SyncthingService.State.INIT;
@ -121,7 +121,7 @@ public class MainActivity extends SyncthingActivity
// Check if the usage reporting minimum delay passed by. // Check if the usage reporting minimum delay passed by.
Boolean usageReportingDelayPassed = (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY); Boolean usageReportingDelayPassed = (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY);
RestApi restApi = getApi(); RestApi restApi = getApi();
if (usageReportingDelayPassed && restApi != null && !restApi.isUsageReportingDecided()) { if (usageReportingDelayPassed && restApi != null && restApi.isConfigLoaded() && !restApi.isUsageReportingDecided()) {
showUsageReportingDialog(restApi); showUsageReportingDialog(restApi);
} }
break; break;
@ -350,6 +350,7 @@ public class MainActivity extends SyncthingActivity
outState.putString(DEVICEID_KEY, deviceID.getText().toString()); outState.putString(DEVICEID_KEY, deviceID.getText().toString());
} }
Util.dismissDialogSafe(mRestartDialog, this); Util.dismissDialogSafe(mRestartDialog, this);
Util.dismissDialogSafe(mUsageReportingDialog, this);
} }
@Override @Override
@ -371,17 +372,13 @@ public class MainActivity extends SyncthingActivity
} }
public void showRestartDialog(){ public void showRestartDialog(){
mRestartDialog = createRestartDialog(); mRestartDialog = new AlertDialog.Builder(this)
mRestartDialog.show();
}
private Dialog createRestartDialog(){
return new AlertDialog.Builder(this)
.setMessage(R.string.dialog_confirm_restart) .setMessage(R.string.dialog_confirm_restart)
.setPositiveButton(android.R.string.yes, (dialogInterface, i1) -> this.startService(new Intent(this, SyncthingService.class) .setPositiveButton(android.R.string.yes, (dialogInterface, i1) -> this.startService(new Intent(this, SyncthingService.class)
.setAction(SyncthingService.ACTION_RESTART))) .setAction(SyncthingService.ACTION_RESTART)))
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.create(); .create();
mRestartDialog.show();
} }
public void showQrCodeDialog(String deviceId, Bitmap qrCode) { public void showQrCodeDialog(String deviceId, Bitmap qrCode) {
@ -492,6 +489,7 @@ public class MainActivity extends SyncthingActivity
* Displays dialog asking user to accept/deny usage reporting. * Displays dialog asking user to accept/deny usage reporting.
*/ */
private void showUsageReportingDialog(RestApi restApi) { private void showUsageReportingDialog(RestApi restApi) {
Log.v(TAG, "showUsageReportingDialog triggered.");
final DialogInterface.OnClickListener listener = (dialog, which) -> { final DialogInterface.OnClickListener listener = (dialog, which) -> {
try { try {
switch (which) { switch (which) {
@ -519,7 +517,8 @@ public class MainActivity extends SyncthingActivity
.inflate(R.layout.dialog_usage_reporting, null); .inflate(R.layout.dialog_usage_reporting, null);
TextView tv = v.findViewById(R.id.example); TextView tv = v.findViewById(R.id.example);
tv.setText(report); tv.setText(report);
new AlertDialog.Builder(MainActivity.this) Util.dismissDialogSafe(mUsageReportingDialog, MainActivity.this);
mUsageReportingDialog = new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.usage_reporting_dialog_title) .setTitle(R.string.usage_reporting_dialog_title)
.setView(v) .setView(v)
.setPositiveButton(R.string.yes, listener) .setPositiveButton(R.string.yes, listener)

View file

@ -388,8 +388,7 @@ public class SettingsActivity extends SyncthingActivity {
} }
mRestartOnWakeup.setChecked(mOptions.restartOnWakeup); mRestartOnWakeup.setChecked(mOptions.restartOnWakeup);
mRestApi.getSystemStatus(systemStatus -> mUrAccepted.setChecked(mRestApi.isUsageReportingAccepted());
mUrAccepted.setChecked(mOptions.isUsageReportingAccepted(systemStatus.urVersionMax)));
} }
@Override @Override
@ -504,11 +503,8 @@ public class SettingsActivity extends SyncthingActivity {
mOptions.restartOnWakeup = (boolean) o; mOptions.restartOnWakeup = (boolean) o;
break; break;
case "urAccepted": case "urAccepted":
mRestApi.getSystemStatus(systemStatus -> { mRestApi.setUsageReporting((boolean) o);
mOptions.urAccepted = ((boolean) o) mOptions = mRestApi.getOptions();
? systemStatus.urVersionMax
: Options.USAGE_REPORTING_DENIED;
});
break; break;
default: throw new InvalidParameterException(); default: throw new InvalidParameterException();
} }

View file

@ -784,6 +784,15 @@ public class RestApi {
return mUrl; return mUrl;
} }
public Boolean isUsageReportingAccepted() {
Options options = getOptions();
if (options == null) {
Log.e(TAG, "isUsageReportingAccepted called while options == null");
return false;
}
return options.isUsageReportingAccepted(mUrVersionMax);
}
public Boolean isUsageReportingDecided() { public Boolean isUsageReportingDecided() {
Options options = getOptions(); Options options = getOptions();
if (options == null) { if (options == null) {