use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class FeedFragment method updateFeed.
private void updateFeed() {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getNewsFeed(Utils.getSessionIDHeader()).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
Utils.eventCache.setList(response.body().getEvents());
displayEvents(Utils.eventCache);
}
// Server Error
feedSwipeRefreshLayout.setRefreshing(false);
}
@Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
// Network Error
feedSwipeRefreshLayout.setRefreshing(false);
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class FileComplaintFragment method addComplaint.
private void addComplaint() {
final String complaint = descriptionAutoCompleteTextview.getText().toString();
final String suggestion;
final String locationDetails;
if (!(editTextSuggestions.getText().toString().isEmpty())) {
suggestion = editTextSuggestions.getText().toString();
} else {
suggestion = "";
}
if (!(editTextLocationDetails.getText().toString().isEmpty())) {
locationDetails = editTextLocationDetails.getText().toString();
} else {
locationDetails = "";
}
if (Location == null) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response!
new AlertDialog.Builder(getContext()).setTitle("Location Needed").setMessage("You have not specified your location. The app will by default make \"IIT Area\" as your location.").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Location = new LatLng(19.133810, 72.913257);
Address = "IIT Area";
ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {
@Override
public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
Bundle bundle = getArguments();
bundle.putString(Constants.USER_ID, userId);
ComplaintsFragment complaintsFragment = new ComplaintsFragment();
complaintsFragment.setArguments(bundle);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
transaction.addToBackStack(complaintsFragment.getTag());
manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
transaction.commit();
}
@Override
public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
Log.i(TAG, "failure in addComplaint: " + t.toString());
Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
}
});
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getContext(), "Submission aborted", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
}).create().show();
} else {
ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {
@Override
public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
Bundle bundle = getArguments();
bundle.putString(Constants.USER_ID, userId);
ComplaintsFragment complaintsFragment = new ComplaintsFragment();
complaintsFragment.setArguments(bundle);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
transaction.addToBackStack(complaintsFragment.getTag());
manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
transaction.commit();
}
@Override
public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
Log.i(TAG, "failure in addComplaint: " + t.toString());
Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
}
});
}
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class RecyclerViewFragment method initRecyclerView.
/**
* Initialize scrolling on the adapter
*/
private void initRecyclerView() {
getActivityBuffer().safely(new ActivityBuffer.IRunnable() {
@Override
public void run(Activity pActivity) {
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
if (((layoutManager.getChildCount() + layoutManager.findFirstVisibleItemPosition()) > (layoutManager.getItemCount() - 5)) && (!loading) && (!allLoaded)) {
loading = true;
String sessionIDHeader = Utils.getSessionIDHeader();
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
Call<List<T>> call = getCall(retrofitInterface, sessionIDHeader, getPostCount());
call.enqueue(new Callback<List<T>>() {
@Override
public void onResponse(Call<List<T>> call, Response<List<T>> response) {
if (getActivity() == null || getView() == null)
return;
loading = false;
if (response.isSuccessful()) {
List<T> posts = adapter.getPosts();
posts.addAll(response.body());
if (response.body().size() == 0) {
showLoader = false;
allLoaded = true;
}
adapter.setPosts(posts);
adapter.notifyDataSetChanged();
}
}
@Override
public void onFailure(Call<List<T>> call, Throwable t) {
loading = false;
}
});
}
}
}
});
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class UserFragment method loadUser.
public void loadUser(String userID) {
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 = response.body();
populateViews();
}
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class MessMenuWidget method updateAppWidget.
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
// Construct the RemoteViews object
views = new RemoteViews(context.getPackageName(), R.layout.mess_menu_widget);
SessionManager sessionManager = new SessionManager(context);
if (sessionManager.isLoggedIn()) {
ServiceGenerator serviceGenerator = new ServiceGenerator(context);
RetrofitInterface retrofitInterface = serviceGenerator.getRetrofitInterface();
retrofitInterface.getInstituteMessMenu(sessionManager.getSessionID()).enqueue(new Callback<List<HostelMessMenu>>() {
@Override
public void onResponse(Call<List<HostelMessMenu>> call, Response<List<HostelMessMenu>> response) {
if (response.isSuccessful()) {
instituteMessMenu = response.body();
displayMenu(sessionManager.getCurrentUser().getHostel());
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onFailure(Call<List<HostelMessMenu>> call, Throwable t) {
// Network error
}
});
} else {
views.setTextViewText(R.id.meal_text_view, "Login to see your mess menu");
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
Aggregations