Search in sources :

Example 1 with WidgetPresenter

use of com.mxt.anitrend.presenter.widget.WidgetPresenter 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());
            }
        }
    });
}
Also used : MediaList(com.mxt.anitrend.model.entity.anilist.MediaList) ProgressDialog(android.app.ProgressDialog) BaseConsumer(com.mxt.anitrend.base.custom.consumer.BaseConsumer) WidgetPresenter(com.mxt.anitrend.presenter.widget.WidgetPresenter)

Example 2 with WidgetPresenter

use of com.mxt.anitrend.presenter.widget.WidgetPresenter in project anitrend-app by AniTrend.

the class MediaDialogUtil method onDialogNegative.

/**
 * Dialog negative or delete handler method
 * <br/>
 *
 * @param context from a fragment activity derived class
 */
private static void onDialogNegative(Context context, CustomSeriesManageBase seriesManageBase, MaterialDialog dialog) {
    dialog.dismiss();
    ProgressDialog progressDialog = NotifyUtil.createProgressDialog(context, R.string.text_processing_request);
    progressDialog.show();
    seriesManageBase.persistChanges();
    WidgetPresenter<ResponseBody> presenter = new WidgetPresenter<>(context);
    presenter.setParams(seriesManageBase.getParam());
    @KeyUtil.RequestType int requestType = KeyUtil.MUT_DELETE_MEDIA_LIST;
    presenter.requestData(requestType, context, new RetroCallback<ResponseBody>() {

        @Override
        public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
            try {
                progressDialog.dismiss();
                if (response.isSuccessful()) {
                    presenter.getDatabase().getBoxStore(MediaList.class).remove(seriesManageBase.getModel());
                    presenter.notifyAllListeners(new BaseConsumer<>(requestType, seriesManageBase.getModel()), 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();
            }
        }

        @Override
        public void onFailure(@NonNull Call<ResponseBody> 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();
            }
        }
    });
}
Also used : ProgressDialog(android.app.ProgressDialog) ResponseBody(okhttp3.ResponseBody) BaseConsumer(com.mxt.anitrend.base.custom.consumer.BaseConsumer) WidgetPresenter(com.mxt.anitrend.presenter.widget.WidgetPresenter)

Aggregations

ProgressDialog (android.app.ProgressDialog)2 BaseConsumer (com.mxt.anitrend.base.custom.consumer.BaseConsumer)2 WidgetPresenter (com.mxt.anitrend.presenter.widget.WidgetPresenter)2 MediaList (com.mxt.anitrend.model.entity.anilist.MediaList)1 ResponseBody (okhttp3.ResponseBody)1