use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.
the class LoginActivity method login.
private void login(String authorizationCode, final String redirectURI, String gcmID) {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.login(authorizationCode, redirectURI, gcmID).enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
if (response.isSuccessful()) {
Log.d(TAG, "Login request successful");
session.createLoginSession(redirectURI, response.body().getUser(), response.body().getSessionID());
Intent i = new Intent(mContext, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
// Save credentials in AccountManager to keep user logged in
// Go to MainActivity
}
// Server error
}
@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
// Network Error
}
});
}
use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.
the class AddEventFragment method sendImage.
private void sendImage() {
progressDialog.setMessage("Uploading Image");
ImageUploadRequest imageUploadRequest = new ImageUploadRequest(base64Image);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.uploadImage("sessionid=" + getArguments().getString(SESSION_ID), imageUploadRequest).enqueue(new Callback<ImageUploadResponse>() {
@Override
public void onResponse(Call<ImageUploadResponse> call, Response<ImageUploadResponse> response) {
if (response.isSuccessful()) {
ImageUploadResponse imageUploadResponse = response.body();
String imageURL = imageUploadResponse.getPictureURL();
addEvent(imageURL);
}
}
@Override
public void onFailure(Call<ImageUploadResponse> call, Throwable t) {
progressDialog.dismiss();
}
});
}
use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.
the class FeedFragment method updateFeed.
private void updateFeed() {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNewsFeed("sessionid=" + getArguments().getString(SESSION_ID)).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
NewsFeedResponse newsFeedResponse = response.body();
final List<Event> events = newsFeedResponse.getEvents();
FeedAdapter feedAdapter = new FeedAdapter(events, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
String eventJson = new Gson().toJson(events.get(position));
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, eventJson);
EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle);
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
transaction.commit();
}
});
feedRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feed_recycler_view);
feedRecyclerView.setAdapter(feedAdapter);
feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
appDatabase.dbDao().deleteEvents();
appDatabase.dbDao().insertEvents(events);
// Server Error
feedSwipeRefreshLayout.setRefreshing(false);
}
}
@Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
// Network Error
feedSwipeRefreshLayout.setRefreshing(false);
}
});
}
use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.
the class ProfileFragment method onStart.
@Override
public void onStart() {
super.onStart();
Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getUser("sessionid=" + getArguments().getString(SESSION_ID), userID).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
user = response.body();
populateViews();
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
}
});
}
use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.
the class MainActivity method fetchNotifications.
private void fetchNotifications() {
NotificationsRequest notificationsRequest = new NotificationsRequest(0, 20);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNotifications(notificationsRequest).enqueue(new Callback<NotificationsResponse>() {
@Override
public void onResponse(Call<NotificationsResponse> call, Response<NotificationsResponse> response) {
if (response.isSuccessful()) {
notificationsResponse = response.body();
if (showNotifications) {
showNotifications();
showNotifications = false;
}
}
// Server Error
}
@Override
public void onFailure(Call<NotificationsResponse> call, Throwable t) {
// Network Error
}
});
}
Aggregations