From 4de996711fb1d440cacb0508f486985b274f56a9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 4 Aug 2021 22:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/BaseActivity.kt | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 306e61943..1d8b1f7cf 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -12,7 +12,6 @@ import android.view.MenuItem import android.view.View import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity -import androidx.preference.PreferenceManager import androidx.viewbinding.ViewBinding import com.google.android.renderscript.Toolkit import io.legado.app.App @@ -180,7 +179,9 @@ abstract class BaseActivity( } if (imageBg) { try { - window.decorView.background = BitmapDrawable(resources, getBackgroundImage(ThemeConfig.getBgImage(this) ?: return)) + getBackgroundImage()?.let { + window.decorView.background = BitmapDrawable(resources, it) + } } catch (e: OutOfMemoryError) { toastOnUi(e.localizedMessage) } catch (e: Exception) { @@ -189,20 +190,14 @@ abstract class BaseActivity( } } - private fun getBackgroundImage(bitmap: Bitmap): Bitmap { - when (Theme.getTheme()) { - Theme.Light -> PreferenceManager.getDefaultSharedPreferences(this).getInt(bgImageBlurring, 0).apply { - if (this != 0) { - return Toolkit.blur(bitmap, this) - } - } - Theme.Dark -> PreferenceManager.getDefaultSharedPreferences(this).getInt(bgImageNBlurring, 0).apply { - if (this != 0) { - return Toolkit.blur(bitmap, this) - } - } + private fun getBackgroundImage(): Bitmap? { + val bgImage = ThemeConfig.getBgImage(this) ?: return null + val blur = if (AppConfig.isNightTheme) { + getPrefInt(bgImageBlurring, 0) + } else { + getPrefInt(bgImageNBlurring, 0) } - return bitmap + return Toolkit.blur(bgImage, blur) } private fun setupSystemBar() {