diff options
Diffstat (limited to 'app')
6 files changed, 22 insertions, 11 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java index 0e189274..943dbf2d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java @@ -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(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index 850ada27..d4c4caee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -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(); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java index 99d046c9..80fbb74e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java @@ -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); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java index 8eb52a66..1c3113ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java @@ -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)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java index 6efa6487..b19875f5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java @@ -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); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java index 227b7665..2d78a388 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FavoriteMultiReddit.java @@ -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()) { |