diff options
14 files changed, 174 insertions, 99 deletions
diff --git a/app/app.iml b/app/app.iml index 04b642c5..33b02e84 100644 --- a/app/app.iml +++ b/app/app.iml @@ -105,15 +105,15 @@ <orderEntry type="library" exported="" name="antlr4-4.5" level="project" /> <orderEntry type="library" exported="" name="activeandroid-3.1.0-SNAPSHOT" level="project" /> <orderEntry type="library" exported="" name="twitter4j-stream-4.0.4" level="project" /> - <orderEntry type="library" exported="" name="antlr4-runtime-4.5" level="project" /> <orderEntry type="library" exported="" name="antlr4-annotations-4.5" level="project" /> + <orderEntry type="library" exported="" name="antlr4-runtime-4.5" level="project" /> <orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" /> <orderEntry type="library" exported="" name="library-1.0-rc1" level="project" /> <orderEntry type="library" exported="" name="org.abego.treelayout.core-1.0.1" level="project" /> <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" /> - <orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" /> - <orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" /> <orderEntry type="library" exported="" name="adapters-1.0-rc1" level="project" /> + <orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" /> + <orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" /> <orderEntry type="library" exported="" name="compiler-1.0-rc1" level="project" /> <orderEntry type="library" exported="" name="baseLibrary-1.0-rc1" level="project" /> <orderEntry type="library" exported="" name="twitter-text-1.13.0" level="project" /> @@ -122,8 +122,8 @@ <orderEntry type="library" exported="" name="twitter4j-media-support-4.0.4" level="project" /> <orderEntry type="library" exported="" name="commons-codec-1.10" level="project" /> <orderEntry type="library" exported="" name="support-v13-23.0.1" level="project" /> - <orderEntry type="library" exported="" name="kotlin-stdlib-0.12.613" level="project" /> <orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" /> + <orderEntry type="library" exported="" name="kotlin-stdlib-0.12.613" level="project" /> <orderEntry type="library" exported="" name="twitter4j-core-4.0.4" level="project" /> </component> </module>
\ No newline at end of file diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java index 8b68b128..24299306 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java @@ -61,7 +61,7 @@ public class StatusCommandCongratulate extends StatusCommand implements IConfirm @Override public boolean isEnabled() { - return !getOriginalStatus().getUser().isProtected(); + return !getOriginalStatus().getUser().isTweetProtected(); } // -------------------------- OTHER METHODS -------------------------- 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 d8d9e4a8..9d7085ad 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 @@ -58,7 +58,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.isTweetProtected() && user.getId() != account.userID; } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandReview.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandReview.java index df5f6515..50614c0d 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandReview.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandReview.java @@ -31,8 +31,6 @@ import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.view.DialogHelper; import net.lacolaco.smileessence.view.dialog.ReviewDialogFragment; -import twitter4j.Status; - public class StatusCommandReview extends StatusCommand { // --------------------------- CONSTRUCTORS --------------------------- @@ -50,7 +48,7 @@ public class StatusCommandReview extends StatusCommand { @Override public boolean isEnabled() { - return !getOriginalStatus().getUser().isProtected(); + return !getOriginalStatus().getUser().isTweetProtected(); } // -------------------------- OTHER METHODS -------------------------- diff --git a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandTextQuote.java b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandTextQuote.java index 534e7e1a..9b051ff7 100644 --- a/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandTextQuote.java +++ b/app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandTextQuote.java @@ -49,7 +49,7 @@ public class StatusCommandTextQuote extends StatusCommand { @Override public boolean isEnabled() { - return !getStatus().getUser().isProtected(); + return !getStatus().getUser().isTweetProtected(); } // -------------------------- OTHER METHODS -------------------------- 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 3d0cf8d3..65323a9e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java @@ -1,7 +1,10 @@ package net.lacolaco.smileessence.entity; +import android.databinding.BaseObservable; +import android.databinding.Bindable; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import net.lacolaco.smileessence.BR; import net.lacolaco.smileessence.twitter.util.TwitterUtils; import net.lacolaco.smileessence.util.ListUtils; import twitter4j.*; @@ -10,7 +13,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -public class Tweet { +public class Tweet extends BaseObservable { // キャッシュ こっちは soft reference private static Cache<Long, Tweet> storage = CacheBuilder.newBuilder().softValues().build(); @@ -64,8 +67,14 @@ public class Tweet { text = TwitterUtils.replaceURLEntities(status.getText(), status.getURLEntities(), false); createdAt = status.getCreatedAt(); source = status.getSource(); - favoriteCount = status.getFavoriteCount(); - retweetCount = status.getRetweetCount(); + if (status.getFavoriteCount() != status.getFavoriteCount()) { + favoriteCount = status.getFavoriteCount(); + notifyPropertyChanged(BR.favoriteCount); + } + if (status.getRetweetCount() != status.getRetweetCount()) { + retweetCount = status.getRetweetCount(); + notifyPropertyChanged(BR.retweetCount); + } mentions = status.getUserMentionEntities(); hashtags = status.getHashtagEntities(); @@ -80,6 +89,7 @@ public class Tweet { } } + @Bindable public String getTwitterUrl() { return String.format("https://twitter.com/%s/status/%s", getOriginalTweet().getUser().getScreenName(), getOriginalTweet().getId()); } @@ -120,10 +130,12 @@ public class Tweet { } } + @Bindable public int getFavoriteCount() { return favoriteCount; } + @Bindable public int getRetweetCount() { return retweetCount; } 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..20e38878 100644 --- a/app/src/main/java/net/lacolaco/smileessence/entity/User.java +++ b/app/src/main/java/net/lacolaco/smileessence/entity/User.java @@ -1,9 +1,12 @@ package net.lacolaco.smileessence.entity; +import android.databinding.BaseObservable; +import android.databinding.Bindable; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import net.lacolaco.smileessence.BR; -public class User { +public class User extends BaseObservable { // 重複防止用キャッシュ こっちは weak reference private static Cache<Long, User> storage = CacheBuilder.newBuilder().weakValues().build(); @@ -24,7 +27,7 @@ public class User { // インスタンス private long id; - private boolean isProtected; + private boolean tweetProtected; private String screenName; private String name; private String profileImageUrl; @@ -44,37 +47,80 @@ public class User { private void update(twitter4j.User user) { id = user.getId(); - isProtected = user.isProtected(); - screenName = user.getScreenName(); - name = user.getName(); - profileImageUrl = user.getProfileImageURLHttps(); - profileBannerUrl = user.getProfileBannerURL(); - description = user.getDescription(); - location = user.getLocation(); - url = user.getURL(); - favoritesCount = user.getFavouritesCount(); - statusesCount = user.getStatusesCount(); - friendsCount = user.getFriendsCount(); - followersCount = user.getFollowersCount(); - isVerified = user.isVerified(); + if (isTweetProtected() != user.isProtected()) { + tweetProtected = user.isProtected(); + notifyPropertyChanged(BR.tweetProtected); + } + if (!getScreenName().equals(user.getScreenName())) { + screenName = user.getScreenName(); + notifyPropertyChanged(BR.screenName); + } + if (!getName().equals(user.getName())) { + name = user.getName(); + notifyPropertyChanged(BR.name); + } + if (!getProfileImageUrl().equals(user.getProfileBackgroundImageUrlHttps())) { + profileImageUrl = user.getProfileImageURLHttps(); + notifyPropertyChanged(BR.profileImageUrl); + } + if (!getProfileBannerUrl().equals(user.getProfileBannerURL())) { + profileBannerUrl = user.getProfileBannerURL(); + notifyPropertyChanged(BR.profileBannerUrl); + } + if (!getDescription().equals(user.getDescription())) { + description = user.getDescription(); + notifyPropertyChanged(BR.description); + } + if (!getLocation().equals(user.getLocation())) { + location = user.getLocation(); + notifyPropertyChanged(BR.location); + } + if (!getUrl().equals(user.getURL())) { + url = user.getURL(); + notifyPropertyChanged(BR.url); + } + if (getFavoritesCount() != user.getFavouritesCount()) { + favoritesCount = user.getFavouritesCount(); + notifyPropertyChanged(BR.favoritesCount); + } + if (getStatusesCount() != user.getStatusesCount()) { + statusesCount = user.getStatusesCount(); + notifyPropertyChanged(BR.statusesCount); + } + if (getFriendsCount() != user.getFriendsCount()) { + friendsCount = user.getFriendsCount(); + notifyPropertyChanged(BR.friendsCount); + } + if (getFollowersCount() != user.getFollowersCount()) { + followersCount = user.getFollowersCount(); + notifyPropertyChanged(BR.followersCount); + } + if (isVerified() != user.isVerified()) { + isVerified = user.isVerified(); + notifyPropertyChanged(BR.verified); + } } public long getId() { return id; } - public boolean isProtected() { - return isProtected; + @Bindable // TODO: workaround for bugs in com.android.databinding + public boolean isTweetProtected() { + return tweetProtected; } + @Bindable public String getScreenName() { return screenName; } + @Bindable public String getName() { return name; } + @Bindable public String getProfileImageUrl() { return profileImageUrl; } @@ -96,38 +142,47 @@ public class User { return null; } + @Bindable public String getProfileBannerUrl() { return profileBannerUrl; } + @Bindable public String getDescription() { return description; } + @Bindable public String getLocation() { return location; } + @Bindable public String getUrl() { return url; } + @Bindable public int getFavoritesCount() { return favoritesCount; } + @Bindable public int getStatusesCount() { return statusesCount; } + @Bindable public int getFriendsCount() { return friendsCount; } + @Bindable public int getFollowersCount() { return followersCount; } + @Bindable public boolean isVerified() { return isVerified; } diff --git a/app/src/main/java/net/lacolaco/smileessence/util/NameStyles.java b/app/src/main/java/net/lacolaco/smileessence/util/NameStyles.java index 31c56324..5657b4b0 100644 --- a/app/src/main/java/net/lacolaco/smileessence/util/NameStyles.java +++ b/app/src/main/java/net/lacolaco/smileessence/util/NameStyles.java @@ -24,11 +24,15 @@ package net.lacolaco.smileessence.util; +import net.lacolaco.smileessence.entity.User; + public class NameStyles { // -------------------------- STATIC METHODS -------------------------- - public static String getNameString(int style, String screenName, String name) { + public static String getNameString(int style, User user) { + String name = user.getName(); + String screenName = user.getScreenName(); switch (style) { case 1: { return String.format("%s / %s", name, screenName); 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 d21c67c7..fff25cdc 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 @@ -252,7 +252,7 @@ public class StatusDetailDialogFragment extends StackableDialogFragment implemen private boolean isNotRetweetable(Account account, Tweet tweet) { User user = tweet.getOriginalTweet().getUser(); - return user.isProtected() || user.getId() == account.userID; + return user.isTweetProtected() || user.getId() == account.userID; } private boolean isRetweetDeletable(Account account, Tweet 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 cd8c935e..7a4aa13c 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 @@ -318,7 +318,7 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements textViewFriendCount.setText(String.valueOf(user.getFriendsCount())); textViewFollowerCount.setText(String.valueOf(user.getFollowersCount())); textViewFavoriteCount.setText(String.valueOf(user.getFavoritesCount())); - textViewProtected.setVisibility(user.isProtected() ? View.VISIBLE : View.GONE); + textViewProtected.setVisibility(user.isTweetProtected() ? View.VISIBLE : View.GONE); String htmlDescription = getHtmlDescription(user.getDescription()); textViewDescription.setText(Html.fromHtml(htmlDescription)); textViewDescription.setMovementMethod(LinkMovementMethod.getInstance()); 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 5680ccc7..78f1025e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java @@ -40,6 +40,7 @@ import net.lacolaco.smileessence.R; import net.lacolaco.smileessence.activity.MainActivity; import net.lacolaco.smileessence.data.FavoriteCache; import net.lacolaco.smileessence.data.ImageCache; +import net.lacolaco.smileessence.databinding.ListItemStatusBinding; import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.preference.UserPreferenceHelper; @@ -159,25 +160,26 @@ public class StatusViewModel implements IViewModel { lastTasks.clear(); if (convertedView == null) { - convertedView = inflater.inflate(R.layout.list_item_status, null); + ListItemStatusBinding binding = ListItemStatusBinding.inflate(inflater, null, false); + convertedView = binding.getRoot(); + convertedView.setTag(binding); } + ListItemStatusBinding binding = (ListItemStatusBinding) convertedView.getTag(); + binding.setTweet(getTweet()); + //return convertedView; + 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(tweet.getUser().getProfileImageUrl(), icon); - icon.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onIconClick(activity); - } - }); + icon.setOnClickListener(v -> onIconClick(activity)); TextView header = (TextView) convertedView.findViewById(R.id.textview_status_header); header.setTextSize(textSize); int colorHeader = Themes.getStyledColor(activity, theme, R.attr.color_status_text_header, 0); int colorMineHeader = Themes.getStyledColor(activity, theme, R.attr.color_status_text_mine, 0); header.setTextColor(isMyStatus() ? colorMineHeader : colorHeader); - header.setText(NameStyles.getNameString(nameStyle, tweet.getUser().getScreenName(), tweet.getUser().getName())); + header.setText(NameStyles.getNameString(nameStyle, tweet.getUser())); 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); diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/UserViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/UserViewModel.java index 3c25bf31..47c3f6fc 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/UserViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/UserViewModel.java @@ -60,7 +60,7 @@ public class UserViewModel { friendsCount = user.getFriendsCount(); followersCount = user.getFollowersCount(); favoritesCount = user.getFavoritesCount(); - isProtected = user.isProtected(); + isProtected = user.isTweetProtected(); isVerified = user.isVerified(); } diff --git a/app/src/main/res/layout/list_item_status.xml b/app/src/main/res/layout/list_item_status.xml index 92905d47..b9477778 100644 --- a/app/src/main/res/layout/list_item_status.xml +++ b/app/src/main/res/layout/list_item_status.xml @@ -23,65 +23,69 @@ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ~ SOFTWARE. --> +<layout xmlns:android="http://schemas.android.com/apk/res/android"> + <data> + <variable name="tweet" type="net.lacolaco.smileessence.entity.Tweet" /> + </data> + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="5dp"> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:padding="5dp"> - - <com.android.volley.toolbox.NetworkImageView - android:id="@+id/imageview_status_icon" - android:layout_width="36dp" - android:layout_height="36dp" - android:layout_alignParentLeft="true" - android:layout_alignParentTop="true" /> + <com.android.volley.toolbox.NetworkImageView + android:id="@+id/imageview_status_icon" + android:layout_width="36dp" + android:layout_height="36dp" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" /> - <TextView - android:id="@+id/textview_status_header" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_marginLeft="5dp" - android:layout_toRightOf="@+id/imageview_status_icon" - android:gravity="top" /> + <TextView + android:id="@+id/textview_status_header" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentTop="true" + android:layout_marginLeft="5dp" + android:layout_toRightOf="@+id/imageview_status_icon" + android:gravity="top" /> - <TextView - android:id="@+id/textview_status_text" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignLeft="@+id/textview_status_header" - android:layout_alignParentRight="true" - android:layout_below="@+id/textview_status_header" - android:layout_marginBottom="3dp" - android:layout_marginTop="1dp" /> + <TextView + android:id="@+id/textview_status_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignLeft="@+id/textview_status_header" + android:layout_alignParentRight="true" + android:layout_below="@+id/textview_status_header" + android:layout_marginBottom="3dp" + android:layout_marginTop="1dp" /> - <TextView - android:id="@+id/textview_status_footer" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignLeft="@+id/textview_status_text" - android:layout_below="@+id/textview_status_text" - android:layout_marginRight="2dp" /> + <TextView + android:id="@+id/textview_status_footer" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignLeft="@+id/textview_status_text" + android:layout_below="@+id/textview_status_text" + android:layout_marginRight="2dp" /> - <ImageView - android:id="@+id/imageview_status_favorited" - android:layout_width="30dp" - android:layout_height="wrap_content" - android:layout_alignBottom="@+id/textview_status_header" - android:layout_alignParentRight="true" - android:layout_alignParentTop="true" - android:layout_alignTop="@+id/textview_status_header" - android:contentDescription="" - android:src="?attr/icon_status_favorite_on" /> + <ImageView + android:id="@+id/imageview_status_favorited" + android:layout_width="30dp" + android:layout_height="wrap_content" + android:layout_alignBottom="@+id/textview_status_header" + android:layout_alignParentRight="true" + android:layout_alignParentTop="true" + android:layout_alignTop="@+id/textview_status_header" + android:contentDescription="" + android:src="?attr/icon_status_favorite_on" /> - <LinearLayout - android:id="@+id/view_status_embedded_status" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignLeft="@+id/textview_status_text" - android:layout_below="@+id/textview_status_footer" - android:layout_marginRight="1dp" - android:layout_marginTop="3dp" - android:orientation="vertical" - android:visibility="gone" /> -</RelativeLayout>
\ No newline at end of file + <LinearLayout + android:id="@+id/view_status_embedded_status" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignLeft="@+id/textview_status_text" + android:layout_below="@+id/textview_status_footer" + android:layout_marginRight="1dp" + android:layout_marginTop="3dp" + android:orientation="vertical" + android:visibility="gone" /> + </RelativeLayout> +</layout>
\ No newline at end of file diff --git a/build.gradle b/build.gradle index 8f71995c..5ae8a93a 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:1.3.+' - classpath 'com.android.databinding:dataBinder:1.+' + classpath 'com.android.databinding:dataBinder:+' classpath 'me.tatarka:gradle-retrolambda:+' } } |