Search in sources :

Example 6 with CommentModel

use of org.wordpress.android.fluxc.model.CommentModel in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method showComment.

/*
     * display the current comment
     */
private void showComment() {
    if (!isAdded() || getView() == null)
        return;
    // these two views contain all the other views except the progress bar
    final ScrollView scrollView = (ScrollView) getView().findViewById(R.id.scroll_view);
    final View layoutBottom = getView().findViewById(R.id.layout_bottom);
    // hide container views when comment is null (will happen when opened from a notification)
    if (mComment == null) {
        scrollView.setVisibility(View.GONE);
        layoutBottom.setVisibility(View.GONE);
        if (mNote != null) {
            SiteModel site = mSiteStore.getSiteBySiteId(mNote.getSiteId());
            if (site == null) {
                ToastUtils.showToast(getActivity(), R.string.error_load_comment);
                return;
            }
            // Check if the comment is already in our store
            CommentModel comment = mCommentStore.getCommentBySiteAndRemoteId(site, mNote.getCommentId());
            if (comment != null) {
                // It exists, then show it as a "Notification"
                showCommentAsNotification(mNote, site, comment);
            } else {
                // It's not in our store yet, request it.
                RemoteCommentPayload payload = new RemoteCommentPayload(site, mNote.getCommentId());
                mDispatcher.dispatch(CommentActionBuilder.newFetchCommentAction(payload));
                setProgressVisible(true);
                // Show a "temporary" comment built from the note data, the view will be refreshed once the
                // comment has been fetched.
                showCommentAsNotification(mNote, site, null);
            }
        }
        return;
    }
    scrollView.setVisibility(View.VISIBLE);
    layoutBottom.setVisibility(View.VISIBLE);
    // Add action buttons footer
    if (mNote == null && mLayoutButtons.getParent() == null) {
        mCommentContentLayout.addView(mLayoutButtons);
    }
    final WPNetworkImageView imgAvatar = (WPNetworkImageView) getView().findViewById(R.id.image_avatar);
    final TextView txtName = (TextView) getView().findViewById(R.id.text_name);
    final TextView txtDate = (TextView) getView().findViewById(R.id.text_date);
    txtName.setText(mComment.getAuthorName() == null ? getString(R.string.anonymous) : HtmlUtils.fastUnescapeHtml(mComment.getAuthorName()));
    txtDate.setText(DateTimeUtils.javaDateToTimeSpan(DateTimeUtils.dateFromIso8601(mComment.getDatePublished()), WordPress.getContext()));
    int maxImageSz = getResources().getDimensionPixelSize(R.dimen.reader_comment_max_image_size);
    CommentUtils.displayHtmlComment(mTxtContent, mComment.getContent(), maxImageSz, mImageLoader);
    int avatarSz = getResources().getDimensionPixelSize(R.dimen.avatar_sz_large);
    if (mComment.getAuthorProfileImageUrl() != null) {
        imgAvatar.setImageUrl(GravatarUtils.fixGravatarUrl(mComment.getAuthorProfileImageUrl(), avatarSz), WPNetworkImageView.ImageType.AVATAR);
    } else if (mComment.getAuthorEmail() != null) {
        String avatarUrl = GravatarUtils.gravatarFromEmail(mComment.getAuthorEmail(), avatarSz);
        imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
    } else {
        imgAvatar.setImageUrl(null, WPNetworkImageView.ImageType.AVATAR);
    }
    updateStatusViews();
    // navigate to author's blog when avatar or name clicked
    if (mComment.getAuthorUrl() != null) {
        View.OnClickListener authorListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ReaderActivityLauncher.openUrl(getActivity(), mComment.getAuthorUrl());
            }
        };
        imgAvatar.setOnClickListener(authorListener);
        txtName.setOnClickListener(authorListener);
        txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.reader_hyperlink));
    } else {
        txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.grey_darken_30));
    }
    showPostTitle(mSite, mComment.getRemotePostId());
    // make sure reply box is showing
    if (mLayoutReply.getVisibility() != View.VISIBLE && canReply()) {
        AniUtils.animateBottomBar(mLayoutReply, true);
        if (mEditReply != null && mShouldFocusReplyField) {
            mEditReply.performClick();
            disableShouldFocusReplyField();
        }
    }
    getFragmentManager().invalidateOptionsMenu();
}
Also used : ScrollView(android.widget.ScrollView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) SiteModel(org.wordpress.android.fluxc.model.SiteModel) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) ScrollView(android.widget.ScrollView) CommentModel(org.wordpress.android.fluxc.model.CommentModel) RemoteCommentPayload(org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload)

Example 7 with CommentModel

use of org.wordpress.android.fluxc.model.CommentModel in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getActivity().getApplication()).component().inject(this);
    switch(getArguments().getInt(KEY_MODE)) {
        case FROM_BLOG_COMMENT:
            setComment((CommentModel) getArguments().getSerializable(KEY_COMMENT), (SiteModel) getArguments().getSerializable(WordPress.SITE));
            break;
        case FROM_NOTE:
            setNote(getArguments().getString(KEY_NOTE_ID));
            setReplyText(getArguments().getString(KEY_REPLY_TEXT));
            setIdForFragmentContainer(getArguments().getInt(KEY_FRAGMENT_CONTAINER_ID));
            break;
    }
    if (savedInstanceState != null) {
        mIdForFragmentContainer = savedInstanceState.getInt(KEY_FRAGMENT_CONTAINER_ID);
        if (savedInstanceState.getString(KEY_NOTE_ID) != null) {
            // The note will be set in onResume()
            // See WordPress.deferredInit()
            mRestoredNoteId = savedInstanceState.getString(KEY_NOTE_ID);
        } else {
            SiteModel site = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
            CommentModel comment = (CommentModel) savedInstanceState.getSerializable(KEY_COMMENT);
            setComment(comment, site);
        }
    }
    setHasOptionsMenu(true);
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 8 with CommentModel

use of org.wordpress.android.fluxc.model.CommentModel in project WordPress-Android by wordpress-mobile.

the class CommentsListFragment method getAdapter.

private CommentAdapter getAdapter() {
    if (mAdapter == null) {
        // called after comments have been loaded
        CommentAdapter.OnDataLoadedListener dataLoadedListener = new CommentAdapter.OnDataLoadedListener() {

            @Override
            public void onDataLoaded(boolean isEmpty) {
                if (!isAdded())
                    return;
                if (!isEmpty) {
                    // Hide the empty view if there are already some displayed comments
                    mFilteredCommentsView.hideEmptyView();
                } else if (!mIsUpdatingComments) {
                    // Change LOADING to NO_CONTENT message
                    mFilteredCommentsView.updateEmptyView(EmptyViewMessageType.NO_CONTENT);
                }
            }
        };
        // adapter calls this to request more comments from server when it reaches the end
        CommentAdapter.OnLoadMoreListener loadMoreListener = new CommentAdapter.OnLoadMoreListener() {

            @Override
            public void onLoadMore() {
                if (mCanLoadMoreComments && !mIsUpdatingComments) {
                    updateComments(true);
                }
            }
        };
        // adapter calls this when selected comments have changed (CAB)
        CommentAdapter.OnSelectedItemsChangeListener changeListener = new CommentAdapter.OnSelectedItemsChangeListener() {

            @Override
            public void onSelectedItemsChanged() {
                if (mActionMode != null) {
                    if (getSelectedCommentCount() == 0) {
                        mActionMode.finish();
                    } else {
                        updateActionModeTitle();
                        // must invalidate to ensure onPrepareActionMode is called
                        mActionMode.invalidate();
                    }
                }
            }
        };
        CommentAdapter.OnCommentPressedListener pressedListener = new CommentAdapter.OnCommentPressedListener() {

            @Override
            public void onCommentPressed(int position, View view) {
                CommentModel comment = getAdapter().getItem(position);
                if (comment == null) {
                    return;
                }
                if (mActionMode == null) {
                    mFilteredCommentsView.invalidate();
                    if (getActivity() instanceof OnCommentSelectedListener) {
                        ((OnCommentSelectedListener) getActivity()).onCommentSelected(comment.getRemoteCommentId());
                    }
                } else {
                    getAdapter().toggleItemSelected(position, view);
                }
            }

            @Override
            public void onCommentLongPressed(int position, View view) {
                // enable CAB if it's not already enabled
                if (mActionMode == null) {
                    if (getActivity() instanceof AppCompatActivity) {
                        ((AppCompatActivity) getActivity()).startSupportActionMode(new ActionModeCallback());
                        getAdapter().setEnableSelection(true);
                        getAdapter().setItemSelected(position, true, view);
                    }
                } else {
                    getAdapter().toggleItemSelected(position, view);
                }
            }
        };
        mAdapter = new CommentAdapter(getActivity(), mSite);
        mAdapter.setOnCommentPressedListener(pressedListener);
        mAdapter.setOnDataLoadedListener(dataLoadedListener);
        mAdapter.setOnLoadMoreListener(loadMoreListener);
        mAdapter.setOnSelectedItemsChangeListener(changeListener);
    }
    return mAdapter;
}
Also used : AppCompatActivity(android.support.v7.app.AppCompatActivity) View(android.view.View) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 9 with CommentModel

use of org.wordpress.android.fluxc.model.CommentModel in project WordPress-Android by wordpress-mobile.

the class CommentList method isSameList.

/*
     * does passed list contain the same comments as this list?
     */
public boolean isSameList(CommentList comments) {
    if (comments == null || comments.size() != this.size()) {
        return false;
    }
    for (final CommentModel comment : comments) {
        int index = this.indexOfCommentId(comment.getRemoteCommentId());
        if (index == -1) {
            return false;
        }
        final CommentModel thisComment = this.get(index);
        if (!thisComment.getStatus().equals(comment.getStatus())) {
            return false;
        }
        if (!thisComment.getContent().equals(comment.getContent())) {
            return false;
        }
        if (!thisComment.getAuthorName().equals(comment.getAuthorName())) {
            return false;
        }
        if (!thisComment.getAuthorEmail().equals(comment.getAuthorEmail())) {
            return false;
        }
        if (!thisComment.getAuthorUrl().equals(comment.getAuthorUrl())) {
            return false;
        }
    }
    return true;
}
Also used : CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Aggregations

CommentModel (org.wordpress.android.fluxc.model.CommentModel)9 View (android.view.View)2 SiteModel (org.wordpress.android.fluxc.model.SiteModel)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 ImageView (android.widget.ImageView)1 ProgressBar (android.widget.ProgressBar)1 RelativeLayout (android.widget.RelativeLayout)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 Subscribe (org.greenrobot.eventbus.Subscribe)1 CommentStatus (org.wordpress.android.fluxc.model.CommentStatus)1 RemoteCommentPayload (org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload)1 RemoteCreateCommentPayload (org.wordpress.android.fluxc.store.CommentStore.RemoteCreateCommentPayload)1 CommentList (org.wordpress.android.models.CommentList)1 FilteredRecyclerView (org.wordpress.android.ui.FilteredRecyclerView)1 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)1