use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class RecyclerViewFragment method updateData.
/**
* Update the data clearing existing
*/
protected void updateData() {
// Skip if we're already destroyed
if (getActivity() == null || getView() == null)
return;
// Clear variables
allLoaded = false;
// Keep current search query
final String requestSearchQuery = searchQuery;
// Make the request
String sessionIDHeader = Utils.getSessionIDHeader();
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
Call<List<T>> call = getCall(retrofitInterface, sessionIDHeader, 0);
call.enqueue(new Callback<List<T>>() {
@Override
public void onResponse(Call<List<T>> call, Response<List<T>> response) {
// Check if search query was changed in the meanwhile
if (!Objects.equals(requestSearchQuery, searchQuery)) {
return;
}
// Update display
if (response.isSuccessful()) {
List<T> posts = response.body();
displayData(posts);
}
swipeRefreshLayout.setRefreshing(false);
}
@Override
public void onFailure(Call<List<T>> call, Throwable t) {
swipeRefreshLayout.setRefreshing(false);
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class SettingsFragment method toggleShowContact.
private void toggleShowContact(final SwitchPreferenceCompat showContactPref, Object option) {
final boolean isChecked = (boolean) option;
showContactPref.setEnabled(false);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserShowContactPatchRequest(isChecked)).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (getActivity() == null || getView() == null)
return;
if (response.isSuccessful()) {
showContactPref.setChecked(response.body().getShowContactNumber());
showContactPref.setEnabled(true);
Utils.currentUserCache = response.body();
} else {
showContactPref.setChecked(!isChecked);
showContactPref.setEnabled(true);
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
if (getActivity() == null || getView() == null)
return;
showContactPref.setChecked(!isChecked);
showContactPref.setEnabled(true);
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class SettingsFragment method onStart.
@Override
public void onStart() {
super.onStart();
// Set toolbar title
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Settings");
Utils.setSelectedMenuItem(getActivity(), R.id.nav_settings);
if (Utils.currentUserCache == null) {
// Get the user id
Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID);
// Fill in the user
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new EmptyCallback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
if (getActivity() == null || getView() == null)
return;
User user = response.body();
showContactPref.setChecked(user.getShowContactNumber());
showContactPref.setEnabled(true);
Utils.currentUserCache = user;
}
}
});
} else {
showContactPref.setChecked(Utils.currentUserCache.getShowContactNumber());
showContactPref.setEnabled(true);
}
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class SettingsFragment method logout.
private void logout() {
final SessionManager sessionManager = new SessionManager(getContext());
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.logout(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
sessionManager.logout();
Utils.clearCookies(getActivity());
Intent intent = new Intent(getContext(), LoginActivity.class);
startActivity(intent);
getActivity().finish();
}
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class BodyHeadViewHolder method bindView.
public void bindView(final Body body, final Fragment fragment) {
/* Set body information */
bodyName.setText(body.getBodyName());
bodySubtitle.setText(body.getBodyShortDescription());
/* Return if it's a min body */
if (body.getBodyDescription() == null) {
return;
}
Utils.getMarkwon().setMarkdown(bodyDescription, body.getBodyDescription());
/* Check if user is already following
* Initialize follow button */
setupFollowButton(fragment.getContext(), body);
followButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.updateBodyFollowing(Utils.getSessionIDHeader(), body.getBodyID(), body.getBodyUserFollows() ? 0 : 1).enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
body.setBodyUserFollows(!body.getBodyUserFollows());
body.setBodyFollowersCount(body.getBodyUserFollows() ? body.getBodyFollowersCount() + 1 : body.getBodyFollowersCount() - 1);
setupFollowButton(fragment.getContext(), body);
}
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
Toast.makeText(fragment.getContext(), "Network Error", Toast.LENGTH_LONG).show();
}
});
}
});
/* Initialize web button */
if (body.getBodyWebsiteURL() != null && !body.getBodyWebsiteURL().isEmpty()) {
webBodyButton.setVisibility(View.VISIBLE);
webBodyButton.setOnClickListener(new View.OnClickListener() {
String bodywebURL = body.getBodyWebsiteURL();
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(bodywebURL));
fragment.startActivity(browserIntent);
}
});
}
/* Initialize share button */
shareBodyButton.setOnClickListener(new View.OnClickListener() {
String shareUrl = ShareURLMaker.getBodyURL(body);
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i.putExtra(Intent.EXTRA_TEXT, shareUrl);
fragment.startActivity(Intent.createChooser(i, "Share URL"));
}
});
}
Aggregations