mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Fix subreddits disappear in anonymous multireddit after favoriting it.
This commit is contained in:
parent
82db567fdc
commit
d5f3761973
@ -168,7 +168,7 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
|
||||
FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
|
||||
@Override
|
||||
public void success(ArrayList<MultiReddit> multiReddits) {
|
||||
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
InsertMultireddit.insertMultireddits(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
multiReddits, mAccountName, () -> {
|
||||
mInsertSuccess = true;
|
||||
((MultiRedditListingFragment) mFragment).stopRefreshProgressbar();
|
||||
|
@ -298,7 +298,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
|
||||
@Override
|
||||
public void success(ArrayList<MultiReddit> multiReddits) {
|
||||
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
|
||||
InsertMultireddit.insertMultireddits(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
|
||||
mInsertMultiredditSuccess = true;
|
||||
sectionsPagerAdapter.stopMultiRedditRefreshProgressbar();
|
||||
});
|
||||
|
@ -7,15 +7,16 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao;
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
|
||||
public class InsertMultireddit {
|
||||
|
||||
public static void insertMultireddit(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
ArrayList<MultiReddit> multiReddits, String accountName,
|
||||
InsertMultiRedditListener insertMultiRedditListener) {
|
||||
public static void insertMultireddits(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
ArrayList<MultiReddit> multiReddits, String accountName,
|
||||
InsertMultiRedditListener insertMultiRedditListener) {
|
||||
executor.execute(() -> {
|
||||
MultiRedditDao multiRedditDao = redditDataRoomDatabase.multiRedditDao();
|
||||
List<MultiReddit> existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName);
|
||||
@ -39,7 +40,16 @@ public class InsertMultireddit {
|
||||
MultiReddit multiReddit,
|
||||
InsertMultiRedditListener insertMultiRedditListener) {
|
||||
executor.execute(() -> {
|
||||
redditDataRoomDatabase.multiRedditDao().insert(multiReddit);
|
||||
if (multiReddit.getOwner().equals("-")) {
|
||||
ArrayList<AnonymousMultiredditSubreddit> allAnonymousMultiRedditSubreddits =
|
||||
(ArrayList<AnonymousMultiredditSubreddit>) redditDataRoomDatabase.anonymousMultiredditSubredditDao().getAllAnonymousMultiRedditSubreddits(multiReddit.getPath());
|
||||
redditDataRoomDatabase.multiRedditDao().insert(multiReddit);
|
||||
if (allAnonymousMultiRedditSubreddits != null) {
|
||||
redditDataRoomDatabase.anonymousMultiredditSubredditDao().insertAll(allAnonymousMultiRedditSubreddits);
|
||||
}
|
||||
} else {
|
||||
redditDataRoomDatabase.multiRedditDao().insert(multiReddit);
|
||||
}
|
||||
handler.post(insertMultiRedditListener::success);
|
||||
});
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class CreateMultiReddit {
|
||||
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
|
||||
}
|
||||
redditDataRoomDatabase.multiRedditDao().insert(new MultiReddit(multipath, name, name, description,
|
||||
null, null, null, "-", 0, System.currentTimeMillis(), true, false, false));
|
||||
null, null, "private", "-", 0, System.currentTimeMillis(), true, false, false));
|
||||
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
||||
for (String s : subreddits) {
|
||||
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s));
|
||||
|
@ -51,9 +51,10 @@ public class EditMultiReddit {
|
||||
MultiReddit multiReddit,
|
||||
EditMultiRedditListener editMultiRedditListener) {
|
||||
executor.execute(() -> {
|
||||
redditDataRoomDatabase.multiRedditDao().insert(multiReddit);
|
||||
ArrayList<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
||||
for (String s : multiReddit.getSubreddits()) {
|
||||
ArrayList<String> subreddits = multiReddit.getSubreddits();
|
||||
redditDataRoomDatabase.multiRedditDao().insert(multiReddit);
|
||||
for (String s : subreddits) {
|
||||
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multiReddit.getPath(), s));
|
||||
}
|
||||
redditDataRoomDatabase.anonymousMultiredditSubredditDao().insertAll(anonymousMultiredditSubreddits);
|
||||
|
@ -32,7 +32,7 @@ public class FavoriteMultiReddit {
|
||||
params.put(APIUtils.MAKE_FAVORITE_KEY, String.valueOf(makeFavorite));
|
||||
params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON);
|
||||
oauthRetrofit.create(RedditAPI.class).favoriteMultiReddit(APIUtils.getOAuthHeader(accessToken),
|
||||
params).enqueue(new Callback<String>() {
|
||||
params).enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
|
Loading…
Reference in New Issue
Block a user