aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-03-09 15:20:06 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-03-09 15:20:06 +0000
commit1ecdb93139ccf9dca793ebdc9380db2ac7db5aad (patch)
tree3d4a0f668618ded9b4dfc5b6e7ba2d2f6d71cbfc /app/src/main/java
parent6bdf38b99662961d3a5faab8b01c8abe1e16b607 (diff)
downloadinfinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.tar
infinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.tar.gz
infinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.tar.bz2
infinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.tar.lz
infinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.tar.xz
infinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.tar.zst
infinity-for-reddit-1ecdb93139ccf9dca793ebdc9380db2ac7db5aad.zip
Fix crash when subscribing in anonymous mode.
Diffstat (limited to 'app/src/main/java')
-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);
});