mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Retrieve subreddit data for subscribed private subs (#586)
Fetch active user count, subreddit icon etc. for subscribed private subs
This commit is contained in:
parent
9ef1b4decd
commit
5ec29e0c96
@ -493,7 +493,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
}
|
||||
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
|
@ -433,7 +433,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
}
|
||||
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
|
@ -402,7 +402,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
|
||||
mRetrofit, iconImageUrl -> {
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
|
@ -424,7 +424,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
|
||||
mRetrofit, iconImageUrl -> {
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
|
@ -451,7 +451,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
|
||||
mRetrofit, iconImageUrl -> {
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
|
@ -436,7 +436,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
|
||||
mRetrofit, iconImageUrl -> {
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
|
@ -588,7 +588,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
|
||||
private void fetchSubredditData() {
|
||||
if (!mFetchSubredditInfoSuccess) {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
||||
@ -1580,6 +1580,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
SidebarFragment fragment = new SidebarFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SidebarFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
|
@ -518,7 +518,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
if (mPost.getSubredditIconUrl() == null) {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed().substring(2),
|
||||
mRetrofit, iconImageUrl -> {
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
|
@ -30,6 +30,9 @@ public interface RedditAPI {
|
||||
@GET("r/{subredditName}/about.json?raw_json=1")
|
||||
Call<String> getSubredditData(@Path("subredditName") String subredditName);
|
||||
|
||||
@GET("r/{subredditName}/about.json?raw_json=1")
|
||||
Call<String> getSubredditDataOauth(@Path("subredditName") String subredditName, @HeaderMap Map<String, String> headers);
|
||||
|
||||
@GET("subreddits/mine/subscriber?raw_json=1")
|
||||
Call<String> getSubscribedThing(@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
|
||||
|
||||
|
@ -14,7 +14,7 @@ import retrofit2.Retrofit;
|
||||
public class LoadSubredditIcon {
|
||||
|
||||
public static void loadSubredditIcon(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
String subredditName, Retrofit retrofit,
|
||||
String subredditName, String accessToken, Retrofit oauthRetrofit, Retrofit retrofit,
|
||||
LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
|
||||
executor.execute(() -> {
|
||||
SubredditDao subredditDao = redditDataRoomDatabase.subredditDao();
|
||||
@ -23,7 +23,7 @@ public class LoadSubredditIcon {
|
||||
String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl();
|
||||
handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl));
|
||||
} else {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(retrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) {
|
||||
ArrayList<SubredditData> singleSubredditDataList = new ArrayList<>();
|
||||
|
@ -255,6 +255,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
private ArrayList<String> readPosts;
|
||||
private Unbinder unbinder;
|
||||
private Map<String, String> subredditOrUserIcons = new HashMap<>();
|
||||
private String accessToken;
|
||||
|
||||
public PostFragment() {
|
||||
// Required empty public constructor
|
||||
@ -424,7 +425,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
postType = getArguments().getInt(EXTRA_POST_TYPE);
|
||||
|
||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||
accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
|
||||
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
|
||||
@ -1687,7 +1688,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
} else {
|
||||
if (isSubreddit) {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
subredditOrUserName, mRetrofit,
|
||||
subredditOrUserName, accessToken, mOauthRetrofit, mRetrofit,
|
||||
iconImageUrl -> {
|
||||
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
|
||||
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
|
||||
|
@ -56,34 +56,39 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomS
|
||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
|
||||
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel;
|
||||
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SidebarFragment extends Fragment {
|
||||
|
||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
public static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||
public SubredditViewModel mSubredditViewModel;
|
||||
@BindView(R.id.swipe_refresh_layout_sidebar_fragment)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
@BindView(R.id.markdown_recycler_view_sidebar_fragment)
|
||||
RecyclerView recyclerView;
|
||||
private Activity activity;
|
||||
private String subredditName;
|
||||
public SubredditViewModel mSubredditViewModel;
|
||||
private LinearLayoutManagerBugFixed linearLayoutManager;
|
||||
private int markdownColor;
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
Retrofit mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private Activity activity;
|
||||
private String mAccessToken;
|
||||
private String subredditName;
|
||||
private LinearLayoutManagerBugFixed linearLayoutManager;
|
||||
private int markdownColor;
|
||||
private String sidebarDescription;
|
||||
|
||||
public SidebarFragment() {
|
||||
@ -100,6 +105,7 @@ public class SidebarFragment extends Fragment {
|
||||
|
||||
ButterKnife.bind(this, rootView);
|
||||
|
||||
mAccessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
|
||||
if (subredditName == null) {
|
||||
Toast.makeText(activity, R.string.error_getting_subreddit_name, Toast.LENGTH_SHORT).show();
|
||||
@ -218,7 +224,7 @@ public class SidebarFragment extends Fragment {
|
||||
|
||||
public void fetchSubredditData() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
@ -803,7 +803,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
return;
|
||||
} else {
|
||||
for (int i = currentSearchIndex - 1; i >= 0; i--) {
|
||||
if (visibleComments.get(i).getCommentRawText() !=null &&
|
||||
if (visibleComments.get(i).getCommentRawText() != null &&
|
||||
visibleComments.get(i).getCommentRawText().toLowerCase().contains(query.toLowerCase())) {
|
||||
if (mCommentsAdapter != null) {
|
||||
mCommentsAdapter.highlightSearchResult(i);
|
||||
@ -1318,7 +1318,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
|
||||
private void fetchCommentsRespectRecommendedSort(boolean changeRefreshState, boolean checkSortState, String sortType) {
|
||||
if (mRespectSubredditRecommendedSortType && mPost != null) {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit, mPost.getSubredditName(),
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, mPost.getSubredditName(), mAccessToken,
|
||||
new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
@ -1760,11 +1760,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
if (mCommentsAdapter != null && chooseYourView != null) {
|
||||
int currentPosition = ((LinearLayoutManagerBugFixed) chooseYourView.getLayoutManager()).findFirstVisibleItemPosition();
|
||||
//int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition);
|
||||
int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? currentPosition - 1 : currentPosition);
|
||||
int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? currentPosition - 1 : currentPosition);
|
||||
if (previousParentPosition < 0) {
|
||||
return;
|
||||
}
|
||||
mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? previousParentPosition + 1 : previousParentPosition);
|
||||
mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? previousParentPosition + 1 : previousParentPosition);
|
||||
mIsSmoothScrolling = true;
|
||||
chooseYourView.getLayoutManager().startSmoothScroll(mSmoothScroller);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package ml.docilealligator.infinityforreddit.subreddit;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -15,10 +17,16 @@ import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class FetchSubredditData {
|
||||
public static void fetchSubredditData(Retrofit retrofit, String subredditName, final FetchSubredditDataListener fetchSubredditDataListener) {
|
||||
public static void fetchSubredditData(Retrofit oauthRetrofit, Retrofit retrofit, String subredditName, String accessToken, final FetchSubredditDataListener fetchSubredditDataListener) {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
|
||||
Call<String> subredditData = api.getSubredditData(subredditName);
|
||||
Call<String> subredditData;
|
||||
if (oauthRetrofit == null || TextUtils.isEmpty(accessToken)) {
|
||||
subredditData = api.getSubredditData(subredditName);
|
||||
} else {
|
||||
RedditAPI oauthApi = oauthRetrofit.create(RedditAPI.class);
|
||||
subredditData = oauthApi.getSubredditDataOauth(subredditName, APIUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
subredditData.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
@ -51,7 +59,7 @@ public class FetchSubredditData {
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, String> headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : Collections.unmodifiableMap(map);
|
||||
Map<String, String> headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : Collections.unmodifiableMap(map);
|
||||
Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers);
|
||||
subredditDataCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
@ -68,7 +76,7 @@ public class FetchSubredditData {
|
||||
public void onParseSubredditListingDataFail() {
|
||||
fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class SubredditSubscription {
|
||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
String subredditName,
|
||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||
FetchSubredditData.fetchSubredditData(retrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(null, retrofit, subredditName, "", new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
insertSubscription(executor, handler, redditDataRoomDatabase,
|
||||
@ -76,7 +76,7 @@ public class SubredditSubscription {
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
if (action.equals("sub")) {
|
||||
FetchSubredditData.fetchSubredditData(retrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
insertSubscription(executor, handler, redditDataRoomDatabase,
|
||||
|
Loading…
Reference in New Issue
Block a user