blob: ef8952b8582bc51fab5bc9bf5d23d03f2ed96b44 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package ml.docilealligator.infinityforreddit.asynctasks;
import android.os.Handler;
import androidx.annotation.NonNull;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
public class CheckIsSubscribedToSubreddit {
public static void checkIsSubscribedToSubreddit(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
String subredditName, @NonNull String accountName,
CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener) {
executor.execute(() -> {
if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) {
if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) {
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
}
}
SubscribedSubredditData subscribedSubredditData = redditDataRoomDatabase.subscribedSubredditDao().getSubscribedSubreddit(subredditName, accountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : accountName);
handler.post(() -> {
if (subscribedSubredditData != null) {
checkIsSubscribedToSubredditListener.isSubscribed();
} else {
checkIsSubscribedToSubredditListener.isNotSubscribed();
}
});
});
}
public interface CheckIsSubscribedToSubredditListener {
void isSubscribed();
void isNotSubscribed();
}
}
|