Search in sources :

Example 1 with SlideInItemAnimator

use of io.plaidapp.ui.recyclerview.SlideInItemAnimator in project plaid by nickbutcher.

the class PlayerActivity method bindPlayer.

void bindPlayer() {
    if (player == null)
        return;
    final Resources res = getResources();
    final NumberFormat nf = NumberFormat.getInstance();
    Glide.with(this).load(player.getHighQualityAvatarUrl()).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
    playerName.setText(player.name.toLowerCase());
    if (!TextUtils.isEmpty(player.bio)) {
        DribbbleUtils.parseAndSetText(bio, player.bio);
    } else {
        bio.setVisibility(View.GONE);
    }
    shotCount.setText(res.getQuantityString(R.plurals.shots, player.shots_count, nf.format(player.shots_count)));
    if (player.shots_count == 0) {
        shotCount.setCompoundDrawablesRelativeWithIntrinsicBounds(null, getDrawable(R.drawable.avd_no_shots), null, null);
    }
    setFollowerCount(player.followers_count);
    likesCount.setText(res.getQuantityString(R.plurals.likes, player.likes_count, nf.format(player.likes_count)));
    // load the users shots
    dataManager = new PlayerShotsDataManager(this, player) {

        @Override
        public void onDataLoaded(List<Shot> data) {
            if (data != null && data.size() > 0) {
                if (adapter.getDataItemCount() == 0) {
                    loading.setVisibility(View.GONE);
                    ViewUtils.setPaddingTop(shots, likesCount.getBottom());
                }
                adapter.addAndResort(data);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    shots.setAdapter(adapter);
    shots.setItemAnimator(new SlideInItemAnimator());
    shots.setVisibility(View.VISIBLE);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    shots.setLayoutManager(layoutManager);
    shots.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadData();
        }
    });
    shots.setHasFixedSize(true);
    // forward on any clicks above the first item in the grid (i.e. in the paddingTop)
    // to 'pass through' to the view behind
    shots.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int firstVisible = layoutManager.findFirstVisibleItemPosition();
            if (firstVisible > 0)
                return false;
            // if no data loaded then pass through
            if (adapter.getDataItemCount() == 0) {
                return container.dispatchTouchEvent(event);
            }
            final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0);
            if (vh == null)
                return false;
            final int firstTop = vh.itemView.getTop();
            if (event.getY() < firstTop) {
                return container.dispatchTouchEvent(event);
            }
            return false;
        }
    });
    // check if following
    if (dataManager.getDribbblePrefs().isLoggedIn()) {
        if (player.id == dataManager.getDribbblePrefs().getUserId()) {
            TransitionManager.beginDelayedTransition(container);
            follow.setVisibility(View.GONE);
            ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight() - ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin);
        } else {
            final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id);
            followingCall.enqueue(new Callback<Void>() {

                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    following = response.isSuccessful();
                    if (!following)
                        return;
                    TransitionManager.beginDelayedTransition(container);
                    follow.setText(R.string.following);
                    follow.setActivated(true);
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                }
            });
        }
    }
    if (player.shots_count > 0) {
        // kick off initial load
        dataManager.loadData();
    } else {
        loading.setVisibility(View.GONE);
    }
}
Also used : PlayerShotsDataManager(io.plaidapp.data.api.dribbble.PlayerShotsDataManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) Resources(android.content.res.Resources) Shot(io.plaidapp.data.api.dribbble.model.Shot) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) NumberFormat(java.text.NumberFormat)

Example 2 with SlideInItemAnimator

use of io.plaidapp.ui.recyclerview.SlideInItemAnimator in project plaid by nickbutcher.

the class PlayerSheet method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.player_sheet);
    ButterKnife.bind(this);
    final Intent intent = getIntent();
    @PlayerSheetMode final int mode = intent.getIntExtra(EXTRA_MODE, -1);
    switch(mode) {
        case MODE_SHOT_LIKES:
            shot = intent.getParcelableExtra(EXTRA_SHOT);
            title.setText(getResources().getQuantityString(R.plurals.fans, (int) shot.likes_count, NumberFormat.getInstance().format(shot.likes_count)));
            dataManager = new ShotLikesDataManager(this, shot.id) {

                @Override
                public void onDataLoaded(List<Like> likes) {
                    adapter.addItems(likes);
                }
            };
            break;
        case MODE_FOLLOWERS:
            player = intent.getParcelableExtra(EXTRA_USER);
            title.setText(getResources().getQuantityString(R.plurals.follower_count, player.followers_count, NumberFormat.getInstance().format(player.followers_count)));
            dataManager = new FollowersDataManager(this, player.id) {

                @Override
                public void onDataLoaded(List<Follow> followers) {
                    adapter.addItems(followers);
                }
            };
            break;
        default:
            throw new IllegalArgumentException("Unknown launch mode.");
    }
    bottomSheet.registerCallback(new BottomSheet.Callbacks() {

        @Override
        public void onSheetDismissed() {
            finishAfterTransition();
        }

        @Override
        public void onSheetPositionChanged(int sheetTop, boolean interacted) {
            if (interacted && close.getVisibility() != View.VISIBLE) {
                close.setVisibility(View.VISIBLE);
                close.setAlpha(0f);
                close.animate().alpha(1f).setDuration(400L).setInterpolator(getLinearOutSlowInInterpolator(PlayerSheet.this)).start();
            }
            if (sheetTop == 0) {
                showClose();
            } else {
                showDown();
            }
        }
    });
    layoutManager = new LinearLayoutManager(this);
    playerList.setLayoutManager(layoutManager);
    playerList.setItemAnimator(new SlideInItemAnimator());
    adapter = new PlayerAdapter(this);
    dataManager.registerCallback(adapter);
    playerList.setAdapter(adapter);
    playerList.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadData();
        }
    });
    playerList.addOnScrollListener(titleElevation);
    // kick off initial load
    dataManager.loadData();
}
Also used : Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) FollowersDataManager(io.plaidapp.data.api.dribbble.FollowersDataManager) ShotLikesDataManager(io.plaidapp.data.api.dribbble.ShotLikesDataManager) Like(io.plaidapp.data.api.dribbble.model.Like) Follow(io.plaidapp.data.api.dribbble.model.Follow) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) BottomSheet(io.plaidapp.ui.widget.BottomSheet) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener)

Example 3 with SlideInItemAnimator

use of io.plaidapp.ui.recyclerview.SlideInItemAnimator in project plaid by nickbutcher.

the class SearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();
    dataManager = new SearchDataManager(this) {

        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, getTransition(R.transition.search_show_results));
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, getTransition(R.transition.auto));
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
    results.setAdapter(adapter);
    results.setItemAnimator(new SlideInItemAnimator());
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    setupTransitions();
    onNewIntent(getIntent());
    ShortcutHelper.reportSearchUsed(this);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) SearchDataManager(io.plaidapp.data.SearchDataManager) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) Point(android.graphics.Point)

Aggregations

InfiniteScrollListener (io.plaidapp.ui.recyclerview.InfiniteScrollListener)3 SlideInItemAnimator (io.plaidapp.ui.recyclerview.SlideInItemAnimator)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Point (android.graphics.Point)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 SearchDataManager (io.plaidapp.data.SearchDataManager)1 FollowersDataManager (io.plaidapp.data.api.dribbble.FollowersDataManager)1 PlayerShotsDataManager (io.plaidapp.data.api.dribbble.PlayerShotsDataManager)1 ShotLikesDataManager (io.plaidapp.data.api.dribbble.ShotLikesDataManager)1 Follow (io.plaidapp.data.api.dribbble.model.Follow)1 Like (io.plaidapp.data.api.dribbble.model.Like)1 Shot (io.plaidapp.data.api.dribbble.model.Shot)1