Commit a8f5de0f authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add remove hostname method to cache; add possibility to set null to selected...

Add remove hostname method to cache; add possibility to set null to selected server, also avoiding a possible NPE
parent 9f39e38e
......@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.log.RCLog;
import chat.rocket.core.utils.Pair;
import io.reactivex.BackpressureStrategy;
......@@ -41,7 +42,11 @@ public class RocketChatCache {
}
public void setSelectedServerHostname(String hostname) {
setString(KEY_SELECTED_SERVER_HOSTNAME, hostname.toLowerCase());
String newHostname = null;
if (hostname != null) {
newHostname = hostname.toLowerCase();
}
setString(KEY_SELECTED_SERVER_HOSTNAME, newHostname);
}
public void addHostname(@NonNull String hostname, @Nullable String hostnameAvatarUri, String siteName) {
......@@ -86,6 +91,20 @@ public class RocketChatCache {
return Collections.emptyList();
}
public void removeHostname(String hostname) {
String json = getString(KEY_HOSTNAME_LIST, null);
if (TextUtils.isEmpty(json)) {
return;
}
try {
JSONObject jsonObj = new JSONObject(json);
jsonObj.remove(hostname);
setString(KEY_HOSTNAME_LIST, jsonObj.toString());
} catch (JSONException e) {
RCLog.e(e);
}
}
public String getSelectedRoomId() {
return getString(getSelectedServerHostname() + KEY_SELECTED_ROOM_ID, null);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment