mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-06 22:54:47 +01:00
Prototype multicomm
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
parent
5e6a6c6c25
commit
54fdca4fb6
@ -159,8 +159,17 @@ public class CreateMultiRedditActivity extends BaseActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a list of community qualified names seperated by a comma
|
||||
StringBuilder subredditList = new StringBuilder();
|
||||
String prefix = "";
|
||||
for (SubredditWithSelection s : mSubreddits) {
|
||||
subredditList.append(prefix);
|
||||
prefix = ",";
|
||||
subredditList.append(s.getQualifiedName());
|
||||
}
|
||||
|
||||
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
"/user/" + mAccountName + "/m/" + nameEditText.getText().toString(),
|
||||
mAccountName, subredditList.toString(),
|
||||
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
|
||||
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
|
||||
@Override
|
||||
|
@ -970,7 +970,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
this.postFilter = postFilter;
|
||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
//showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@ -1012,7 +1013,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
|
||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
//showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -63,6 +63,7 @@ public class CreateMultiReddit {
|
||||
|
||||
public static void anonymousCreateMultiReddit(Executor executor, Handler handler,
|
||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
String accountName,
|
||||
String multipath, String name, String description,
|
||||
List<SubredditWithSelection> subreddits,
|
||||
CreateMultiRedditListener createMultiRedditListener) {
|
||||
@ -71,7 +72,7 @@ public class CreateMultiReddit {
|
||||
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
|
||||
}
|
||||
redditDataRoomDatabase.multiRedditDao().insert(new MultiReddit(multipath, name, name, description,
|
||||
null, null, "private", "-", 0, System.currentTimeMillis(), true, false, false));
|
||||
null, null, "private", accountName, 0, System.currentTimeMillis(), true, false, false));
|
||||
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
||||
for (SubredditWithSelection s : subreddits) {
|
||||
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s.getQualifiedName()));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.toldi.infinityforlemmy.post;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.paging.ListenableFuturePagingSource;
|
||||
@ -13,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -97,15 +99,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
this.subredditOrUserName = path;
|
||||
} else {
|
||||
if (sortType != null) {
|
||||
if (path.endsWith("/")) {
|
||||
multiRedditPath = path + sortType.getType().value;
|
||||
} else {
|
||||
multiRedditPath = path + "/" + sortType.getType().value;
|
||||
}
|
||||
} else {
|
||||
multiRedditPath = path;
|
||||
}
|
||||
multiRedditPath = path;
|
||||
}
|
||||
this.postType = postType;
|
||||
if (sortType == null) {
|
||||
@ -184,14 +178,11 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
return loadSearchPosts(loadParams, api);
|
||||
case TYPE_SUBREDDIT:
|
||||
return loadSubredditPosts(loadParams, api);
|
||||
default:
|
||||
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||
// Return a dummy result
|
||||
return Futures.immediateFuture(new LoadResult.Page<>(new ArrayList<>(), null, null));
|
||||
case TYPE_MULTI_REDDIT:
|
||||
return loadMultipleSubredditPosts(loadParams, api, List.of(multiRedditPath.split(Pattern.quote("+"))));
|
||||
/* default:
|
||||
return loadAnonymousHomePosts(loadParams, api);*/
|
||||
return loadMultipleSubredditPosts(loadParams, api, List.of(multiRedditPath.split(Pattern.quote(","))));
|
||||
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||
default:
|
||||
return loadAnonymousHomePosts(loadParams, api);
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +300,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
for (String community : communities) {
|
||||
ListenableFuture<Response<String>> subredditPost;
|
||||
|
||||
subredditPost = api.getPosts(null, sortType.getType().value, loadParams.getKey(), 25, null, community, false, accessToken);
|
||||
subredditPost = api.getPostsListenableFuture(null, sortType.getType().value, loadParams.getKey(), 25, null, community, false, accessToken);
|
||||
|
||||
ListenableFuture<LoadResult<Integer, Post>> communityFuture = Futures.transform(subredditPost,
|
||||
this::transformData, executor);
|
||||
@ -333,6 +324,12 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (sortType.getType().equals(SortType.Type.NEW)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
combinedPosts.sort((o1, o2) -> Long.compare(o2.getPostTimeMillis(), o1.getPostTimeMillis()));
|
||||
}
|
||||
}
|
||||
return new LoadResult.Page<>(combinedPosts, null, null);
|
||||
}, executor);
|
||||
}
|
||||
@ -350,20 +347,6 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
|
||||
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(multiRedditPosts, this::transformData, executor);
|
||||
|
||||
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
||||
Futures.catching(pageFuture, HttpException.class,
|
||||
LoadResult.Error::new, executor);
|
||||
|
||||
return Futures.catching(partialLoadResultFuture,
|
||||
IOException.class, LoadResult.Error::new, executor);
|
||||
}
|
||||
|
||||
private ListenableFuture<LoadResult<String, Post>> loadAnonymousHomePosts(@NonNull LoadParams<String> loadParams, LemmyAPI api) {
|
||||
ListenableFuture<Response<String>> anonymousHomePosts;
|
||||
anonymousHomePosts = api.getSubredditBestPostsListenableFuture(subredditOrUserName, sortType.getType(), sortType.getTime(), loadParams.getKey());
|
||||
|
||||
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(anonymousHomePosts, this::transformData, executor);
|
||||
|
||||
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
||||
Futures.catching(pageFuture, HttpException.class,
|
||||
LoadResult.Error::new, executor);
|
||||
@ -372,6 +355,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
IOException.class, LoadResult.Error::new, executor);
|
||||
}*/
|
||||
|
||||
private ListenableFuture<LoadResult<Integer, Post>> loadAnonymousHomePosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||
if (subredditOrUserName == null) {
|
||||
// Return empty list
|
||||
return Futures.immediateFuture(new LoadResult.Page<>(new ArrayList<>(), null, null));
|
||||
}
|
||||
return loadMultipleSubredditPosts(loadParams, api, Arrays.asList(subredditOrUserName.split(Pattern.quote(","))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getKeyReuseSupported() {
|
||||
//TODO: Figure out why this is needed
|
||||
|
Loading…
x
Reference in New Issue
Block a user