diff options
4 files changed, 41 insertions, 52 deletions
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java index 0c54eb5e..0c87ab27 100644 --- a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java +++ b/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java @@ -50,8 +50,8 @@ public class EventViewModelTest extends InstrumentationTestCase { Status status = mock.getReplyMock(); User source = mock.getUserMock(); EventViewModel event = new EventViewModel(EventViewModel.EnumEvent.FAVORITED, source, status); - assertEquals(source.getId(), event.getSourceUserID()); - assertEquals(status.getId(), event.getTargetStatusID()); + assertEquals(source.getId(), event.source.getId()); + assertEquals(status.getId(), event.targetObject.getId()); assertEquals(context.getString(R.string.format_event_favorited, source.getScreenName()), event.getFormattedString(context)); event = new EventViewModel(EventViewModel.EnumEvent.RECEIVE_MESSAGE, source); Configuration config = context.getResources().getConfiguration(); 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 b1f88dc6..71a4f928 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/User.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/User.java @@ -177,7 +177,7 @@ public class User extends UIObservable { return isVerified; } - + // helper methods public String getUserHomeURL() { return String.format("https://twitter.com/%s", getScreenName()); } 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 a5074c6a..f21ad625 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/CustomListFragment.java @@ -113,7 +113,6 @@ public abstract class CustomListFragment<T extends CustomListAdapter> extends Pa 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/viewmodel/EventViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java index 03e41006..7a0180b7 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/EventViewModel.java @@ -34,11 +34,13 @@ 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.entity.RO; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.entity.User; import net.lacolaco.smileessence.preference.UserPreferenceHelper; 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.dialog.UserDetailDialogFragment; import net.lacolaco.smileessence.view.listener.ListItemClickListener; @@ -50,12 +52,8 @@ public class EventViewModel implements IViewModel { // ------------------------------ FIELDS ------------------------------ private EnumEvent event; - private long sourceUserID; - private long targetStatusID; - private String sourceScreenName; - private String sourceName; - private String iconURL; - private String targetText; + private User source; + private Tweet targetObject; private Date createdAt; // --------------------------- CONSTRUCTORS --------------------------- @@ -66,23 +64,15 @@ public class EventViewModel implements IViewModel { public EventViewModel(EnumEvent event, User source, Tweet tweet) { this.event = event; + this.source = source; this.createdAt = new Date(); - this.sourceUserID = source.getId(); - this.sourceScreenName = source.getScreenName(); - this.sourceName = source.getName(); - this.iconURL = source.getProfileImageUrl(); if (tweet != null) { if (event == EnumEvent.RETWEETED) { - this.targetStatusID = tweet.getRetweetedTweet().getId(); - this.targetText = tweet.getRetweetedTweet().getText(); + this.targetObject = tweet.getRetweetedTweet(); } else { - this.targetStatusID = tweet.getId(); - this.targetText = tweet.getText(); + this.targetObject = tweet; } - } else { - this.targetStatusID = -1L; - this.targetText = ""; } } @@ -96,32 +86,8 @@ public class EventViewModel implements IViewModel { return event; } - public String getIconURL() { - return iconURL; - } - - public String getSourceName() { - return sourceName; - } - - public String getSourceScreenName() { - return sourceScreenName; - } - - public long getSourceUserID() { - return sourceUserID; - } - - public long getTargetStatusID() { - return targetStatusID; - } - - public String getTargetText() { - return targetText; - } - public boolean isStatusEvent() { - return targetStatusID != -1L; + return targetObject != null; } // ------------------------ INTERFACE METHODS ------------------------ @@ -129,26 +95,43 @@ public class EventViewModel implements IViewModel { // --------------------- Interface IViewModel --------------------- + private void updateViewUser(MainActivity activity, View convertedView) { + NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon); + ImageCache.getInstance().setImageToView(source.getProfileImageUrl(), icon); + + TextView header = (TextView) convertedView.findViewById(R.id.textview_status_header); + header.setText(getFormattedString()); + } + @Override public View getView(final Activity activity, LayoutInflater inflater, View convertedView) { if (convertedView == null) { convertedView = inflater.inflate(R.layout.list_item_status, null); } + UIObserverBundle bundle = (UIObserverBundle) convertedView.getTag(); + if (bundle != null) { + bundle.detachAll(); + } else { + bundle = new UIObserverBundle(); + convertedView.setTag(bundle); + } + int textSize = UserPreferenceHelper.getInstance().get(R.string.key_setting_text_size, 10); int nameStyle = UserPreferenceHelper.getInstance().get(R.string.key_setting_namestyle, 0); int theme = ((MainActivity) activity).getThemeIndex(); - NetworkImageView icon = (NetworkImageView) convertedView.findViewById(R.id.imageview_status_icon); - ImageCache.getInstance().setImageToView(getIconURL(), icon); + TextView header = (TextView) convertedView.findViewById(R.id.textview_status_header); header.setTextSize(textSize); int colorHeader = Themes.getStyledColor(activity, theme, R.attr.color_status_text_mine, 0); header.setTextColor(colorHeader); - header.setText(getFormattedString()); + + updateViewUser((MainActivity) activity, convertedView); + TextView content = (TextView) convertedView.findViewById(R.id.textview_status_text); content.setTextSize(textSize); int colorNormal = Themes.getStyledColor(activity, theme, R.attr.color_status_text_normal, 0); content.setTextColor(colorNormal); - content.setText(getTargetText()); + content.setText(targetObject.getText()); TextView footer = (TextView) convertedView.findViewById(R.id.textview_status_footer); footer.setTextSize(textSize - 2); int colorFooter = Themes.getStyledColor(activity, theme, R.attr.color_status_text_footer, 0); @@ -160,16 +143,23 @@ public class EventViewModel implements IViewModel { convertedView.setBackgroundColor(colorBgNormal); convertedView.setOnClickListener(new ListItemClickListener(activity, () -> { UserDetailDialogFragment fragment = new UserDetailDialogFragment(); - fragment.setUserID(getSourceUserID()); + fragment.setUserID(source.getId()); DialogHelper.showDialog(activity, fragment); })); + + final View finalView = convertedView; + bundle.attach(source, (x, changes) -> { + if (changes.contains(RO.BASIC)) + updateViewUser((MainActivity) activity, finalView); + }); + return convertedView; } // -------------------------- OTHER METHODS -------------------------- public String getFormattedString() { - return Application.getContext().getString(event.getTextFormatResourceID(), sourceScreenName); + return Application.getContext().getString(event.getTextFormatResourceID(), source.getScreenName()); } public enum EnumEvent { |