diff options
Diffstat (limited to 'app/src')
23 files changed, 243 insertions, 219 deletions
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java index 43db830c..39e154fd 100644 --- a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java +++ b/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java @@ -26,6 +26,7 @@ package net.lacolaco.smileessence.twitter; import android.test.InstrumentationTestCase; +import com.twitter.Validator; import junit.framework.Assert; import net.lacolaco.smileessence.twitter.util.TwitterUtils; @@ -37,9 +38,9 @@ public class TwitterUtilsTest extends InstrumentationTestCase { public void testLength() throws Exception { String text = "test"; - Assert.assertEquals(text.length(), TwitterUtils.getFixedTextLength(text)); + Assert.assertEquals(text.length(), new Validator().getTweetLength(text)); text = "test.com"; - assertNotSame(text.length(), TwitterUtils.getFixedTextLength(text)); + assertNotSame(text.length(), new Validator().getTweetLength(text)); } public void testURL() throws Exception { diff --git a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java index befa8c4e..e65cea28 100644 --- a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java +++ b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java @@ -31,11 +31,11 @@ import android.text.TextUtils; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.command.CommandOpenUserDetail; +import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.notification.NotificationType; import net.lacolaco.smileessence.notification.Notificator; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.util.UIHandler; import net.lacolaco.smileessence.data.PostState; import net.lacolaco.smileessence.view.DialogHelper; @@ -126,16 +126,12 @@ public class IntentRouter { } private static void showStatusDialog(final MainActivity activity, long id) { - TwitterUtils.tryGetStatus(activity.getCurrentAccount(), id, new TwitterUtils.StatusCallback() { - @Override - public void success(Tweet tweet) { + activity.getCurrentAccount().fetchTweet(id, (tweet) -> { + if (tweet != null) { StatusDetailDialogFragment fragment = new StatusDetailDialogFragment(); fragment.setStatusID(tweet.getId()); DialogHelper.showDialog(activity, fragment); - } - - @Override - public void error() { + } else { Notificator.getInstance().publish(R.string.error_intent_status_cannot_load, NotificationType.ALERT); } }); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/message/MessageCommandShare.java b/app/src/main/java/net/lacolaco/smileessence/command/message/MessageCommandShare.java index 5747dfdd..d07ecf13 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/message/MessageCommandShare.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/message/MessageCommandShare.java @@ -60,7 +60,7 @@ public class MessageCommandShare extends MessageCommand { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, TwitterUtils.getMessageSummary(getMessage())); + intent.putExtra(Intent.EXTRA_TEXT, getMessage().getMessageSummary()); IntentUtils.startActivityIfFound(getActivity(), intent); return true; } diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenAclog.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenAclog.java index e10ba654..97867e2a 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenAclog.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenAclog.java @@ -56,6 +56,6 @@ public class UserCommandOpenAclog extends UserCommand { @Override public boolean execute() { - return new CommandOpenURL(getActivity(), TwitterUtils.getAclogTimelineURL(getUser().getScreenName())).execute(); + return new CommandOpenURL(getActivity(), getUser().getAclogTimelineURL()).execute(); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenFavstar.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenFavstar.java index da55fe5e..a91694db 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenFavstar.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenFavstar.java @@ -56,6 +56,6 @@ public class UserCommandOpenFavstar extends UserCommand { @Override public boolean execute() { - return new CommandOpenURL(getActivity(), TwitterUtils.getFavstarRecentURL(getUser().getScreenName())).execute(); + return new CommandOpenURL(getActivity(), getUser().getFavstarRecentURL()).execute(); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenTwilog.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenTwilog.java index 584e1bae..e998d40b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenTwilog.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandOpenTwilog.java @@ -56,6 +56,6 @@ public class UserCommandOpenTwilog extends UserCommand { @Override public boolean execute() { - return new CommandOpenURL(getActivity(), TwitterUtils.getTwilogURL(getUser().getScreenName())).execute(); + return new CommandOpenURL(getActivity(), getUser().getTwilogURL()).execute(); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/Account.java b/app/src/main/java/net/lacolaco/smileessence/entity/Account.java index bcb1d6cb..d5cc6b1b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/Account.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/Account.java @@ -28,6 +28,11 @@ import com.activeandroid.Model; import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Delete; +import net.lacolaco.smileessence.twitter.task.ShowDirectMessageTask; +import net.lacolaco.smileessence.twitter.task.ShowStatusTask; +import net.lacolaco.smileessence.twitter.task.ShowUserTask; +import net.lacolaco.smileessence.twitter.task.TwitterTask; +import net.lacolaco.smileessence.util.Consumer; import twitter4j.Twitter; import twitter4j.TwitterFactory; import twitter4j.TwitterStream; @@ -48,6 +53,8 @@ public class Account extends Model { @Column(name = "ScreenName", notNull = true) public String screenName; + private User user; + // -------------------------- STATIC METHODS -------------------------- public Account() { @@ -79,4 +86,117 @@ public class Account extends Model { stream.setOAuthAccessToken(new AccessToken(accessToken, accessSecret)); return stream; } + + public User getCachedUser() { + if (user == null) { + user = User.fetch(userID); // 強い参照をもたせる + } + return user; // null かも + } + + public void tryGetMessage(long messageID, final MessageCallback callback) { + DirectMessage message = DirectMessage.fetch(messageID); + if (message != null) { + callback.success(message); + } else { + ShowDirectMessageTask task = new ShowDirectMessageTask(getTwitter(), messageID) { + @Override + protected void onPostExecute(DirectMessage directMessage) { + super.onPostExecute(directMessage); + if (directMessage != null) { + callback.success(directMessage); + } else { + callback.error(); + } + } + }; + task.execute(); + } + } + + /** + * Get status from api if not cached + */ + public void tryGetUser(long userID, final UserCallback callback) { + User user = User.fetch(userID); + if (user != null) { + callback.success(user); + ShowUserTask task = new ShowUserTask(getTwitter(), userID); + task.execute(); + } else { + ShowUserTask task = new ShowUserTask(getTwitter(), userID) { + @Override + protected void onPostExecute(User user) { + super.onPostExecute(user); + if (user != null) { + callback.success(user); + } else { + callback.error(); + } + + } + }; + task.execute(); + } + } + + public void fetchTweet(long statusId, Consumer<Tweet> callback, boolean forceRetrieve) { + Tweet tweet = Tweet.fetch(statusId); + if (forceRetrieve || tweet == null) { + new ShowStatusTask(getTwitter(), statusId) { + @Override + protected void onPostExecute(Tweet tweet) { + callback.accept(tweet); + } + }.execute(); + } else { + callback.accept(tweet); + } + } + public void fetchTweet(long statusId, Consumer<Tweet> callback) { + fetchTweet(statusId, callback, false); + } + + public TwitterTask<Tweet> tryGetStatus(long statusID, final StatusCallback callback) { + ShowStatusTask task; + Tweet tweet = Tweet.fetch(statusID); + if (tweet != null) { + callback.success(tweet); + //update cache + task = new ShowStatusTask(getTwitter(), statusID); + } else { + task = new ShowStatusTask(getTwitter(), statusID) { + @Override + protected void onPostExecute(Tweet tweet) { + if (tweet != null) { + callback.success(tweet); + } else { + callback.error(); + } + } + }; + } + return (TwitterTask<Tweet>) task.execute(); + } + + public interface StatusCallback { + + void success(Tweet status); + + void error(); + } + + public interface UserCallback { + + void success(User user); + + void error(); + } + + public interface MessageCallback { + + void success(DirectMessage message); + + void error(); + } } diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/DirectMessage.java b/app/src/main/java/net/lacolaco/smileessence/entity/DirectMessage.java index e5288f29..1f31171f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/DirectMessage.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/DirectMessage.java @@ -5,6 +5,7 @@ import com.google.common.cache.CacheBuilder; import net.lacolaco.smileessence.util.ListUtils; import twitter4j.*; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -105,4 +106,33 @@ public class DirectMessage { public SymbolEntity[] getSymbols() { return symbols; } + + public List<String> getMentioningScreenNames(String excludeScreenName) { + List<String> names = getMentioningScreenNames(); + if (excludeScreenName != null) { + names.remove(excludeScreenName); + } + return names; + } + + public List<String> getMentioningScreenNames() { + List<String> names = new ArrayList<>(); + names.add(getSender().getScreenName()); + if (getSender() != getRecipient()) { + names.add(getRecipient().getScreenName()); + } + if (getMentions() != null) { + for (UserMentionEntity entity : getMentions()) { + if (names.contains(entity.getScreenName())) { + continue; + } + names.add(entity.getScreenName()); + } + } + return names; + } + + public String getMessageSummary() { + return String.format("@%s: %s", getSender().getScreenName(), getText()); + } } 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 1d82e268..3d0cf8d3 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java @@ -6,6 +6,7 @@ import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.util.ListUtils; import twitter4j.*; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -150,4 +151,25 @@ public class Tweet { public long getInReplyTo() { return inReplyTo; } + + public List<String> getMentioningScreenNames(String excludeScreenName) { + List<String> names = getMentioningScreenNames(); + if (excludeScreenName != null) { + names.remove(excludeScreenName); + } + return names; + } + + public List<String> getMentioningScreenNames() { + List<String> names = new ArrayList<>(); + names.add(getUser().getScreenName()); + if (getMentions() != null) { + for (UserMentionEntity entity : getMentions()) { + if (!names.contains(entity.getScreenName())) { + names.add(entity.getScreenName()); + } + } + } + return names; + } } diff --git a/app/src/main/java/net/lacolaco/smileessence/entity/User.java b/app/src/main/java/net/lacolaco/smileessence/entity/User.java index 04f3e4fc..73e94ae4 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/User.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/User.java @@ -131,4 +131,21 @@ public class User { public boolean isVerified() { return isVerified; } + + + public String getUserHomeURL() { + return String.format("https://twitter.com/%s", getScreenName()); + } + + public String getAclogTimelineURL() { + return String.format("http://aclog.koba789.com/%s/timeline", getScreenName()); + } + + public String getFavstarRecentURL() { + return String.format("http://favstar.fm/users/%s/recent", getScreenName()); + } + + public String getTwilogURL() { + return String.format("http://twilog.org/%s", getScreenName()); + } } diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/util/TwitterUtils.java b/app/src/main/java/net/lacolaco/smileessence/twitter/util/TwitterUtils.java index 1886508c..4d957f0b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/util/TwitterUtils.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/util/TwitterUtils.java @@ -45,154 +45,9 @@ import java.util.ArrayList; import java.util.Collection; public class TwitterUtils { - // -------------------------- STATIC METHODS -------------------------- /** - * Get twitter style fixed text length - * - * @return length - */ - public static int getFixedTextLength(String str) { - Validator validator = new Validator(); - return validator.getTweetLength(str); - } - - /** - * Get status from api if not cached - */ - public static TwitterTask<Tweet> tryGetStatus(Account account, long statusID, final StatusCallback callback) { - ShowStatusTask task; - Tweet tweet = Tweet.fetch(statusID); - if (tweet != null) { - callback.success(tweet); - //update cache - task = new ShowStatusTask(account.getTwitter(), statusID); - } else { - task = new ShowStatusTask(account.getTwitter(), statusID) { - @Override - protected void onPostExecute(Tweet tweet) { - if (tweet != null) { - callback.success(tweet); - } else { - callback.error(); - } - } - }; - } - return (TwitterTask<Tweet>) task.execute(); - } - - /** - * Get status from api if not cached - */ - public static void tryGetUser(Account account, long userID, final UserCallback callback) { - User user = User.fetch(userID); - if (user != null) { - callback.success(user); - ShowUserTask task = new ShowUserTask(account.getTwitter(), userID); - task.execute(); - } else { - ShowUserTask task = new ShowUserTask(account.getTwitter(), userID) { - @Override - protected void onPostExecute(User user) { - super.onPostExecute(user); - if (user != null) { - callback.success(user); - } else { - callback.error(); - } - - } - }; - task.execute(); - } - } - - /** - * Get direct message from api if not cached - */ - public static void tryGetMessage(Account account, long messageID, final MessageCallback callback) { - DirectMessage message = DirectMessage.fetch(messageID); - if (message != null) { - callback.success(message); - } else { - ShowDirectMessageTask task = new ShowDirectMessageTask(account.getTwitter(), messageID) { - @Override - protected void onPostExecute(DirectMessage directMessage) { - super.onPostExecute(directMessage); - if (directMessage != null) { - callback.success(directMessage); - } else { - callback.error(); - } - } - }; - task.execute(); - } - } - - /** - * Get array of screenName in own text - * - * @param tweet tweet - * @param excludeScreenName - * @return - */ - public static Collection<String> getScreenNames(Tweet tweet, String excludeScreenName) { - ArrayList<String> names = new ArrayList<>(); - names.add(tweet.getUser().getScreenName()); - if (tweet.getMentions() != null) { - for (UserMentionEntity entity : tweet.getMentions()) { - if (names.contains(entity.getScreenName())) { - continue; - } - names.add(entity.getScreenName()); - } - } - if (excludeScreenName != null) { - names.remove(excludeScreenName); - } - return names; - } - - public static Collection<String> getScreenNames(DirectMessage message, String excludeScreenName) { - ArrayList<String> names = new ArrayList<>(); - names.add(message.getSender().getScreenName()); - if (!message.getRecipient().getScreenName().equals(message.getSender().getScreenName())) { - names.add(message.getRecipient().getScreenName()); - } - if (message.getMentions() != null) { - for (UserMentionEntity entity : message.getMentions()) { - if (names.contains(entity.getScreenName())) { - continue; - } - names.add(entity.getScreenName()); - } - } - if (excludeScreenName != null) { - names.remove(excludeScreenName); - } - return names; - } - - public static String getUserHomeURL(String screenName) { - return String.format("https://twitter.com/%s", screenName); - } - - public static String getAclogTimelineURL(String screenName) { - return String.format("http://aclog.koba789.com/%s/timeline", screenName); - } - - public static String getFavstarRecentURL(String screenName) { - return String.format("http://favstar.fm/users/%s/recent", screenName); - } - - public static String getTwilogURL(String screenName) { - return String.format("http://twilog.org/%s", screenName); - } - - /** * Replace urls by entities * * @param text raw text @@ -222,31 +77,4 @@ public class TwitterUtils { public static int getPagingCount(MainActivity activity) { return UserPreferenceHelper.getInstance().get(R.string.key_setting_timelines, 20); } - - public static String getMessageSummary(DirectMessage message) { - return String.format("@%s: %s", message.getSender().getScreenName(), message.getText()); - } - - // -------------------------- INNER CLASSES -------------------------- - - public interface StatusCallback { - - void success(Tweet status); - - void error(); - } - - public interface UserCallback { - - void success(User user); - - void error(); - } - - public interface MessageCallback { - - void success(DirectMessage message); - - void error(); - } } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java index 2fb4ea9e..439c8c56 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java @@ -46,7 +46,6 @@ import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.logging.Logger; import net.lacolaco.smileessence.preference.UserPreferenceHelper; import net.lacolaco.smileessence.twitter.task.TweetTask; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.util.BitmapThumbnailTask; import net.lacolaco.smileessence.util.IntentUtils; import net.lacolaco.smileessence.util.UIHandler; @@ -144,7 +143,7 @@ public class PostFragment extends PageFragment implements TextWatcher, View.OnFo if (postState.getInReplyToStatusID() >= 0) { viewGroupReply.setVisibility(View.VISIBLE); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetStatus(account, postState.getInReplyToStatusID(), new TwitterUtils.StatusCallback() { + account.tryGetStatus(postState.getInReplyToStatusID(), new Account.StatusCallback() { @Override public void success(Tweet tweet) { View header = viewGroupReply.findViewById(R.id.layout_post_reply_status); @@ -188,9 +187,10 @@ public class PostFragment extends PageFragment implements TextWatcher, View.OnFo } public void updateTextCount(CharSequence s) { - int remainingCount = 140 - TwitterUtils.getFixedTextLength(s.toString()); + Validator validator = new Validator(); + int remainingCount = 140 - validator.getTweetLength(s.toString()); if (!TextUtils.isEmpty(PostState.getState().getMediaFilePath())) { - remainingCount -= new Validator().getShortUrlLength(); + remainingCount -= validator.getShortUrlLength(); } textViewCount.setText(String.valueOf(remainingCount)); if (remainingCount == 140) { 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 7fe1c5cd..676c2db0 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 @@ -41,7 +41,6 @@ import net.lacolaco.smileessence.command.CommandOpenURL; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.task.DeleteMessageTask; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.view.adapter.MessageListAdapter; import net.lacolaco.smileessence.view.listener.ListItemClickListener; @@ -80,7 +79,7 @@ public class MessageDetailDialogFragment extends StackableDialogFragment impleme public void onClick(final View v) { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetMessage(account, getMessageID(), new TwitterUtils.MessageCallback() { + account.tryGetMessage(getMessageID(), new Account.MessageCallback() { @Override public void success(DirectMessage message) { switch (v.getId()) { 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 d2c487b3..dcf24f38 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 @@ -34,7 +34,6 @@ import net.lacolaco.smileessence.command.CommandOpenURL; import net.lacolaco.smileessence.command.CommandOpenUserDetail; import net.lacolaco.smileessence.command.CommandSaveAsTemplate; import net.lacolaco.smileessence.entity.Account; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; import java.util.ArrayList; @@ -70,7 +69,7 @@ public class MessageMenuDialogFragment extends MenuDialogFragment { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetMessage(account, getMessageID(), new TwitterUtils.MessageCallback() { + account.tryGetMessage(getMessageID(), new Account.MessageCallback() { @Override public void success(DirectMessage message) { List<Command> commands = getCommands(activity, message, account); @@ -93,7 +92,7 @@ public class MessageMenuDialogFragment extends MenuDialogFragment { public void addBottomCommands(Activity activity, DirectMessage message, Account account, ArrayList<Command> commands) { commands.add(new CommandSaveAsTemplate(activity, message.getText())); //User - for (String screenName : TwitterUtils.getScreenNames(message, null)) { + for (String screenName : message.getMentioningScreenNames()) { commands.add(new CommandOpenUserDetail(activity, screenName, account)); } for (Command command : getHashtagCommands(activity, message)) { 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 8e9c9402..acd9420b 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 @@ -43,7 +43,6 @@ import com.twitter.Validator; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.twitter.task.SendMessageTask; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.data.PostState; import twitter4j.Twitter; @@ -94,9 +93,10 @@ public class SendMessageDialogFragment extends StackableDialogFragment implement @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - int remainingCount = 140 - TwitterUtils.getFixedTextLength(s.toString()); + Validator validator = new Validator(); + int remainingCount = 140 - validator.getTweetLength(s.toString()); if (!TextUtils.isEmpty(PostState.getState().getMediaFilePath())) { - remainingCount -= new Validator().getShortUrlLength(); + remainingCount -= validator.getShortUrlLength(); } textViewCount.setText(String.valueOf(remainingCount)); if (remainingCount == 140) { 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 2965c465..d21c67c7 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 @@ -48,7 +48,6 @@ import net.lacolaco.smileessence.twitter.task.DeleteStatusTask; import net.lacolaco.smileessence.twitter.task.FavoriteTask; import net.lacolaco.smileessence.twitter.task.RetweetTask; import net.lacolaco.smileessence.twitter.task.UnfavoriteTask; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.data.PostState; import net.lacolaco.smileessence.view.adapter.StatusListAdapter; @@ -135,7 +134,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen if (inReplyToStatusId == -1) { listView.setVisibility(View.GONE); } else { - TwitterUtils.tryGetStatus(account, inReplyToStatusId, new TwitterUtils.StatusCallback() { + account.tryGetStatus(inReplyToStatusId, new Account.StatusCallback() { @Override public void success(Tweet tweet) { adapter.addToTop(new StatusViewModel(tweet)); @@ -272,7 +271,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen if (account.userID == originalTweet.getUser().getId()) { builder.addScreenName(account.screenName); } - builder.addScreenNames(TwitterUtils.getScreenNames(originalTweet, account.screenName)); + builder.addScreenNames(originalTweet.getMentioningScreenNames(account.screenName)); String text = builder.buildText(); int selStart = originalTweet.getUser().getScreenName().length() + 2; // "@" and " " 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 e73f03b4..77c3ea29 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 @@ -35,7 +35,6 @@ import net.lacolaco.smileessence.command.CommandOpenUserDetail; import net.lacolaco.smileessence.command.CommandSaveAsTemplate; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; import java.util.ArrayList; @@ -43,7 +42,6 @@ import java.util.List; import twitter4j.HashtagEntity; import twitter4j.MediaEntity; -import twitter4j.Status; import twitter4j.URLEntity; public class StatusMenuDialogFragment extends MenuDialogFragment { @@ -88,7 +86,7 @@ public class StatusMenuDialogFragment extends MenuDialogFragment { public void addBottomCommands(Activity activity, Tweet tweet, Account account, ArrayList<Command> commands) { commands.add(new CommandSaveAsTemplate(activity, tweet.getOriginalTweet().getText())); //User - for (String screenName : TwitterUtils.getScreenNames(tweet, null)) { + for (String screenName : tweet.getMentioningScreenNames()) { commands.add(new CommandOpenUserDetail(activity, screenName, account)); } for (Command command : getHashtagCommands(activity, tweet)) { 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 146d3d8d..e7be7485 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 @@ -115,7 +115,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements public void onClick(final View v) { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetUser(account, getUserID(), new TwitterUtils.UserCallback() { + account.tryGetUser(getUserID(), new Account.UserCallback() { @Override public void success(final User user) { switch (v.getId()) { @@ -128,23 +128,23 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements break; } case R.id.textview_user_detail_screenname: { - openUrl(TwitterUtils.getUserHomeURL(user.getScreenName())); + openUrl(user.getUserHomeURL()); break; } case R.id.textview_user_detail_tweet_count: { - openUrl(TwitterUtils.getUserHomeURL(user.getScreenName())); + openUrl(user.getUserHomeURL()); break; } case R.id.textview_user_detail_friend_count: { - openUrl(String.format("%s/following", TwitterUtils.getUserHomeURL(user.getScreenName()))); + openUrl(String.format("%s/following", user.getUserHomeURL())); break; } case R.id.textview_user_detail_follower_count: { - openUrl(String.format("%s/followers", TwitterUtils.getUserHomeURL(user.getScreenName()))); + openUrl(String.format("%s/followers", user.getUserHomeURL())); break; } case R.id.textview_user_detail_favorite_count: { - openUrl(String.format("%s/favorites", TwitterUtils.getUserHomeURL(user.getScreenName()))); + openUrl(String.format("%s/favorites", user.getUserHomeURL())); break; } case R.id.button_user_detail_follow: { @@ -252,7 +252,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements tabHost.setCurrentTab(0); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetUser(account, getUserID(), new TwitterUtils.UserCallback() { + account.tryGetUser(getUserID(), new Account.UserCallback() { @Override public void success(User user) { try { @@ -296,7 +296,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements } String html = description; html = html.replaceAll("https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+", "<a href=\"$0\">$0</a>"); - html = html.replaceAll("@([a-zA-Z0-9_]+)", "<a href=\"" + TwitterUtils.getUserHomeURL("$1") + "\">$0</a>"); + html = html.replaceAll("@([a-zA-Z0-9_]+)", "<a href=\"https://twitter.com/$1\">$0</a>"); html = html.replaceAll("\r\n", "<br />"); return html; } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java index 0883b99e..c8005e62 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserMenuDialogFragment.java @@ -32,7 +32,6 @@ import net.lacolaco.smileessence.command.Command; import net.lacolaco.smileessence.command.CommandSearchOnTwitter; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.User; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.view.adapter.CustomListAdapter; import java.util.ArrayList; @@ -63,7 +62,7 @@ public class UserMenuDialogFragment extends MenuDialogFragment { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetUser(account, getUserID(), new TwitterUtils.UserCallback() { + account.tryGetUser(getUserID(), new Account.UserCallback() { @Override public void success(User user) { List<Command> commands = getCommands(activity, user, account); 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 2385019d..5680ccc7 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java @@ -43,7 +43,6 @@ import net.lacolaco.smileessence.data.ImageCache; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.preference.UserPreferenceHelper; -import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.util.Morse; import net.lacolaco.smileessence.util.NameStyles; import net.lacolaco.smileessence.util.StringUtils; @@ -221,7 +220,7 @@ public class StatusViewModel implements IViewModel { embeddedStatus.setVisibility(View.VISIBLE); final Account account = ((MainActivity) activity).getCurrentAccount(); for (long id : embeddedStatusIDs) { - AsyncTask task = TwitterUtils.tryGetStatus(account, id, new TwitterUtils.StatusCallback() { + AsyncTask task = account.tryGetStatus(id, new Account.StatusCallback() { @Override public void success(Tweet tweet) { StatusViewModel viewModel = new StatusViewModel(tweet); diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/menu/MainActivityMenuHelper.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/menu/MainActivityMenuHelper.java index aa02ded6..9838500c 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/menu/MainActivityMenuHelper.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/menu/MainActivityMenuHelper.java @@ -32,6 +32,8 @@ import android.view.SubMenu; import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.*; import net.lacolaco.smileessence.command.CommandOpenURL; +import net.lacolaco.smileessence.entity.User; +import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.data.PostState; @@ -71,6 +73,7 @@ public class MainActivityMenuHelper { } public static boolean onItemSelected(MainActivity activity, MenuItem item) { + User user = activity.getCurrentAccount().getCachedUser(); switch (item.getItemId()) { case R.id.actionbar_post: { openPostPage(activity); @@ -106,15 +109,27 @@ public class MainActivityMenuHelper { return true; } case R.id.actionbar_favstar: { - new CommandOpenURL(activity, TwitterUtils.getFavstarRecentURL(activity.getCurrentAccount().screenName)).execute(); + if (user == null) { + Notificator.getInstance().publish(R.string.notice_application_starting); + } else { + new CommandOpenURL(activity, user.getFavstarRecentURL()).execute(); + } return true; } case R.id.actionbar_aclog: { - new CommandOpenURL(activity, TwitterUtils.getAclogTimelineURL(activity.getCurrentAccount().screenName)).execute(); + if (user == null) { + Notificator.getInstance().publish(R.string.notice_application_starting); + } else { + new CommandOpenURL(activity, user.getAclogTimelineURL()).execute(); + } return true; } case R.id.actionbar_twilog: { - new CommandOpenURL(activity, TwitterUtils.getTwilogURL(activity.getCurrentAccount().screenName)).execute(); + if (user == null) { + Notificator.getInstance().publish(R.string.notice_application_starting); + } else { + new CommandOpenURL(activity, user.getTwilogURL()).execute(); + } return true; } case R.id.actionbar_report: { diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 37fa7e2a..600f4f3c 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -196,6 +196,7 @@ <string name="notice_error_rate_limit">レートリミットを超えています</string> <string name="notice_error_search">検索に失敗しました</string> <string name="notice_no_commands_available">使用できるコマンドがありません</string> + <string name="notice_application_starting">起動処理が完了していません</string> <string name="command_user_reply">リプライを送る</string> <string name="command_user_add_to_reply">リプライ先に追加する</string> <string name="command_user_open_favstar">Favstarを開く</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e840eb6d..7f55b40b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,6 +196,7 @@ <string name="notice_error_rate_limit">Rate limit exceeded</string> <string name="notice_error_search">Failed to search</string> <string name="notice_no_commands_available">No commands available</string> + <string name="notice_application_starting">Application initialization is not complete.</string> <string name="command_user_reply">Reply</string> <string name="command_user_add_to_reply">Add to reply</string> <string name="command_user_open_favstar">Open favstar</string> |