mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-07 07:04:44 +01:00
Prototype multicomm
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
parent
c387e4abbc
commit
ee7f2e271c
@ -159,8 +159,17 @@ public class CreateMultiRedditActivity extends BaseActivity {
|
|||||||
return true;
|
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,
|
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||||
"/user/" + mAccountName + "/m/" + nameEditText.getText().toString(),
|
mAccountName, subredditList.toString(),
|
||||||
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
|
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
|
||||||
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
|
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -970,7 +970,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
//showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -1012,7 +1013,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
|
||||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
//showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,6 +63,7 @@ public class CreateMultiReddit {
|
|||||||
|
|
||||||
public static void anonymousCreateMultiReddit(Executor executor, Handler handler,
|
public static void anonymousCreateMultiReddit(Executor executor, Handler handler,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
|
String accountName,
|
||||||
String multipath, String name, String description,
|
String multipath, String name, String description,
|
||||||
List<SubredditWithSelection> subreddits,
|
List<SubredditWithSelection> subreddits,
|
||||||
CreateMultiRedditListener createMultiRedditListener) {
|
CreateMultiRedditListener createMultiRedditListener) {
|
||||||
@ -71,7 +72,7 @@ public class CreateMultiReddit {
|
|||||||
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
|
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
|
||||||
}
|
}
|
||||||
redditDataRoomDatabase.multiRedditDao().insert(new MultiReddit(multipath, name, name, description,
|
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<>();
|
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
||||||
for (SubredditWithSelection s : subreddits) {
|
for (SubredditWithSelection s : subreddits) {
|
||||||
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s.getQualifiedName()));
|
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s.getQualifiedName()));
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.toldi.infinityforlemmy.post;
|
package eu.toldi.infinityforlemmy.post;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.paging.ListenableFuturePagingSource;
|
import androidx.paging.ListenableFuturePagingSource;
|
||||||
@ -13,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -96,17 +98,9 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||||
if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) {
|
if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
this.subredditOrUserName = path;
|
this.subredditOrUserName = path;
|
||||||
} else {
|
|
||||||
if (sortType != null) {
|
|
||||||
if (path.endsWith("/")) {
|
|
||||||
multiRedditPath = path + sortType.getType().value;
|
|
||||||
} else {
|
|
||||||
multiRedditPath = path + "/" + sortType.getType().value;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
multiRedditPath = path;
|
multiRedditPath = path;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
if (sortType == null) {
|
if (sortType == null) {
|
||||||
if (path.equals("local") || path.equals("all")) {
|
if (path.equals("local") || path.equals("all")) {
|
||||||
@ -184,14 +178,11 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
return loadSearchPosts(loadParams, api);
|
return loadSearchPosts(loadParams, api);
|
||||||
case TYPE_SUBREDDIT:
|
case TYPE_SUBREDDIT:
|
||||||
return loadSubredditPosts(loadParams, api);
|
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:
|
case TYPE_MULTI_REDDIT:
|
||||||
return loadMultipleSubredditPosts(loadParams, api, List.of(multiRedditPath.split(Pattern.quote("+"))));
|
return loadMultipleSubredditPosts(loadParams, api, List.of(multiRedditPath.split(Pattern.quote(","))));
|
||||||
/* default:
|
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
return loadAnonymousHomePosts(loadParams, api);*/
|
default:
|
||||||
|
return loadAnonymousHomePosts(loadParams, api);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +300,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
for (String community : communities) {
|
for (String community : communities) {
|
||||||
ListenableFuture<Response<String>> subredditPost;
|
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,
|
ListenableFuture<LoadResult<Integer, Post>> communityFuture = Futures.transform(subredditPost,
|
||||||
this::transformData, executor);
|
this::transformData, executor);
|
||||||
@ -333,6 +324,12 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
return result;
|
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);
|
return new LoadResult.Page<>(combinedPosts, null, null);
|
||||||
}, executor);
|
}, 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>> 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 =
|
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
||||||
Futures.catching(pageFuture, HttpException.class,
|
Futures.catching(pageFuture, HttpException.class,
|
||||||
LoadResult.Error::new, executor);
|
LoadResult.Error::new, executor);
|
||||||
@ -372,6 +355,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
IOException.class, LoadResult.Error::new, executor);
|
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
|
@Override
|
||||||
public boolean getKeyReuseSupported() {
|
public boolean getKeyReuseSupported() {
|
||||||
//TODO: Figure out why this is needed
|
//TODO: Figure out why this is needed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user