aboutsummaryrefslogtreecommitdiffstats
path: root/app/src
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-09-15 21:09:02 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-09-15 21:09:02 +0900
commitb0c57a24c881607f26d1c43640552b24a574a8e4 (patch)
treef4b3a8dd758a9dd0526b2291f9e252603b0810b5 /app/src
parent897cdb295354cf8d8806270302cd7697cd76c54e (diff)
downloadSmileEssence-b0c57a24c881607f26d1c43640552b24a574a8e4.tar.gz
com.android.databinding まだぴよぴよしてる...
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandCongratulate.java2
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandFavAndRT.java2
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandReview.java4
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/command/status/StatusCommandTextQuote.java2
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/Tweet.java18
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/User.java89
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/util/NameStyles.java6
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/StatusDetailDialogFragment.java2
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java2
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java18
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/viewmodel/UserViewModel.java2
-rw-r--r--app/src/main/res/layout/list_item_status.xml116
12 files changed, 169 insertions, 94 deletions
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