mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 14:21:16 +00:00
Use integer constants for usage reporting.
This commit is contained in:
parent
b75f025238
commit
09bba7140a
3 changed files with 28 additions and 30 deletions
|
@ -114,7 +114,7 @@ public class MainActivity extends SyncthingActivity
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||||
mDrawerFragment.requestGuiUpdate();
|
mDrawerFragment.requestGuiUpdate();
|
||||||
if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY &&
|
if (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY &&
|
||||||
getApi().getUsageReportAccepted() == RestApi.UsageReportSetting.UNDECIDED) {
|
getApi().getUsageReportAccepted() == RestApi.USAGE_REPORTING_UNDECIDED) {
|
||||||
showUsageReportingDialog();
|
showUsageReportingDialog();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -422,11 +422,11 @@ public class MainActivity extends SyncthingActivity
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
getApi().setUsageReportAccepted(RestApi.UsageReportSetting.ACCEPTED,
|
getApi().setUsageReportAccepted(RestApi.USAGE_REPORTING_ACCEPTED,
|
||||||
MainActivity.this);
|
MainActivity.this);
|
||||||
break;
|
break;
|
||||||
case DialogInterface.BUTTON_NEGATIVE:
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
getApi().setUsageReportAccepted(RestApi.UsageReportSetting.DENIED,
|
getApi().setUsageReportAccepted(RestApi.USAGE_REPORTING_DENIED,
|
||||||
MainActivity.this);
|
MainActivity.this);
|
||||||
break;
|
break;
|
||||||
case DialogInterface.BUTTON_NEUTRAL:
|
case DialogInterface.BUTTON_NEUTRAL:
|
||||||
|
|
|
@ -84,8 +84,8 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
value = api.getLocalDevice().name;
|
value = api.getLocalDevice().name;
|
||||||
break;
|
break;
|
||||||
case USAGE_REPORT_ACCEPTED:
|
case USAGE_REPORT_ACCEPTED:
|
||||||
RestApi.UsageReportSetting setting = api.getUsageReportAccepted();
|
int setting = api.getUsageReportAccepted();
|
||||||
value = Boolean.toString(setting == RestApi.UsageReportSetting.ACCEPTED);
|
value = Boolean.toString(setting == RestApi.USAGE_REPORTING_ACCEPTED);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = api.getValue(RestApi.TYPE_OPTIONS, pref.getKey());
|
value = api.getValue(RestApi.TYPE_OPTIONS, pref.getKey());
|
||||||
|
@ -272,9 +272,9 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
updated.name = (String) o;
|
updated.name = (String) o;
|
||||||
mSyncthingService.getApi().editDevice(updated, getActivity(), null);
|
mSyncthingService.getApi().editDevice(updated, getActivity(), null);
|
||||||
} else if (preference.getKey().equals(USAGE_REPORT_ACCEPTED)) {
|
} else if (preference.getKey().equals(USAGE_REPORT_ACCEPTED)) {
|
||||||
RestApi.UsageReportSetting setting = ((Boolean) o)
|
int setting = ((Boolean) o)
|
||||||
? RestApi.UsageReportSetting.ACCEPTED
|
? RestApi.USAGE_REPORTING_ACCEPTED
|
||||||
: RestApi.UsageReportSetting.DENIED;
|
: RestApi.USAGE_REPORTING_DENIED;
|
||||||
mSyncthingService.getApi().setUsageReportAccepted(setting, getActivity());
|
mSyncthingService.getApi().setUsageReportAccepted(setting, getActivity());
|
||||||
} else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
|
} else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
|
||||||
boolean isArray = preference.getKey().equals("listenAddress") ||
|
boolean isArray = preference.getKey().equals("listenAddress") ||
|
||||||
|
|
|
@ -58,6 +58,12 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
*/
|
*/
|
||||||
public static final String TOTAL_STATS = "total";
|
public static final String TOTAL_STATS = "total";
|
||||||
|
|
||||||
|
public static final int USAGE_REPORTING_UNDECIDED = 0;
|
||||||
|
public static final int USAGE_REPORTING_ACCEPTED = 2;
|
||||||
|
public static final int USAGE_REPORTING_DENIED = -1;
|
||||||
|
private static final List<Integer> USAGE_REPORTING_DECIDED =
|
||||||
|
Arrays.asList(USAGE_REPORTING_ACCEPTED, USAGE_REPORTING_DENIED);
|
||||||
|
|
||||||
public static class Device implements Serializable {
|
public static class Device implements Serializable {
|
||||||
public List<String> addresses;
|
public List<String> addresses;
|
||||||
public String name;
|
public String name;
|
||||||
|
@ -1025,41 +1031,33 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
return mGuiPassword;
|
return mGuiPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum UsageReportSetting {
|
|
||||||
UNDECIDED,
|
|
||||||
ACCEPTED,
|
|
||||||
DENIED,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns value of usage reporting preference.
|
* Returns value of usage reporting preference.
|
||||||
*/
|
*/
|
||||||
public UsageReportSetting getUsageReportAccepted() {
|
public int getUsageReportAccepted() {
|
||||||
try {
|
try {
|
||||||
switch (mConfig.getJSONObject(TYPE_OPTIONS).getInt("urAccepted")) {
|
int value = mConfig.getJSONObject(TYPE_OPTIONS).getInt("urAccepted");
|
||||||
case 0: return UsageReportSetting.UNDECIDED;
|
if (value > USAGE_REPORTING_ACCEPTED)
|
||||||
case 1: return UsageReportSetting.UNDECIDED;
|
throw new RuntimeException("Inalid usage reporting value");
|
||||||
case 2: return UsageReportSetting.ACCEPTED;
|
if (!USAGE_REPORTING_DECIDED.contains(value))
|
||||||
case -1: return UsageReportSetting.DENIED;
|
value = USAGE_REPORTING_UNDECIDED;
|
||||||
default: throw new RuntimeException("Invalid usage report value");
|
|
||||||
}
|
return value;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to read usage report value", e);
|
Log.w(TAG, "Failed to read usage report value", e);
|
||||||
return UsageReportSetting.DENIED;
|
return USAGE_REPORTING_DENIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets new value for usage reporting preference.
|
* Sets new value for usage reporting preference.
|
||||||
*/
|
*/
|
||||||
public void setUsageReportAccepted(UsageReportSetting value, Activity activity) {
|
public void setUsageReportAccepted(int value, Activity activity) {
|
||||||
int v = 0;
|
if (BuildConfig.DEBUG && !USAGE_REPORTING_DECIDED.contains(value))
|
||||||
switch (value) {
|
throw new IllegalArgumentException("Invalid value for usage report");
|
||||||
case ACCEPTED: v = 2; break;
|
|
||||||
case DENIED: v = -1; break;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
mConfig.getJSONObject(TYPE_OPTIONS).put("urAccepted", v);
|
mConfig.getJSONObject(TYPE_OPTIONS).put("urAccepted", value);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to set usage report value", e);
|
Log.w(TAG, "Failed to set usage report value", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue