migrating to new theme engine

This commit is contained in:
Mariotaku Lee 2016-12-18 10:32:11 +08:00
parent 8398953ec8
commit 049f9f65b1
6 changed files with 107 additions and 47 deletions

View File

@ -0,0 +1,58 @@
package org.mariotaku.chameleon;
/**
* Created by mariotaku on 2016/12/18.
*/
public class Chameleon {
/**
* Created by mariotaku on 2016/12/18.
*/
public static class Theme {
int primaryColor;
int accentColor;
int toolbarColor;
boolean toolbarColored;
public int getAccentColor() {
return accentColor;
}
public void setAccentColor(int accentColor) {
this.accentColor = accentColor;
}
public int getPrimaryColor() {
return primaryColor;
}
public void setPrimaryColor(int primaryColor) {
this.primaryColor = primaryColor;
}
public int getToolbarColor() {
return toolbarColor;
}
public void setToolbarColor(int toolbarColor) {
this.toolbarColor = toolbarColor;
}
public boolean isToolbarColored() {
return toolbarColored;
}
public void setToolbarColored(boolean toolbarColored) {
this.toolbarColored = toolbarColored;
}
}
/**
* Created by mariotaku on 2016/12/18.
*/
public interface Themeable {
Theme getOverrideTheme();
}
}

View File

@ -0,0 +1,31 @@
package org.mariotaku.ktextension
import android.annotation.TargetApi
import android.os.Build
import android.webkit.CookieManager
/**
* Created by mariotaku on 2016/12/18.
*/
fun CookieManager.removeAllCookiesSupport(callback: ((Boolean) -> Unit)? = null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
@Suppress("DEPRECATION")
removeAllCookie()
callback?.invoke(true)
return
}
CookieManagerSupportL.removeAllCookiesL(this, callback)
}
internal object CookieManagerSupportL {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun removeAllCookiesL(manager: CookieManager, callback: ((Boolean) -> Unit)?) {
if (callback != null) {
manager.removeAllCookies { callback(it) }
} else {
manager.removeAllCookies(null)
}
}
}

View File

@ -28,22 +28,18 @@ import android.content.res.Resources
import android.graphics.Rect
import android.nfc.NfcAdapter
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceFragmentCompat
import android.support.v7.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback
import android.support.v7.view.menu.ActionMenuItemView
import android.support.v7.widget.Toolbar
import android.support.v7.widget.TwidereActionMenuView
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import com.afollestad.appthemeengine.ATE
import com.afollestad.appthemeengine.ATEActivity
import com.afollestad.appthemeengine.Config
import com.afollestad.appthemeengine.customizers.ATEStatusBarCustomizer
import com.afollestad.appthemeengine.customizers.ATEToolbarCustomizer
import com.squareup.otto.Bus
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.kpreferences.KPreferences
import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.Constants
@ -62,10 +58,9 @@ import java.util.*
import javax.inject.Inject
@SuppressLint("Registered")
open class BaseActivity : ATEActivity(), Constants, IExtendedActivity, IThemedActivity,
open class BaseActivity : AppCompatActivity(), Constants, IExtendedActivity, IThemedActivity,
IControlBarActivity, OnFitSystemWindowsListener, SystemWindowsInsetsCallback,
KeyboardShortcutCallback, OnPreferenceDisplayDialogCallback, ATEToolbarCustomizer,
ATEStatusBarCustomizer {
KeyboardShortcutCallback, OnPreferenceDisplayDialogCallback, Chameleon.Themeable {
@Inject
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
@Inject
@ -260,11 +255,6 @@ open class BaseActivity : ATEActivity(), Constants, IExtendedActivity, IThemedAc
override val themeBackgroundOption: String
get() = ThemeUtils.getThemeBackgroundOption(this)
override fun getATEKey(): String? {
return ThemeUtils.getATEKey(this)
}
override fun onApplyThemeResource(theme: Resources.Theme, resId: Int, first: Boolean) {
super.onApplyThemeResource(theme, resId, first)
if (window != null && shouldApplyWindowBackground) {
@ -350,22 +340,8 @@ open class BaseActivity : ATEActivity(), Constants, IExtendedActivity, IThemedAc
return false
}
override fun getStatusBarColor(): Int {
return ATE.USE_DEFAULT
}
override fun getToolbarColor(toolbar: Toolbar?): Int {
return ATE.USE_DEFAULT
}
override fun getLightStatusBarMode(): Int {
//noinspection WrongConstant
return ThemeUtils.getLightStatusBarMode(Config.statusBarColor(this, ateKey))
}
override fun getLightToolbarMode(toolbar: Toolbar?): Int {
//noinspection WrongConstant
return ThemeUtils.getLightToolbarMode(Config.toolbarColor(this, ateKey, toolbar))
override fun getOverrideTheme(): Chameleon.Theme {
return Chameleon.Theme()
}
companion object {

View File

@ -25,7 +25,6 @@ import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import android.text.TextUtils.isEmpty
import android.util.Log
@ -37,6 +36,7 @@ import android.webkit.WebView
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_browser_sign_in.*
import org.attoparser.ParseException
import org.mariotaku.ktextension.removeAllCookiesSupport
import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.twitter.TwitterOAuth
import org.mariotaku.restfu.oauth.OAuthAuthorization
@ -77,11 +77,7 @@ class BrowserSignInActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_browser_sign_in)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().removeAllCookie()
} else {
CookieManager.getInstance().removeAllCookies(null)
}
CookieManager.getInstance().removeAllCookiesSupport()
webView.setWebViewClient(AuthorizationWebViewClient(this))
webView.isVerticalScrollBarEnabled = false
webView.addJavascriptInterface(InjectorJavaScriptInterface(this), "injector")

View File

@ -197,10 +197,6 @@ class MediaViewerActivity : BaseActivity(), IExtendedActivity, ATEToolbarCustomi
setBarVisibility(!isBarShowing)
}
override fun getATEKey(): String? {
return VALUE_THEME_NAME_DARK
}
override fun getInitialPosition(): Int {
return media.indexOf(initialMedia)
}

View File

@ -1277,21 +1277,24 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
setupBaseActionBar()
}
val activity = activity as BaseActivity
if (Config.coloredActionBar(activity, activity.ateKey)) {
val theme = activity.overrideTheme
primaryColor = theme.primaryColor
primaryColorDark = ThemeUtils.computeDarkColor(primaryColor)
if (theme.isToolbarColored) {
primaryColor = color
primaryColorDark = ThemeUtils.computeDarkColor(color)
} else {
primaryColor = Config.primaryColor(activity, activity.ateKey)
primaryColor = theme.primaryColor
primaryColorDark = Color.BLACK
}
if (actionBarBackground != null) {
actionBarBackground!!.color = primaryColor
}
val taskColor: Int
if (Config.coloredActionBar(activity, activity.ateKey)) {
if (theme.isToolbarColored) {
taskColor = color
} else {
taskColor = Config.toolbarColor(activity, activity.ateKey, toolbar)
taskColor = theme.toolbarColor
}
if (user != null) {
val name = userColorNameManager.getDisplayName(user, nameFirst)
@ -1399,11 +1402,11 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
val tabContrastColor = ThemeUtils.getColorDependent(currentTabColor)
toolbarTabs.setIconColor(tabContrastColor)
toolbarTabs.setLabelColor(tabContrastColor)
if (Config.coloredActionBar(activity, activity.ateKey)) {
val theme = activity.overrideTheme
if (theme.isToolbarColored) {
toolbarTabs.setStripColor(tabContrastColor)
} else {
toolbarTabs.setStripColor(ThemeUtils.getOptimalAccentColor(uiColor,
tabContrastColor))
toolbarTabs.setStripColor(ThemeUtils.getOptimalAccentColor(uiColor, tabContrastColor))
}
toolbarTabs.updateAppearance()
}