aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/entity/User.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/entity/User.java')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/entity/User.java89
1 files changed, 72 insertions, 17 deletions
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;
}