Fix #2203: Require number of uploads not to have decimal (#2615)

This commit is contained in:
Adam Jones 2019-03-17 16:54:55 +00:00 committed by GitHub
parent 0b25730a18
commit 3b7b6f91a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 40 deletions

View file

@ -42,6 +42,10 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
private static final ContentValues[] EMPTY = {};
private static int COMMIT_THRESHOLD = 10;
// Arbitrary limit to cap the number of contributions to ever load. This is a maximum built
// into the app, rather than the user's setting. Also see Github issue #52.
public static final int ABSOLUTE_CONTRIBUTIONS_LOAD_LIMIT = 500;
@SuppressWarnings("WeakerAccess")
@Inject MediaWikiApi mwApi;
@Inject
@ -52,13 +56,6 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
super(context, autoInitialize);
}
private int getLimit() {
int limit = 500;
Timber.d("Max number of uploads set to %d", limit);
return limit; // FIXME: Parameterize!
}
private boolean fileExists(ContentProviderClient client, String filename) {
if (filename == null) {
return false;
@ -100,7 +97,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
while (!done) {
try {
result = mwApi.logEvents(user, lastModified, queryContinue, getLimit());
result = mwApi.logEvents(user, lastModified, queryContinue, ABSOLUTE_CONTRIBUTIONS_LOAD_LIMIT);
} catch (IOException e) {
// There isn't really much we can do, eh?
// FIXME: Perhaps add EventLogging?

View file

@ -61,9 +61,9 @@ public class SettingsFragment extends PreferenceFragment {
});
final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads");
int uploads = defaultKvStore.getInt(Prefs.UPLOADS_SHOWING, 100);
uploadLimit.setText(uploads + "");
uploadLimit.setSummary(uploads + "");
int currentUploadLimit = defaultKvStore.getInt(Prefs.UPLOADS_SHOWING, 100);
uploadLimit.setText(Integer.toString(currentUploadLimit));
uploadLimit.setSummary(Integer.toString(currentUploadLimit));
uploadLimit.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -76,36 +76,25 @@ public class SettingsFragment extends PreferenceFragment {
@Override
public void afterTextChanged(Editable s) {
int value;
if (s.length()>0)
try {
value = Integer.parseInt(s.toString());
if (value > 500) {
uploadLimit.getEditText().setError(getString((R.string.maximum_limit_alert)));
defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 500);
defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(500 + "");
uploadLimit.setText(500 + "");
} else if (value == 0) {
uploadLimit.getEditText().setError(getString(R.string.cannot_be_zero));
defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 100);
defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(100 + "");
uploadLimit.setText(100 + "");
} else {
defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, value);
defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(String.valueOf(value));
}
} catch (Exception e) {
uploadLimit.getEditText().setError(getString(R.string.enter_valid));
defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, 100);
defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(100 + "");
uploadLimit.setText(100 + "");
if (s.length() == 0) return;
int value = Integer.parseInt(s.toString());
if (value > 500) {
uploadLimit.getEditText().setError(getString(R.string.maximum_limit_alert));
value = 500;
} else if (value == 0) {
uploadLimit.getEditText().setError(getString(R.string.cannot_be_zero));
value = 100;
}
defaultKvStore.putInt(Prefs.UPLOADS_SHOWING, value);
defaultKvStore.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setText(Integer.toString(value));
uploadLimit.setSummary(Integer.toString(value));
}
});
Preference betaTesterPreference = findPreference("becomeBetaTester");
betaTesterPreference.setOnPreferenceClickListener(preference -> {
Utils.handleWebUrl(getActivity(), Uri.parse(getResources().getString(R.string.beta_opt_in_link)));

View file

@ -192,7 +192,7 @@
<string name="maximum_limit_alert">Unable to display more than 500</string>
<string name="enter_valid">Enter a valid number</string>
<string name="cannot_be_zero">Upload limit cannot be 0</string>
<string name="set_limit">Set Recent Upload Limit</string>
<string name="set_limit">Recent upload limit</string>
<string name="login_failed_2fa_not_supported">Two factor authentication is currently not supported.</string>
<string name="logout_verification">Do you really want to logout?</string>
<string name="commons_logo">Commons Logo</string>

View file

@ -26,7 +26,7 @@
android:key="uploads"
android:defaultValue="100"
android:title= "@string/set_limit"
android:inputType="numberDecimal"
android:inputType="number"
android:maxLength="3" />
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleSwitchPreference