Main activity theming

This commit is contained in:
Zakhar Timoshenko
2023-06-30 21:27:20 +03:00
parent 0098bdd07e
commit f01fd18711
26 changed files with 267 additions and 166 deletions

View File

@@ -28,13 +28,12 @@ class SegmentedBarView @JvmOverloads constructor(
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val segmentsData = ArrayList<Segment>()
private val segmentsSizes = ArrayList<Float>()
private val outlineColor = context.getThemeColor(materialR.attr.colorOutline)
private var cornerSize = 0f
private var scaleFactor = 1f
private var scaleAnimator: ValueAnimator? = null
init {
paint.strokeWidth = context.resources.resolveDp(1f)
paint.strokeWidth = context.resources.resolveDp(0f)
outlineProvider = OutlineProvider()
clipToOutline = true
}
@@ -57,12 +56,10 @@ class SegmentedBarView @JvmOverloads constructor(
paint.style = Paint.Style.FILL
val segmentWidth = segmentsSizes[i]
canvas.drawRoundRect(0f, 0f, x + cornerSize, height.toFloat(), cornerSize, cornerSize, paint)
paint.color = outlineColor
paint.style = Paint.Style.STROKE
canvas.drawRoundRect(0f, 0f, x + cornerSize, height.toFloat(), cornerSize, cornerSize, paint)
x -= segmentWidth
}
paint.color = outlineColor
paint.style = Paint.Style.STROKE
canvas.drawRoundRect(0f, 0f, w, height.toFloat(), cornerSize, cornerSize, paint)
}

View File

@@ -105,12 +105,12 @@ class ExploreFragment :
R.id.button_history -> HistoryActivity.newIntent(v.context)
R.id.button_local -> MangaListActivity.newIntent(v.context, MangaSource.LOCAL)
R.id.button_bookmarks -> BookmarksActivity.newIntent(v.context)
R.id.button_suggestions -> SuggestionsActivity.newIntent(v.context)
//R.id.button_suggestions -> SuggestionsActivity.newIntent(v.context)
R.id.button_favourites -> FavouriteCategoriesActivity.newIntent(v.context)
R.id.button_random -> {
viewModel.openRandom()
return
}
//R.id.button_random -> {
// viewModel.openRandom()
// return
//}
else -> return
}

View File

@@ -33,13 +33,13 @@ fun exploreButtonsAD(
binding.buttonBookmarks.setOnClickListener(clickListener)
binding.buttonHistory.setOnClickListener(clickListener)
binding.buttonLocal.setOnClickListener(clickListener)
binding.buttonSuggestions.setOnClickListener(clickListener)
//binding.buttonSuggestions.setOnClickListener(clickListener)
binding.buttonFavourites.setOnClickListener(clickListener)
binding.buttonRandom.setOnClickListener(clickListener)
//binding.buttonRandom.setOnClickListener(clickListener)
bind {
binding.buttonSuggestions.isVisible = item.isSuggestionsEnabled
}
//bind {
// binding.buttonSuggestions.isVisible = item.isSuggestionsEnabled
//}
}
fun exploreSourcesHeaderAD(

View File

@@ -364,7 +364,7 @@ class MainActivity :
viewBinding.toolbarCard.background = if (isOpened) {
null
} else {
ContextCompat.getDrawable(this, R.drawable.toolbar_background)
ContextCompat.getDrawable(this, R.drawable.search_bar_background)
}
val padding = if (isOpened) 0 else resources.getDimensionPixelOffset(R.dimen.margin_normal)
viewBinding.appbar.updatePadding(left = padding, right = padding)

View File

@@ -2,14 +2,18 @@ package org.koitharu.kotatsu.settings.tools.views
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.core.widget.TextViewCompat
import com.google.android.material.color.MaterialColors
import okio.ByteString.Companion.decodeHex
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.ui.widgets.SegmentedBarView
import org.koitharu.kotatsu.core.util.FileSize
@@ -17,6 +21,7 @@ import org.koitharu.kotatsu.core.util.ext.getThemeColor
import org.koitharu.kotatsu.databinding.LayoutMemoryUsageBinding
import org.koitharu.kotatsu.settings.tools.model.StorageUsage
class MemoryUsageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
@@ -35,9 +40,9 @@ class MemoryUsageView @JvmOverloads constructor(
}
fun bind(usage: StorageUsage?) {
val storageSegment = SegmentedBarView.Segment(usage?.savedManga?.percent ?: 0f, segmentColor(1))
val pagesSegment = SegmentedBarView.Segment(usage?.pagesCache?.percent ?: 0f, segmentColor(2))
val otherSegment = SegmentedBarView.Segment(usage?.otherCache?.percent ?: 0f, segmentColor(3))
val storageSegment = SegmentedBarView.Segment(usage?.savedManga?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorPrimary))
val pagesSegment = SegmentedBarView.Segment(usage?.pagesCache?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorSecondary))
val otherSegment = SegmentedBarView.Segment(usage?.otherCache?.percent ?: 0f, segmentColor(com.google.android.material.R.attr.colorTertiary))
with(binding) {
bar.animateSegments(listOf(storageSegment, pagesSegment, otherSegment).filter { it.percent > 0f })
@@ -67,11 +72,26 @@ class MemoryUsageView @JvmOverloads constructor(
}
}
private fun getHue(hex: String): Float {
val r = (hex.substring(0, 2).toInt(16)).toFloat()
val g = (hex.substring(2, 4).toInt(16)).toFloat()
val b = (hex.substring(4, 6).toInt(16)).toFloat()
var hue = 0F
if ((r >= g) && (g >= b)) {
hue = 60 * (g - b) / (r - b)
} else if ((g > r) && (r >= b)) {
hue = 60 * (2 - (r - b) / (g - b))
}
return hue
}
@ColorInt
private fun segmentColor(i: Int): Int {
val hue = (93.6f * i) % 360
val color = ColorUtils.HSLToColor(floatArrayOf(hue, 0.4f, 0.6f))
val backgroundColor = context.getThemeColor(com.google.android.material.R.attr.colorSecondaryContainer)
private fun segmentColor(@AttrRes resId: Int): Int {
val colorHex = String.format("%06x", context.getThemeColor(resId))
val hue = getHue(colorHex)
val color = ColorUtils.HSLToColor(floatArrayOf(hue, 0.5f, 0.5f))
val backgroundColor = context.getThemeColor(com.google.android.material.R.attr.colorSurfaceContainerHigh)
return MaterialColors.harmonize(color, backgroundColor)
}
}