From 4705332a9a658ebd20d0f1e9080c18b76934f591 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 24 Jan 2018 13:13:18 +0900 Subject: [PATCH] Fix usage reporting dialog setting wrong version (fixes #1003) --- .../syncthingandroid/activities/MainActivity.java | 14 +++++++++----- .../activities/SettingsActivity.java | 12 ++++++++---- .../nutomic/syncthingandroid/model/Options.java | 3 +-- .../nutomic/syncthingandroid/model/SystemInfo.java | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index 526cc3fb..51109185 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -108,10 +108,12 @@ public class MainActivity extends StateDialogActivity showBatteryOptimizationDialogIfNecessary(); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); mDrawerFragment.requestGuiUpdate(); - if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY && - getApi().getOptions().isUsageReportingAccepted()) { - showUsageReportingDialog(); - } + getApi().getSystemInfo(systemInfo -> { + if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY && + !getApi().getOptions().isUsageReportingAccepted(systemInfo.urVersionMax)) { + showUsageReportingDialog(); + } + }); break; case ERROR: finish(); @@ -452,7 +454,9 @@ public class MainActivity extends StateDialogActivity Options options = getApi().getOptions(); switch (which) { case DialogInterface.BUTTON_POSITIVE: - options.urAccepted = options.urVersionMax; + getApi().getSystemInfo(systemInfo -> { + options.urAccepted = systemInfo.urVersionMax; + }); break; case DialogInterface.BUTTON_NEGATIVE: options.urAccepted = Options.USAGE_REPORTING_DENIED; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index a3d8ec84..39a4c6c6 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -239,7 +239,8 @@ public class SettingsActivity extends SyncthingActivity { mRelaysEnabled.setChecked(mOptions.relaysEnabled); mGlobalAnnounceServers.setText(joiner.join(mOptions.globalAnnounceServers)); mAddress.setText(mGui.address); - mUrAccepted.setChecked(mOptions.isUsageReportingAccepted()); + mApi.getSystemInfo(systemInfo -> + mUrAccepted.setChecked(mOptions.isUsageReportingAccepted(systemInfo.urVersionMax))); } @Override @@ -281,9 +282,12 @@ public class SettingsActivity extends SyncthingActivity { break; case "address": mGui.address = (String) o; break; case "urAccepted": - mOptions.urAccepted = ((boolean) o) - ? mOptions.urVersionMax - : Options.USAGE_REPORTING_DENIED; + mApi.getSystemInfo(systemInfo -> { + mOptions.urAccepted = ((boolean) o) + ? systemInfo.urVersionMax + : Options.USAGE_REPORTING_DENIED; + mApi.editSettings(mGui, mOptions, getActivity()); + }); break; default: throw new InvalidParameterException(); } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java b/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java index b4131310..659fb1ea 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/model/Options.java @@ -18,7 +18,6 @@ public class Options { public int natRenewalMinutes; public int natTimeoutSeconds; public int urAccepted; - public int urVersionMax; public String urUniqueId; public String urURL; public boolean urPostInsecurely; @@ -39,7 +38,7 @@ public class Options { public static final int USAGE_REPORTING_UNDECIDED = 0; public static final int USAGE_REPORTING_DENIED = -1; - public boolean isUsageReportingAccepted() { + public boolean isUsageReportingAccepted(int urVersionMax) { return urAccepted == urVersionMax; } } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/model/SystemInfo.java b/app/src/main/java/com/nutomic/syncthingandroid/model/SystemInfo.java index 909b7e29..9bb085d8 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/model/SystemInfo.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/model/SystemInfo.java @@ -11,4 +11,5 @@ public class SystemInfo { public boolean discoveryEnabled; public int discoveryMethods; public Map discoveryErrors; + public int urVersionMax; }