mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-29 04:17:12 +01:00
Add a fast scroller on SubscribedSubredditsListingFragment.
This commit is contained in:
parent
c79a65300b
commit
90fa50f5d1
@ -85,4 +85,5 @@ dependencies {
|
|||||||
implementation 'com.r0adkll:slidableactivity:2.1.0'
|
implementation 'com.r0adkll:slidableactivity:2.1.0'
|
||||||
implementation 'com.atlassian.commonmark:commonmark:0.13.1'
|
implementation 'com.atlassian.commonmark:commonmark:0.13.1'
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
|
implementation 'me.zhanghai.android.fastscroll:library:1.1.2'
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
|
import me.zhanghai.android.fastscroll.PopupTextProvider;
|
||||||
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
|
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
|
||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.FavoriteThing;
|
import ml.docilealligator.infinityforreddit.FavoriteThing;
|
||||||
@ -30,7 +31,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib
|
|||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
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_DIVIDER = 0;
|
||||||
private static final int VIEW_TYPE_FAVORITE_SUBREDDIT = 1;
|
private static final int VIEW_TYPE_FAVORITE_SUBREDDIT = 1;
|
||||||
private static final int VIEW_TYPE_SUBREDDIT_DIVIDER = 2;
|
private static final int VIEW_TYPE_SUBREDDIT_DIVIDER = 2;
|
||||||
@ -409,6 +410,51 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
this.userIconUrl = userIconUrl;
|
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 {
|
public interface ItemClickListener {
|
||||||
void onClick(String name, String iconUrl, boolean subredditIsUser);
|
void onClick(String name, String iconUrl, boolean subredditIsUser);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import javax.inject.Named;
|
|||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
|
||||||
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
|
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
|
||||||
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
|
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
|
||||||
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
|
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
|
||||||
@ -122,6 +123,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
|
|||||||
}
|
}
|
||||||
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
new FastScrollerBuilder(mRecyclerView).build();
|
||||||
|
|
||||||
mSubscribedSubredditViewModel = new ViewModelProvider(this,
|
mSubscribedSubredditViewModel = new ViewModelProvider(this,
|
||||||
new SubscribedSubredditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName))
|
new SubscribedSubredditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName))
|
||||||
|
Loading…
Reference in New Issue
Block a user