Skip to content

Commit

Permalink
Now auto generates a new nospam instead of asking for one
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Sep 23, 2014
1 parent 027b70d commit 55ad0bf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
47 changes: 22 additions & 25 deletions app/src/main/java/im/tox/antox/fragments/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void onCreate(Bundle savedInstanceState) {
bindPreferenceSummaryToValue(findPreference("status_message"));
bindPreferenceSummaryToValue(findPreference("language"));
bindPreferenceSummaryToValue(findPreference("tox_id"));
bindPreferenceSummaryToValue(findPreference("nospam"));
bindPreferenceSummaryToValue(findPreference("active_account"));

/* Override the Tox ID click functionality to display a dialog with the qr image
Expand Down Expand Up @@ -115,6 +114,28 @@ public boolean onPreferenceClick(Preference preference) {
return true;
}
});

Preference nospamPreference = (Preference) findPreference("nospam");
nospamPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
ToxSingleton toxSingleton = ToxSingleton.getInstance();
try {
Random random = new Random();
int nospam = random.nextInt(1234567890);
toxSingleton.jTox.setNospam(nospam);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("tox_id", toxSingleton.jTox.getAddress());
editor.commit();
bindPreferenceSummaryToValue(findPreference("tox_id"));
} catch (ToxException e) {
e.printStackTrace();
}

return true;
}
});
}

/**
Expand Down Expand Up @@ -227,30 +248,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
db.updateUserDetail(sharedPreferences.getString("active_account", ""), "status_message", sharedPreferences.getString(key, ""));
}

if (key.equals("nospam")) {
ToxSingleton toxSingleton = ToxSingleton.getInstance();
try {
String nospamString = sharedPreferences.getString("nospam", "");
int nospam;
// Check if they entered an empty nospam
if (!nospamString.equals("")) {
nospam = Integer.parseInt(sharedPreferences.getString("nospam", ""));
} else {
Random random = new Random();
nospam = random.nextInt(1000);
}

toxSingleton.jTox.setNospam(nospam);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("tox_id", toxSingleton.jTox.getAddress());
editor.commit();
bindPreferenceSummaryToValue(findPreference("tox_id"));

} catch (ToxException e) {
e.printStackTrace();
}
}

if (key.equals("enable_udp")) {
ToxSingleton toxSingleton = ToxSingleton.getInstance();

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@
<!-- Advanced strings -->
<string name="pref_udp">Enable UDP</string>
<string name="pref_advanced">Advanced</string>
<string name="pref_nospam">Nospam</string>
<string name="pref_nospam">Generate New Nospam</string>

</resources>
9 changes: 2 additions & 7 deletions app/src/main/res/xml/pref_other.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@
android:title="@string/pref_udp"
android:defaultValue="false" />

<EditTextPreference
<Preference
android:key="nospam"
android:title="@string/pref_nospam"
android:defaultValue=""
android:numeric="integer"
android:inputType="number"
android:singleLine="true"
android:maxLines="1" />
android:title="@string/pref_nospam" />

<Preference
android:key="tox_id"
Expand Down

0 comments on commit 55ad0bf

Please sign in to comment.