Fixed dark theme issue.

This commit is contained in:
Amine Bou 2018-05-07 10:16:02 +02:00
parent c17980a032
commit 4846c870fa
5 changed files with 21 additions and 9 deletions

View File

@ -577,9 +577,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
LibsBuilder()
.withActivityStyle(
if (appColors.isDarkTheme) {
Libs.ActivityStyle.LIGHT_DARK_TOOLBAR
} else {
Libs.ActivityStyle.DARK
} else {
Libs.ActivityStyle.LIGHT_DARK_TOOLBAR
}
)
.withAboutIconShown(true)

View File

@ -2,14 +2,17 @@ package apps.amine.bou.readerforselfoss
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.content.ContextCompat
import android.support.v4.view.ViewPager
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
import android.widget.Toast
import apps.amine.bou.readerforselfoss.api.selfoss.Item
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
@ -54,8 +57,6 @@ class ReaderActivity : AppCompatActivity() {
}
override fun onCreate(savedInstanceState: Bundle?) {
val appColors = AppColors(this@ReaderActivity)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_reader)
@ -88,7 +89,7 @@ class ReaderActivity : AppCompatActivity() {
currentItem = intent.getIntExtra("currentItem", 0)
pager.adapter = ScreenSlidePagerAdapter(supportFragmentManager)
pager.adapter = ScreenSlidePagerAdapter(supportFragmentManager, AppColors(this@ReaderActivity))
pager.currentItem = currentItem
}
@ -175,8 +176,10 @@ class ReaderActivity : AppCompatActivity() {
oldInstanceState!!.clear()
}
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) :
private inner class ScreenSlidePagerAdapter(fm: FragmentManager, val appColors: AppColors) :
FragmentStatePagerAdapter(fm) {
override fun getCount(): Int {
return allItems.size
}
@ -184,6 +187,12 @@ class ReaderActivity : AppCompatActivity() {
override fun getItem(position: Int): ArticleFragment {
return ArticleFragment.newInstance(position, allItems)
}
override fun startUpdate(container: ViewGroup) {
super.startUpdate(container)
container.background = ColorDrawable(ContextCompat.getColor(this@ReaderActivity, appColors.colorBackground))
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {

View File

@ -17,6 +17,7 @@ class AppColors(a: Activity) {
@ColorInt val colorAccent: Int
@ColorInt val colorAccentDark: Int
@ColorInt val cardBackgroundColor: Int
@ColorInt val colorBackground: Int
val isDarkTheme: Boolean
init {
@ -48,10 +49,12 @@ class AppColors(a: Activity) {
false
)
if (isDarkTheme) {
colorBackground = if (isDarkTheme) {
a.setTheme(R.style.NoBarDark)
R.color.darkBackground
} else {
a.setTheme(R.style.NoBar)
android.R.color.background_light
}
val wrapper = Context::class.java

View File

@ -24,7 +24,7 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="colorAccentDark">@color/colorAccentDark</item>
<item name="cardBackgroundColor">@color/md_grey_800</item>
<item name="android:colorBackground">#303030</item>
<item name="android:colorBackground">@color/darkBackground</item>
<item name="bnbBackgroundColor">@color/md_grey_900</item>
<item name="android:textColorPrimary">@color/md_white_1000</item>
<item name="android:textColorSecondary">@color/md_grey_600</item>

View File

@ -10,7 +10,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong