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,24 +111,29 @@ public class SettingsFragment extends PreferenceFragmentCompat { ...@@ -111,24 +111,29 @@ 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);
// Get the user id if (Utils.currentUserCache == null) {
Bundle bundle = getArguments(); // Get the user id
String userID = bundle.getString(Constants.USER_ID); Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID);
// Fill in the user
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface(); // Fill in the user
retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new EmptyCallback<User>() { RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
@Override retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new EmptyCallback<User>() {
public void onResponse(Call<User> call, Response<User> response) { @Override
if (response.isSuccessful()) { public void onResponse(Call<User> call, Response<User> response) {
if(getActivity() == null || getView() == null) return; if (response.isSuccessful()) {
User user = response.body(); if (getActivity() == null || getView() == null) return;
showContactPref.setChecked(user.getShowContactNumber()); User user = response.body();
showContactPref.setEnabled(true); showContactPref.setChecked(user.getShowContactNumber());
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