Search in sources :

Example 1 with LoadMoreAdapter

use of me.zhanghai.android.douya.ui.LoadMoreAdapter in project Douya by DreaminginCodeZH.

the class BroadcastFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    CustomTabsHelperFragment.attachTo(this);
    mBroadcastAndCommentListResource = BroadcastAndCommentListResource.attachTo(mBroadcastId, mBroadcast, this);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.setTitle(getTitle());
    activity.setSupportActionBar(mToolbar);
    mContainerLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ActivityCompat.finishAfterTransition(getActivity());
        }
    });
    ViewCompat.setTransitionName(mSharedView, Broadcast.makeTransitionName(mBroadcastId));
    // This magically gives better visual effect when the broadcast is partially visible. Using
    // setEnterSharedElementCallback() disables this hack when no transition is used to start
    // this Activity.
    ActivityCompat.setEnterSharedElementCallback(activity, new SharedElementCallback() {

        @Override
        public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
            mBroadcastCommentList.scrollToPosition(0);
        }
    });
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mBroadcastAndCommentListResource.loadBroadcast();
            mBroadcastAndCommentListResource.loadCommentList(false);
        }
    });
    mBroadcastCommentList.setHasFixedSize(true);
    mBroadcastCommentList.setItemAnimator(new NoChangeAnimationItemAnimator());
    mBroadcastCommentList.setLayoutManager(new LinearLayoutManager(activity));
    mBroadcastAdapter = new SingleBroadcastAdapter(null, this);
    setBroadcast(mBroadcastAndCommentListResource.getBroadcast());
    mCommentAdapter = new CommentAdapter(mBroadcastAndCommentListResource.getCommentList(), new ClickableSimpleAdapter.OnItemClickListener<Comment, CommentAdapter.ViewHolder>() {

        @Override
        public void onItemClick(RecyclerView parent, Comment item, CommentAdapter.ViewHolder holder) {
            onShowCommentAction(item);
        }
    });
    mAdapter = new LoadMoreAdapter(R.layout.load_more_item, mBroadcastAdapter, mCommentAdapter);
    mBroadcastCommentList.setAdapter(mAdapter);
    mBroadcastCommentList.addOnScrollListener(new OnVerticalScrollListener() {

        public void onScrolledToBottom() {
            mBroadcastAndCommentListResource.loadCommentList(true);
        }
    });
    CheatSheetUtils.setup(mSendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onSendComment();
        }
    });
    updateSendCommentStatus();
    if (savedInstanceState == null) {
        if (mShowSendComment) {
            TransitionUtils.postAfterTransition(this, new Runnable() {

                @Override
                public void run() {
                    onShowSendComment();
                }
            });
        }
    }
    TransitionUtils.setEnterReturnExplode(this);
    TransitionUtils.setupTransitionOnActivityCreated(this);
}
Also used : Comment(me.zhanghai.android.douya.network.api.info.apiv2.Comment) AppCompatActivity(android.support.v7.app.AppCompatActivity) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) SharedElementCallback(android.support.v4.app.SharedElementCallback) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)

Example 2 with LoadMoreAdapter

use of me.zhanghai.android.douya.ui.LoadMoreAdapter in project Douya by DreaminginCodeZH.

the class BaseBroadcastListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    CustomTabsHelperFragment.attachTo(this);
    mBroadcastListResource = onAttachBroadcastListResource();
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            onSwipeRefresh();
        }
    });
    mBroadcastList.setHasFixedSize(true);
    mBroadcastList.setItemAnimator(new NoChangeAnimationItemAnimator());
    // Always use StaggeredGridLayoutManager so that instance state can be saved.
    Activity activity = getActivity();
    int columnCount = CardUtils.getColumnCount(activity);
    mBroadcastList.setLayoutManager(new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL));
    mBroadcastAdapter = new BroadcastAdapter(mBroadcastListResource.get(), this);
    mAdapter = new LoadMoreAdapter(R.layout.load_more_card_item, mBroadcastAdapter);
    mBroadcastList.setAdapter(mAdapter);
    final AppBarHost appBarHost = (AppBarHost) getParentFragment();
    mBroadcastList.addOnScrollListener(new OnVerticalScrollWithPagingTouchSlopListener(activity) {

        @Override
        public void onScrolled(int dy) {
            if (!RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
                onShow();
            }
        }

        @Override
        public void onScrolledUp() {
            onShow();
        }

        private void onShow() {
            appBarHost.showAppBar();
            mSendFab.show();
        }

        @Override
        public void onScrolledDown() {
            if (RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
                appBarHost.hideAppBar();
                mSendFab.hide();
            }
        }

        @Override
        public void onScrolledToBottom() {
            mBroadcastListResource.load(true);
        }
    });
    updateRefreshing();
    CheatSheetUtils.setup(mSendFab);
    mSendFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onSendBroadcast();
        }
    });
}
Also used : Activity(android.app.Activity) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) FriendlySwipeRefreshLayout(me.zhanghai.android.douya.ui.FriendlySwipeRefreshLayout) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) OnVerticalScrollWithPagingTouchSlopListener(me.zhanghai.android.douya.ui.OnVerticalScrollWithPagingTouchSlopListener) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator) AppBarHost(me.zhanghai.android.douya.ui.AppBarHost)

Example 3 with LoadMoreAdapter

use of me.zhanghai.android.douya.ui.LoadMoreAdapter in project Douya by DreaminginCodeZH.

the class NotificationListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mNotificationListResource = NotificationListResource.attachTo(this);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
        }
    });
    mNotificationList.setHasFixedSize(true);
    mNotificationList.setItemAnimator(new NoChangeAnimationItemAnimator());
    Activity activity = getActivity();
    mNotificationList.setLayoutManager(new LinearLayoutManager(activity));
    mNotificationAdapter = new NotificationAdapter(mNotificationListResource.get(), activity);
    mNotificationAdapter.setListener(this);
    mAdapter = new LoadMoreAdapter(R.layout.load_more_item, mNotificationAdapter);
    mNotificationList.setAdapter(mAdapter);
    mNotificationList.addOnScrollListener(new OnVerticalScrollListener() {

        @Override
        public void onScrolledToBottom() {
            mNotificationListResource.load(true);
        }
    });
    updateRefreshing();
}
Also used : Activity(android.app.Activity) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)

Example 4 with LoadMoreAdapter

use of me.zhanghai.android.douya.ui.LoadMoreAdapter in project Douya by DreaminginCodeZH.

the class UserListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mUserListResource = onAttachUserListResource();
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mUserListResource.load(false);
        }
    });
    // TODO: OK?
    //mUserList.setHasFixedSize(true);
    mUserList.setItemAnimator(new NoChangeAnimationItemAnimator());
    mUserList.setLayoutManager(new LinearLayoutManager(getActivity()));
    mUserAdapter = onCreateAdapter();
    if (mUserListResource.has()) {
        //noinspection unchecked
        mUserAdapter.replace(mUserListResource.get());
    }
    mAdapter = new LoadMoreAdapter(R.layout.load_more_item, mUserAdapter);
    mUserList.setAdapter(mAdapter);
    mUserList.addOnScrollListener(new OnVerticalScrollListener() {

        @Override
        public void onScrolledToBottom() {
            mUserListResource.load(true);
        }
    });
    updateRefreshing();
}
Also used : LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)4 LoadMoreAdapter (me.zhanghai.android.douya.ui.LoadMoreAdapter)4 NoChangeAnimationItemAnimator (me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 OnVerticalScrollListener (me.zhanghai.android.douya.ui.OnVerticalScrollListener)3 Activity (android.app.Activity)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 BindView (butterknife.BindView)2 SharedElementCallback (android.support.v4.app.SharedElementCallback)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 Comment (me.zhanghai.android.douya.network.api.info.apiv2.Comment)1 AppBarHost (me.zhanghai.android.douya.ui.AppBarHost)1 FriendlySwipeRefreshLayout (me.zhanghai.android.douya.ui.FriendlySwipeRefreshLayout)1 OnVerticalScrollWithPagingTouchSlopListener (me.zhanghai.android.douya.ui.OnVerticalScrollWithPagingTouchSlopListener)1