aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt39
1 files changed, 22 insertions, 17 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
index ef82b3f5..e62be3e2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
@@ -67,6 +67,14 @@ import com.pitchedapps.frost.utils.isIndirectImageUrl
import com.pitchedapps.frost.utils.logFrostEvent
import com.pitchedapps.frost.utils.sendFrostEmail
import com.pitchedapps.frost.utils.setFrostColors
+import kotlinx.coroutines.CoroutineExceptionHandler
+import kotlinx.coroutines.Deferred
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.async
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import org.koin.core.KoinComponent
+import org.koin.core.inject
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
@@ -75,17 +83,13 @@ import java.util.Date
import java.util.Locale
import kotlin.math.abs
import kotlin.math.max
-import kotlinx.coroutines.CoroutineExceptionHandler
-import kotlinx.coroutines.Deferred
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.async
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
/**
* Created by Allan Wang on 2017-07-15.
*/
-class ImageActivity : KauBaseActivity() {
+class ImageActivity : KauBaseActivity(), KoinComponent {
+
+ private val prefs: Prefs by inject()
@Volatile
internal var errorRef: Throwable? = null
@@ -106,7 +110,7 @@ class ImageActivity : KauBaseActivity() {
set(value) {
if (field == value) return
field = value
- value.update(binding.imageFab)
+ value.update(binding.imageFab, prefs)
}
private lateinit var dragHelper: ViewDragHelper
@@ -144,8 +148,8 @@ class ImageActivity : KauBaseActivity() {
private lateinit var binding: ActivityImageBinding
private var bottomBehavior: BottomSheetBehavior<View>? = null
- private val baseBackgroundColor = if (Prefs.blackMediaBg) Color.BLACK
- else Prefs.bgColor.withMinAlpha(235)
+ private val baseBackgroundColor = if (prefs.blackMediaBg) Color.BLACK
+ else prefs.bgColor.withMinAlpha(235)
private fun loadError(e: Throwable) {
if (e.message?.contains("<!DOCTYPE html>") == true) {
@@ -195,9 +199,9 @@ class ImageActivity : KauBaseActivity() {
if (text.isNullOrBlank()) {
imageText.gone()
} else {
- imageText.setTextColor(if (Prefs.blackMediaBg) Color.WHITE else Prefs.textColor)
+ imageText.setTextColor(if (prefs.blackMediaBg) Color.WHITE else prefs.textColor)
imageText.setBackgroundColor(
- (if (Prefs.blackMediaBg) Color.BLACK else Prefs.bgColor)
+ (if (prefs.blackMediaBg) Color.BLACK else prefs.bgColor)
.colorToForeground(0.2f).withAlpha(255)
)
imageText.text = text
@@ -217,7 +221,7 @@ class ImageActivity : KauBaseActivity() {
imageText.bringToFront()
}
}
- imageProgress.tint(if (Prefs.blackMediaBg) Color.WHITE else Prefs.accentColor)
+ imageProgress.tint(if (prefs.blackMediaBg) Color.WHITE else prefs.accentColor)
imageFab.setOnClickListener { fabAction.onClick(this@ImageActivity) }
imagePhoto.setOnImageEventListener(object :
SubsamplingScaleImageView.DefaultOnImageEventListener() {
@@ -405,10 +409,10 @@ class ImageActivity : KauBaseActivity() {
internal enum class FabStates(
val iicon: IIcon,
- val iconColor: Int = Prefs.iconColor,
+ val iconColorProvider: (Prefs) -> Int = { it.iconColor },
val backgroundTint: Int = Int.MAX_VALUE
) {
- ERROR(GoogleMaterial.Icon.gmd_error, Color.WHITE, Color.RED) {
+ ERROR(GoogleMaterial.Icon.gmd_error, { Color.WHITE }, Color.RED) {
override fun onClick(activity: ImageActivity) {
val err =
activity.errorRef?.takeIf { it !is FileNotFoundException && it.message != "Image failed to decode using JPEG decoder" }
@@ -460,8 +464,9 @@ internal enum class FabStates(
* https://github.com/AllanWang/KAU/issues/184
*
*/
- fun update(fab: FloatingActionButton) {
- val tint = if (backgroundTint != Int.MAX_VALUE) backgroundTint else Prefs.accentColor
+ fun update(fab: FloatingActionButton, prefs: Prefs) {
+ val tint = if (backgroundTint != Int.MAX_VALUE) backgroundTint else prefs.accentColor
+ val iconColor = iconColorProvider(prefs)
if (fab.isHidden) {
fab.setIcon(iicon, color = iconColor)
fab.backgroundTintList = ColorStateList.valueOf(tint)