fixed fanfou status format

This commit is contained in:
Mariotaku Lee 2017-03-21 10:33:27 +08:00
parent e81213f184
commit 26f16af5fc
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
11 changed files with 43 additions and 38 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -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<BaseActivity>, 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<IControlBarActivity.ControlBarOffsetListener>()
@ -115,7 +120,7 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, 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<BaseActivity>, 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() {

View File

@ -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
}

View File

@ -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]
}

View File

@ -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() {

View File

@ -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<Int>(KEY_THEME_BACKGROUND_ALPHA, 0xFF) {
override fun read(preferences: SharedPreferences): Int {
return preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA)

View File

@ -127,6 +127,7 @@ fun <T> newMicroBlogInstance(context: Context, endpoint: Endpoint, auth: Authori
UserAgentExtraHeaders(MicroBlogAPIFactory.getTwidereUserAgent(context))
}
val holder = DependencyHolder.get(context)
var extraRequestParams: Map<String, String>? = null
when (cls) {
TwitterUpload::class.java -> {
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
@ -158,11 +159,14 @@ fun <T> 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<T>(cls)

View File

@ -1550,8 +1550,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
itemCounts[ITEM_IDX_REPLY_LOAD_MORE] = 1
inflater = LayoutInflater.from(context)
cardBackgroundColor = ThemeUtils.getCardBackgroundColor(context,
ThemeUtils.getThemeBackgroundOption(context),
ThemeUtils.getUserThemeBackgroundAlpha(context))
preferences[themeBackgroundOptionKey], preferences[themeBackgroundAlphaKey])
val listener = StatusAdapterLinkClickHandler<List<ParcelableStatus>>(context, preferences)
listener.setAdapter(this)
twidereLinkify = TwidereLinkify(listener)

View File

@ -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<UserKey>(EXTRA_ACCOUNT_KEY)

View File

@ -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)
}
}
}