diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-10-05 15:58:59 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-10-05 15:58:59 +0900 |
commit | 9db537d339faa3ad44dfdcadb23f4c14bd8aceb4 (patch) | |
tree | 6b151cdfd0ca7dc44b9a189045b2b2cbc5aefc21 /app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.kt | |
parent | 52ad6edcb217762154a80990c34ca94772393848 (diff) | |
download | SmileEssence-9db537d339faa3ad44dfdcadb23f4c14bd8aceb4.tar.gz |
kotlin work part. 1
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.kt')
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.kt | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.kt b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.kt new file mode 100644 index 00000000..22a90374 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.kt @@ -0,0 +1,65 @@ +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 + +class Accounts { + class AccessTokenTask(private val twitter: Twitter, private val requestToken: RequestToken, private val pinCode: String) : BackgroundTask<AccessToken, Void>() { + + @Throws(TwitterException::class) + override fun doInBackground(): AccessToken { + return twitter.getOAuthAccessToken(requestToken, pinCode) + } + } + + class RequestTokenTask(private val twitter: Twitter) : BackgroundTask<RequestToken, Void>() { + + @Throws(TwitterException::class) + override fun doInBackground(): RequestToken { + return twitter.getOAuthRequestToken("oob") + } + } + + class BlockIDsTask(private val account: Account) : BackgroundTask<List<Long>, Void>() { + + @Throws(TwitterException::class) + override fun doInBackground(): List<Long> { + val idList = ArrayList<Long>() + var cursor: Long = -1 + + while (cursor != 0L) { + val blocksIDs = account.twitter.getBlocksIDs(cursor) + cursor = blocksIDs.nextCursor + for (id in blocksIDs.iDs) { + idList.add(id) + } + } + + return idList + } + } + + class MutesIDsTask(private val account: Account) : BackgroundTask<List<Long>, Void>() { + + @Throws(TwitterException::class) + override fun doInBackground(): List<Long> { + val idList = ArrayList<Long>() + var cursor: Long = -1 + while (cursor != 0L) { + val mutesIDs = account.twitter.getMutesIDs(cursor) + cursor = mutesIDs.nextCursor + for (id in mutesIDs.iDs) { + idList.add(id) + } + } + return idList + } + } +} |