diff options
Diffstat (limited to 'app/src/main/java/net')
17 files changed, 54 insertions, 48 deletions
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 374590af..cc35bdb0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java @@ -360,7 +360,7 @@ public class MainActivity extends Activity { public void updateActionBarIcon() { final ImageView homeIcon = (ImageView) findViewById(android.R.id.home); - new ShowUserTask(currentAccount, currentAccount.userID) + new ShowUserTask(currentAccount, currentAccount.getUserId()) .onDoneUI(user -> { String urlHttps = user.getProfileImageUrl(); homeIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java index fe1a100f..9d5f5471 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java @@ -59,7 +59,7 @@ public class StatusCommandFavAndRT extends StatusCommand implements IConfirmable @Override public boolean isEnabled() { User user = getOriginalStatus().getUser(); - return !user.isProtected() && user.getId() != account.userID; + return !user.isProtected() && user.getId() != account.getUserId(); } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java index 8f485b93..fa8cc5e0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandMakeAnonymous.java @@ -29,6 +29,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.command.IConfirmable; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; +import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.NotificationType; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.TweetBuilder; @@ -52,13 +53,14 @@ public class StatusCommandMakeAnonymous extends StatusCommand implements IConfir // --------------------------- CONSTRUCTORS --------------------------- public static String build(Activity activity, Tweet tweet, Account account) { + User user = account.getUser(); String str = tweet.getText(); String header = ""; if (str.startsWith(".")) { str = str.replaceFirst(".", ""); } - if (str.startsWith(String.format("@%s", account.screenName))) { - str = str.replaceFirst(String.format("@%s", account.screenName), "").trim(); + if (str.startsWith(String.format("@%s", user.getScreenName()))) { + str = str.replaceFirst(String.format("@%s", user.getScreenName()), "").trim(); } str = activity.getString(R.string.format_status_command_make_anonymous, str).trim(); return str; diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java index 5562c2b4..f132db1e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandNanigaja.java @@ -29,6 +29,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.command.IConfirmable; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; +import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.NotificationType; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.TweetBuilder; @@ -64,13 +65,14 @@ public class StatusCommandNanigaja extends StatusCommand implements IConfirmable // -------------------------- OTHER METHODS -------------------------- public String build() { + User user = account.getUser(); String str = getOriginalStatus().getText(); String header = ""; if (str.startsWith(".")) { str = str.replaceFirst(".", ""); } - if (str.startsWith(String.format("@%s", account.screenName))) { - str = str.replaceFirst(String.format("@%s", account.screenName), "").trim(); + if (str.startsWith(String.format("@%s", user.getScreenName()))) { + str = str.replaceFirst(String.format("@%s", user.getScreenName()), "").trim(); header = "@" + getOriginalStatus().getUser().getScreenName(); } str = String.format("%s %s", header, String.format(getFormatString(getActivity()), str)).trim(); 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 d0736f93..793eb610 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 @@ -55,7 +55,7 @@ public class UserCommandBlock extends UserCommand implements IConfirmable { @Override public boolean isEnabled() { - return getUser().getId() != account.userID; + return getUser().getId() != account.getUserId(); } // -------------------------- OTHER METHODS -------------------------- 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 65da7eba..5b185dbc 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 @@ -55,7 +55,7 @@ public class UserCommandReportForSpam extends UserCommand implements IConfirmabl @Override public boolean isEnabled() { - return getUser().getId() != account.userID; + return getUser().getId() != account.getUserId(); } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java index 7a88ceb1..3b60f54e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/user/UserCommandSendMessage.java @@ -53,7 +53,7 @@ public class UserCommandSendMessage extends UserCommand { @Override public boolean isEnabled() { - return account.userID != getUser().getId(); + return account.getUserId() != getUser().getId(); } // -------------------------- OTHER METHODS -------------------------- 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 d35a6402..524bc39e 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 @@ -55,7 +55,7 @@ public class UserCommandUnblock extends UserCommand implements IConfirmable { @Override public boolean isEnabled() { - return getUser().getId() != account.userID; + return getUser().getId() != account.getUserId(); } // -------------------------- OTHER METHODS -------------------------- 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 79d6da9f..f78a1317 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/Account.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/Account.java @@ -45,13 +45,13 @@ public class Account extends Model { private User user; @Column(name = "Token", notNull = true) - public String accessToken; + private String accessToken; @Column(name = "Secret", notNull = true) - public String accessSecret; + private String accessSecret; @Column(name = "UserID", notNull = true) - public long userID; - @Deprecated @Column(name = "ScreenName", notNull = true) - public String screenName; + private long userID; + @Column(name = "ScreenName", notNull = true) + private String screenName; // Required by ActiveAndroid public Account() { } @@ -85,11 +85,16 @@ public class Account extends Model { return stream; } - public User getCachedUser() { + // MAY return incomplete object + public User getUser() { if (user == null) { user = User.fetch(userID); // 強い参照をもたせる } - return user; // null かも + if (user == null) { + user = User._makeSkeleton(getUserId(), screenName); + } + + return user; } @Deprecated 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 73e94ae4..98bd6a8a 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/User.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/User.java @@ -14,14 +14,28 @@ public class User { public synchronized static User fromTwitter(final twitter4j.User st) { User u = fetch(st.getId()); if (u == null) { - u = new User(st); + u = new User(); storage.put(st.getId(), u); - } else { - u.update(st); } + + u.update(st); return u; } + // only for initialization; DO NOT have reference for this object + public synchronized static User _makeSkeleton(long id, String screenName) { + User u = fetch(id); + if (u != null) { + return u; + } else { + u = new User(); + u.id = id; + u.screenName = screenName; + storage.put(id, u); + return u; + } + } + // インスタンス private long id; private boolean isProtected; @@ -38,8 +52,7 @@ public class User { private int followersCount; private boolean isVerified; - private User(twitter4j.User st) { - update(st); + private User() { } private void update(twitter4j.User user) { 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 bc95414f..481e093b 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java @@ -91,7 +91,7 @@ public class UserStreamListener implements twitter4j.UserStreamListener, Connect if (tweet.getUser().getId() == account.getUserId()) { addToHistory(new EventViewModel(EventViewModel.EnumEvent.RETWEETED, tweet.getUser(), tweet)); } - } else if (account.getCachedUser() != null && tweet.getMentions().contains(account.getCachedUser().getScreenName())) { + } else if (tweet.getMentions().contains(account.getUser().getScreenName())) { EventViewModel mentioned = new EventViewModel(EventViewModel.EnumEvent.MENTIONED, tweet.getUser(), tweet); Notificator.getInstance().publish(mentioned.getFormattedString()); } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java index 4cdd7d3f..a5074c6a 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java @@ -92,8 +92,7 @@ public abstract class CustomListFragment<T extends CustomListAdapter> extends Pa public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View page = inflater.inflate(R.layout.fragment_list, container, false); PullToRefreshListView listView = getListView(page); - T adapter = getAdapter(); - listView.setAdapter(adapter); + listView.setAdapter(getAdapter()); listView.setOnScrollListener(this); listView.setOnRefreshListener(this); listView.setMode(getRefreshMode()); @@ -108,14 +107,13 @@ public abstract class CustomListFragment<T extends CustomListAdapter> extends Pa @Override public void onViewStateRestored(Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); - if (savedInstanceState != null) { - } } protected PullToRefreshListView getListView(View page) { return (PullToRefreshListView) page.findViewById(R.id.fragment_list_listview); } + // must be called in UI thread protected void updateListViewWithNotice(AbsListView absListView, boolean addedToTop) { T adapter = getAdapter(); int before = adapter.getCount(); 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 7917e7ca..8a15228d 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 @@ -228,7 +228,7 @@ public class MessageDetailDialogFragment extends StackableDialogFragment impleme } private boolean isDeletable(Account account, DirectMessage message) { - return message.getSender().getId() == account.userID; + return message.getSender().getId() == account.getUserId(); } private void openMenu(MainActivity activity) { 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 e7bc7f07..6b8f739b 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 @@ -38,7 +38,6 @@ import net.lacolaco.smileessence.command.CommandOpenURL; import net.lacolaco.smileessence.data.PostState; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.notification.NotificationType; import net.lacolaco.smileessence.notification.Notificator; import net.lacolaco.smileessence.twitter.TweetBuilder; @@ -245,7 +244,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen TweetBuilder builder = new TweetBuilder(); builder.addScreenName(originalTweet.getUser().getScreenName()); for (String screenName : originalTweet.getMentions()) { - if (!screenName.equals(account.getCachedUser().getScreenName())) { + if (!screenName.equals(account.getUser().getScreenName())) { builder.addScreenName(screenName); } } 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 1538ed7b..83e06619 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 @@ -377,7 +377,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements private void updateRelationship(Activity activity, final long userId) { MainActivity mainActivity = (MainActivity) activity; Account account = mainActivity.getCurrentAccount(); - if (userId == account.userID) { + if (userId == account.getUserId()) { textViewFollowed.setText(R.string.user_detail_followed_is_me); buttonFollow.setVisibility(View.GONE); } else { 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 5fd54bf8..53f6b679 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java @@ -150,7 +150,7 @@ public class StatusViewModel implements IViewModel { if (tweet.isRetweet()) { int colorBgRetweet = Themes.getStyledColor(activity, theme, R.attr.color_status_bg_retweet, 0); convertedView.setBackgroundColor(colorBgRetweet); - } else if (account.getCachedUser() != null && tweet.getOriginalTweet().getMentions().contains(account.getCachedUser().getScreenName())) { + } else if (tweet.getOriginalTweet().getMentions().contains(account.getUser().getScreenName())) { int colorBgMention = Themes.getStyledColor(activity, theme, R.attr.color_status_bg_mention, 0); convertedView.setBackgroundColor(colorBgMention); } else { 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 28bc5cd0..58a866fa 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 @@ -71,7 +71,6 @@ 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); @@ -107,27 +106,15 @@ public class MainActivityMenuHelper { return true; } case R.id.actionbar_favstar: { - if (user == null) { - Notificator.getInstance().publish(R.string.notice_application_starting); - } else { - new CommandOpenURL(activity, user.getFavstarRecentURL()).execute(); - } + new CommandOpenURL(activity, activity.getCurrentAccount().getUser().getFavstarRecentURL()).execute(); return true; } case R.id.actionbar_aclog: { - if (user == null) { - Notificator.getInstance().publish(R.string.notice_application_starting); - } else { - new CommandOpenURL(activity, user.getAclogTimelineURL()).execute(); - } + new CommandOpenURL(activity, activity.getCurrentAccount().getUser().getAclogTimelineURL()).execute(); return true; } case R.id.actionbar_twilog: { - if (user == null) { - Notificator.getInstance().publish(R.string.notice_application_starting); - } else { - new CommandOpenURL(activity, user.getTwilogURL()).execute(); - } + new CommandOpenURL(activity, activity.getCurrentAccount().getUser().getTwilogURL()).execute(); return true; } case R.id.actionbar_report: { |