use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class NotificationsAdapter method onClick.
@Override
public void onClick(Notification notification, FragmentActivity fragmentActivity) {
/* Mark notification read */
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
String sessId = Utils.getSessionIDHeader();
retrofitInterface.markNotificationRead(sessId, notification.getNotificationId().toString()).enqueue(new EmptyCallback<Void>());
ShortcutBadger.applyCount(fragmentActivity.getApplicationContext(), NotificationId.decrementAndGetCurrentCount());
/* Close the bottom sheet */
notificationsFragment.dismiss();
Gson gson = Utils.gson;
/* Open event */
if (notification.isEvent()) {
Event event = gson.fromJson(gson.toJson(notification.getNotificationActor()), Event.class);
Utils.openEventFragment(event, fragmentActivity);
} else if (notification.isNews()) {
NewsFragment newsFragment = new NewsFragment();
NewsArticle newsArticle = gson.fromJson(gson.toJson(notification.getNotificationActor()), NewsArticle.class);
newsFragment.withId(newsArticle.getId());
Utils.updateFragment(newsFragment, fragmentActivity);
} else if (notification.isBlogPost()) {
PlacementBlogPost post = gson.fromJson(gson.toJson(notification.getNotificationActor()), PlacementBlogPost.class);
Fragment fragment;
if (post.getLink().contains("training")) {
fragment = (new TrainingBlogFragment()).withId(post.getId());
} else {
fragment = (new PlacementBlogFragment()).withId(post.getId());
}
Utils.updateFragment(fragment, fragmentActivity);
}
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class MainActivity method fetchNotifications.
/**
* Get the notifications from memory cache or network
*/
private void fetchNotifications() {
// Try memory cache
if (Utils.notificationCache != null) {
showNotifications();
return;
}
// Get from network
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getNotifications(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<List<Notification>>() {
@Override
public void onResponse(Call<List<Notification>> call, Response<List<Notification>> response) {
if (response.isSuccessful()) {
Utils.notificationCache = new UpdatableList<>();
Utils.notificationCache.setList(response.body());
showNotifications();
NotificationId.setCurrentCount(Utils.notificationCache.size());
ShortcutBadger.applyCount(getApplicationContext(), NotificationId.getCurrentCount());
}
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class MainActivity method updateFCMId.
/**
* Update FCM Id and update profile
*/
private void updateFCMId() {
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
final String fcmId = instanceIdResult.getToken();
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserFCMPatchRequest(fcmId, getCurrentVersion())).enqueue(new EmptyCallback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
session.createLoginSession(response.body().getUserName(), response.body(), session.getSessionID());
currentUser = response.body();
Utils.currentUserCache = currentUser;
} else {
session.logout();
currentUser = null;
Toast.makeText(MainActivity.this, "Your session has expired!", Toast.LENGTH_LONG).show();
}
}
});
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class LoginActivity method login.
private void login(final String authorizationCode, final String redirectURL) {
/* This can be null if play services is hung */
RetrofitInterface retrofitInterface = getRetrofitInterface();
Call<LoginResponse> call;
if (fcmId == null) {
call = retrofitInterface.login(authorizationCode, redirectURL);
} else {
call = retrofitInterface.login(authorizationCode, redirectURL, fcmId);
}
call.enqueue(new EmptyCallback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
if (response.isSuccessful()) {
session.createLoginSession(response.body().getUser().getUserName(), response.body().getUser(), response.body().getSessionID());
progressDialog.dismiss();
openMainActivity();
finish();
} else {
Toast.makeText(LoginActivity.this, "Authorization Failed!", Toast.LENGTH_LONG).show();
progressDialog.dismiss();
}
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class ExploreFragment method onStart.
@Override
public void onStart() {
super.onStart();
// Initialize
sessionId = Utils.getSessionIDHeader();
initRecyclerView();
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Explore");
Utils.setSelectedMenuItem(getActivity(), R.id.nav_explore);
final EditText searchEditText = getView().findViewById(R.id.explore_search);
// Get all bodies
if (allBodies.size() == 0) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getAllBodies(sessionId).enqueue(new EmptyCallback<List<Body>>() {
@Override
public void onResponse(Call<List<Body>> call, Response<List<Body>> response) {
allBodies = response.body();
bodies = allBodies;
updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
}
});
} else {
// Check if search box is not empty
if (searchEditText.getText() != null && !searchEditText.getText().toString().equals("")) {
updateAdapter(bodies, events, users);
} else {
updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
}
getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
}
// Close keyboard on search click
searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
MainActivity.hideKeyboard(getActivity());
return true;
}
return false;
}
});
// Search on text change in search
searchEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
currentQuery = s.toString();
if (currentQuery.length() >= 3) {
doSearch(searchEditText.getText().toString());
} else if (currentQuery.length() == 0) {
updateAdapter(allBodies, new ArrayList<Event>(), new ArrayList<User>());
}
}
});
}
Aggregations