mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-28 02:24:45 +01:00
Fixing issue with swiping to see new posts.
This commit fixes the issue with Fetching new posts when swiping on the post detail page.
This commit is contained in:
parent
ecdd9da9c8
commit
6d5ba059f8
@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.SaveComment;
|
|||||||
import eu.toldi.infinityforlemmy.SaveThing;
|
import eu.toldi.infinityforlemmy.SaveThing;
|
||||||
import eu.toldi.infinityforlemmy.SortType;
|
import eu.toldi.infinityforlemmy.SortType;
|
||||||
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
|
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
|
||||||
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||||
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
|
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
|
||||||
import eu.toldi.infinityforlemmy.comment.Comment;
|
import eu.toldi.infinityforlemmy.comment.Comment;
|
||||||
@ -533,62 +534,31 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
Handler handler = new Handler(Looper.getMainLooper());
|
Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) {
|
if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) {
|
||||||
|
int nextPage = posts.size() / 25 + 1;
|
||||||
|
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
RedditAPI api = (mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit).create(RedditAPI.class);
|
LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
|
||||||
Call<String> call;
|
Call<String> call;
|
||||||
String afterKey = posts.isEmpty() ? null : posts.get(posts.size() - 1).getFullName();
|
|
||||||
switch (postType) {
|
switch (postType) {
|
||||||
case PostPagingSource.TYPE_SUBREDDIT:
|
case PostPagingSource.TYPE_SUBREDDIT:
|
||||||
if (mAccessToken == null) {
|
call = api.getPosts(null, sortType.value, nextPage, 25, null, post.getSubredditNamePrefixed(), false, mAccessToken);
|
||||||
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
|
|
||||||
} else {
|
|
||||||
call = api.getSubredditBestPostsOauth(subredditName, sortType,
|
|
||||||
sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_USER:
|
case PostPagingSource.TYPE_USER:
|
||||||
if (mAccessToken == null) {
|
call = api.getUserPosts(username, sortType.value, nextPage, 25, false, mAccessToken);
|
||||||
call = api.getUserPosts(username, afterKey, sortType, sortTime);
|
|
||||||
} else {
|
|
||||||
call = api.getUserPostsOauth(username, userWhere, afterKey, sortType,
|
|
||||||
sortTime, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_SEARCH:
|
case PostPagingSource.TYPE_SEARCH:
|
||||||
if (subredditName == null) {
|
call = api.search(query, null, subredditName, null, "Post", sortType.value, "All", nextPage, 25, mAccessToken);
|
||||||
if (mAccessToken == null) {
|
|
||||||
call = api.searchPosts(query, afterKey, sortType, sortTime,
|
|
||||||
trendingSource);
|
|
||||||
} else {
|
|
||||||
call = api.searchPostsOauth(query, afterKey, sortType,
|
|
||||||
sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mAccessToken == null) {
|
|
||||||
call = api.searchPostsInSpecificSubreddit(subredditName, query,
|
|
||||||
sortType, sortTime, afterKey);
|
|
||||||
} else {
|
|
||||||
call = api.searchPostsInSpecificSubredditOauth(subredditName, query,
|
|
||||||
sortType, sortTime, afterKey,
|
|
||||||
APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||||
if (mAccessToken == null) {
|
// TODO: Implement multi community
|
||||||
call = api.getMultiRedditPosts(multiPath, afterKey, sortTime);
|
|
||||||
} else {
|
|
||||||
call = api.getMultiRedditPostsOauth(multiPath, afterKey,
|
|
||||||
sortTime, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
//case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT
|
// TODO: Implement anonymous front page
|
||||||
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
call = api.getBestPosts(sortType, sortTime, afterKey,
|
String type = (subredditName.equals("all")) ? "All" : (subredditName.equals("local")) ? "Local" : "Subscribed";
|
||||||
APIUtils.getOAuthHeader(mAccessToken));
|
call = api.getPosts(type, sortType.value, nextPage, 25, null, null, false, mAccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -101,7 +101,16 @@ public interface LemmyAPI {
|
|||||||
Call<String> postDelete(@Body DeletePostDTO params);
|
Call<String> postDelete(@Body DeletePostDTO params);
|
||||||
|
|
||||||
@GET("api/v3/user")
|
@GET("api/v3/user")
|
||||||
ListenableFuture<Response<String>> getUserPosts(
|
ListenableFuture<Response<String>> getUserPostsListenableFuture(
|
||||||
|
@Query("username") String username,
|
||||||
|
@Query("sort") String sort,
|
||||||
|
@Query("page") Integer page,
|
||||||
|
@Query("limit") Integer limit,
|
||||||
|
@Query("saved_only") Boolean saved_only,
|
||||||
|
@Query("auth") String access_token);
|
||||||
|
|
||||||
|
@GET("api/v3/user")
|
||||||
|
Call<String> getUserPosts(
|
||||||
@Query("username") String username,
|
@Query("username") String username,
|
||||||
@Query("sort") String sort,
|
@Query("sort") String sort,
|
||||||
@Query("page") Integer page,
|
@Query("page") Integer page,
|
||||||
@ -129,7 +138,19 @@ public interface LemmyAPI {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@GET("api/v3/post/list")
|
@GET("api/v3/post/list")
|
||||||
ListenableFuture<Response<String>> getPosts(
|
ListenableFuture<Response<String>> getPostsListenableFuture(
|
||||||
|
@Query("type_") String type_,
|
||||||
|
@Query("sort") String sort,
|
||||||
|
@Query("page") Integer page,
|
||||||
|
@Query("limit") Integer limit,
|
||||||
|
@Query("community_id") Integer community_id,
|
||||||
|
@Query("community_name") String community_name,
|
||||||
|
@Query("saved_only") Boolean saved_only,
|
||||||
|
@Query("auth") String auth
|
||||||
|
);
|
||||||
|
|
||||||
|
@GET("api/v3/post/list")
|
||||||
|
Call<String> getPosts(
|
||||||
@Query("type_") String type_,
|
@Query("type_") String type_,
|
||||||
@Query("sort") String sort,
|
@Query("sort") String sort,
|
||||||
@Query("page") Integer page,
|
@Query("page") Integer page,
|
||||||
|
@ -243,7 +243,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
}
|
}
|
||||||
String feed_type = Objects.equals(subredditOrUserName, "all") ? "All" : Objects.equals(subredditOrUserName, "local") ? "Local" : "Subscribed";
|
String feed_type = Objects.equals(subredditOrUserName, "all") ? "All" : Objects.equals(subredditOrUserName, "local") ? "Local" : "Subscribed";
|
||||||
|
|
||||||
bestPost = api.getPosts(feed_type,sortType.getType().value,page,25,null,null,false,accessToken);
|
bestPost = api.getPostsListenableFuture(feed_type, sortType.getType().value, page, 25, null, null, false, accessToken);
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(bestPost, this::transformData, executor);
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(bestPost, this::transformData, executor);
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
private ListenableFuture<LoadResult<Integer, Post>> loadSubredditPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
private ListenableFuture<LoadResult<Integer, Post>> loadSubredditPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||||
ListenableFuture<Response<String>> subredditPost;
|
ListenableFuture<Response<String>> subredditPost;
|
||||||
|
|
||||||
subredditPost = api.getPosts(null,sortType.getType().value,loadParams.getKey(),25,null,subredditOrUserName,false,accessToken);
|
subredditPost = api.getPostsListenableFuture(null, sortType.getType().value, loadParams.getKey(), 25, null, subredditOrUserName, false, accessToken);
|
||||||
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(subredditPost, this::transformData, executor);
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(subredditPost, this::transformData, executor);
|
||||||
@ -273,7 +273,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
|
|
||||||
private ListenableFuture<LoadResult<Integer, Post>> loadUserPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
private ListenableFuture<LoadResult<Integer, Post>> loadUserPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||||
ListenableFuture<Response<String>> userPosts;
|
ListenableFuture<Response<String>> userPosts;
|
||||||
userPosts = api.getUserPosts(subredditOrUserName, sortType.getType().value, loadParams.getKey(), 25, userWhere.equals(USER_WHERE_SAVED), accessToken);
|
userPosts = api.getUserPostsListenableFuture(subredditOrUserName, sortType.getType().value, loadParams.getKey(), 25, userWhere.equals(USER_WHERE_SAVED), accessToken);
|
||||||
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(userPosts, this::transformData, executor);
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(userPosts, this::transformData, executor);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user