aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/twitter/task/SavedSearches.java
blob: 3817727479f48f5b9f2637f47b807e29b94aa72c (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package net.lacolaco.smileessence.twitter.task;

import net.lacolaco.smileessence.data.Account;
import net.lacolaco.smileessence.entity.SavedSearch;
import net.lacolaco.smileessence.util.BackgroundTask;
import net.lacolaco.smileessence.util.ListUtils;

import java.util.List;

public class SavedSearches {
    public static class Create extends BackgroundTask<SavedSearch, Void> {
        private final Account account;
        private final String query;

        public Create(Account account, String query) {
            this.account = account;
            this.query = query;
        }

        @Override
        protected SavedSearch doInBackground() throws Exception {
            return SavedSearch.fromTwitter(account.getTwitter().savedSearches().createSavedSearch(query));
        }
    }

    public static class Destroy extends BackgroundTask<Void, Void> {
        private final Account account;
        private final long id;

        public Destroy(Account account, long id) {
            this.account = account;
            this.id = id;
        }

        @Override
        protected Void doInBackground() throws Exception {
            account.getTwitter().savedSearches().destroySavedSearch(id);
            return null;
        }
    }

    public static class All extends BackgroundTask<List<SavedSearch>, Void> {
        private final Account account;

        public All(Account account) {
            this.account = account;
        }

        @Override
        protected List<SavedSearch> doInBackground() throws Exception {
            return ListUtils.map(account.getTwitter().savedSearches().getSavedSearches(), SavedSearch::fromTwitter);
        }
    }
}