Search in sources :

Example 6 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class CommitCommentsPresenter method onHandleComment.

@Override
public void onHandleComment(@NonNull String text, @Nullable Bundle bundle) {
    CommentRequestModel model = new CommentRequestModel();
    model.setBody(text);
    manageDisposable(RxHelper.getObservable(RestProvider.getRepoService(isEnterprise()).postCommitComment(login, repoId, sha, model)).doOnSubscribe(disposable -> sendToView(view -> view.showBlockingProgress(0))).subscribe(comment -> sendToView(view -> view.addComment(comment)), throwable -> {
        onError(throwable);
        sendToView(CommitCommentsMvp.View::hideBlockingProgress);
    }));
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Bundle(android.os.Bundle) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) ActivityHelper(com.fastaccess.helper.ActivityHelper) TimelineModel(com.fastaccess.data.dao.TimelineModel) CommentsHelper(com.fastaccess.provider.timeline.CommentsHelper) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) R(com.fastaccess.R) PopupMenu(android.widget.PopupMenu) View(android.view.View) Observable(io.reactivex.Observable) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) Nullable(android.support.annotation.Nullable) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel)

Example 7 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class GistCommentsFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == BundleConstant.REQUEST_CODE) {
            if (data == null) {
                onRefresh();
                return;
            }
            Bundle bundle = data.getExtras();
            if (bundle != null) {
                boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
                Comment commentsModel = bundle.getParcelable(BundleConstant.ITEM);
                if (commentsModel == null)
                    return;
                if (isNew) {
                    adapter.addItem(commentsModel);
                    recycler.smoothScrollToPosition(adapter.getItemCount());
                } else {
                    int position = adapter.getItem(commentsModel);
                    if (position != -1) {
                        adapter.swapItem(commentsModel, position);
                        recycler.smoothScrollToPosition(position);
                    } else {
                        adapter.addItem(commentsModel);
                        recycler.smoothScrollToPosition(adapter.getItemCount());
                    }
                }
            }
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) Bundle(android.os.Bundle)

Example 8 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class GistCommentsPresenter method onHandleComment.

@Override
public void onHandleComment(@NonNull String text, @Nullable Bundle bundle, String gistId) {
    CommentRequestModel model = new CommentRequestModel();
    model.setBody(text);
    manageDisposable(RxHelper.getObservable(RestProvider.getGistService(isEnterprise()).createGistComment(gistId, model)).doOnSubscribe(disposable -> sendToView(view -> view.showBlockingProgress(0))).subscribe(comment -> sendToView(view -> view.onAddNewComment(comment)), throwable -> {
        onError(throwable);
        sendToView(GistCommentsMvp.View::hideBlockingProgress);
    }));
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Bundle(android.os.Bundle) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) TextUtils(android.text.TextUtils) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) R(com.fastaccess.R) PopupMenu(android.widget.PopupMenu) View(android.view.View) Nullable(android.support.annotation.Nullable) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel)

Example 9 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class GistCommentsPresenter method onHandleDeletion.

@Override
public void onHandleDeletion(@Nullable Bundle bundle) {
    if (bundle != null) {
        long commId = bundle.getLong(BundleConstant.EXTRA, 0);
        String gistId = bundle.getString(BundleConstant.ID);
        if (commId != 0 && gistId != null) {
            makeRestCall(RestProvider.getGistService(isEnterprise()).deleteGistComment(gistId, commId), booleanResponse -> sendToView(view -> {
                if (booleanResponse.code() == 204) {
                    Comment comment = new Comment();
                    comment.setId(commId);
                    view.onRemove(comment);
                } else {
                    view.showMessage(R.string.error, R.string.error_deleting_comment);
                }
            }));
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Bundle(android.os.Bundle) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) TextUtils(android.text.TextUtils) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) R(com.fastaccess.R) PopupMenu(android.widget.PopupMenu) View(android.view.View) Nullable(android.support.annotation.Nullable) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) Comment(com.fastaccess.data.dao.model.Comment)

Example 10 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class IssueTimelineFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == BundleConstant.REQUEST_CODE) {
            if (data == null) {
                onRefresh();
                return;
            }
            Bundle bundle = data.getExtras();
            if (bundle != null) {
                boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
                Comment commentsModel = bundle.getParcelable(BundleConstant.ITEM);
                if (commentsModel == null) {
                    // shit happens, refresh()?
                    onRefresh();
                    return;
                }
                adapter.notifyDataSetChanged();
                if (isNew) {
                    adapter.addItem(TimelineModel.constructComment(commentsModel));
                    recycler.smoothScrollToPosition(adapter.getItemCount());
                } else {
                    int position = adapter.getItem(TimelineModel.constructComment(commentsModel));
                    if (position != -1) {
                        adapter.swapItem(TimelineModel.constructComment(commentsModel), position);
                        recycler.smoothScrollToPosition(position);
                    } else {
                        adapter.addItem(TimelineModel.constructComment(commentsModel));
                        recycler.smoothScrollToPosition(adapter.getItemCount());
                    }
                }
            } else {
                // bundle size is too large? refresh the api
                onRefresh();
            }
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) Bundle(android.os.Bundle)

Aggregations

Comment (com.fastaccess.data.dao.model.Comment)19 Bundle (android.os.Bundle)11 PopupMenu (android.widget.PopupMenu)8 NonNull (android.support.annotation.NonNull)7 Nullable (android.support.annotation.Nullable)7 View (android.view.View)7 R (com.fastaccess.R)7 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)7 TimelineModel (com.fastaccess.data.dao.TimelineModel)7 Login (com.fastaccess.data.dao.model.Login)7 ReactionTypes (com.fastaccess.data.dao.types.ReactionTypes)7 BundleConstant (com.fastaccess.helper.BundleConstant)7 RxHelper (com.fastaccess.helper.RxHelper)7 RestProvider (com.fastaccess.provider.rest.RestProvider)7 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)7 ArrayList (java.util.ArrayList)7 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)6 ActivityHelper (com.fastaccess.helper.ActivityHelper)5 CommentsHelper (com.fastaccess.provider.timeline.CommentsHelper)5 ReactionsProvider (com.fastaccess.provider.timeline.ReactionsProvider)5