Commit b21a9e47 authored by Varun Patil's avatar Varun Patil

Memcache current user in utils

parent e79b2aa7
...@@ -45,6 +45,7 @@ public final class Utils { ...@@ -45,6 +45,7 @@ public final class Utils {
public static UpdatableList<Event> eventCache = new UpdatableList<>(); public static UpdatableList<Event> eventCache = new UpdatableList<>();
public static UpdatableList<Notification> notificationCache = null; public static UpdatableList<Notification> notificationCache = null;
public static UpdatableList<Body> bodyCache = new UpdatableList<>(); public static UpdatableList<Body> bodyCache = new UpdatableList<>();
public static User currentUserCache = null;
private static String sessionId; private static String sessionId;
private static RetrofitInterface retrofitInterface; private static RetrofitInterface retrofitInterface;
......
...@@ -427,6 +427,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -427,6 +427,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (response.isSuccessful()) { if (response.isSuccessful()) {
session.createLoginSession(response.body().getUserName(), response.body(), session.getSessionID()); session.createLoginSession(response.body().getUserName(), response.body(), session.getSessionID());
currentUser = response.body(); currentUser = response.body();
Utils.currentUserCache = currentUser;
} else { } else {
session.logout(); session.logout();
currentUser = null; currentUser = null;
......
...@@ -111,6 +111,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { ...@@ -111,6 +111,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
toolbar.setTitle("Settings"); toolbar.setTitle("Settings");
Utils.setSelectedMenuItem(getActivity(), R.id.nav_settings); Utils.setSelectedMenuItem(getActivity(), R.id.nav_settings);
if (Utils.currentUserCache == null) {
// Get the user id // Get the user id
Bundle bundle = getArguments(); Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID); String userID = bundle.getString(Constants.USER_ID);
...@@ -121,14 +122,18 @@ public class SettingsFragment extends PreferenceFragmentCompat { ...@@ -121,14 +122,18 @@ public class SettingsFragment extends PreferenceFragmentCompat {
@Override @Override
public void onResponse(Call<User> call, Response<User> response) { public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
if(getActivity() == null || getView() == null) return; if (getActivity() == null || getView() == null) return;
User user = response.body(); User user = response.body();
showContactPref.setChecked(user.getShowContactNumber()); showContactPref.setChecked(user.getShowContactNumber());
showContactPref.setEnabled(true); showContactPref.setEnabled(true);
Utils.currentUserCache = user;
} }
} }
}); });
} else {
showContactPref.setChecked(Utils.currentUserCache.getShowContactNumber());
showContactPref.setEnabled(true);
}
} }
public void toggleShowContact(final SwitchPreferenceCompat showContactPref, Object o) { public void toggleShowContact(final SwitchPreferenceCompat showContactPref, Object o) {
...@@ -142,6 +147,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { ...@@ -142,6 +147,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
if (response.isSuccessful()) { if (response.isSuccessful()) {
showContactPref.setChecked(response.body().getShowContactNumber()); showContactPref.setChecked(response.body().getShowContactNumber());
showContactPref.setEnabled(true); showContactPref.setEnabled(true);
Utils.currentUserCache = response.body();
} else { } else {
showContactPref.setChecked(!isChecked); showContactPref.setChecked(!isChecked);
showContactPref.setEnabled(true); showContactPref.setEnabled(true);
......
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