aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.java
blob: 7842e349096da184b39da7a3225e1d443269fc24 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package net.lacolaco.smileessence.twitter.task;

import net.lacolaco.smileessence.data.Account;
import net.lacolaco.smileessence.util.BackgroundTask;
import twitter4j.IDs;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;

import java.util.ArrayList;
import java.util.List;

public class Accounts {
    public static class AccessTokenTask extends BackgroundTask<AccessToken, Void> {
        private final Twitter twitter;
        private final RequestToken requestToken;
        private final String pinCode;

        public AccessTokenTask(Twitter twitter, RequestToken requestToken, String pinCode) {
            this.twitter = twitter;
            this.requestToken = requestToken;
            this.pinCode = pinCode;
        }

        @Override
        protected AccessToken doInBackground() throws TwitterException {
            return twitter.getOAuthAccessToken(requestToken, pinCode);
        }
    }

    public static class RequestTokenTask extends BackgroundTask<RequestToken, Void> {
        private final Twitter twitter;

        public RequestTokenTask(Twitter twitter) {
            this.twitter = twitter;
        }

        @Override
        protected RequestToken doInBackground() throws TwitterException {
            return twitter.getOAuthRequestToken("oob");
        }
    }

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

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

        @Override
        protected List<Long> doInBackground() throws TwitterException {
            List<Long> idList = new ArrayList<>();
            long cursor = -1;

            while (cursor != 0) {
                IDs blocksIDs = account.getTwitter().getBlocksIDs(cursor);
                cursor = blocksIDs.getNextCursor();
                for (long id : blocksIDs.getIDs()) {
                    idList.add(id);
                }
            }

            return idList;
        }
    }

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

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

        @Override
        protected List<Long> doInBackground() throws TwitterException {
            List<Long> idList = new ArrayList<>();
            long cursor = -1;
            while (cursor != 0) {
                IDs mutesIDs = account.getTwitter().getMutesIDs(cursor);
                cursor = mutesIDs.getNextCursor();
                for (long id : mutesIDs.getIDs()) {
                    idList.add(id);
                }
            }
            return idList;
        }
    }
}