use of com.mxt.anitrend.model.entity.anilist.MediaList in project anitrend-app by AniTrend.
the class MediaActionUtil method onResponse.
/**
* Invoked for a received HTTP response.
* <p>
* Note: An HTTP response may still indicate an application-level failure such as a 404 or 500.
* Call {@link Response#isSuccessful()} to determine if the response indicates success.
*
* @param call the origination requesting object
* @param response the response from the network
*/
@Override
public void onResponse(@NonNull Call<MediaList> call, @NonNull Response<MediaList> response) {
if (lifecycle != null && lifecycle.getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
MediaList seriesStatus;
if (response.isSuccessful() && (seriesStatus = response.body()) != null) {
if (!TextUtils.isEmpty(seriesStatus.getStatus()))
presenter.getDatabase().getBoxStore(MediaList.class).put(seriesStatus);
showActionDialog();
} else {
Log.e(this.toString(), ErrorUtil.getError(response));
NotifyUtil.makeText(context, R.string.text_error_request, Toast.LENGTH_SHORT).show();
}
dismissProgress();
}
}
use of com.mxt.anitrend.model.entity.anilist.MediaList in project anitrend-app by AniTrend.
the class MediaDialogUtil method onDialogPositive.
/**
* Dialog negative or delete handler method
* <br/>
*
* @param context from a fragment activity derived class
*/
private static void onDialogPositive(Context context, CustomSeriesManageBase seriesManageBase, MaterialDialog dialog, boolean isNewEntry) {
dialog.dismiss();
ProgressDialog progressDialog = NotifyUtil.createProgressDialog(context, R.string.text_processing_request);
progressDialog.show();
seriesManageBase.persistChanges();
WidgetPresenter<MediaList> presenter = new WidgetPresenter<>(context);
presenter.setParams(seriesManageBase.getParam());
@KeyUtil.RequestType int requestType = KeyUtil.MUT_SAVE_MEDIA_LIST;
presenter.requestData(requestType, context, new RetroCallback<MediaList>() {
@Override
public void onResponse(@NonNull Call<MediaList> call, @NonNull Response<MediaList> response) {
try {
MediaList responseBody;
progressDialog.dismiss();
if (response.isSuccessful() && (responseBody = response.body()) != null) {
if (seriesManageBase.getModel().getMedia() != null)
responseBody.setMedia(seriesManageBase.getModel().getMedia());
presenter.getDatabase().getBoxStore(MediaList.class).put(responseBody);
presenter.notifyAllListeners(new BaseConsumer<>(requestType, responseBody), false);
NotifyUtil.makeText(context, context.getString(R.string.text_changes_saved), R.drawable.ic_check_circle_white_24dp, Toast.LENGTH_SHORT).show();
} else {
Log.e(this.toString(), ErrorUtil.getError(response));
NotifyUtil.makeText(context, context.getString(R.string.text_error_request), R.drawable.ic_warning_white_18dp, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Log.e(this.toString(), e.getLocalizedMessage());
}
}
@Override
public void onFailure(@NonNull Call<MediaList> call, @NonNull Throwable throwable) {
throwable.printStackTrace();
try {
progressDialog.dismiss();
NotifyUtil.makeText(context, context.getString(R.string.text_error_request), R.drawable.ic_warning_white_18dp, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Log.e(this.toString(), e.getLocalizedMessage());
}
}
});
}
use of com.mxt.anitrend.model.entity.anilist.MediaList in project anitrend-app by AniTrend.
the class CustomSeriesManageBase method setModel.
public void setModel(MediaBase model, boolean isNewEntry) {
if (isNewEntry) {
this.model = new MediaList();
this.model.setMedia(model);
}
bindFields();
populateFields();
}
use of com.mxt.anitrend.model.entity.anilist.MediaList in project anitrend-app by AniTrend.
the class CustomSeriesManageBase method setModel.
public void setModel(MediaList model, boolean isNewEntry) {
if (isNewEntry) {
this.model = new MediaList();
this.model.setMedia(model.getMedia());
}
bindFields();
populateFields();
}
use of com.mxt.anitrend.model.entity.anilist.MediaList in project anitrend-app by AniTrend.
the class GroupSeriesListAdapter method getFilter.
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
String filter = constraint.toString();
if (filter.isEmpty()) {
data = clone;
} else {
data = new ArrayList<>();
for (EntityGroup model : clone) {
if (model instanceof MediaList) {
MediaBase mediaBase = ((MediaList) model).getMedia();
if (mediaBase.getTitle().getEnglish().toLowerCase(Locale.getDefault()).contains(filter) || mediaBase.getTitle().getRomaji().toLowerCase(Locale.getDefault()).contains(filter) || mediaBase.getTitle().getOriginal().toLowerCase(Locale.getDefault()).contains(filter))
data.add(model);
}
}
}
FilterResults results = new FilterResults();
results.values = data;
return results;
}
@Override
@SuppressWarnings("unchecked")
protected void publishResults(CharSequence constraint, FilterResults results) {
data = new ArrayList<>((List<EntityGroup>) results.values);
notifyDataSetChanged();
}
};
}
Aggregations