瀏覽代碼

Use correct color for reader loading indicator (#5645)

Night theme color will be used when black or gray background color is used.
Ivan Iskandar 3 年之前
父節點
當前提交
7a1b6142df

+ 15 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt

@@ -16,6 +16,7 @@ import android.graphics.Paint
 import android.graphics.PorterDuff
 import android.os.Build
 import android.os.Bundle
+import android.view.Gravity
 import android.view.KeyEvent
 import android.view.Menu
 import android.view.MenuItem
@@ -24,6 +25,7 @@ import android.view.View.LAYER_TYPE_HARDWARE
 import android.view.WindowManager
 import android.view.animation.Animation
 import android.view.animation.AnimationUtils
+import android.widget.FrameLayout
 import android.widget.SeekBar
 import android.widget.Toast
 import androidx.core.graphics.ColorUtils
@@ -32,6 +34,7 @@ import androidx.core.view.WindowInsetsCompat
 import androidx.core.view.WindowInsetsControllerCompat
 import androidx.core.view.isInvisible
 import androidx.core.view.isVisible
+import androidx.core.view.updateLayoutParams
 import androidx.lifecycle.lifecycleScope
 import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
 import com.google.android.material.shape.MaterialShapeDrawable
@@ -59,9 +62,11 @@ import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
 import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsSheet
 import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
 import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
+import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
 import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
 import eu.kanade.tachiyomi.util.storage.getUriCompat
 import eu.kanade.tachiyomi.util.system.GLUtil
+import eu.kanade.tachiyomi.util.system.createReaderThemeContext
 import eu.kanade.tachiyomi.util.system.hasDisplayCutout
 import eu.kanade.tachiyomi.util.system.isNightMode
 import eu.kanade.tachiyomi.util.system.toast
@@ -137,6 +142,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
 
     private val windowInsetsController by lazy { WindowInsetsControllerCompat(window, binding.root) }
 
+    private var loadingIndicator: ReaderProgressIndicator? = null
+
     var isScrollingThroughPages = false
         private set
 
@@ -600,8 +607,13 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
             binding.rightChapter.setTooltip(R.string.action_next_chapter)
         }
 
-        binding.pleaseWait.isVisible = true
-        binding.pleaseWait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long))
+        val loadingIndicatorContext = createReaderThemeContext(preferences.readerTheme().get())
+        loadingIndicator = ReaderProgressIndicator(loadingIndicatorContext).apply {
+            updateLayoutParams<FrameLayout.LayoutParams> {
+                gravity = Gravity.CENTER
+            }
+        }
+        binding.readerContainer.addView(loadingIndicator)
     }
 
     private fun showReadingModeToast(mode: Int) {
@@ -620,7 +632,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
      * hides or disables the reader prev/next buttons if there's a prev or next chapter
      */
     fun setChapters(viewerChapters: ViewerChapters) {
-        binding.pleaseWait.isVisible = false
+        binding.readerContainer.removeView(loadingIndicator)
         viewer?.setChapters(viewerChapters)
         binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name
 

+ 10 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt

@@ -23,6 +23,9 @@ class PagerConfig(
     preferences: PreferencesHelper = Injekt.get()
 ) : ViewerConfig(preferences, scope) {
 
+    var theme = preferences.readerTheme().get()
+        private set
+
     var automaticBackground = false
         private set
 
@@ -39,7 +42,13 @@ class PagerConfig(
 
     init {
         preferences.readerTheme()
-            .register({ automaticBackground = it == 3 }, { imagePropertyChangedListener?.invoke() })
+            .register(
+                {
+                    theme = it
+                    automaticBackground = it == 3
+                },
+                { imagePropertyChangedListener?.invoke() }
+            )
 
         preferences.imageScaleType()
             .register({ imageScaleType = it }, { imagePropertyChangedListener?.invoke() })

+ 8 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt

@@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
 import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.ZoomType
 import eu.kanade.tachiyomi.ui.webview.WebViewActivity
 import eu.kanade.tachiyomi.util.system.ImageUtil
+import eu.kanade.tachiyomi.util.system.createReaderThemeContext
 import eu.kanade.tachiyomi.util.system.dpToPx
 import eu.kanade.tachiyomi.widget.ViewPagerAdapter
 import rx.Observable
@@ -58,11 +59,7 @@ class PagerPageHolder(
     /**
      * Loading progress bar to indicate the current progress.
      */
-    private val progressIndicator = ReaderProgressIndicator(context).apply {
-        updateLayoutParams<LayoutParams> {
-            gravity = Gravity.CENTER
-        }
-    }
+    private val progressIndicator: ReaderProgressIndicator
 
     /**
      * Image view that supports subsampling on zoom.
@@ -118,6 +115,12 @@ class PagerPageHolder(
     }
 
     init {
+        val indicatorContext = context.createReaderThemeContext(viewer.config.theme)
+        progressIndicator = ReaderProgressIndicator(indicatorContext).apply {
+            updateLayoutParams<LayoutParams> {
+                gravity = Gravity.CENTER
+            }
+        }
         addView(progressIndicator)
         observeStatus()
         viewer.activity.addOnMenuVisibilityListener(visibilityListener)

+ 6 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt

@@ -28,6 +28,9 @@ class WebtoonConfig(
     var sidePadding = 0
         private set
 
+    var theme = preferences.readerTheme().get()
+        private set
+
     init {
         preferences.cropBordersWebtoon()
             .register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
@@ -50,6 +53,9 @@ class WebtoonConfig(
 
         preferences.dualPageInvertWebtoon()
             .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() })
+
+        preferences.readerTheme()
+            .register({ theme = it }, { imagePropertyChangedListener?.invoke() })
     }
 
     override var navigator: ViewerNavigation = defaultNavigation()

+ 3 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt

@@ -27,6 +27,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
 import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
 import eu.kanade.tachiyomi.ui.webview.WebViewActivity
 import eu.kanade.tachiyomi.util.system.ImageUtil
+import eu.kanade.tachiyomi.util.system.createReaderThemeContext
 import eu.kanade.tachiyomi.util.system.dpToPx
 import rx.Observable
 import rx.Subscription
@@ -345,7 +346,8 @@ class WebtoonPageHolder(
         progressContainer = FrameLayout(context)
         frame.addView(progressContainer, MATCH_PARENT, parentHeight)
 
-        val progress = ReaderProgressIndicator(context).apply {
+        val indicatorContext = context.createReaderThemeContext(viewer.config.theme)
+        val progress = ReaderProgressIndicator(indicatorContext).apply {
             updateLayoutParams<FrameLayout.LayoutParams> {
                 gravity = Gravity.CENTER_HORIZONTAL
                 updateMargins(top = parentHeight / 4)

+ 21 - 0
app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt

@@ -284,3 +284,24 @@ fun Context.isTablet(): Boolean {
 fun Context.isNightMode(): Boolean {
     return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
 }
+
+/**
+ * Creates night mode Context depending on reader theme/background
+ */
+fun Context.createReaderThemeContext(readerThemeSelected: Int): Context {
+    val isDarkBackground = when (readerThemeSelected) {
+        1, 2 -> true // Black, Gray
+        3 -> isNightMode() // Automatic bg uses activity background by default
+        else -> false // White
+    }
+    val expected = if (isDarkBackground) Configuration.UI_MODE_NIGHT_YES else Configuration.UI_MODE_NIGHT_NO
+    if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK != expected) {
+        val overrideConfig = Configuration(resources.configuration).apply {
+            uiMode = (uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()) or expected
+        }
+        return createConfigurationContext(overrideConfig).also {
+            it.theme.setTo(theme)
+        }
+    }
+    return this
+}

+ 0 - 9
app/src/main/res/layout/reader_activity.xml

@@ -15,15 +15,6 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent" />
 
-        <com.google.android.material.progressindicator.CircularProgressIndicator
-            android:id="@+id/please_wait"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center"
-            android:indeterminate="true"
-            android:visibility="gone"
-            tools:visibility="visible" />
-
         <eu.kanade.tachiyomi.ui.reader.PageIndicatorTextView
             android:id="@+id/page_number"
             style="@style/TextAppearance.Regular.Caption"