Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 1fd130d

Browse files
committed
Save apikey, server to sharedPreferences while login
1 parent 74b7344 commit 1fd130d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ public SharedPreferences getSettings() {
341341
public Person getYou() {
342342
return you;
343343
}
344+
public void saveServerName(String serverName) {
345+
String username=null;
346+
try {
347+
username = you.getEmail();
348+
} catch (Exception e) {
349+
//SQL Exception can occur if name is not updated!
350+
ZLog.logException(e);
351+
}
352+
Editor globalEditor = this.globalSettings.edit();
353+
serverStringSet.add((username != null) ? serverName + " - " + username : serverName);
354+
globalEditor.putStringSet(GLOBAL_SETTINGS_REALMS, new HashSet<String>(serverStringSet));
355+
globalEditor.apply();
356+
}
344357
public void createNewRealm() {
345358
SharedPreferences.Editor editor = this.globalSettings.edit();
346359
currentRealm = serverStringSet.size();

app/src/main/java/com/zulip/android/networking/AsyncLogin.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ protected void onPostExecute(String result) {
5151
JSONObject obj = new JSONObject(result);
5252

5353
if (obj.getString("result").equals("success")) {
54-
this.app.setLoggedInApiKey(obj.getString("api_key"));
55-
this.context.openHome();
56-
callback.onTaskComplete(result, obj);
57-
54+
if (startedFromAddRealm) {
55+
} else {
56+
this.app.setServerURL(serverURL);
57+
this.app.setLoggedInApiKey(obj.getString("api_key"));
58+
ZulipApp.get().saveServerName(realmName);
59+
this.context.openHome();
60+
}
5861
return;
5962
}
6063
} catch (JSONException e) {

0 commit comments

Comments
 (0)