mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 08:11:17 +00:00
Catch invalid input numbers (fixes #324).
This commit is contained in:
parent
46d914bc1e
commit
396a46ad12
2 changed files with 37 additions and 19 deletions
|
@ -10,6 +10,7 @@ import android.preference.EditTextPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.support.v4.preference.PreferenceFragment;
|
import android.support.v4.preference.PreferenceFragment;
|
||||||
|
import android.text.InputType;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -241,6 +242,15 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||||
if (preference instanceof EditTextPreference) {
|
if (preference instanceof EditTextPreference) {
|
||||||
EditTextPreference pref = (EditTextPreference) preference;
|
EditTextPreference pref = (EditTextPreference) preference;
|
||||||
|
if ((pref.getEditText().getInputType() & InputType.TYPE_CLASS_NUMBER) > 0) {
|
||||||
|
try {
|
||||||
|
o = Integer.parseInt((String) o);
|
||||||
|
o = o.toString();
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.w(TAG, "Invalid number: " + o);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
pref.setSummary((String) o);
|
pref.setSummary((String) o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,10 +263,15 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mRescanInterval)) {
|
} else if (preference.equals(mRescanInterval)) {
|
||||||
|
try {
|
||||||
mFolder.RescanIntervalS = Integer.parseInt((String) o);
|
mFolder.RescanIntervalS = Integer.parseInt((String) o);
|
||||||
mRescanInterval.setSummary((String) o);
|
mRescanInterval.setSummary((String) o);
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.w(TAG, "Invalid rescan interval: "+ o);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} else if (preference.equals(mFolderMaster)) {
|
} else if (preference.equals(mFolderMaster)) {
|
||||||
mFolder.ReadOnly = (Boolean) o;
|
mFolder.ReadOnly = (Boolean) o;
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
|
@ -291,10 +306,14 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mVersioningKeep)) {
|
} else if (preference.equals(mVersioningKeep)) {
|
||||||
|
try {
|
||||||
((RestApi.SimpleVersioning) mFolder.Versioning)
|
((RestApi.SimpleVersioning) mFolder.Versioning)
|
||||||
.setParams(Integer.parseInt((String) o));
|
.setParams(Integer.parseInt((String) o));
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.w(TAG, "Invalid versioning option: "+ o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -172,11 +172,18 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||||
// Convert new value to integer if input type is number.
|
// Convert new value to integer if input type is number.
|
||||||
if (preference instanceof EditTextPreference) {
|
if (preference instanceof EditTextPreference) {
|
||||||
EditTextPreference etp = (EditTextPreference) preference;
|
EditTextPreference pref = (EditTextPreference) preference;
|
||||||
if (etp.getEditText().getInputType() == InputType.TYPE_CLASS_NUMBER) {
|
if ((pref.getEditText().getInputType() & InputType.TYPE_CLASS_NUMBER) > 0) {
|
||||||
|
try {
|
||||||
o = Integer.parseInt((String) o);
|
o = Integer.parseInt((String) o);
|
||||||
|
o = o.toString();
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.w(TAG, "Invalid number: " + o);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pref.setSummary((String) o);
|
||||||
|
}
|
||||||
|
|
||||||
if (preference.equals(mSyncOnlyCharging) || preference.equals(mSyncOnlyWifi)) {
|
if (preference.equals(mSyncOnlyCharging) || preference.equals(mSyncOnlyWifi)) {
|
||||||
mSyncthingService.updateState();
|
mSyncthingService.updateState();
|
||||||
|
@ -216,14 +223,6 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
((SyncthingActivity) getActivity()).getApi().requireRestart(getActivity());
|
((SyncthingActivity) getActivity()).getApi().requireRestart(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the preference value as summary.
|
|
||||||
if (preference instanceof EditTextPreference) {
|
|
||||||
String value = (o instanceof String)
|
|
||||||
? (String) o
|
|
||||||
: Integer.toString((Integer) o);
|
|
||||||
preference.setSummary(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue