aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/twitter/task/Users.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/twitter/task/Users.java')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/twitter/task/Users.java195
1 files changed, 195 insertions, 0 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Users.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Users.java
new file mode 100644
index 00000000..27c6e54e
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Users.java
@@ -0,0 +1,195 @@
+package net.lacolaco.smileessence.twitter.task;
+
+import net.lacolaco.smileessence.data.Account;
+import net.lacolaco.smileessence.entity.User;
+import net.lacolaco.smileessence.util.BackgroundTask;
+import net.lacolaco.smileessence.util.ListUtils;
+import twitter4j.Relationship;
+import twitter4j.TwitterException;
+import twitter4j.UserList;
+
+import java.util.List;
+
+public class Users {
+ public static class GetTask extends BackgroundTask<User, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+ private final String screenName;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public GetTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ this.screenName = null;
+ }
+
+ public GetTask(Account account, String screenName) {
+ this.account = account;
+ this.screenName = screenName;
+ this.userID = -1;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected User doInBackground() throws TwitterException {
+ if (screenName != null) {
+ return User.fromTwitter(account.getTwitter().users().showUser(screenName));
+ } else {
+ return User.fromTwitter(account.getTwitter().users().showUser(userID));
+ }
+ }
+ }
+
+ public static class GetManyTask extends BackgroundTask<List<String>, Void> {
+
+ private final Account account;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public GetManyTask(Account account) {
+ this.account = account;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected List<String> doInBackground() throws TwitterException {
+ return ListUtils.map(account.getTwitter().list().getUserLists(account.getUserId()), UserList::getFullName);
+ }
+ }
+
+ public static class FollowTask extends BackgroundTask<User, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public FollowTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected User doInBackground() throws TwitterException {
+ return User.fromTwitter(account.getTwitter().friendsFollowers().createFriendship(userID));
+ }
+ }
+
+ public static class UnfollowTask extends BackgroundTask<User, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public UnfollowTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected User doInBackground() throws TwitterException {
+ return User.fromTwitter(account.getTwitter().friendsFollowers().destroyFriendship(userID));
+ }
+ }
+
+ public static class BlockTask extends BackgroundTask<User, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public BlockTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected User doInBackground() throws TwitterException {
+ return User.fromTwitter(account.getTwitter().users().createBlock(userID));
+ }
+ }
+
+ public static class ReportForSpamTask extends BackgroundTask<User, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public ReportForSpamTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected User doInBackground() throws TwitterException {
+ return User.fromTwitter(account.getTwitter().spamReporting().reportSpam(userID));
+ }
+ }
+
+ public static class UnblockTask extends BackgroundTask<User, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public UnblockTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ protected User doInBackground() throws TwitterException {
+ return User.fromTwitter(account.getTwitter().users().destroyBlock(userID));
+ }
+ }
+
+ public static class ShowFriendshipTask extends BackgroundTask<Relationship, Void> {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private final Account account;
+ private final long userID;
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public ShowFriendshipTask(Account account, long userID) {
+ this.account = account;
+ this.userID = userID;
+ }
+
+ @Override
+ protected Relationship doInBackground() throws TwitterException {
+ return account.getTwitter().friendsFollowers().showFriendship(account.getTwitter().getId(), userID);
+ }
+ }
+}