aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java11
2 files changed, 14 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java
index d2895479..fcd824a1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/account/AccountDao.java
@@ -13,6 +13,9 @@ public interface AccountDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(Account account);
+ @Query("SELECT EXISTS (SELECT 1 FROM accounts WHERE username = '-')")
+ boolean isAnonymousAccountInserted();
+
@Query("SELECT * FROM accounts WHERE username != '-'")
List<Account> getAllAccounts();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java
index eab9957d..296e319b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java
@@ -9,6 +9,7 @@ import java.util.Map;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
@@ -127,6 +128,11 @@ public class SubredditSubscription {
executor.execute(() -> {
SubscribedSubredditData subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), subredditData.getName(),
subredditData.getIconUrl(), accountName, false);
+ if (accountName.equals("-")) {
+ if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) {
+ redditDataRoomDatabase.accountDao().insert(new Account("-", null, null, null, null, null, 0, false));
+ }
+ }
redditDataRoomDatabase.subscribedSubredditDao().insert(subscribedSubredditData);
handler.post(subredditSubscriptionListener::onSubredditSubscriptionSuccess);
});
@@ -137,6 +143,11 @@ public class SubredditSubscription {
String subredditName, String accountName,
SubredditSubscriptionListener subredditSubscriptionListener) {
executor.execute(() -> {
+ if (accountName.equals("-")) {
+ if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) {
+ redditDataRoomDatabase.accountDao().insert(new Account("-", null, null, null, null, null, 0, false));
+ }
+ }
redditDataRoomDatabase.subscribedSubredditDao().deleteSubscribedSubreddit(subredditName, accountName);
handler.post(subredditSubscriptionListener::onSubredditSubscriptionSuccess);
});