diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-04-15 12:58:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-04-15 12:58:55 +0000 |
commit | 90fa50f5d1f89b544cc519c439ad3dca5bddb879 (patch) | |
tree | 1bfd5bdccb18984ef40d42ca81b5f13eb6aecb12 /app/src/main/java | |
parent | c79a65300bcbd3a5547fbf17ea6eca9d3393c338 (diff) | |
download | infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.tar infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.tar.gz infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.tar.bz2 infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.tar.lz infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.tar.xz infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.tar.zst infinity-for-reddit-90fa50f5d1f89b544cc519c439ad3dca5bddb879.zip |
Add a fast scroller on SubscribedSubredditsListingFragment.
Diffstat (limited to 'app/src/main/java')
2 files changed, 49 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java index 3f503fea..d5cb996a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java @@ -21,6 +21,7 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; +import me.zhanghai.android.fastscroll.PopupTextProvider; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.FavoriteThing; @@ -30,7 +31,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { +public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements PopupTextProvider { private static final int VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER = 0; private static final int VIEW_TYPE_FAVORITE_SUBREDDIT = 1; private static final int VIEW_TYPE_SUBREDDIT_DIVIDER = 2; @@ -409,6 +410,51 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte this.userIconUrl = userIconUrl; } + @NonNull + @Override + public String getPopupText(int position) { + switch (getItemViewType(position)) { + case VIEW_TYPE_SUBREDDIT: + if (hasClearSelectionRow && position == 0) { + return ""; + } else if (itemClickListener != null && !hasClearSelectionRow && position == 0) { + return ""; + } else if (hasClearSelectionRow && position == 1) { + return ""; + } else { + int offset; + if (itemClickListener != null) { + if (hasClearSelectionRow) { + offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ? + mFavoriteSubscribedSubredditData.size() + 4 : 0; + } else { + offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ? + mFavoriteSubscribedSubredditData.size() + 3 : 0; + } + } else { + offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ? + mFavoriteSubscribedSubredditData.size() + 2 : 0; + } + + return mSubscribedSubredditData.get(position - offset).getName().substring(0, 1).toUpperCase(); + } + case VIEW_TYPE_FAVORITE_SUBREDDIT: + int offset; + if (itemClickListener != null) { + if (hasClearSelectionRow) { + offset = 3; + } else { + offset = 2; + } + } else { + offset = 1; + } + return mFavoriteSubscribedSubredditData.get(position - offset).getName().substring(0, 1).toUpperCase(); + default: + return ""; + } + } + public interface ItemClickListener { void onClick(String name, String iconUrl, boolean subredditIsUser); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java index 09bd6e32..7ee62bdf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java @@ -29,6 +29,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import me.zhanghai.android.fastscroll.FastScrollerBuilder; import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; @@ -122,6 +123,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra } mRecyclerView.setAdapter(adapter); + new FastScrollerBuilder(mRecyclerView).build(); mSubscribedSubredditViewModel = new ViewModelProvider(this, new SubscribedSubredditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName)) |