From 6f562b5582b9b998422895acfa95fdd1d2295d11 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 26 Jan 2016 20:46:41 +0800 Subject: [PATCH] improved GNU social profile support --- .../twidere/api/twitter/model/User.java | 26 ++++++++++++++++--- .../twidere/util/TwitterContentUtils.java | 24 +++++++++++++++++ .../support/AccountsDashboardFragment.java | 3 ++- .../twidere/util/MediaLoaderWrapper.java | 2 +- .../org/mariotaku/twidere/util/Utils.java | 25 +----------------- 5 files changed, 51 insertions(+), 29 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/User.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/User.java index f0907aecb..7a2969507 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/User.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/User.java @@ -114,6 +114,11 @@ public class User extends TwitterResponseObject implements Comparable { @JsonField(name = "profile_background_color") String profileBackgroundColor; + /** + * For GNU social compatibility + */ + @JsonField(name = "backgroundcolor") + String backgroundcolor; @JsonField(name = "profile_background_image_url") String profileBackgroundImageUrl; @@ -133,9 +138,21 @@ public class User extends TwitterResponseObject implements Comparable { @JsonField(name = "profile_banner_url") String profileBannerUrl; + /** + * For GNU social compatibility + */ + @JsonField(name = "cover_photo") + String coverPhoto; + @JsonField(name = "profile_link_color") String profileLinkColor; + /** + * For GNU social compatibility + */ + @JsonField(name = "linkcolor") + String linkcolor; + @JsonField(name = "profile_sidebar_border_color") String profileSidebarBorderColor; @@ -301,7 +318,8 @@ public class User extends TwitterResponseObject implements Comparable { public String getProfileBackgroundColor() { - return profileBackgroundColor; + if (profileBackgroundColor != null) return profileBackgroundColor; + return backgroundcolor; } @@ -316,7 +334,8 @@ public class User extends TwitterResponseObject implements Comparable { public String getProfileBannerImageUrl() { - return profileBannerUrl; + if (profileBannerUrl != null) return profileBannerUrl; + return coverPhoto; } @@ -331,7 +350,8 @@ public class User extends TwitterResponseObject implements Comparable { public String getProfileLinkColor() { - return profileLinkColor; + if (profileLinkColor != null) return profileLinkColor; + return linkcolor; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java index cc292c9e1..0c856ef97 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java @@ -44,6 +44,7 @@ import org.mariotaku.twidere.model.ConsumerKeyType; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.util.collection.LongSparseMap; +import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor; import java.nio.charset.Charset; import java.util.ArrayList; @@ -328,4 +329,27 @@ public class TwitterContentUtils { return isFiltered(database, status.user_id, status.text_plain, status.text_html, status.source, status.retweeted_by_user_id, status.quoted_user_id, filter_rts); } + + @Nullable + public static String getBestBannerUrl(@Nullable final String baseUrl, final int width) { + if (baseUrl == null) return null; + final String type = getBestBannerType(width); + final String authority = PreviewMediaExtractor.getAuthority(baseUrl); + return authority != null && authority.endsWith(".twimg.com") ? baseUrl + "/" + type : baseUrl; + } + + public static String getBestBannerType(final int width) { + if (width <= 320) + return "mobile"; + else if (width <= 520) + return "web"; + else if (width <= 626) + return "ipad"; + else if (width <= 640) + return "mobile_retina"; + else if (width <= 1040) + return "web_retina"; + else + return "ipad_retina"; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java index 2dc517d75..c2504123f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java @@ -99,6 +99,7 @@ import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.SharedPreferencesWrapper; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.TransitionUtils; +import org.mariotaku.twidere.util.TwitterContentUtils; import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.content.SupportFragmentReloadCursorObserver; @@ -652,7 +653,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo final Resources res = getResources(); final int defWidth = res.getDisplayMetrics().widthPixels; final int width = bannerWidth > 0 ? bannerWidth : defWidth; - final String bannerUrl = Utils.getBestBannerUrl(account.profile_banner_url, width); + final String bannerUrl = TwitterContentUtils.getBestBannerUrl(account.profile_banner_url, width); final ImageView bannerView = mAccountProfileBannerView; if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(bannerUrl, bannerView.getTag())) { mMediaLoader.displayProfileBanner(mAccountProfileBannerView, bannerUrl, this); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java index 109c3d57c..46447387a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java @@ -35,7 +35,7 @@ import org.mariotaku.twidere.util.imageloader.OvalBitmapDisplayer; import javax.inject.Singleton; -import static org.mariotaku.twidere.util.Utils.getBestBannerUrl; +import static org.mariotaku.twidere.util.TwitterContentUtils.getBestBannerUrl; @Singleton public class MediaLoaderWrapper implements Constants { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 7e4b43dc3..885e52873 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -37,7 +37,6 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; @@ -201,14 +200,13 @@ import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses; import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.ConversationEntries; -import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.provider.TwidereDataStore.Filters.Users; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; import org.mariotaku.twidere.service.RefreshService; import org.mariotaku.twidere.util.TwidereLinkify.HighlightStyle; import org.mariotaku.twidere.util.content.ContentResolverUtils; +import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor; import org.mariotaku.twidere.util.menu.TwidereMenuInfo; -import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener; import org.mariotaku.twidere.view.CardMediaContainer.PreviewStyle; import org.mariotaku.twidere.view.ShapedImageView; import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle; @@ -1150,27 +1148,6 @@ public final class Utils implements Constants { return cr.update(CachedUsers.CONTENT_URI, values, where.getSQL(), null) != 0; } - - public static String getBestBannerUrl(final String baseUrl, final int width) { - final String type = getBestBannerType(width); - return TextUtils.isEmpty(baseUrl) ? null : baseUrl + "/" + type; - } - - public static String getBestBannerType(final int width) { - if (width <= 320) - return "mobile"; - else if (width <= 520) - return "web"; - else if (width <= 626) - return "ipad"; - else if (width <= 640) - return "mobile_retina"; - else if (width <= 1040) - return "web_retina"; - else - return "ipad_retina"; - } - public static File getBestCacheDir(final Context context, final String cacheDirName) { if (context == null) throw new NullPointerException(); final File extCacheDir;