diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-09-05 22:14:51 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-09-05 22:14:51 +0900 |
commit | 2d61eddd1d25d91f62394c4e13545f5bf28686df (patch) | |
tree | f682f6600acf5e3ad7d039091e23666bdc125ee4 /app | |
parent | ad696ee8a8ca761c8ef61a8a4300d5ae85c016d0 (diff) | |
download | SmileEssence-2d61eddd1d25d91f62394c4e13545f5bf28686df.tar.gz |
TwitterUtils.tryGetStatus を呼ぶ回数を減らした
Diffstat (limited to 'app')
5 files changed, 54 insertions, 75 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java index d15b2e86..84bde3c0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java +++ b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java @@ -50,7 +50,7 @@ public class IntentRouter { // ------------------------------ FIELDS ------------------------------ public static final String TWITTER_HOST = "twitter.com"; - private static final Pattern TWITTER_STATUS_PATTERN = Pattern.compile("\\A/(?:#!)/?(?:\\w{1,15})/status(es)?/(\\d+)\\z", Pattern.CASE_INSENSITIVE); + private static final Pattern TWITTER_STATUS_PATTERN = Pattern.compile("\\A/(?:#!/)?(?:\\w{1,15})/status(es)?/(\\d+)\\z", Pattern.CASE_INSENSITIVE); private static final Pattern TWITTER_USER_PATTERN = Pattern.compile("\\A/(?:#!/)?(\\w{1,15})/?\\z", Pattern.CASE_INSENSITIVE); private static final Pattern TWITTER_POST_PATTERN = Pattern.compile("\\A/(intent/tweet|share)\\z", Pattern.CASE_INSENSITIVE); @@ -91,12 +91,12 @@ public class IntentRouter { } Matcher statusMatcher = TWITTER_STATUS_PATTERN.matcher(uri.getPath()); if (statusMatcher.find()) { - showStatusDialog(activity, Long.getLong(statusMatcher.group(0))); + showStatusDialog(activity, Long.getLong(statusMatcher.group(1))); return; } Matcher userMatcher = TWITTER_USER_PATTERN.matcher(uri.getPath()); if (userMatcher.find()) { - showUserDialog(activity, statusMatcher.group(0)); + showUserDialog(activity, statusMatcher.group(1)); return; } } 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 84585ebf..99146758 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 @@ -111,8 +111,7 @@ public class CustomListAdapter<T extends IViewModel> extends BaseAdapter { public void addToBottom(T... items) { synchronized (LOCK) { - List<T> buffer = Arrays.asList(items); - for (T item : buffer) { + for (T item : items) { if (list.contains(item)) { list.remove(item); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java index 049c3ee2..c41fd22c 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/QuoteDialogFragment.java @@ -64,24 +64,18 @@ public class QuoteDialogFragment extends MenuDialogFragment { @Override protected void setMenuItems(final CustomListAdapter<Command> adapter) { final MainActivity activity = (MainActivity) getActivity(); - final Account account = activity.getCurrentAccount(); - - TwitterUtils.tryGetStatus(account, getStatusID(), new TwitterUtils.StatusCallback() { - @Override - public void success(Tweet tweet) { - List<Command> commands = getCommands(activity, tweet); - Command.filter(commands); - for (Command command : commands) { - adapter.addToBottom(command); - } - adapter.update(); - } + Tweet tweet = Tweet.fetch(getStatusID()); - @Override - public void error() { - dismiss(); + if (tweet != null) { + List<Command> commands = getCommands(activity, tweet); + Command.filter(commands); + for (Command command : commands) { + adapter.addToBottom(command); } - }); + adapter.update(); + } else { + dismiss(); + } } // -------------------------- OTHER METHODS -------------------------- 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 d7e08af6..137c8ebd 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 @@ -66,6 +66,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen // ------------------------------ FIELDS ------------------------------ private static final String KEY_STATUS_ID = "statusID"; + private Tweet tweet; // --------------------- GETTER / SETTER METHODS --------------------- @@ -88,43 +89,34 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen public void onClick(final View v) { final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - TwitterUtils.tryGetStatus(account, getStatusID(), new TwitterUtils.StatusCallback() { - @Override - public void success(Tweet tweet) { - switch (v.getId()) { - case R.id.button_status_detail_reply: { - replyToStatus(activity, account, tweet); - break; - } - case R.id.button_status_detail_retweet: { - final Long retweetID = (Long) v.getTag(); - toggleRetweet(activity, account, tweet, retweetID); - break; - } - case R.id.button_status_detail_favorite: { - Boolean isFavorited = (Boolean) v.getTag(); - toggleFavorite(activity, account, tweet, isFavorited); - break; - } - case R.id.button_status_detail_delete: { - deleteStatus(activity, account, tweet); - break; - } - case R.id.button_status_detail_menu: { - openMenu(activity); - break; - } - default: { - dismiss(); - } - } - } - - @Override - public void error() { + switch (v.getId()) { + case R.id.button_status_detail_reply: { + replyToStatus(activity, account, tweet); + break; } - }); + case R.id.button_status_detail_retweet: { + final Long retweetID = (Long) v.getTag(); + toggleRetweet(activity, account, tweet, retweetID); + break; + } + case R.id.button_status_detail_favorite: { + Boolean isFavorited = (Boolean) v.getTag(); + toggleFavorite(activity, account, tweet, isFavorited); + break; + } + case R.id.button_status_detail_delete: { + deleteStatus(activity, account, tweet); + break; + } + case R.id.button_status_detail_menu: { + openMenu(activity); + break; + } + default: { + dismiss(); + } + } } // ------------------------ OVERRIDE METHODS ------------------------ @@ -134,7 +126,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen final MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); - final Tweet tweet = Tweet.fetch(getStatusID()); + tweet = Tweet.fetch(getStatusID()); final StatusViewModel status = new StatusViewModel(tweet); View header = getTitleView(activity, account, status); ListView listView = (ListView) header.findViewById(R.id.listview_status_detail_reply_to); @@ -153,7 +145,6 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen @Override public void error() { - } }); } 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 8fcc6c35..e73f03b4 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 @@ -68,24 +68,19 @@ public class StatusMenuDialogFragment extends MenuDialogFragment { @Override protected void setMenuItems(final CustomListAdapter<Command> adapter) { final MainActivity activity = (MainActivity) getActivity(); - final Account account = activity.getCurrentAccount(); - - TwitterUtils.tryGetStatus(account, getStatusID(), new TwitterUtils.StatusCallback() { - @Override - public void success(Tweet tweet) { - List<Command> commands = getCommands(activity, tweet, account); - Command.filter(commands); - for (Command command : commands) { - adapter.addToBottom(command); - } - adapter.update(); + Account account = activity.getCurrentAccount(); + Tweet tweet = Tweet.fetch(getStatusID()); + + if (tweet != null) { + List<Command> commands = getCommands(activity, tweet, account); + Command.filter(commands); + for (Command command : commands) { + adapter.addToBottom(command); } - - @Override - public void error() { - dismiss(); - } - }); + adapter.update(); + } else { + dismiss(); + } } // -------------------------- OTHER METHODS -------------------------- |