use of io.plaidapp.ui.recyclerview.InfiniteScrollListener 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);
}
}
use of io.plaidapp.ui.recyclerview.InfiniteScrollListener in project plaid by nickbutcher.
the class HomeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
setActionBar(toolbar);
if (savedInstanceState == null) {
animateToolbar();
}
setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
dribbblePrefs = DribbblePrefs.get(this);
designerNewsPrefs = DesignerNewsPrefs.get(this);
filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() {
@Override
public void requestDribbbleAuthorisation(View sharedElement, Source forSource) {
Intent login = new Intent(HomeActivity.this, DribbbleLogin.class);
MorphTransform.addExtras(login, ContextCompat.getColor(HomeActivity.this, R.color.background_dark), sharedElement.getHeight() / 2);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElement, getString(R.string.transition_dribbble_login));
startActivityForResult(login, getAuthSourceRequestCode(forSource), options.toBundle());
}
});
dataManager = new DataManager(this, filtersAdapter) {
@Override
public void onDataLoaded(List<? extends PlaidItem> data) {
adapter.addAndResort(data);
checkEmptyState();
}
};
adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
grid.setAdapter(adapter);
layoutManager = new GridLayoutManager(this, columns);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return adapter.getItemColumnSpan(position);
}
});
grid.setLayoutManager(layoutManager);
grid.addOnScrollListener(toolbarElevation);
grid.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
@Override
public void onLoadMore() {
dataManager.loadAllDataSources();
}
});
grid.setHasFixedSize(true);
grid.addItemDecoration(new GridItemDividerDecoration(adapter.getDividedViewHolderClasses(), this, R.dimen.divider_height, R.color.divider));
grid.setItemAnimator(new HomeGridItemAnimator());
// drawer layout treats fitsSystemWindows specially so we have to handle insets ourselves
drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.leftMargin += insets.getSystemWindowInsetLeft();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
grid.setPadding(// landscape
grid.getPaddingLeft() + insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), // landscape
grid.getPaddingRight() + insets.getSystemWindowInsetRight(), grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// inset the fab for the navbar
ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
// portrait
lpFab.bottomMargin += insets.getSystemWindowInsetBottom();
// landscape
lpFab.rightMargin += insets.getSystemWindowInsetRight();
fab.setLayoutParams(lpFab);
View postingStub = findViewById(R.id.stub_posting_progress);
ViewGroup.MarginLayoutParams lpPosting = (ViewGroup.MarginLayoutParams) postingStub.getLayoutParams();
// portrait
lpPosting.bottomMargin += insets.getSystemWindowInsetBottom();
// landscape
lpPosting.rightMargin += insets.getSystemWindowInsetRight();
postingStub.setLayoutParams(lpPosting);
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
final boolean ltr = filtersList.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
filtersList.setPaddingRelative(filtersList.getPaddingStart(), filtersList.getPaddingTop() + insets.getSystemWindowInsetTop(), filtersList.getPaddingEnd() + (ltr ? insets.getSystemWindowInsetRight() : 0), filtersList.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
setupTaskDescription();
filtersList.setAdapter(filtersAdapter);
filtersList.setItemAnimator(new FilterAdapter.FilterAnimator());
filtersAdapter.registerFilterChangedCallback(filtersChangedCallbacks);
dataManager.loadAllDataSources();
ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(filtersList);
checkEmptyState();
}
use of io.plaidapp.ui.recyclerview.InfiniteScrollListener 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();
}
use of io.plaidapp.ui.recyclerview.InfiniteScrollListener 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);
}
Aggregations