Skip to content

Commit

Permalink
Highlight original status and series type in edit manga dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Jays2Kings committed Apr 9, 2022
1 parent 39a2f4a commit 9e86556
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import eu.kanade.tachiyomi.data.image.coil.MangaFetcher
import eu.kanade.tachiyomi.data.image.coil.loadManga
import eu.kanade.tachiyomi.databinding.EditMangaDialogBinding
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.icon
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.isLocal
import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.isInNightMode
import eu.kanade.tachiyomi.util.system.materialAlertDialog
Expand Down Expand Up @@ -124,6 +127,15 @@ class EditMangaDialog : DialogController {
}
}
setGenreTags(manga.getGenres().orEmpty())
if (!isLocal) {
binding.mangaStatus.originalPosition = manga.originalStatus
binding.seriesType.originalPosition = manga.seriesType(true) - 1
infoController.presenter.source.icon()?.let { icon ->
val bitD = ImageUtil.resizeBitMapDrawable(icon, resources, 24.dpToPx)
binding.mangaStatus.originalIcon = bitD ?: icon
binding.seriesType.originalIcon = bitD ?: icon
}
}
binding.mangaStatus.setSelection(manga.status.coerceIn(SManga.UNKNOWN, SManga.ON_HIATUS))
val oldType = manga.seriesType()
binding.seriesType.setSelection(oldType - 1)
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package eu.kanade.tachiyomi.util.system

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
Expand Down Expand Up @@ -53,6 +55,17 @@ object ImageUtil {
return null
}

fun resizeBitMapDrawable(drawable: Drawable, resources: Resources?, size: Int): Drawable? {
val b = (drawable as? BitmapDrawable)?.bitmap
val bitmapResized: Bitmap? = if (b != null) {
Bitmap.createScaledBitmap(b, size, size, false)
} else {
null
}
return if (bitmapResized != null) BitmapDrawable(resources, bitmapResized)
else null
}

fun isAnimatedAndSupported(stream: InputStream): Boolean {
try {
val type = getImageType(stream) ?: return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) :
private var entries = emptyList<String>()
var selectedPosition = 0
private set
var originalPosition: Int? = null
var originalIcon: Drawable? = null
private var pref: Preference<Int>? = null
private var prefOffset = 0
private var popup: PopupMenu? = null
Expand All @@ -47,6 +49,14 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) :
0.5f
)

private val slightAccent by lazy {
ColorUtils.blendARGB(
context.getResourceColor(R.attr.colorSecondary),
context.getResourceColor(R.attr.colorOnBackground),
0.9f
)
}

var onItemSelectedListener: ((Int) -> Unit)? = null
set(value) {
field = value
Expand Down Expand Up @@ -115,6 +125,7 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) :
it.title = it.title?.tintText(blendedAccent)
}
}
updateOriginalPositionMenu()
binding.detailView.text = entries.getOrNull(selection).orEmpty()
}

Expand Down Expand Up @@ -253,10 +264,30 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) :
menuItem.title =
menuItem.title?.tintText(blendedAccent)
}
updateOriginalPositionMenu()
this.popup = popup
return popup
}

private fun updateOriginalPositionMenu() {
popup ?: return
val originalPosition = originalPosition ?: return
if (originalPosition != selectedPosition &&
originalPosition >= 0 && originalPosition < popup?.menu?.size() ?: 0
) {
popup?.menu?.getItem(originalPosition)?.let { menuItem ->
menuItem.icon = tintedOG()
menuItem
}
}
}

private fun tintedOG(): Drawable? {
return originalIcon ?: ContextCompat.getDrawable(context, R.drawable.ic_browse_outline_24dp)?.mutate()?.apply {
setTint(slightAccent)
}
}

private fun tintedCheck(): Drawable? {
return ContextCompat.getDrawable(context, R.drawable.ic_check_24dp)?.mutate()?.apply {
setTint(blendedAccent)
Expand Down

0 comments on commit 9e86556

Please sign in to comment.