fixed dialog theme window attribute

This commit is contained in:
Mariotaku Lee 2017-08-01 14:42:20 +08:00
parent c2000055f2
commit 56d21301d2
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 20 additions and 6 deletions

View File

@ -54,6 +54,7 @@ import org.mariotaku.ktextension.systemWindowInsets
import org.mariotaku.ktextension.unregisterReceiverSafe
import org.mariotaku.restfu.http.RestHttpClient
import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME
import org.mariotaku.twidere.activity.iface.IBaseActivity
import org.mariotaku.twidere.activity.iface.IControlBarActivity
@ -126,6 +127,9 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
protected val gifShareProvider: GifShareProvider?
get() = gifShareProviderFactory.newInstance(this)
protected val isDialogTheme: Boolean
get() = ThemeUtils.getBooleanFromAttribute(this, R.attr.isDialogTheme)
override final val currentThemeBackgroundAlpha by lazy {
themeBackgroundAlpha
}
@ -381,7 +385,7 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
}
private fun onApplyNavigationStyle(navbarStyle: String, themeColor: Int) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || isDialogTheme) return
when (navbarStyle) {
NavbarStyle.TRANSPARENT -> {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)

View File

@ -27,6 +27,7 @@ import android.graphics.PorterDuff
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import android.support.annotation.AttrRes
import android.support.annotation.ColorInt
import android.support.annotation.StyleRes
import android.support.v4.content.ContextCompat
@ -448,7 +449,7 @@ object ThemeUtils {
}
}
fun getColorFromAttribute(context: Context, attr: Int, styleRes: Int = 0, def: Int = 0): Int {
fun getColorFromAttribute(context: Context, @AttrRes attr: Int, styleRes: Int = 0, def: Int = 0): Int {
val a = context.obtainStyledAttributes(null, intArrayOf(attr), 0, styleRes)
try {
return a.getColor(0, def)
@ -457,7 +458,16 @@ object ThemeUtils {
}
}
fun getDrawableFromThemeAttribute(context: Context, attr: Int): Drawable {
fun getBooleanFromAttribute(context: Context, @AttrRes attr: Int, styleRes: Int = 0, def: Boolean = false): Boolean {
val a = context.obtainStyledAttributes(null, intArrayOf(attr), 0, styleRes)
try {
return a.getBoolean(0, def)
} finally {
a.recycle()
}
}
fun getDrawableFromThemeAttribute(context: Context, @AttrRes attr: Int): Drawable {
val a = TintTypedArray.obtainStyledAttributes(context, null, intArrayOf(attr))
try {
return a.getDrawable(0)

View File

@ -13,7 +13,7 @@
<attr name="quoteIndicatorBackgroundColor" format="color"/>
<attr name="linePageIndicatorStyle" format="reference"/>
<attr name="mediaLabelBackground" format="color"/>
<attr name="isDialogTheme" format="boolean"/>
</declare-styleable>
<declare-styleable name="TwidereTheme">
<attr name="darkThemeResource" format="reference"/>

View File

@ -62,8 +62,8 @@
<item name="profileImageStyleLarge">@style/Widget.ProfileImage.Large</item>
<item name="cardItemBackgroundColor">@color/background_color_card_item_dark</item>
<!-- Twidere specific styles -->
<item name="isDialogTheme">true</item>
<item name="menuIconColor">@color/action_icon_light</item>
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
<item name="quoteIndicatorBackgroundColor">@color/quote_indicator_background_dark</item>

View File

@ -63,8 +63,8 @@
<item name="profileImageStyleLarge">@style/Widget.Light.ProfileImage.Large</item>
<item name="cardItemBackgroundColor">@color/background_color_card_item_light</item>
<!-- Twidere specific styles -->
<item name="isDialogTheme">true</item>
<item name="menuIconColor">@color/action_icon_dark</item>
<item name="messageBubbleColor">@color/message_bubble_color_light</item>
<item name="quoteIndicatorBackgroundColor">@color/quote_indicator_background_light</item>