mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +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() {
|
FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArrayList<MultiReddit> multiReddits) {
|
public void success(ArrayList<MultiReddit> multiReddits) {
|
||||||
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
InsertMultireddit.insertMultireddits(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||||
multiReddits, mAccountName, () -> {
|
multiReddits, mAccountName, () -> {
|
||||||
mInsertSuccess = true;
|
mInsertSuccess = true;
|
||||||
((MultiRedditListingFragment) mFragment).stopRefreshProgressbar();
|
((MultiRedditListingFragment) mFragment).stopRefreshProgressbar();
|
||||||
|
@ -298,7 +298,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
|
FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ArrayList<MultiReddit> multiReddits) {
|
public void success(ArrayList<MultiReddit> multiReddits) {
|
||||||
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
|
InsertMultireddit.insertMultireddits(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
|
||||||
mInsertMultiredditSuccess = true;
|
mInsertMultiredditSuccess = true;
|
||||||
sectionsPagerAdapter.stopMultiRedditRefreshProgressbar();
|
sectionsPagerAdapter.stopMultiRedditRefreshProgressbar();
|
||||||
});
|
});
|
||||||
|
@ -7,15 +7,16 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
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.MultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao;
|
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|
||||||
|
|
||||||
public class InsertMultireddit {
|
public class InsertMultireddit {
|
||||||
|
|
||||||
public static void insertMultireddit(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
|
public static void insertMultireddits(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
ArrayList<MultiReddit> multiReddits, String accountName,
|
ArrayList<MultiReddit> multiReddits, String accountName,
|
||||||
InsertMultiRedditListener insertMultiRedditListener) {
|
InsertMultiRedditListener insertMultiRedditListener) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
MultiRedditDao multiRedditDao = redditDataRoomDatabase.multiRedditDao();
|
MultiRedditDao multiRedditDao = redditDataRoomDatabase.multiRedditDao();
|
||||||
List<MultiReddit> existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName);
|
List<MultiReddit> existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName);
|
||||||
@ -39,7 +40,16 @@ public class InsertMultireddit {
|
|||||||
MultiReddit multiReddit,
|
MultiReddit multiReddit,
|
||||||
InsertMultiRedditListener insertMultiRedditListener) {
|
InsertMultiRedditListener insertMultiRedditListener) {
|
||||||
executor.execute(() -> {
|
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);
|
handler.post(insertMultiRedditListener::success);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,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, null, "-", 0, System.currentTimeMillis(), true, false, false));
|
null, null, "private", "-", 0, System.currentTimeMillis(), true, false, false));
|
||||||
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
||||||
for (String s : subreddits) {
|
for (String s : subreddits) {
|
||||||
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s));
|
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s));
|
||||||
|
@ -51,9 +51,10 @@ public class EditMultiReddit {
|
|||||||
MultiReddit multiReddit,
|
MultiReddit multiReddit,
|
||||||
EditMultiRedditListener editMultiRedditListener) {
|
EditMultiRedditListener editMultiRedditListener) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
redditDataRoomDatabase.multiRedditDao().insert(multiReddit);
|
|
||||||
ArrayList<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
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));
|
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multiReddit.getPath(), s));
|
||||||
}
|
}
|
||||||
redditDataRoomDatabase.anonymousMultiredditSubredditDao().insertAll(anonymousMultiredditSubreddits);
|
redditDataRoomDatabase.anonymousMultiredditSubredditDao().insertAll(anonymousMultiredditSubreddits);
|
||||||
|
@ -32,7 +32,7 @@ public class FavoriteMultiReddit {
|
|||||||
params.put(APIUtils.MAKE_FAVORITE_KEY, String.valueOf(makeFavorite));
|
params.put(APIUtils.MAKE_FAVORITE_KEY, String.valueOf(makeFavorite));
|
||||||
params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON);
|
params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON);
|
||||||
oauthRetrofit.create(RedditAPI.class).favoriteMultiReddit(APIUtils.getOAuthHeader(accessToken),
|
oauthRetrofit.create(RedditAPI.class).favoriteMultiReddit(APIUtils.getOAuthHeader(accessToken),
|
||||||
params).enqueue(new Callback<String>() {
|
params).enqueue(new Callback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user