From 26f16af5fcd9ec4a4fd42ab6d67bf822e4fa2ebb Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 21 Mar 2017 10:33:27 +0800 Subject: [PATCH] fixed fanfou status format --- .../library/fanfou/api/SearchResources.java | 4 ++-- .../org/mariotaku/twidere/util/ThemeUtils.java | 18 ------------------ .../mariotaku/twidere/activity/BaseActivity.kt | 13 +++++++++---- .../mariotaku/twidere/activity/HomeActivity.kt | 6 +++++- .../twidere/activity/ImageCropperActivity.kt | 10 +++++++--- .../twidere/app/TwidereApplication.kt | 3 +++ .../twidere/constant/PreferenceKeys.kt | 3 ++- .../extension/model/CredentialsExtensions.kt | 6 +++++- .../twidere/fragment/StatusFragment.kt | 3 +-- .../mariotaku/twidere/fragment/UserFragment.kt | 8 ++------ .../org/mariotaku/twidere/util/Analyzer.kt | 7 +++++++ 11 files changed, 43 insertions(+), 38 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/fanfou/api/SearchResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/fanfou/api/SearchResources.java index aa8c6bf64..19f1d9423 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/fanfou/api/SearchResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/fanfou/api/SearchResources.java @@ -21,13 +21,13 @@ package org.mariotaku.microblog.library.fanfou.api; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.param.Query; import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.microblog.library.twitter.model.Paging; import org.mariotaku.microblog.library.twitter.model.ResponseList; import org.mariotaku.microblog.library.twitter.model.Status; import org.mariotaku.microblog.library.twitter.model.User; +import org.mariotaku.restfu.annotation.method.GET; +import org.mariotaku.restfu.annotation.param.Query; /** * Created by mariotaku on 16/3/10. diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java index 9b802239d..66544762b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java @@ -239,12 +239,6 @@ public class ThemeUtils implements Constants { } } - public static String getThemeBackgroundOption(final Context context) { - if (context == null) return VALUE_THEME_BACKGROUND_DEFAULT; - final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context); - return pref.getString(KEY_THEME_BACKGROUND, VALUE_THEME_BACKGROUND_DEFAULT); - } - public static int getThemeForegroundColor(final Context context) { return getThemeForegroundColor(context, 0); } @@ -283,14 +277,6 @@ public class ThemeUtils implements Constants { return pref.getInt(KEY_THEME_COLOR, def); } - public static int getUserThemeBackgroundAlpha(final Context context) { - if (context == null) return DEFAULT_THEME_BACKGROUND_ALPHA; - final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context); - return TwidereMathUtils.clamp(pref.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA), - ThemeBackgroundPreference.MIN_ALPHA, ThemeBackgroundPreference.MAX_ALPHA); - } - - public static int getActionBarAlpha(final int alpha) { final int normalizedAlpha = TwidereMathUtils.clamp(alpha, 0, 0xFF); final int delta = ThemeBackgroundPreference.MAX_ALPHA - normalizedAlpha; @@ -343,10 +329,6 @@ public class ThemeUtils implements Constants { return VALUE_THEME_BACKGROUND_SOLID.equals(option); } - public static boolean isTransparentBackground(final Context context) { - return isTransparentBackground(getThemeBackgroundOption(context)); - } - public static boolean isTransparentBackground(final String option) { return VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option); } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt index b2ba461fe..2b4c8dee1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt @@ -50,9 +50,11 @@ import org.mariotaku.kpreferences.get import org.mariotaku.restfu.http.RestHttpClient import org.mariotaku.twidere.BuildConfig import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME -import org.mariotaku.twidere.activity.iface.IControlBarActivity import org.mariotaku.twidere.activity.iface.IBaseActivity +import org.mariotaku.twidere.activity.iface.IControlBarActivity import org.mariotaku.twidere.activity.iface.IThemedActivity +import org.mariotaku.twidere.constant.themeBackgroundAlphaKey +import org.mariotaku.twidere.constant.themeBackgroundOptionKey import org.mariotaku.twidere.constant.themeColorKey import org.mariotaku.twidere.constant.themeKey import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback @@ -102,6 +104,9 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity, IThe lateinit var restHttpClient: RestHttpClient private val actionHelper = IBaseActivity.ActionHelper(this) + private val themePreferences by lazy { + getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) + } // Registered listeners private val controlBarOffsetListeners = ArrayList() @@ -115,7 +120,7 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity, IThe } if (ThemeUtils.isTransparentBackground(themeBackgroundOption)) { theme.colorToolbar = ColorUtils.setAlphaComponent(theme.colorToolbar, - ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(this))) + ThemeUtils.getActionBarAlpha(themePreferences[themeBackgroundAlphaKey])) } theme.statusBarColor = ChameleonUtils.darkenColor(theme.colorToolbar) theme.lightStatusBarMode = LightStatusBarMode.AUTO @@ -272,11 +277,11 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity, IThe } override val themeBackgroundAlpha: Int - get() = ThemeUtils.getUserThemeBackgroundAlpha(this) + get() = themePreferences[themeBackgroundAlphaKey] override val themeBackgroundOption: String - get() = ThemeUtils.getThemeBackgroundOption(this) + get() = themePreferences[themeBackgroundOptionKey] protected open val shouldApplyWindowBackground: Boolean get() { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt index 4ae9ab5a3..ded10dd7d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt @@ -778,7 +778,11 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp private fun setupBars() { val backgroundOption = currentThemeBackgroundOption val isTransparent = ThemeUtils.isTransparentBackground(backgroundOption) - val actionBarAlpha = if (isTransparent) ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(this)) else 0xFF + val actionBarAlpha = if (isTransparent) { + ThemeUtils.getActionBarAlpha(preferences[themeBackgroundAlphaKey]) + } else { + 0xFF + } actionsButton.alpha = actionBarAlpha / 255f } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ImageCropperActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ImageCropperActivity.kt index 4b14f1de7..f932b41f9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ImageCropperActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ImageCropperActivity.kt @@ -26,9 +26,11 @@ import com.soundcloud.android.crop.CropImageActivity import org.mariotaku.kpreferences.get import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants +import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME import org.mariotaku.twidere.activity.iface.IThemedActivity +import org.mariotaku.twidere.constant.themeBackgroundAlphaKey +import org.mariotaku.twidere.constant.themeBackgroundOptionKey import org.mariotaku.twidere.constant.themeKey -import org.mariotaku.twidere.util.ThemeUtils import org.mariotaku.twidere.util.theme.getCurrentThemeResource /** @@ -40,6 +42,8 @@ class ImageCropperActivity : CropImageActivity(), IThemedActivity { override val currentThemeBackgroundAlpha by lazy { themeBackgroundAlpha } override val currentThemeBackgroundOption by lazy { themeBackgroundOption } + private val preferences by lazy { getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) } + private var doneCancelBar: Toolbar? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -61,9 +65,9 @@ class ImageCropperActivity : CropImageActivity(), IThemedActivity { } override val themeBackgroundAlpha: Int - get() = ThemeUtils.getUserThemeBackgroundAlpha(this) + get() = preferences[themeBackgroundAlphaKey] override val themeBackgroundOption: String - get() = ThemeUtils.getThemeBackgroundOption(this) + get() = preferences[themeBackgroundOptionKey] } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt index 7b4606386..1cf5f82fa 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt @@ -130,6 +130,8 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis listenExternalThemeChange() loadDefaultFeatures() + + Analyzer.preferencesChanged(sharedPreferences) } private fun loadDefaultFeatures() { @@ -267,6 +269,7 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis } } } + Analyzer.preferencesChanged(preferences) } override fun onTerminate() { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt index 8720e9f55..1e8559c28 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt @@ -18,7 +18,6 @@ import org.mariotaku.twidere.model.account.cred.Credentials import org.mariotaku.twidere.model.sync.SyncProviderInfo import org.mariotaku.twidere.preference.ThemeBackgroundPreference import org.mariotaku.twidere.util.sync.SyncProviderInfoFactory -import org.mariotaku.twidere.view.ProfileImageView /** * Created by mariotaku on 16/8/25. @@ -73,6 +72,8 @@ val streamingEnabledKey = KBooleanKey("streaming_enabled", false) val streamingNonMeteredNetworkKey = KBooleanKey("streaming_non_metered_network", true) val streamingPowerSavingKey = KBooleanKey("streaming_power_saving", true) +val themeBackgroundOptionKey = KStringKey(KEY_THEME_BACKGROUND, VALUE_THEME_BACKGROUND_DEFAULT) + object themeBackgroundAlphaKey : KSimpleKey(KEY_THEME_BACKGROUND_ALPHA, 0xFF) { override fun read(preferences: SharedPreferences): Int { return preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt index 7530b70ee..35b059080 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt @@ -127,6 +127,7 @@ fun newMicroBlogInstance(context: Context, endpoint: Endpoint, auth: Authori UserAgentExtraHeaders(MicroBlogAPIFactory.getTwidereUserAgent(context)) } val holder = DependencyHolder.get(context) + var extraRequestParams: Map? = null when (cls) { TwitterUpload::class.java -> { val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences) @@ -158,11 +159,14 @@ fun newMicroBlogInstance(context: Context, endpoint: Endpoint, auth: Authori } AccountType.FANFOU -> { factory.setConstantPool(sFanfouConstantPool) + if (cls != FanfouStream::class.java) { + extraRequestParams = mapOf("format" to "html") + } } } val converterFactory = TwitterConverterFactory() factory.setRestConverterFactory(converterFactory) - factory.setRestRequestFactory(MicroBlogAPIFactory.TwidereRestRequestFactory(null)) + factory.setRestRequestFactory(MicroBlogAPIFactory.TwidereRestRequestFactory(extraRequestParams)) factory.setHttpRequestFactory(MicroBlogAPIFactory.TwidereHttpRequestFactory(extraHeaders)) factory.setExceptionFactory(MicroBlogAPIFactory.TwidereExceptionFactory(converterFactory)) return factory.build(cls) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt index 809496bde..22201a25e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt @@ -1550,8 +1550,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks>(context, preferences) listener.setAdapter(this) twidereLinkify = TwidereLinkify(listener) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index 5ed8c825c..c139948c6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -100,11 +100,8 @@ import org.mariotaku.twidere.activity.iface.IBaseActivity import org.mariotaku.twidere.adapter.SupportTabsAdapter import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.annotation.Referral +import org.mariotaku.twidere.constant.* import org.mariotaku.twidere.constant.KeyboardShortcutConstants.* -import org.mariotaku.twidere.constant.displaySensitiveContentsKey -import org.mariotaku.twidere.constant.lightFontKey -import org.mariotaku.twidere.constant.newDocumentApiKey -import org.mariotaku.twidere.constant.profileImageStyleKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.extension.loadOriginalProfileImage import org.mariotaku.twidere.extension.loadProfileBanner @@ -673,8 +670,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, userColorNameManager.registerNicknameChangedListener(this) nameFirst = preferences.getBoolean(KEY_NAME_FIRST) cardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity, - ThemeUtils.getThemeBackgroundOption(activity), - ThemeUtils.getUserThemeBackgroundAlpha(activity)) + preferences[themeBackgroundOptionKey], preferences[themeBackgroundAlphaKey]) actionBarShadowColor = 0xA0000000.toInt() val args = arguments val accountId: UserKey = args.getParcelable(EXTRA_ACCOUNT_KEY) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/Analyzer.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/Analyzer.kt index 7e3d08653..e5fcb9328 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/Analyzer.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/Analyzer.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.util import android.app.Application +import android.content.SharedPreferences import org.mariotaku.twidere.annotation.AccountType /** @@ -35,6 +36,8 @@ abstract class Analyzer { protected abstract fun init(application: Application) + protected abstract fun preferencesChanged(preferences: SharedPreferences) + interface Event { val name: String get() = "Custom Event" @@ -66,5 +69,9 @@ abstract class Analyzer { fun logException(throwable: Throwable) { implementation?.logException(throwable) } + + fun preferencesChanged(preferences: SharedPreferences) { + implementation?.preferencesChanged(preferences) + } } }