Skip to content

Commit

Permalink
Simplifying profile updating in ToxService
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Apr 4, 2014
1 parent a425fa1 commit cf9df6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@ public void updateSettings(View view) {
if (!nameHintText.getText().toString().equals(getString(R.id.settings_name_hint))) {
editor.putString("saved_name_hint", nameHintText.getText().toString());
UserDetails.username = nameHintText.getText().toString();
updatedSettings[0] = nameHintText.getText().toString();
}

if (!noteHintText.getText().toString().equals(getString(R.id.settings_note_hint))) {
editor.putString("saved_note_hint", noteHintText.getText().toString());
UserDetails.note = noteHintText.getText().toString();
updatedSettings[2] = noteHintText.getText().toString();
}
editor.putString("saved_status_hint", statusSpinner.getSelectedItem().toString());
if (statusSpinner.getSelectedItem().toString().equals("Online"))
Expand All @@ -211,14 +209,11 @@ public void updateSettings(View view) {
if (statusSpinner.getSelectedItem().toString().equals("Busy"))
UserDetails.status = ToxUserStatus.TOX_USERSTATUS_BUSY;

updatedSettings[1] = statusSpinner.getSelectedItem().toString();

editor.commit();

/* Send an intent to ToxService notifying change of settings */
Intent updateSettings = new Intent(this, ToxService.class);
updateSettings.setAction(Constants.UPDATE_SETTINGS);
updateSettings.putExtra("newSettings", updatedSettings);
this.startService(updateSettings);

Context context = getApplicationContext();
Expand Down
21 changes: 4 additions & 17 deletions app/src/main/java/im/tox/antox/tox/ToxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import im.tox.antox.activities.MainActivity;
import im.tox.antox.callbacks.AntoxOnFriendRequestCallback;
import im.tox.antox.callbacks.AntoxOnMessageCallback;
import im.tox.antox.utils.UserDetails;
import im.tox.jtoxcore.FriendExistsException;
import im.tox.jtoxcore.ToxException;
import im.tox.jtoxcore.ToxFriend;
Expand Down Expand Up @@ -66,24 +67,10 @@ protected void onHandleIntent(Intent intent) {
break;

case Constants.UPDATE_SETTINGS:
String[] newSettings = intent.getStringArrayExtra("newSettings");

/* If not empty, update the users settings which is passed in intent from SettingsActivity */
try {
if (!newSettings[0].equals(""))
toxSingleton.jTox.setName(newSettings[0]);

if (!newSettings[1].equals("")) {
if (newSettings[1].equals("Away"))
toxSingleton.jTox.setUserStatus(ToxUserStatus.TOX_USERSTATUS_AWAY);
else if (newSettings[1].equals("Busy"))
toxSingleton.jTox.setUserStatus(ToxUserStatus.TOX_USERSTATUS_BUSY);
else
toxSingleton.jTox.setUserStatus(ToxUserStatus.TOX_USERSTATUS_NONE);
}

if (!newSettings[2].equals(""))
toxSingleton.jTox.setStatusMessage(newSettings[2]);
toxSingleton.jTox.setName(UserDetails.username);
toxSingleton.jTox.setUserStatus(UserDetails.status);
toxSingleton.jTox.setStatusMessage(UserDetails.note);
} catch (ToxException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit cf9df6d

Please sign in to comment.