Search in sources :

Example 1 with RecyclerItemDecoration

use of org.wordpress.android.widgets.RecyclerItemDecoration in project WordPress-Android by wordpress-mobile.

the class ReaderUserListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reader_activity_userlist);
    setTitle(null);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    if (savedInstanceState != null) {
        mRestorePosition = savedInstanceState.getInt(ReaderConstants.KEY_RESTORE_POSITION);
    }
    int spacingHorizontal = 0;
    int spacingVertical = DisplayUtils.dpToPx(this, 1);
    mRecyclerView = (ReaderRecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));
    long blogId = getIntent().getLongExtra(ReaderConstants.ARG_BLOG_ID, 0);
    long postId = getIntent().getLongExtra(ReaderConstants.ARG_POST_ID, 0);
    long commentId = getIntent().getLongExtra(ReaderConstants.ARG_COMMENT_ID, 0);
    loadUsers(blogId, postId, commentId);
}
Also used : RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) ReaderRecyclerView(org.wordpress.android.ui.reader.views.ReaderRecyclerView) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with RecyclerItemDecoration

use of org.wordpress.android.widgets.RecyclerItemDecoration in project WordPress-Android by wordpress-mobile.

the class FilteredRecyclerView method init.

private void init() {
    inflate(getContext(), R.layout.filtered_list_component, this);
    int spacingHorizontal = 0;
    int spacingVertical = DisplayUtils.dpToPx(getContext(), 1);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));
    mToolbar = (Toolbar) findViewById(R.id.toolbar_with_spinner);
    mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
    mEmptyView = (TextView) findViewById(R.id.empty_view);
    // progress bar that appears when loading more items
    mProgressLoadMore = (ProgressBar) findViewById(R.id.progress_loading);
    mProgressLoadMore.setVisibility(View.GONE);
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(getContext(), (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new SwipeToRefreshHelper.RefreshListener() {

        @Override
        public void onRefreshStarted() {
            post(new Runnable() {

                @Override
                public void run() {
                    if (!NetworkUtils.checkConnection(getContext())) {
                        mSwipeToRefreshHelper.setRefreshing(false);
                        updateEmptyView(EmptyViewMessageType.NETWORK_ERROR);
                        return;
                    }
                    if (mFilterListener != null) {
                        mFilterListener.onLoadData();
                    }
                }
            });
        }
    });
    if (mSpinner == null) {
        mSpinner = (Spinner) findViewById(R.id.filter_spinner);
    }
}
Also used : RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Example 3 with RecyclerItemDecoration

use of org.wordpress.android.widgets.RecyclerItemDecoration in project WordPress-Android by wordpress-mobile.

the class PostsListFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.post_list_fragment, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    mProgressLoadMore = (ProgressBar) view.findViewById(R.id.progress);
    mFabView = view.findViewById(R.id.fab_button);
    mEmptyView = view.findViewById(R.id.empty_view);
    mEmptyViewTitle = (TextView) mEmptyView.findViewById(R.id.title_empty);
    mEmptyViewImage = (ImageView) mEmptyView.findViewById(R.id.image_empty);
    Context context = getActivity();
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    int spacingVertical = mIsPage ? 0 : context.getResources().getDimensionPixelSize(R.dimen.card_gutters);
    int spacingHorizontal = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));
    // https://code.google.com/p/android/issues/detail?id=175331
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mFabView.setVisibility(View.GONE);
    }
    mFabView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            newPost();
        }
    });
    return view;
}
Also used : Context(android.content.Context) RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 4 with RecyclerItemDecoration

use of org.wordpress.android.widgets.RecyclerItemDecoration in project WordPress-Android by wordpress-mobile.

the class ReaderCommentListActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    setContentView(R.layout.reader_activity_comment_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (savedInstanceState != null) {
        mBlogId = savedInstanceState.getLong(ReaderConstants.ARG_BLOG_ID);
        mPostId = savedInstanceState.getLong(ReaderConstants.ARG_POST_ID);
        mRestorePosition = savedInstanceState.getInt(ReaderConstants.KEY_RESTORE_POSITION);
        mHasUpdatedComments = savedInstanceState.getBoolean(KEY_HAS_UPDATED_COMMENTS);
        mInterceptedUri = savedInstanceState.getString(ReaderConstants.ARG_INTERCEPTED_URI);
    } else {
        mBlogId = getIntent().getLongExtra(ReaderConstants.ARG_BLOG_ID, 0);
        mPostId = getIntent().getLongExtra(ReaderConstants.ARG_POST_ID, 0);
        mDirectOperation = (DirectOperation) getIntent().getSerializableExtra(ReaderConstants.ARG_DIRECT_OPERATION);
        mCommentId = getIntent().getLongExtra(ReaderConstants.ARG_COMMENT_ID, 0);
        mInterceptedUri = getIntent().getStringExtra(ReaderConstants.ARG_INTERCEPTED_URI);
        // connection so we can show existing comments while offline
        if (NetworkUtils.isNetworkAvailable(this)) {
            ReaderCommentTable.purgeCommentsForPost(mBlogId, mPostId);
        }
    }
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.swipe_to_refresh), new SwipeToRefreshHelper.RefreshListener() {

        @Override
        public void onRefreshStarted() {
            updatePostAndComments();
        }
    });
    mRecyclerView = (ReaderRecyclerView) findViewById(R.id.recycler_view);
    int spacingHorizontal = 0;
    int spacingVertical = DisplayUtils.dpToPx(this, 1);
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));
    mCommentBox = (ViewGroup) findViewById(R.id.layout_comment_box);
    mEditComment = (SuggestionAutoCompleteText) mCommentBox.findViewById(R.id.edit_comment);
    mEditComment.getAutoSaveTextHelper().setUniqueId(String.format(Locale.US, "%d%d", mPostId, mBlogId));
    mSubmitReplyBtn = mCommentBox.findViewById(R.id.btn_submit_reply);
    if (!loadPost()) {
        ToastUtils.showToast(this, R.string.reader_toast_err_get_post);
        finish();
        return;
    }
    mRecyclerView.setAdapter(getCommentAdapter());
    if (savedInstanceState != null) {
        setReplyToCommentId(savedInstanceState.getLong(KEY_REPLY_TO_COMMENT_ID), false);
    }
    refreshComments();
    mSuggestionServiceConnectionManager = new SuggestionServiceConnectionManager(this, mBlogId);
    mSuggestionAdapter = SuggestionUtils.setupSuggestions(mBlogId, this, mSuggestionServiceConnectionManager, mPost.isWP());
    if (mSuggestionAdapter != null) {
        mEditComment.setAdapter(mSuggestionAdapter);
    }
    AnalyticsUtils.trackWithReaderPostDetails(AnalyticsTracker.Stat.READER_ARTICLE_COMMENTS_OPENED, mPost);
}
Also used : SuggestionServiceConnectionManager(org.wordpress.android.ui.suggestion.util.SuggestionServiceConnectionManager) RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) View(android.view.View) TextView(android.widget.TextView) ReaderRecyclerView(org.wordpress.android.ui.reader.views.ReaderRecyclerView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Example 5 with RecyclerItemDecoration

use of org.wordpress.android.widgets.RecyclerItemDecoration in project WordPress-Android by wordpress-mobile.

the class ReaderPostListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.reader_fragment_post_cards, container, false);
    mRecyclerView = (FilteredRecyclerView) rootView.findViewById(R.id.reader_recycler_view);
    Context context = container.getContext();
    // view that appears when current tag/blog has no posts - box images in this view are
    // displayed and animated for tags only
    mEmptyView = rootView.findViewById(R.id.empty_custom_view);
    mEmptyViewBoxImages = mEmptyView.findViewById(R.id.layout_box_images);
    mRecyclerView.setLogT(AppLog.T.READER);
    mRecyclerView.setCustomEmptyView(mEmptyView);
    mRecyclerView.setFilterListener(new FilteredRecyclerView.FilterListener() {

        @Override
        public List<FilterCriteria> onLoadFilterCriteriaOptions(boolean refresh) {
            return null;
        }

        @Override
        public void onLoadFilterCriteriaOptionsAsync(FilteredRecyclerView.FilterCriteriaAsyncLoaderListener listener, boolean refresh) {
            loadTags(listener);
        }

        @Override
        public void onLoadData() {
            if (!isAdded()) {
                return;
            }
            if (!NetworkUtils.checkConnection(getActivity())) {
                mRecyclerView.setRefreshing(false);
                return;
            }
            if (mFirstLoad) {
                /* let onResume() take care of this logic, as the FilteredRecyclerView.FilterListener onLoadData method
                    * is called on two moments: once for first time load, and then each time the swipe to refresh gesture
                    * triggers a refresh
                    */
                mRecyclerView.setRefreshing(false);
                mFirstLoad = false;
            } else {
                switch(getPostListType()) {
                    case TAG_FOLLOWED:
                    case TAG_PREVIEW:
                        updatePostsWithTag(getCurrentTag(), UpdateAction.REQUEST_NEWER);
                        break;
                    case BLOG_PREVIEW:
                        updatePostsInCurrentBlogOrFeed(UpdateAction.REQUEST_NEWER);
                        break;
                }
                // make sure swipe-to-refresh progress shows since this is a manual refresh
                mRecyclerView.setRefreshing(true);
            }
        }

        @Override
        public void onFilterSelected(int position, FilterCriteria criteria) {
            onTagChanged((ReaderTag) criteria);
        }

        @Override
        public FilterCriteria onRecallSelection() {
            if (hasCurrentTag()) {
                return getCurrentTag();
            } else {
                AppLog.w(T.READER, "reader post list > no current tag in onRecallSelection");
                return ReaderUtils.getDefaultTag();
            }
        }

        @Override
        public String onShowEmptyViewMessage(EmptyViewMessageType emptyViewMsgType) {
            return null;
        }

        @Override
        public void onShowCustomEmptyView(EmptyViewMessageType emptyViewMsgType) {
            setEmptyTitleAndDescription(EmptyViewMessageType.NETWORK_ERROR.equals(emptyViewMsgType) || EmptyViewMessageType.PERMISSION_ERROR.equals(emptyViewMsgType) || EmptyViewMessageType.GENERIC_ERROR.equals(emptyViewMsgType));
        }
    });
    // add the item decoration (dividers) to the recycler, skipping the first item if the first
    // item is the tag toolbar (shown when viewing posts in followed tags) - this is to avoid
    // having the tag toolbar take up more vertical space than necessary
    int spacingHorizontal = context.getResources().getDimensionPixelSize(R.dimen.reader_card_margin);
    int spacingVertical = context.getResources().getDimensionPixelSize(R.dimen.reader_card_gutters);
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical, false));
    // the following will change the look and feel of the toolbar to match the current design
    mRecyclerView.setToolbarBackgroundColor(ContextCompat.getColor(context, R.color.blue_medium));
    mRecyclerView.setToolbarSpinnerTextColor(ContextCompat.getColor(context, R.color.white));
    mRecyclerView.setToolbarSpinnerDrawable(R.drawable.ic_dropdown_blue_light_24dp);
    mRecyclerView.setToolbarLeftAndRightPadding(getResources().getDimensionPixelSize(R.dimen.margin_medium) + spacingHorizontal, getResources().getDimensionPixelSize(R.dimen.margin_extra_large) + spacingHorizontal);
    // add a menu to the filtered recycler's toolbar
    if (mAccountStore.hasAccessToken() && (getPostListType() == ReaderPostListType.TAG_FOLLOWED || getPostListType() == ReaderPostListType.SEARCH_RESULTS)) {
        setupRecyclerToolbar();
    }
    mRecyclerView.setSwipeToRefreshEnabled(isSwipeToRefreshSupported());
    // bar that appears at top after new posts are loaded
    mNewPostsBar = rootView.findViewById(R.id.layout_new_posts);
    mNewPostsBar.setVisibility(View.GONE);
    mNewPostsBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mRecyclerView.scrollRecycleViewToPosition(0);
            refreshPosts();
        }
    });
    // progress bar that appears when loading more posts
    mProgress = (ProgressBar) rootView.findViewById(R.id.progress_footer);
    mProgress.setVisibility(View.GONE);
    return rootView;
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) FilterCriteria(org.wordpress.android.models.FilterCriteria) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) SearchView(android.support.v7.widget.SearchView) ReaderSiteHeaderView(org.wordpress.android.ui.reader.views.ReaderSiteHeaderView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) AutoCompleteTextView(android.widget.AutoCompleteTextView) RecyclerView(android.support.v7.widget.RecyclerView) ReaderTag(org.wordpress.android.models.ReaderTag) RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) EmptyViewMessageType(org.wordpress.android.ui.EmptyViewMessageType) List(java.util.List) ReaderTagList(org.wordpress.android.models.ReaderTagList) ArrayList(java.util.ArrayList)

Aggregations

RecyclerItemDecoration (org.wordpress.android.widgets.RecyclerItemDecoration)5 View (android.view.View)4 TextView (android.widget.TextView)3 Context (android.content.Context)2 ActionBar (android.support.v7.app.ActionBar)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Toolbar (android.support.v7.widget.Toolbar)2 ImageView (android.widget.ImageView)2 ReaderRecyclerView (org.wordpress.android.ui.reader.views.ReaderRecyclerView)2 SwipeToRefreshHelper (org.wordpress.android.util.helpers.SwipeToRefreshHelper)2 CustomSwipeRefreshLayout (org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)2 SearchView (android.support.v7.widget.SearchView)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FilterCriteria (org.wordpress.android.models.FilterCriteria)1 ReaderTag (org.wordpress.android.models.ReaderTag)1