diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-08 00:08:53 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-08 00:12:36 +0900 |
commit | a1940cef528042771fc334fc88e106701cd6b13d (patch) | |
tree | 2681f0bf599e10a29f206adb5fcdeb0cfe3016cb /app | |
parent | 0adb9dc37bbd413b0dcc287d891b57b67a25e0c1 (diff) | |
download | SmileEssence-a1940cef528042771fc334fc88e106701cd6b13d.tar.gz |
task 整理
Diffstat (limited to 'app')
75 files changed, 964 insertions, 1733 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/Application.java b/app/src/main/java/net/lacolaco/smileessence/Application.java index 88c6ca5d..674bc499 100644 --- a/app/src/main/java/net/lacolaco/smileessence/Application.java +++ b/app/src/main/java/net/lacolaco/smileessence/Application.java @@ -29,8 +29,8 @@ import com.crashlytics.android.core.CrashlyticsCore; import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.RefWatcher; import io.fabric.sdk.android.Fabric; -import net.lacolaco.smileessence.data.OrmaHolder; import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.data.OrmaHolder; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.preference.UserPreferenceHelper; import net.lacolaco.smileessence.util.Themes; diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java index c53a4e1f..a0cb91d2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/EditExtractionActivity.java @@ -31,7 +31,6 @@ import android.text.TextUtils; import android.util.SparseBooleanArray; import android.view.*; import android.widget.AbsListView; -import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import net.lacolaco.smileessence.Application; diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java index 4b411d1d..e2871e17 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java @@ -50,12 +50,13 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.data.Account; import net.lacolaco.smileessence.data.ExtractionWord; import net.lacolaco.smileessence.data.PostState; -import net.lacolaco.smileessence.entity.*; +import net.lacolaco.smileessence.entity.RBinding; +import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.preference.InternalPreferenceHelper; import net.lacolaco.smileessence.twitter.UserStreamListener; -import net.lacolaco.smileessence.twitter.task.ShowUserTask; +import net.lacolaco.smileessence.twitter.task.Users; import net.lacolaco.smileessence.util.BitmapOptimizer; import net.lacolaco.smileessence.util.BitmapURLTask; import net.lacolaco.smileessence.util.IntentUtils; @@ -395,7 +396,7 @@ public class MainActivity extends Activity implements Application.OnCurrentAccou account.refreshListSubscriptions(); account.refreshUserMuteList(); account.refreshSavedSearches(); - new ShowUserTask(account, account.getUserId()).execute(); + new Users.GetTask(account, account.getUserId()).execute(); User user = account.getUser(); diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java index 6c4cceb4..d88a1a9e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java @@ -35,8 +35,8 @@ import android.widget.*; import com.android.volley.toolbox.NetworkImageView; import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; -import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.preference.InternalPreferenceHelper; diff --git a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java index 1636dffb..39fc5822 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/CommandOpenUserDetail.java @@ -28,7 +28,7 @@ import android.app.Activity; import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.ShowUserTask; +import net.lacolaco.smileessence.twitter.task.Users; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment; @@ -56,7 +56,7 @@ public class CommandOpenUserDetail extends Command { @Override public boolean execute() { - new ShowUserTask(Application.getInstance().getCurrentAccount(), screenName) + new Users.GetTask(Application.getInstance().getCurrentAccount(), screenName) .onDoneUI(user -> { UserDetailDialogFragment fragment = new UserDetailDialogFragment(); fragment.setUserID(user.getId()); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java index 78036005..c4461c33 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandBlock.java @@ -30,7 +30,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.command.IConfirmable; import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.BlockTask; +import net.lacolaco.smileessence.twitter.task.Users; public class UserCommandBlock extends UserCommand implements IConfirmable { @@ -51,7 +51,7 @@ public class UserCommandBlock extends UserCommand implements IConfirmable { @Override public boolean execute() { - new BlockTask(Application.getInstance().getCurrentAccount(), getUser().getId()) + new Users.BlockTask(Application.getInstance().getCurrentAccount(), getUser().getId()) .onDone(user -> Notificator.getInstance().publish(R.string.notice_block_succeeded)) .onFail(ex -> Notificator.getInstance().alert(R.string.notice_block_failed)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java index eeef236f..a05c5e82 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandReportForSpam.java @@ -30,7 +30,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.command.IConfirmable; import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.ReportForSpamTask; +import net.lacolaco.smileessence.twitter.task.Users; public class UserCommandReportForSpam extends UserCommand implements IConfirmable { @@ -51,7 +51,7 @@ public class UserCommandReportForSpam extends UserCommand implements IConfirmabl @Override public boolean execute() { - new ReportForSpamTask(Application.getInstance().getCurrentAccount(), getUser().getId()) + new Users.ReportForSpamTask(Application.getInstance().getCurrentAccount(), getUser().getId()) .onDone(user -> Notificator.getInstance().publish(R.string.notice_r4s_succeeded)) .onFail(ex -> Notificator.getInstance().alert(R.string.notice_r4s_failed)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java index 5fae1fa5..a4d9f893 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandUnblock.java @@ -30,7 +30,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.command.IConfirmable; import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.UnblockTask; +import net.lacolaco.smileessence.twitter.task.Users; public class UserCommandUnblock extends UserCommand implements IConfirmable { @@ -51,7 +51,7 @@ public class UserCommandUnblock extends UserCommand implements IConfirmable { @Override public boolean execute() { - new UnblockTask(Application.getInstance().getCurrentAccount(), getUser().getId()) + new Users.UnblockTask(Application.getInstance().getCurrentAccount(), getUser().getId()) .onDone(user -> Notificator.getInstance().publish(R.string.notice_unblock_succeeded)) .onFail(x -> Notificator.getInstance().alert(R.string.notice_unblock_failed)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/data/Account.java b/app/src/main/java/net/lacolaco/smileessence/data/Account.java index 01b62b0b..e540de44 100644 --- a/app/src/main/java/net/lacolaco/smileessence/data/Account.java +++ b/app/src/main/java/net/lacolaco/smileessence/data/Account.java @@ -31,10 +31,9 @@ import net.lacolaco.smileessence.entity.DirectMessage; import net.lacolaco.smileessence.entity.SavedSearch; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.entity.User; -import net.lacolaco.smileessence.twitter.task.BlockIDsTask; -import net.lacolaco.smileessence.twitter.task.GetUserListsTask; -import net.lacolaco.smileessence.twitter.task.MutesIDsTask; -import net.lacolaco.smileessence.twitter.task.SavedSearches; +import net.lacolaco.smileessence.twitter.task.Accounts; +import net.lacolaco.smileessence.twitter.task.Searches; +import net.lacolaco.smileessence.twitter.task.Users; import net.lacolaco.smileessence.util.BackgroundTask; import twitter4j.Twitter; import twitter4j.TwitterFactory; @@ -62,7 +61,8 @@ public class Account { @Column public String oauthTokenSecret; - public Account() { } + public Account() { + } // --------------------- static methods --------------------- public static synchronized Account get(long i) { @@ -168,7 +168,7 @@ public class Account { // --------------------- List subscription cache --------------------- public BackgroundTask<List<String>, Void> refreshListSubscriptions() { - return new GetUserListsTask(this) + return new Users.GetManyTask(this) .onDone(lists -> { listSubscriptions.clear(); listSubscriptions.addAll(lists); @@ -192,8 +192,8 @@ public class Account { // --------------------- User mute cache --------------------- public List<BackgroundTask> refreshUserMuteList() { List<BackgroundTask> tasks = new ArrayList<>(); - tasks.add(new BlockIDsTask(this).onDone(muteUserIds::addAll).execute()); - tasks.add(new MutesIDsTask(this).onDone(muteUserIds::addAll).execute()); + tasks.add(new Accounts.BlockIDsTask(this).onDone(muteUserIds::addAll).execute()); + tasks.add(new Accounts.MutesIDsTask(this).onDone(muteUserIds::addAll).execute()); return tasks; } @@ -202,6 +202,6 @@ public class Account { } public BackgroundTask<List<SavedSearch>, Void> refreshSavedSearches() { - return new SavedSearches.All(this).onDone(SavedSearch::replace).execute(); + return new Searches.GetAllSavedSearchesTask(this).onDone(SavedSearch::replace).execute(); } }
\ No newline at end of file diff --git a/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.java b/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.java index 10d0b631..88e4539c 100644 --- a/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.java +++ b/app/src/main/java/net/lacolaco/smileessence/data/ExtractionWord.java @@ -24,12 +24,13 @@ package net.lacolaco.smileessence.data; -import com.github.gfx.android.orma.annotation.Column; -import com.github.gfx.android.orma.annotation.OnConflict; import com.github.gfx.android.orma.annotation.PrimaryKey; import com.github.gfx.android.orma.annotation.Table; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.regex.Pattern; @Table @@ -43,13 +44,13 @@ public class ExtractionWord { // --------------------- static methods --------------------- public static List<ExtractionWord> cached() { - synchronized(mutex) { + synchronized (mutex) { return new ArrayList<>(cache); } } public static synchronized void load() { - synchronized(mutex) { + synchronized (mutex) { OrmaDatabase orma = OrmaHolder.getORMA(); cache = new HashSet<>(orma.selectFromExtractionWord().toList()); } @@ -62,13 +63,14 @@ public class ExtractionWord { public static synchronized ExtractionWord add(String patternString) { ExtractionWord extractionWord = new ExtractionWord(patternString); relation().upserter().execute(extractionWord); - synchronized(mutex) { + synchronized (mutex) { cache.add(extractionWord); } return extractionWord; } - public ExtractionWord() { } + public ExtractionWord() { + } private ExtractionWord(String patternString) { this.patternString = patternString; diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.java b/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.java index ba9be9e5..5ade81b2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/RBinding.java @@ -8,6 +8,5 @@ public enum RBinding { // User BASIC, - DETAIL, - ; + DETAIL,; } diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/SavedSearch.java b/app/src/main/java/net/lacolaco/smileessence/entity/SavedSearch.java index 0ac26ccc..6ea6dea4 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/SavedSearch.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/SavedSearch.java @@ -1,6 +1,9 @@ package net.lacolaco.smileessence.entity; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class SavedSearch implements IdObject { private static Map<Long, SavedSearch> storage = new HashMap<>(); diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java b/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java index af989a1d..2e70d705 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java @@ -4,7 +4,7 @@ import android.net.Uri; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.twitter.task.ShowStatusTask; +import net.lacolaco.smileessence.twitter.task.Tweets; import net.lacolaco.smileessence.util.BackgroundTask; import net.lacolaco.smileessence.util.ListUtils; import twitter4j.Status; @@ -29,7 +29,7 @@ public class Tweet extends EntitySupport { } }; } else { - return new ShowStatusTask(account, statusId); + return new Tweets.GetTask(account, statusId); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/OAuthSession.java b/app/src/main/java/net/lacolaco/smileessence/twitter/OAuthSession.java index dd36e582..aff9e9c2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/OAuthSession.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/OAuthSession.java @@ -24,8 +24,7 @@ package net.lacolaco.smileessence.twitter; -import net.lacolaco.smileessence.twitter.task.AccessTokenTask; -import net.lacolaco.smileessence.twitter.task.RequestTokenTask; +import net.lacolaco.smileessence.twitter.task.Accounts; import twitter4j.Twitter; import twitter4j.TwitterFactory; import twitter4j.auth.AccessToken; @@ -47,7 +46,7 @@ public class OAuthSession { public String getAuthorizationURL() { Twitter twitter = new TwitterFactory().getInstance(); - RequestTokenTask task = new RequestTokenTask(twitter); + Accounts.RequestTokenTask task = new Accounts.RequestTokenTask(twitter); task.execute(); try { requestToken = task.getImmediately(); @@ -61,7 +60,7 @@ public class OAuthSession { public AccessToken getAccessToken(String pinCode) { Twitter twitter = new TwitterFactory().getInstance(); - AccessTokenTask task = new AccessTokenTask(twitter, requestToken, pinCode); + Accounts.AccessTokenTask task = new Accounts.AccessTokenTask(twitter, requestToken, pinCode); task.execute(); try { return task.getImmediately(); diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/StatusFilter.java b/app/src/main/java/net/lacolaco/smileessence/twitter/StatusFilter.java index 244b5218..6e09d533 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/StatusFilter.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/StatusFilter.java @@ -89,7 +89,7 @@ public class StatusFilter { public <T> void filter(Class<T> klass, T status) { Map<Object, Consumer<?>> map = addHandlers.get(klass); if (map != null) { - for(Consumer f_ : map.values()) { + for (Consumer f_ : map.values()) { //noinspection unchecked f_.accept(status); } @@ -99,7 +99,7 @@ public class StatusFilter { public void remove(Class klass, long id) { Map<Object, Consumer<Long>> map = removeHandlers.get(klass); if (map != null) { - for(Consumer<Long> f : map.values()) { + for (Consumer<Long> f : map.values()) { f.accept(id); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java b/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java index 25d13195..8b05bc16 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java @@ -31,7 +31,6 @@ import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.preference.UserPreferenceHelper; import net.lacolaco.smileessence.viewmodel.EventViewModel; import net.lacolaco.smileessence.viewmodel.MessageViewModel; import net.lacolaco.smileessence.viewmodel.StatusViewModel; diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/AccessTokenTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/AccessTokenTask.java deleted file mode 100644 index 4f0a2b86..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/AccessTokenTask.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.auth.AccessToken; -import twitter4j.auth.RequestToken; - -public class AccessTokenTask extends BackgroundTask<AccessToken, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Twitter twitter; - private final RequestToken requestToken; - private final String pinCode; - - // --------------------------- CONSTRUCTORS --------------------------- - - 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); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.java new file mode 100644 index 00000000..369a0974 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Accounts.java @@ -0,0 +1,109 @@ +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> { + + // ------------------------------ FIELDS ------------------------------ + + private final Twitter twitter; + private final RequestToken requestToken; + private final String pinCode; + + // --------------------------- CONSTRUCTORS --------------------------- + + 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> { + + // ------------------------------ FIELDS ------------------------------ + + private final Twitter twitter; + + // --------------------------- CONSTRUCTORS --------------------------- + + 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; + + // --------------------------- CONSTRUCTORS --------------------------- + + public BlockIDsTask(Account account) { + this.account = account; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @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; + + // --------------------------- CONSTRUCTORS --------------------------- + + public MutesIDsTask(Account account) { + this.account = account; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @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; + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/BlockIDsTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/BlockIDsTask.java deleted file mode 100644 index 0fe510c2..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/BlockIDsTask.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.IDs; -import twitter4j.TwitterException; - -import java.util.ArrayList; -import java.util.List; - -public class BlockIDsTask extends BackgroundTask<List<Long>, Void> { - - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public BlockIDsTask(Account account) { - this.account = account; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @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; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/BlockTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/BlockTask.java deleted file mode 100644 index 620758c8..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/BlockTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -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 twitter4j.TwitterException; - -public 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)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/DeleteMessageTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/DeleteMessageTask.java deleted file mode 100644 index 4e35c7a9..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/DeleteMessageTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.DirectMessage; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class DeleteMessageTask extends BackgroundTask<DirectMessage, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long messageID; - - // --------------------------- CONSTRUCTORS --------------------------- - - public DeleteMessageTask(Account account, long messageID) { - this.account = account; - this.messageID = messageID; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected DirectMessage doInBackground() throws TwitterException { - return DirectMessage.fromTwitter(account.getTwitter().directMessages().destroyDirectMessage(messageID)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/DeleteStatusTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/DeleteStatusTask.java deleted file mode 100644 index e21e79e9..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/DeleteStatusTask.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class DeleteStatusTask extends BackgroundTask<Tweet, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long statusID; - - // --------------------------- CONSTRUCTORS --------------------------- - - public DeleteStatusTask(Account account, long statusID) { - this.account = account; - this.statusID = statusID; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected Tweet doInBackground() throws TwitterException { - Tweet t = Tweet.fromTwitter(account.getTwitter().tweets().destroyStatus(statusID), account.getUserId()); - Tweet.remove(t.getId()); - return t; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/DirectMessagesTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/DirectMessagesTask.java deleted file mode 100644 index f431fc85..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/DirectMessagesTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.DirectMessage; -import twitter4j.TwitterException; - -import java.util.List; - -public class DirectMessagesTask extends TimelineTask<DirectMessage> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public DirectMessagesTask(Account account) { - this.account = account; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected List<DirectMessage> doInBackground() throws TwitterException { - return DirectMessage.fromTwitter(account.getTwitter().directMessages().getDirectMessages(getPaging())); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/FavoriteTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/FavoriteTask.java deleted file mode 100644 index bc537ba2..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/FavoriteTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class FavoriteTask extends BackgroundTask<Tweet, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long statusID; - - // --------------------------- CONSTRUCTORS --------------------------- - - public FavoriteTask(Account account, long statusID) { - this.account = account; - this.statusID = statusID; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected Tweet doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().favorites().createFavorite(statusID), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/FollowTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/FollowTask.java deleted file mode 100644 index f38b1756..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/FollowTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -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 twitter4j.TwitterException; - -public 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)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java deleted file mode 100644 index 2c82493a..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java +++ /dev/null @@ -1,42 +0,0 @@ -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -import java.util.ArrayList; -import java.util.List; - -public class GetTalkTask extends BackgroundTask<List<Tweet>, Tweet> { - private final Account account; - private final long statusId; - - public GetTalkTask(Account account, long statusId) { - this.account = account; - this.statusId = statusId; - } - - @Override - protected List<Tweet> doInBackground() { - ArrayList<Tweet> list = new ArrayList<>(); - long id = statusId; - while (id != -1) { - Tweet tweet = Tweet.fetch(id); - if (tweet == null) { - try { - tweet = Tweet.fromTwitter(account.getTwitter().showStatus(id), account.getUserId()); - } catch (TwitterException ignored) { } - } - - if (tweet == null) { - break; - } else { - list.add(tweet); - progress(tweet); - id = tweet.getInReplyToStatusId(); - } - } - return list; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetUserListsTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetUserListsTask.java deleted file mode 100644 index d92d405d..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetUserListsTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.util.BackgroundTask; -import net.lacolaco.smileessence.util.ListUtils; -import twitter4j.TwitterException; -import twitter4j.UserList; - -import java.util.List; - -public class GetUserListsTask extends BackgroundTask<List<String>, Void> { - - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public GetUserListsTask(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); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/HomeTimelineTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/HomeTimelineTask.java deleted file mode 100644 index 798835b0..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/HomeTimelineTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import twitter4j.TwitterException; - -import java.util.List; - -public class HomeTimelineTask extends TimelineTask<Tweet> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public HomeTimelineTask(Account account) { - this.account = account; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected List<Tweet> doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().timelines().getHomeTimeline(getPaging()), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/MentionsTimelineTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/MentionsTimelineTask.java deleted file mode 100644 index c2448b01..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/MentionsTimelineTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import twitter4j.TwitterException; - -import java.util.List; - -public class MentionsTimelineTask extends TimelineTask<Tweet> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public MentionsTimelineTask(Account account) { - this.account = account; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected List<Tweet> doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().timelines().getMentionsTimeline(getPaging()), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Messages.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Messages.java new file mode 100644 index 00000000..533a242a --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Messages.java @@ -0,0 +1,96 @@ +package net.lacolaco.smileessence.twitter.task; + +import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.entity.DirectMessage; +import net.lacolaco.smileessence.util.BackgroundTask; +import twitter4j.TwitterException; + +import java.util.List; + +public class Messages { + public static class CreateTask extends BackgroundTask<DirectMessage, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final String userID; + private final String text; + + // --------------------------- CONSTRUCTORS --------------------------- + + public CreateTask(Account account, String screenName, String text) { + this.account = account; + this.userID = screenName; + this.text = text; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected DirectMessage doInBackground() throws TwitterException { + return DirectMessage.fromTwitter(account.getTwitter().directMessages().sendDirectMessage(userID, text)); + } + } + + public static class DestroyTask extends BackgroundTask<DirectMessage, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final long messageID; + + // --------------------------- CONSTRUCTORS --------------------------- + + public DestroyTask(Account account, long messageID) { + this.account = account; + this.messageID = messageID; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected DirectMessage doInBackground() throws TwitterException { + return DirectMessage.fromTwitter(account.getTwitter().directMessages().destroyDirectMessage(messageID)); + } + } + + public static class GetAllReceived extends TimelineTask<DirectMessage> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + + // --------------------------- CONSTRUCTORS --------------------------- + + public GetAllReceived(Account account) { + this.account = account; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<DirectMessage> doInBackground() throws TwitterException { + return DirectMessage.fromTwitter(account.getTwitter().directMessages().getDirectMessages(getPaging())); + } + } + + public static class GetAllSent extends TimelineTask<DirectMessage> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + + // --------------------------- CONSTRUCTORS --------------------------- + + public GetAllSent(Account account) { + this.account = account; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<DirectMessage> doInBackground() throws TwitterException { + return DirectMessage.fromTwitter(account.getTwitter().directMessages().getSentDirectMessages(getPaging())); + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/MutesIDsTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/MutesIDsTask.java deleted file mode 100644 index 13872dd6..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/MutesIDsTask.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.IDs; -import twitter4j.TwitterException; - -import java.util.ArrayList; -import java.util.List; - -public class MutesIDsTask extends BackgroundTask<List<Long>, Void> { - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public MutesIDsTask(Account account) { - this.account = account; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @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; - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ReportForSpamTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/ReportForSpamTask.java deleted file mode 100644 index ef84e598..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ReportForSpamTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -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 twitter4j.TwitterException; - -public 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)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/RequestTokenTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/RequestTokenTask.java deleted file mode 100644 index ae41a5fa..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/RequestTokenTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.auth.RequestToken; - -public class RequestTokenTask extends BackgroundTask<RequestToken, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Twitter twitter; - - // --------------------------- CONSTRUCTORS --------------------------- - - public RequestTokenTask(Twitter twitter) { - this.twitter = twitter; - } - - @Override - protected RequestToken doInBackground() throws TwitterException { - return twitter.getOAuthRequestToken("oob"); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/RetweetTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/RetweetTask.java deleted file mode 100644 index 03cf7a54..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/RetweetTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class RetweetTask extends BackgroundTask<Tweet, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long statusID; - - // --------------------------- CONSTRUCTORS --------------------------- - - public RetweetTask(Account account, long statusID) { - this.account = account; - this.statusID = statusID; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected Tweet doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().tweets().retweetStatus(statusID), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SavedSearches.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/SavedSearches.java deleted file mode 100644 index 38177274..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SavedSearches.java +++ /dev/null @@ -1,54 +0,0 @@ -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); - } - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SearchTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/SearchTask.java deleted file mode 100644 index fba66723..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SearchTask.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.Query; -import twitter4j.QueryResult; -import twitter4j.TwitterException; - -public class SearchTask extends BackgroundTask<QueryResult, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final Query query; - - // --------------------------- CONSTRUCTORS --------------------------- - - public SearchTask(Account account, Query query) { - this.account = account; - this.query = query; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected QueryResult doInBackground() throws TwitterException { - return account.getTwitter().search(query); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.java new file mode 100644 index 00000000..91f6fbcc --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Searches.java @@ -0,0 +1,80 @@ +package net.lacolaco.smileessence.twitter.task; + +import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.entity.SavedSearch; +import net.lacolaco.smileessence.entity.Tweet; +import net.lacolaco.smileessence.util.BackgroundTask; +import net.lacolaco.smileessence.util.ListUtils; +import twitter4j.Query; +import twitter4j.TwitterException; + +import java.util.List; + +public class Searches { + public static class CreateSavedSearchTask extends BackgroundTask<SavedSearch, Void> { + private final Account account; + private final String query; + + public CreateSavedSearchTask(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 DestroySavedSearchTask extends BackgroundTask<Void, Void> { + private final Account account; + private final long id; + + public DestroySavedSearchTask(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 GetAllSavedSearchesTask extends BackgroundTask<List<SavedSearch>, Void> { + private final Account account; + + public GetAllSavedSearchesTask(Account account) { + this.account = account; + } + + @Override + protected List<SavedSearch> doInBackground() throws Exception { + return ListUtils.map(account.getTwitter().savedSearches().getSavedSearches(), SavedSearch::fromTwitter); + } + } + + // TODO: List<Tweet> is not good here + public static class SearchTask extends BackgroundTask<List<Tweet>, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final Query query; + + // --------------------------- CONSTRUCTORS --------------------------- + + public SearchTask(Account account, Query query) { + this.account = account; + this.query = query; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<Tweet> doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().search(query).getTweets(), account.getUserId()); + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SendMessageTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/SendMessageTask.java deleted file mode 100644 index 28e70a90..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SendMessageTask.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.DirectMessage; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class SendMessageTask extends BackgroundTask<DirectMessage, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final String userID; - private final String text; - - // --------------------------- CONSTRUCTORS --------------------------- - - public SendMessageTask(Account account, String screenName, String text) { - this.account = account; - this.userID = screenName; - this.text = text; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected DirectMessage doInBackground() throws TwitterException { - return DirectMessage.fromTwitter(account.getTwitter().directMessages().sendDirectMessage(userID, text)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SentDirectMessagesTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/SentDirectMessagesTask.java deleted file mode 100644 index 795d8118..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/SentDirectMessagesTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.DirectMessage; -import twitter4j.TwitterException; - -import java.util.List; - -public class SentDirectMessagesTask extends TimelineTask<DirectMessage> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public SentDirectMessagesTask(Account account) { - this.account = account; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected List<DirectMessage> doInBackground() throws TwitterException { - return DirectMessage.fromTwitter(account.getTwitter().directMessages().getSentDirectMessages(getPaging())); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowFriendshipTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowFriendshipTask.java deleted file mode 100644 index 77d029f0..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowFriendshipTask.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.Relationship; -import twitter4j.TwitterException; - -public 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); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowStatusTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowStatusTask.java deleted file mode 100644 index 80c6b0c4..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowStatusTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class ShowStatusTask extends BackgroundTask<Tweet, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long id; - - // --------------------------- CONSTRUCTORS --------------------------- - - public ShowStatusTask(Account account, long id) { - this.account = account; - this.id = id; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected Tweet doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().tweets().showStatus(id), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowUserTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowUserTask.java deleted file mode 100644 index 1334caf1..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/ShowUserTask.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -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 twitter4j.TwitterException; - -public class ShowUserTask extends BackgroundTask<User, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long userID; - private final String screenName; - - // --------------------------- CONSTRUCTORS --------------------------- - - public ShowUserTask(Account account, long userID) { - this.account = account; - this.userID = userID; - this.screenName = null; - } - - public ShowUserTask(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)); - } - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/TimelineTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/TimelineTask.java index 0b151a1e..1025d3e9 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/TimelineTask.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/TimelineTask.java @@ -43,6 +43,7 @@ public abstract class TimelineTask<T> extends BackgroundTask<List<T>, Void> { } return this; } + public TimelineTask<T> setSinceId(long sinceId) { if (sinceId > 0) { paging.setSinceId(sinceId); diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Timelines.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Timelines.java new file mode 100644 index 00000000..ae1aa0ea --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Timelines.java @@ -0,0 +1,94 @@ +package net.lacolaco.smileessence.twitter.task; + +import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.entity.Tweet; +import twitter4j.TwitterException; + +import java.util.List; + +public class Timelines { + public static class HomeTimelineTask extends TimelineTask<Tweet> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + + // --------------------------- CONSTRUCTORS --------------------------- + + public HomeTimelineTask(Account account) { + this.account = account; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<Tweet> doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().timelines().getHomeTimeline(getPaging()), account.getUserId()); + } + } + + public static class MentionsTimelineTask extends TimelineTask<Tweet> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + + // --------------------------- CONSTRUCTORS --------------------------- + + public MentionsTimelineTask(Account account) { + this.account = account; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<Tweet> doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().timelines().getMentionsTimeline(getPaging()), account.getUserId()); + } + } + + public static class UserTimelineTask extends TimelineTask<Tweet> { + + // ------------------------------ FIELDS ------------------------------ + + private final long userID; + private final Account account; + + // --------------------------- CONSTRUCTORS --------------------------- + + public UserTimelineTask(Account account, long userID) { + this.account = account; + this.userID = userID; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<Tweet> doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().timelines().getUserTimeline(userID, getPaging()), account.getUserId()); + } + } + + public static class UserListStatusesTask extends TimelineTask<Tweet> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final String listFullName; + + // --------------------------- CONSTRUCTORS --------------------------- + + public UserListStatusesTask(Account account, String listFullName) { + this.account = account; + this.listFullName = listFullName; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected List<Tweet> doInBackground() throws TwitterException { + String[] strings = listFullName.split("/"); + return Tweet.fromTwitter(account.getTwitter().list().getUserListStatuses(strings[0], strings[1], getPaging()), account.getUserId()); + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/TweetReactions.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/TweetReactions.java new file mode 100644 index 00000000..f201492e --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/TweetReactions.java @@ -0,0 +1,74 @@ +package net.lacolaco.smileessence.twitter.task; + +import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.entity.Tweet; +import net.lacolaco.smileessence.util.BackgroundTask; +import twitter4j.TwitterException; + +public class TweetReactions { + public static class RetweetTask extends BackgroundTask<Tweet, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final long statusID; + + // --------------------------- CONSTRUCTORS --------------------------- + + public RetweetTask(Account account, long statusID) { + this.account = account; + this.statusID = statusID; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected Tweet doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().tweets().retweetStatus(statusID), account.getUserId()); + } + } + + public static class FavoriteTask extends BackgroundTask<Tweet, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final long statusID; + + // --------------------------- CONSTRUCTORS --------------------------- + + public FavoriteTask(Account account, long statusID) { + this.account = account; + this.statusID = statusID; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected Tweet doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().favorites().createFavorite(statusID), account.getUserId()); + } + } + + public static class UnfavoriteTask extends BackgroundTask<Tweet, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final long statusID; + + // --------------------------- CONSTRUCTORS --------------------------- + + public UnfavoriteTask(Account account, long statusID) { + this.account = account; + this.statusID = statusID; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected Tweet doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().favorites().destroyFavorite(statusID), account.getUserId()); + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/TweetTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/TweetTask.java deleted file mode 100644 index 33bb526f..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/TweetTask.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Environment; -import android.text.TextUtils; -import net.lacolaco.smileessence.R; -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.logging.Logger; -import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.StatusUpdate; -import twitter4j.TwitterException; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -public class TweetTask extends BackgroundTask<Tweet, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private static final int MEDIA_SIZE_LIMIT = 2 * 1024 * 1024; - private final Account account; - private final StatusUpdate update; - private final String mediaPath; - private String tempFilePath; - private boolean resizeFlag; - - // --------------------------- CONSTRUCTORS --------------------------- - - public TweetTask(Account account, StatusUpdate update, String mediaPath, boolean resize) { - this.account = account; - this.update = update; - this.mediaPath = mediaPath; - resizeFlag = resize; - } - - // --------------------- GETTER / SETTER METHODS --------------------- - - private File getMediaFile() { - File file = new File(mediaPath); - if (file.length() >= MEDIA_SIZE_LIMIT && resizeFlag) { - BitmapFactory.Options opt = new BitmapFactory.Options(); - opt.inJustDecodeBounds = true; //decoder is not return bitmap but set option - BitmapFactory.decodeFile(mediaPath, opt); - tempFilePath = Environment.getExternalStorageDirectory() + "/temp.jpg"; - File compressedFile = new File(tempFilePath); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(compressedFile); - float ratio = (float) file.length() / (float) MEDIA_SIZE_LIMIT; - BitmapFactory.Options resizeOpt = new BitmapFactory.Options(); - resizeOpt.inPurgeable = true; - resizeOpt.inSampleSize = (int) Math.ceil(ratio); - Bitmap bitmap = BitmapFactory.decodeFile(mediaPath, resizeOpt); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); - bitmap.recycle(); - return compressedFile; - } catch (Exception e) { - e.printStackTrace(); - Logger.error(e); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - e.printStackTrace(); - Logger.error(e); - } - } - } - } - return file; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected Tweet doInBackground() throws TwitterException { - try { - if (!TextUtils.isEmpty(mediaPath)) { - File mediaFile = getMediaFile(); - if (mediaFile.exists()) { - update.setMedia(mediaFile); - } - } - return Tweet.fromTwitter(account.getTwitter().tweets().updateStatus(update), account.getUserId()); - } finally { - if (tempFilePath != null) { - new File(tempFilePath).delete(); - } - } - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java new file mode 100644 index 00000000..016f699c --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java @@ -0,0 +1,178 @@ +package net.lacolaco.smileessence.twitter.task; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Environment; +import android.text.TextUtils; +import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.entity.Tweet; +import net.lacolaco.smileessence.logging.Logger; +import net.lacolaco.smileessence.util.BackgroundTask; +import twitter4j.StatusUpdate; +import twitter4j.TwitterException; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Tweets { + public static class GetTask extends BackgroundTask<Tweet, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final long id; + + // --------------------------- CONSTRUCTORS --------------------------- + + public GetTask(Account account, long id) { + this.account = account; + this.id = id; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected Tweet doInBackground() throws TwitterException { + return Tweet.fromTwitter(account.getTwitter().tweets().showStatus(id), account.getUserId()); + } + } + + public static class CreateTask extends BackgroundTask<Tweet, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private static final int MEDIA_SIZE_LIMIT = 2 * 1024 * 1024; + private final Account account; + private final StatusUpdate update; + private final String mediaPath; + private String tempFilePath; + private boolean resizeFlag; + + // --------------------------- CONSTRUCTORS --------------------------- + + public CreateTask(Account account, StatusUpdate update, String mediaPath, boolean resize) { + this.account = account; + this.update = update; + this.mediaPath = mediaPath; + resizeFlag = resize; + } + + // --------------------- GETTER / SETTER METHODS --------------------- + + private File getMediaFile() { + File file = new File(mediaPath); + if (file.length() >= MEDIA_SIZE_LIMIT && resizeFlag) { + BitmapFactory.Options opt = new BitmapFactory.Options(); + opt.inJustDecodeBounds = true; //decoder is not return bitmap but set option + BitmapFactory.decodeFile(mediaPath, opt); + tempFilePath = Environment.getExternalStorageDirectory() + "/temp.jpg"; + File compressedFile = new File(tempFilePath); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(compressedFile); + float ratio = (float) file.length() / (float) MEDIA_SIZE_LIMIT; + BitmapFactory.Options resizeOpt = new BitmapFactory.Options(); + resizeOpt.inPurgeable = true; + resizeOpt.inSampleSize = (int) Math.ceil(ratio); + Bitmap bitmap = BitmapFactory.decodeFile(mediaPath, resizeOpt); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); + bitmap.recycle(); + return compressedFile; + } catch (Exception e) { + e.printStackTrace(); + Logger.error(e); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + Logger.error(e); + } + } + } + } + return file; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected Tweet doInBackground() throws TwitterException { + try { + if (!TextUtils.isEmpty(mediaPath)) { + File mediaFile = getMediaFile(); + if (mediaFile.exists()) { + update.setMedia(mediaFile); + } + } + return Tweet.fromTwitter(account.getTwitter().tweets().updateStatus(update), account.getUserId()); + } finally { + if (tempFilePath != null) { + new File(tempFilePath).delete(); + } + } + } + } + + public static class DestroyTask extends BackgroundTask<Tweet, Void> { + + // ------------------------------ FIELDS ------------------------------ + + private final Account account; + private final long statusID; + + // --------------------------- CONSTRUCTORS --------------------------- + + public DestroyTask(Account account, long statusID) { + this.account = account; + this.statusID = statusID; + } + + // ------------------------ OVERRIDE METHODS ------------------------ + + @Override + protected Tweet doInBackground() throws TwitterException { + Tweet t = Tweet.fromTwitter(account.getTwitter().tweets().destroyStatus(statusID), account.getUserId()); + Tweet.remove(t.getId()); + return t; + } + } + + public static class GetTalkTask extends BackgroundTask<List<Tweet>, Tweet> { + private final Account account; + private final long statusId; + + public GetTalkTask(Account account, long statusId) { + this.account = account; + this.statusId = statusId; + } + + @Override + protected List<Tweet> doInBackground() { + ArrayList<Tweet> list = new ArrayList<>(); + long id = statusId; + while (id != -1) { + Tweet tweet = Tweet.fetch(id); + if (tweet == null) { + try { + tweet = Tweet.fromTwitter(account.getTwitter().showStatus(id), account.getUserId()); + } catch (TwitterException ignored) { + } + } + + if (tweet == null) { + break; + } else { + list.add(tweet); + progress(tweet); + id = tweet.getInReplyToStatusId(); + } + } + return list; + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnblockTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnblockTask.java deleted file mode 100644 index 30377bb5..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnblockTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -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 twitter4j.TwitterException; - -public 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)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnfavoriteTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnfavoriteTask.java deleted file mode 100644 index 62587b5e..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnfavoriteTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.util.BackgroundTask; -import twitter4j.TwitterException; - -public class UnfavoriteTask extends BackgroundTask<Tweet, Void> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final long statusID; - - // --------------------------- CONSTRUCTORS --------------------------- - - public UnfavoriteTask(Account account, long statusID) { - this.account = account; - this.statusID = statusID; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected Tweet doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().favorites().destroyFavorite(statusID), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnfollowTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnfollowTask.java deleted file mode 100644 index da825aeb..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UnfollowTask.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -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 twitter4j.TwitterException; - -public 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)); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UserListStatusesTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/UserListStatusesTask.java deleted file mode 100644 index c54a703b..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UserListStatusesTask.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import twitter4j.TwitterException; - -import java.util.List; - -public class UserListStatusesTask extends TimelineTask<Tweet> { - - // ------------------------------ FIELDS ------------------------------ - - private final Account account; - private final String listFullName; - - // --------------------------- CONSTRUCTORS --------------------------- - - public UserListStatusesTask(Account account, String listFullName) { - this.account = account; - this.listFullName = listFullName; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected List<Tweet> doInBackground() throws TwitterException { - String[] strings = listFullName.split("/"); - return Tweet.fromTwitter(account.getTwitter().list().getUserListStatuses(strings[0], strings[1], getPaging()), account.getUserId()); - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UserTimelineTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/UserTimelineTask.java deleted file mode 100644 index c4d97842..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/UserTimelineTask.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter.task; - -import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.entity.Tweet; -import twitter4j.TwitterException; - -import java.util.List; - -public class UserTimelineTask extends TimelineTask<Tweet> { - - // ------------------------------ FIELDS ------------------------------ - - private final long userID; - private final Account account; - - // --------------------------- CONSTRUCTORS --------------------------- - - public UserTimelineTask(Account account, long userID) { - this.account = account; - this.userID = userID; - } - - // ------------------------ OVERRIDE METHODS ------------------------ - - @Override - protected List<Tweet> doInBackground() throws TwitterException { - return Tweet.fromTwitter(account.getTwitter().timelines().getUserTimeline(userID, getPaging()), account.getUserId()); - } -} 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); + } + } +} diff --git a/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.java b/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.java index 548fc588..1cf4efeb 100644 --- a/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.java +++ b/app/src/main/java/net/lacolaco/smileessence/util/UIObservable.java @@ -8,7 +8,7 @@ public abstract class UIObservable { private Map<Object, UIObserver> observers = new WeakHashMap<>(); public void addObserver(Object weakKey, UIObserver observer) { - synchronized(this) { + synchronized (this) { observers.put(weakKey, observer); } } @@ -24,8 +24,8 @@ public abstract class UIObservable { } protected void notifyChange(EnumSet<RBinding> flags) { - List<UIObserver> obs = new ArrayList<>(); - synchronized(this) { + List<UIObserver> obs = new ArrayList<>(); + synchronized (this) { obs.addAll(observers.values()); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/DialogHelper.java b/app/src/main/java/net/lacolaco/smileessence/view/DialogHelper.java index dc3db869..3a0003d6 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/DialogHelper.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/DialogHelper.java @@ -27,7 +27,10 @@ package net.lacolaco.smileessence.view; import android.app.Activity; import net.lacolaco.smileessence.view.dialog.StackableDialogFragment; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.UUID; /** * DialogFragment のタグの一覧を保持し「全てのダイアログを閉じる」機能を提供するヘルパークラス diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java index dfd395b9..802a0dd3 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java @@ -7,7 +7,8 @@ import android.widget.BaseAdapter; import net.lacolaco.smileessence.util.UIHandler; import net.lacolaco.smileessence.viewmodel.IViewModel; -import java.util.*; +import java.util.ArrayList; +import java.util.List; public abstract class CustomListAdapter<T extends IViewModel> extends BaseAdapter { diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java index 04a38f35..76e72093 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/PageListAdapter.java @@ -129,7 +129,9 @@ public class PageListAdapter extends FragmentPagerAdapter { return fragmentClass; } - public String getName() { return name; } + public String getName() { + return name; + } public Bundle getArgs() { return args; diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java index 7fc367cb..02f90bc2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java @@ -27,7 +27,10 @@ package net.lacolaco.smileessence.view.adapter; import android.app.Activity; import net.lacolaco.smileessence.viewmodel.IViewModel; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; public class UnorderedCustomListAdapter<T extends IViewModel> extends CustomListAdapter<T> { diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java index 2256bb97..ab140c12 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java @@ -42,7 +42,7 @@ import net.lacolaco.smileessence.command.CommandOpenUserDetail; import net.lacolaco.smileessence.data.Account; import net.lacolaco.smileessence.entity.DirectMessage; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.DeleteMessageTask; +import net.lacolaco.smileessence.twitter.task.Messages; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.view.adapter.MessageListAdapter; import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter; @@ -141,7 +141,7 @@ public class MessageDetailDialogFragment extends StackableDialogFragment impleme private void deleteMessage() { ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), () -> { - new DeleteMessageTask(Application.getInstance().getCurrentAccount(), message.getId()) + new Messages.DestroyTask(Application.getInstance().getCurrentAccount(), message.getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_message_delete_succeeded)) .onFail(x -> Notificator.getInstance().alert(R.string.notice_message_delete_failed)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java index d5cd36a1..c3bcbe16 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageMenuDialogFragment.java @@ -26,7 +26,7 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; import android.os.Bundle; -import net.lacolaco.smileessence.command.*; +import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.entity.DirectMessage; import java.util.List; diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java index 7ebf5efe..9a897f8f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SelectSearchQueryDialogFragment.java @@ -37,7 +37,7 @@ import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandOpenSearch; import net.lacolaco.smileessence.entity.SavedSearch; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.SavedSearches; +import net.lacolaco.smileessence.twitter.task.Searches; import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter; import java.util.ArrayList; @@ -55,7 +55,7 @@ public class SelectSearchQueryDialogFragment extends MenuDialogFragment implemen ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_delete_query), () -> { adapter.removeItem(command); adapter.update(); - new SavedSearches.Destroy(Application.getInstance().getCurrentAccount(), command.getQuery().getId()) + new Searches.DestroySavedSearchTask(Application.getInstance().getCurrentAccount(), command.getQuery().getId()) .onDoneUI(x -> { Notificator.getInstance().publish(R.string.notice_search_query_deleted); Application.getInstance().getCurrentAccount().refreshSavedSearches(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java index d423b315..7f165fea 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/SendMessageDialogFragment.java @@ -41,7 +41,7 @@ import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.data.PostState; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.SendMessageTask; +import net.lacolaco.smileessence.twitter.task.Messages; import net.lacolaco.smileessence.util.SystemServiceHelper; public class SendMessageDialogFragment extends StackableDialogFragment implements TextWatcher, View.OnClickListener { @@ -142,7 +142,7 @@ public class SendMessageDialogFragment extends StackableDialogFragment implement private void sendMessage() { SystemServiceHelper.hideIM(getActivity(), editText); String text = editText.getText().toString(); - new SendMessageTask(Application.getInstance().getCurrentAccount(), screenName, text) + new Messages.CreateTask(Application.getInstance().getCurrentAccount(), screenName, text) .onDoneUI(m -> { Notificator.getInstance().publish(R.string.notice_message_send_succeeded); dismiss(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java index 93b5c36c..8f5c7225 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java @@ -42,12 +42,13 @@ import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandAddHashtag; import net.lacolaco.smileessence.command.CommandOpenURL; import net.lacolaco.smileessence.command.CommandOpenUserDetail; -import net.lacolaco.smileessence.data.PostState; import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.data.PostState; import net.lacolaco.smileessence.entity.RBinding; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.*; +import net.lacolaco.smileessence.twitter.task.TweetReactions; +import net.lacolaco.smileessence.twitter.task.Tweets; import net.lacolaco.smileessence.util.Themes; import net.lacolaco.smileessence.util.UIObserverBundle; import net.lacolaco.smileessence.view.DialogHelper; @@ -278,7 +279,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen confirm(() -> { Account account = Application.getInstance().getCurrentAccount(); - new DeleteStatusTask(account, tweet.getOriginalTweet().getId()) + new Tweets.DestroyTask(account, tweet.getOriginalTweet().getId()) .onDone(t -> Notificator.getInstance().publish(R.string.notice_status_delete_succeeded)) .onFail(e -> Notificator.getInstance().alert(R.string.notice_status_delete_failed)) .execute(); @@ -340,12 +341,12 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen private void toggleFavorite() { Account account = Application.getInstance().getCurrentAccount(); if (tweet.isFavoritedBy(account.getUserId())) { - new UnfavoriteTask(account, tweet.getId()) + new TweetReactions.UnfavoriteTask(account, tweet.getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_unfavorite_succeeded)) .onFail(x -> Notificator.getInstance().alert(R.string.notice_unfavorite_failed)) .execute(); } else { - new FavoriteTask(account, tweet.getId()) + new TweetReactions.FavoriteTask(account, tweet.getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_favorite_succeeded)) .onFail(x -> Notificator.getInstance().alert(R.string.notice_favorite_failed)) .execute(); @@ -356,13 +357,13 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen Account account = Application.getInstance().getCurrentAccount(); confirm(() -> { if (tweet.isRetweetedBy(account.getUserId())) { - new DeleteStatusTask(account, tweet.getRetweetIdBy(account.getUserId())) + new Tweets.DestroyTask(account, tweet.getRetweetIdBy(account.getUserId())) .onDone(t -> Notificator.getInstance().publish(R.string.notice_status_delete_succeeded)) .onFail(e -> Notificator.getInstance().alert(R.string.notice_status_delete_failed)) .execute(); dismiss(); } else { - new RetweetTask(account, tweet.getId()) + new TweetReactions.RetweetTask(account, tweet.getId()) .onDone(x -> Notificator.getInstance().publish(R.string.notice_retweet_succeeded)) .onFail(x -> Notificator.getInstance().alert(R.string.notice_retweet_failed)) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java index 3674cbd7..58284536 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusMenuDialogFragment.java @@ -26,7 +26,7 @@ package net.lacolaco.smileessence.view.dialog; import android.app.Activity; import android.os.Bundle; -import net.lacolaco.smileessence.command.*; +import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.entity.Tweet; import java.util.List; diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java index 369d5b07..cc7b2b01 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/TalkChainDialogFragment.java @@ -33,7 +33,7 @@ import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.data.Account; -import net.lacolaco.smileessence.twitter.task.GetTalkTask; +import net.lacolaco.smileessence.twitter.task.Tweets; import net.lacolaco.smileessence.view.adapter.UnorderedCustomListAdapter; import net.lacolaco.smileessence.viewmodel.StatusViewModel; @@ -67,7 +67,7 @@ public class TalkChainDialogFragment extends StackableDialogFragment { final UnorderedCustomListAdapter<StatusViewModel> adapter = new UnorderedCustomListAdapter<>(getActivity()); listView.setAdapter(adapter); - new GetTalkTask(account, getStatusID()).onProgressUI(tweet -> { + new Tweets.GetTalkTask(account, getStatusID()).onProgressUI(tweet -> { adapter.addItemToBottom(new StatusViewModel(tweet)); adapter.updateForce(); }).execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java index 30c80e69..e1867519 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java @@ -41,16 +41,14 @@ import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.Command; -import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.entity.RBinding; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.task.FollowTask; -import net.lacolaco.smileessence.twitter.task.ShowFriendshipTask; -import net.lacolaco.smileessence.twitter.task.UnfollowTask; -import net.lacolaco.smileessence.twitter.task.UserTimelineTask; +import net.lacolaco.smileessence.twitter.task.Timelines; +import net.lacolaco.smileessence.twitter.task.Users; import net.lacolaco.smileessence.util.IntentUtils; import net.lacolaco.smileessence.util.Themes; import net.lacolaco.smileessence.util.UIHandler; @@ -115,7 +113,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements break; } case R.id.textview_user_detail_screenname: - case R.id.textview_user_detail_tweet_count:{ + case R.id.textview_user_detail_tweet_count: { IntentUtils.openUri(getActivity(), user.getUserHomeURL()); break; } @@ -143,7 +141,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { Account currentAccount = Application.getInstance().getCurrentAccount(); - new UserTimelineTask(currentAccount, getUserID()) + new Timelines.UserTimelineTask(currentAccount, getUserID()) .setCount(200) .setSinceId(adapter.getTopID()) .onFail(x -> Notificator.getInstance().alert(R.string.notice_error_get_user_timeline)) @@ -160,7 +158,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { Account currentAccount = Application.getInstance().getCurrentAccount(); - new UserTimelineTask(currentAccount, getUserID()) + new Timelines.UserTimelineTask(currentAccount, getUserID()) .setCount(200) .setMaxId(adapter.getLastID() - 1) .onFail(x -> Notificator.getInstance().alert(R.string.notice_error_get_user_timeline)) @@ -244,7 +242,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements private void executeUserTimelineTask(final StatusListAdapter adapter) { Account account = Application.getInstance().getCurrentAccount(); tabHost.getTabWidget().getChildTabViewAt(1).setVisibility(View.GONE); - new UserTimelineTask(account, user.getId()) + new Timelines.UserTimelineTask(account, user.getId()) .setCount(200) .onFail(x -> Notificator.getInstance().alert(R.string.notice_error_get_user_timeline)) .onDoneUI(tweets -> { @@ -358,7 +356,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements lockFollowButton(); Boolean isFollowing = buttonFollow.getTag() != null ? (Boolean) buttonFollow.getTag() : false; if (isFollowing) { - new UnfollowTask(account, user.getId()) + new Users.UnfollowTask(account, user.getId()) .onDoneUI(result -> { Notificator.getInstance().publish(R.string.notice_unfollow_succeeded); updateRelationship(); @@ -368,7 +366,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements Notificator.getInstance().alert(R.string.notice_unfollow_failed)) .execute(); } else { - new FollowTask(account, user.getId()) + new Users.FollowTask(account, user.getId()) .onDoneUI(result -> { Notificator.getInstance().publish(R.string.notice_follow_succeeded); updateRelationship(); @@ -403,7 +401,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements } else { lockFollowButton(); textViewFollowed.setText(R.string.user_detail_loading); - new ShowFriendshipTask(account, user.getId()).onDoneUI(relationship -> { + new Users.ShowFriendshipTask(account, user.getId()).onDoneUI(relationship -> { boolean isFollowing = relationship.isSourceFollowingTarget(); boolean isFollowed = relationship.isSourceFollowedByTarget(); setFollowButtonState(isFollowing); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/HomeFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/page/HomeFragment.java index 7ff534b1..719a5c53 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/HomeFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/HomeFragment.java @@ -34,8 +34,8 @@ import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.StatusFilter; -import net.lacolaco.smileessence.twitter.task.HomeTimelineTask; import net.lacolaco.smileessence.twitter.task.TimelineTask; +import net.lacolaco.smileessence.twitter.task.Timelines; import net.lacolaco.smileessence.util.UIHandler; import net.lacolaco.smileessence.view.adapter.StatusListAdapter; import net.lacolaco.smileessence.viewmodel.StatusViewModel; @@ -79,7 +79,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { @Override public void refresh() { - runRefreshTask(new HomeTimelineTask(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); + runRefreshTask(new Timelines.HomeTimelineTask(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); } // --------------------- Interface OnRefreshListener2 --------------------- @@ -94,7 +94,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { }); } else { runRefreshTask( - new HomeTimelineTask(Application.getInstance().getCurrentAccount()) + new Timelines.HomeTimelineTask(Application.getInstance().getCurrentAccount()) .setSinceId(getAdapter().getTopID()), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), true); @@ -106,7 +106,7 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { runRefreshTask( - new HomeTimelineTask(Application.getInstance().getCurrentAccount()) + new Timelines.HomeTimelineTask(Application.getInstance().getCurrentAccount()) .setMaxId(getAdapter().getLastID() - 1), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), false); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/MentionsFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/page/MentionsFragment.java index 6d6f4b5e..cfa75d7d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/MentionsFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/MentionsFragment.java @@ -33,8 +33,8 @@ import net.lacolaco.smileessence.data.ExtractionWord; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.StatusFilter; -import net.lacolaco.smileessence.twitter.task.MentionsTimelineTask; import net.lacolaco.smileessence.twitter.task.TimelineTask; +import net.lacolaco.smileessence.twitter.task.Timelines; import net.lacolaco.smileessence.view.adapter.StatusListAdapter; import net.lacolaco.smileessence.viewmodel.StatusViewModel; @@ -86,7 +86,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { @Override public void refresh() { - runRefreshTask(new MentionsTimelineTask(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); + runRefreshTask(new Timelines.MentionsTimelineTask(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); } // --------------------- Interface OnRefreshListener2 --------------------- @@ -94,7 +94,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { runRefreshTask( - new MentionsTimelineTask(Application.getInstance().getCurrentAccount()) + new Timelines.MentionsTimelineTask(Application.getInstance().getCurrentAccount()) .setSinceId(getAdapter().getTopID()), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), true); @@ -105,7 +105,7 @@ public class MentionsFragment extends CustomListFragment<StatusListAdapter> { @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { runRefreshTask( - new MentionsTimelineTask(Application.getInstance().getCurrentAccount()) + new Timelines.MentionsTimelineTask(Application.getInstance().getCurrentAccount()) .setMaxId(getAdapter().getLastID() - 1), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), false); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/MessagesFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/page/MessagesFragment.java index 642c080c..e07cf272 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/MessagesFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/MessagesFragment.java @@ -32,8 +32,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.entity.DirectMessage; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.StatusFilter; -import net.lacolaco.smileessence.twitter.task.DirectMessagesTask; -import net.lacolaco.smileessence.twitter.task.SentDirectMessagesTask; +import net.lacolaco.smileessence.twitter.task.Messages; import net.lacolaco.smileessence.twitter.task.TimelineTask; import net.lacolaco.smileessence.view.adapter.MessageListAdapter; import net.lacolaco.smileessence.viewmodel.MessageViewModel; @@ -79,8 +78,8 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { @Override public void refresh() { - runRefreshTask(new DirectMessagesTask(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); - runRefreshTask(new SentDirectMessagesTask(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); + runRefreshTask(new Messages.GetAllReceived(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); + runRefreshTask(new Messages.GetAllSent(Application.getInstance().getCurrentAccount()), () -> getAdapter().updateForce()); } // --------------------- Interface OnRefreshListener2 --------------------- @@ -88,7 +87,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { @Override public void onPullDownToRefresh(final PullToRefreshBase<ListView> refreshView) { runRefreshTask( - new DirectMessagesTask(Application.getInstance().getCurrentAccount()) + new Messages.GetAllReceived(Application.getInstance().getCurrentAccount()) .setSinceId(getAdapter().getTopID()), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), true); @@ -99,7 +98,7 @@ public class MessagesFragment extends CustomListFragment<MessageListAdapter> { @Override public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) { runRefreshTask( - new DirectMessagesTask(Application.getInstance().getCurrentAccount()) + new Messages.GetAllReceived(Application.getInstance().getCurrentAccount()) .setMaxId(getAdapter().getLastID() - 1), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), false); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/PostFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/page/PostFragment.java index c42bb931..1198c7fd 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/PostFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/PostFragment.java @@ -45,7 +45,7 @@ import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.preference.UserPreferenceHelper; -import net.lacolaco.smileessence.twitter.task.TweetTask; +import net.lacolaco.smileessence.twitter.task.Tweets; import net.lacolaco.smileessence.util.BitmapThumbnailTask; import net.lacolaco.smileessence.util.IntentUtils; import net.lacolaco.smileessence.util.SystemServiceHelper; @@ -324,7 +324,7 @@ public class PostFragment extends PageFragment implements TextWatcher, View.OnFo PostState state = PostState.getState(); MainActivity mainActivity = (MainActivity) getActivity(); boolean resizeFlag = UserPreferenceHelper.getInstance().get(R.string.key_setting_resize_post_image, false); - new TweetTask(Application.getInstance().getCurrentAccount(), state.toStatusUpdate(), state.getMediaFilePath(), resizeFlag) + new Tweets.CreateTask(Application.getInstance().getCurrentAccount(), state.toStatusUpdate(), state.getMediaFilePath(), resizeFlag) .onDoneUI(t -> { Notificator.getInstance().publish(R.string.notice_tweet_succeeded); PostState.newState().beginTransaction().commit(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/SearchFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/page/SearchFragment.java index 393ad7df..99173bf6 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/SearchFragment.java @@ -29,7 +29,10 @@ import android.support.annotation.NonNull; import android.text.Spannable; import android.text.TextUtils; import android.text.method.ArrowKeyMovementMethod; -import android.view.*; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.ImageButton; @@ -41,13 +44,11 @@ import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandOpenSearch; -import net.lacolaco.smileessence.data.Account; import net.lacolaco.smileessence.entity.SavedSearch; -import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.preference.InternalPreferenceHelper; -import net.lacolaco.smileessence.twitter.task.SavedSearches; -import net.lacolaco.smileessence.twitter.task.SearchTask; +import net.lacolaco.smileessence.twitter.task.Searches; +import net.lacolaco.smileessence.util.ListUtils; import net.lacolaco.smileessence.util.SystemServiceHelper; import net.lacolaco.smileessence.util.UIHandler; import net.lacolaco.smileessence.view.DialogHelper; @@ -151,12 +152,10 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem if (adapter.getCount() > 0) { query.setSinceId(adapter.getTopID()); } - runRefreshTask( - new SearchTask(Application.getInstance().getCurrentAccount(), query), - () -> { - updateListViewWithNotice(refreshView.getRefreshableView(), true); - refreshView.onRefreshComplete(); - }); + runRefreshTask(query, () -> { + updateListViewWithNotice(refreshView.getRefreshableView(), true); + refreshView.onRefreshComplete(); + }); } @Override @@ -177,12 +176,10 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem if (adapter.getCount() > 0) { query.setMaxId(adapter.getLastID() - 1); } - runRefreshTask( - new SearchTask(Application.getInstance().getCurrentAccount(), query), - () -> { - updateListViewWithNotice(refreshView.getRefreshableView(), false); - refreshView.onRefreshComplete(); - }); + runRefreshTask(query, () -> { + updateListViewWithNotice(refreshView.getRefreshableView(), false); + refreshView.onRefreshComplete(); + }); } // ------------------------ OVERRIDE METHODS ------------------------ @@ -213,8 +210,8 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem editText.setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent != null && - keyEvent.getAction() == KeyEvent.ACTION_DOWN && - keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + keyEvent.getAction() == KeyEvent.ACTION_DOWN && + keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { search(); } return true; @@ -273,7 +270,7 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem if (TextUtils.isEmpty(text)) { Notificator.getInstance().alert(R.string.notice_query_is_empty); } else { - new SavedSearches.Create(Application.getInstance().getCurrentAccount(), text).onDoneUI(cb -> { + new Searches.CreateSavedSearchTask(Application.getInstance().getCurrentAccount(), text).onDoneUI(cb -> { Notificator.getInstance().publish(R.string.notice_query_saved); Application.getInstance().getCurrentAccount().refreshSavedSearches(); }).onFailUI(ex -> { @@ -304,26 +301,17 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem query.setQuery(queryString); query.setCount(200); query.setResultType(Query.RECENT); - runRefreshTask( - new SearchTask(Application.getInstance().getCurrentAccount(), query), - adapter::updateForce); + runRefreshTask(query, adapter::updateForce); } } - private void runRefreshTask(SearchTask task, Runnable onFinish) { + private void runRefreshTask(Query query, Runnable onFinish) { final SearchListAdapter adapter = getAdapter(); - final Account account = Application.getInstance().getCurrentAccount(); - task + new Searches.SearchTask(Application.getInstance().getCurrentAccount(), query) .onFail(x -> Notificator.getInstance().alert(R.string.notice_error_search)) - .onDoneUI(queryResult -> { - if (queryResult != null) { - List<Tweet> tweets = Tweet.fromTwitter(queryResult.getTweets(), account.getUserId()); - for (Tweet tweet : tweets) { - if (!tweet.isRetweet()) { - adapter.addItem(new StatusViewModel(tweet)); - } - } - } + .onDoneUI(tweets -> { + List<StatusViewModel> e = ListUtils.map(ListUtils.filter(tweets, t -> !t.isRetweet()), StatusViewModel::new); + adapter.addItems(e); }) .onFinishUI(onFinish) .execute(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/UserListFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/page/UserListFragment.java index 86a98767..2ec98dc2 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/UserListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/UserListFragment.java @@ -42,7 +42,7 @@ import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.preference.InternalPreferenceHelper; import net.lacolaco.smileessence.twitter.StatusFilter; import net.lacolaco.smileessence.twitter.task.TimelineTask; -import net.lacolaco.smileessence.twitter.task.UserListStatusesTask; +import net.lacolaco.smileessence.twitter.task.Timelines; import net.lacolaco.smileessence.util.UIHandler; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.view.adapter.UserListListAdapter; @@ -110,7 +110,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im return; } runRefreshTask( - new UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName) + new Timelines.UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName) .setSinceId(adapter.getTopID()), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), true); @@ -130,7 +130,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im return; } runRefreshTask( - new UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName) + new Timelines.UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName) .setMaxId(adapter.getLastID() - 1), () -> { updateListViewWithNotice(refreshView.getRefreshableView(), false); @@ -190,7 +190,7 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im adapter.clear(); adapter.updateForce(); runRefreshTask( - new UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName), + new Timelines.UserListStatusesTask(Application.getInstance().getCurrentAccount(), listFullName), adapter::updateForce); } diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java index d9101c39..4ee609d1 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java @@ -93,7 +93,7 @@ public class EventViewModel implements IViewModel { private void updateViewUser(View convertedView) { NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon); - String iconUrl= source.getProfileImageUrlOriginal(); + String iconUrl = source.getProfileImageUrlOriginal(); ImageCache.getInstance().setImageToView(iconUrl, icon); TextView header = (TextView) convertedView.findViewById(R.id.textview_status_header); diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java index 0f982c5e..8f8927f0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/MessageViewModel.java @@ -33,8 +33,8 @@ import com.android.volley.toolbox.NetworkImageView; import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; -import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.entity.DirectMessage; import net.lacolaco.smileessence.entity.IdObject; import net.lacolaco.smileessence.entity.RBinding; @@ -129,7 +129,7 @@ public class MessageViewModel implements IViewModel, IdObject { int textSize = UserPreferenceHelper.getInstance().getTextSize(); NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon); - String iconUrl= directMessage.getSender().getProfileImageUrlOriginal(); + String iconUrl = directMessage.getSender().getProfileImageUrlOriginal(); ImageCache.getInstance().setImageToView(iconUrl, icon); icon.setOnClickListener(v -> { UserDetailDialogFragment dialogFragment = new UserDetailDialogFragment(); diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java index 608c0186..36ce559e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java @@ -34,13 +34,15 @@ import android.widget.TextView; import com.android.volley.toolbox.NetworkImageView; import net.lacolaco.smileessence.Application; import net.lacolaco.smileessence.R; -import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.data.Account; +import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.entity.IdObject; import net.lacolaco.smileessence.entity.RBinding; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.preference.UserPreferenceHelper; -import net.lacolaco.smileessence.util.*; +import net.lacolaco.smileessence.util.StringUtils; +import net.lacolaco.smileessence.util.Themes; +import net.lacolaco.smileessence.util.UIObserverBundle; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.view.adapter.StatusListAdapter; import net.lacolaco.smileessence.view.dialog.StatusDetailDialogFragment; |