Commit 8085eeff authored by Varun Patil's avatar Varun Patil

Update profile on create MainActivity

parent 833f19e2
......@@ -19,13 +19,14 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator;
import app.insti.api.UnsafeOkHttpClient;
import app.insti.data.Body;
import app.insti.data.Event;
......@@ -48,6 +49,9 @@ import app.insti.fragment.QuickLinksFragment;
import app.insti.fragment.SettingsFragment;
import app.insti.fragment.TrainingBlogFragment;
import app.insti.notifications.NotificationEventReceiver;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_ACCESS_LOCATION;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
......@@ -75,6 +79,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
setContentView(R.layout.activity_main);
session = new SessionManager(getApplicationContext());
updateProfile();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
......@@ -121,6 +127,28 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
private void updateProfile() {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
if (session.isLoggedIn()) {
retrofitInterface.getUserMe(getSessionIDHeader()).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
session.createLoginSession(response.body().getUserLDAPId(), response.body(), session.getSessionID());
currentUser = response.body();
} else {
session.logout();
currentUser = null;
Toast.makeText(MainActivity.this, "You session has expired!", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<User> call, Throwable t) { }
});
}
}
private String getID(String appLinkData) {
if (appLinkData.charAt(appLinkData.length() - 1) == '/')
appLinkData = appLinkData.substring(0, appLinkData.length() - 1);
......
......@@ -65,6 +65,9 @@ public interface RetrofitInterface {
@POST("upload")
Call<ImageUploadResponse> uploadImage(@Header("Cookie") String sessionID, @Body ImageUploadRequest imageUploadRequest);
@GET("user-me")
Call<User> getUserMe(@Header("Cookie") String sessionId);
@GET("user-me/ues/{eventID}")
Call<Void> updateUserEventStatus(@Header("Cookie") String sessionID, @Path("eventID") String eventID, @Query("status") int status);
......
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