mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-28 10:38:48 +03:00
Fix incorrect toolbar text color after theme change (#5388)
This commit is contained in:
parent
aecdd04e04
commit
ab73e98075
1 changed files with 14 additions and 21 deletions
|
@ -4,19 +4,18 @@ import android.animation.Animator
|
||||||
import android.animation.AnimatorListenerAdapter
|
import android.animation.AnimatorListenerAdapter
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.FloatRange
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.core.graphics.blue
|
|
||||||
import androidx.core.graphics.green
|
|
||||||
import androidx.core.graphics.red
|
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
|
import androidx.core.view.children
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.ConcatAdapter
|
import androidx.recyclerview.widget.ConcatAdapter
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
@ -77,7 +76,6 @@ import eu.kanade.tachiyomi.util.hasCustomCover
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
|
||||||
import eu.kanade.tachiyomi.util.system.toShareIntent
|
import eu.kanade.tachiyomi.util.system.toShareIntent
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.getCoordinates
|
import eu.kanade.tachiyomi.util.view.getCoordinates
|
||||||
|
@ -137,7 +135,7 @@ class MangaController :
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
private val coverCache: CoverCache by injectLazy()
|
private val coverCache: CoverCache by injectLazy()
|
||||||
|
|
||||||
private val toolbarTextColor by lazy { view!!.context.getResourceColor(R.attr.colorOnPrimary) }
|
private var toolbarTextView: TextView? = null
|
||||||
|
|
||||||
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
|
private var mangaInfoAdapter: MangaInfoHeaderAdapter? = null
|
||||||
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null
|
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null
|
||||||
|
@ -294,28 +292,22 @@ class MangaController :
|
||||||
updateFilterIconState()
|
updateFilterIconState()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateToolbarTitleAlpha(alpha: Int? = null) {
|
private fun updateToolbarTitleAlpha(@FloatRange(from = 0.0, to = 1.0) alpha: Float? = null) {
|
||||||
val scrolledList = binding.fullRecycler ?: binding.infoRecycler!!
|
val scrolledList = binding.fullRecycler ?: binding.infoRecycler!!
|
||||||
|
if (toolbarTextView == null) {
|
||||||
val calculatedAlpha = when {
|
toolbarTextView = (activity as? MainActivity)?.binding?.toolbar?.children
|
||||||
|
?.find { it is TextView } as TextView
|
||||||
|
}
|
||||||
|
toolbarTextView?.alpha = when {
|
||||||
// Specific alpha provided
|
// Specific alpha provided
|
||||||
alpha != null -> alpha
|
alpha != null -> alpha
|
||||||
|
|
||||||
// First item isn't in view, full opacity
|
// First item isn't in view, full opacity
|
||||||
((scrolledList.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 0) -> 255
|
((scrolledList.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 0) -> 1F
|
||||||
|
|
||||||
// Based on scroll amount when first item is in view
|
// Based on scroll amount when first item is in view
|
||||||
else -> min(scrolledList.computeVerticalScrollOffset(), 255)
|
else -> min(scrolledList.computeVerticalScrollOffset(), 255) / 255F
|
||||||
}
|
}
|
||||||
|
|
||||||
(activity as? MainActivity)?.binding?.toolbar?.setTitleTextColor(
|
|
||||||
Color.argb(
|
|
||||||
calculatedAlpha,
|
|
||||||
toolbarTextColor.red,
|
|
||||||
toolbarTextColor.green,
|
|
||||||
toolbarTextColor.blue
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFilterIconState() {
|
private fun updateFilterIconState() {
|
||||||
|
@ -362,7 +354,8 @@ class MangaController :
|
||||||
chaptersAdapter = null
|
chaptersAdapter = null
|
||||||
settingsSheet = null
|
settingsSheet = null
|
||||||
addSnackbar?.dismiss()
|
addSnackbar?.dismiss()
|
||||||
updateToolbarTitleAlpha(255)
|
updateToolbarTitleAlpha(1F)
|
||||||
|
toolbarTextView = null
|
||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue