diff --git a/AGENTS.md b/AGENTS.md index 096b5fd..a1a469b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,9 +17,11 @@ landscape is the layout that must not break. Portrait must still work. `/home/lotherk/android-sdk/build-tools/35.0.0/aapt2 dump permissions app/build/outputs/apk/debug/app-debug.apk` lists only the two storage permissions. - `minSdk` stays `21`. Check every new AAR's `minSdk` before adding it. -- Grid is always **3 columns**, and exactly **3 rows must fit** the landscape - screen without scrolling. The title lives *inside* the tile — a caption row - below it costs the height those three rows need. +- Grid is always **3 columns** and tiles take their full cell width. The title + lives *inside* the tile. Three rows of 16:9 tiles cannot fit a landscape screen + next to top bar, pills and tab bar (they need ~340dp, the grid has ~216dp), so + the third row is reached by scrolling rather than by shrinking the tiles — + half-width tiles with wide gaps read as a zoomed-out page. - When the choice is "Material default" vs "the iOS app's proportions", take iOS. ## Environment (this machine, verified) @@ -85,6 +87,10 @@ Mandatory: from API 29 scoped storage forbids directory listing (the app uid get - Never size tiles from whichever list is visible: the search tab is shorter (56dp bar) and shrank the tiles for every tab. +- The search `TextWatcher` must not run on other tabs. `selectTab` clears the + field, that fires `afterTextChanged`, and an unguarded `applyFilter("")` refills + the result list with the whole library — which is why "Your stuff" showed every + video. Clear the field first, submit the tab's own list afterwards. - `VideoView` swallows touches; the player needs the transparent `tap_catcher` to bring the chrome back. - Tint AppCompat widgets with `app:tint`, never `android:tint` — lint fails on diff --git a/G2.png b/G2.png new file mode 100644 index 0000000..563aa79 Binary files /dev/null and b/G2.png differ diff --git a/app/src/main/java/dev/lotherk/kidstube/ui/MainActivity.kt b/app/src/main/java/dev/lotherk/kidstube/ui/MainActivity.kt index c5a3f48..855141b 100644 --- a/app/src/main/java/dev/lotherk/kidstube/ui/MainActivity.kt +++ b/app/src/main/java/dev/lotherk/kidstube/ui/MainActivity.kt @@ -79,7 +79,11 @@ class MainActivity : AppCompatActivity() { binding.searchInput.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, a: Int, b: Int, c: Int) = Unit override fun onTextChanged(s: CharSequence?, a: Int, b: Int, c: Int) = Unit - override fun afterTextChanged(s: Editable?) = applyFilter(s?.toString().orEmpty()) + override fun afterTextChanged(s: Editable?) { + // Only the search tab owns this list; clearing the field while + // switching to another tab used to refill it with everything. + if (activeTab == 1) applyFilter(s?.toString().orEmpty()) + } }) binding.grid.post { layoutTiles() } @@ -92,31 +96,26 @@ class MainActivity : AppCompatActivity() { private fun columns(): Int = 3 /** - * Tiles are sized from the available height so exactly three rows fit; the - * leftover width becomes the gaps (see [TileSpacing]). + * Tiles take their cell's width, so the grid looks like the reference instead + * of a zoomed-out page with wide gaps. + * + * Three rows of 16:9 tiles do NOT fit a landscape screen next to the top + * bar, pills and tab bar (3 x ~113dp needs ~340dp, the grid has ~216dp). + * Filling the width is what keeps the type at a readable size; the third row + * is reached by scrolling. */ private fun layoutTiles() { - // Always measure the home grid: the other tabs have a shorter content - // area (search bar) and must not shrink the tiles for everybody. - val source = binding.grid - val width = source.width - val height = source.height - if (width <= 0 || height <= 0) return + val width = binding.grid.width + if (width <= 0) return val density = resources.displayMetrics.density - val rowGap = (8 * density).roundToInt() - val cell = width / columns() - // Every row carries a bottom gap, including the last, and the list has - // its own padding — both must come off before dividing by three, or the - // third row ends up under the tab bar. - val usable = height - source.paddingTop - source.paddingBottom - 3 * rowGap - val byHeight = ((usable / 3.0) * 16.0 / 9.0).toInt() - val tile = min(cell, byHeight).coerceAtLeast((120 * density).roundToInt()) + val gap = (10 * density).roundToInt() + val tile = (width - binding.grid.paddingStart - binding.grid.paddingEnd) / columns() - gap if (tile <= 0 || tile == currentTileWidth) return currentTileWidth = tile for (list in listOf(binding.grid, binding.results)) { while (list.itemDecorationCount > 0) list.removeItemDecorationAt(0) - list.addItemDecoration(TileSpacing(columns(), tile, rowGap)) + list.addItemDecoration(TileSpacing(columns(), tile, gap)) } gridAdapter.tileWidth = tile resultsAdapter.tileWidth = tile @@ -213,12 +212,12 @@ class MainActivity : AppCompatActivity() { binding.grid.visibility = if (index == 0) View.VISIBLE else View.GONE binding.chips.visibility = if (index == 0) View.VISIBLE else View.GONE + // Clear first, fill after: setText fires the watcher. + if (index != 1) binding.searchInput.setText("") when (index) { 1 -> binding.searchInput.requestFocus() 2 -> resultsAdapter.submit(stats.likedItems(), stats.likedKeys()) - else -> binding.searchInput.setText("") } - if (index != 1) binding.searchInput.setText("") refreshEmptyState() binding.grid.post { layoutTiles() } } diff --git a/app/src/main/java/dev/lotherk/kidstube/ui/TileView.kt b/app/src/main/java/dev/lotherk/kidstube/ui/TileView.kt index ad21f49..781358a 100644 --- a/app/src/main/java/dev/lotherk/kidstube/ui/TileView.kt +++ b/app/src/main/java/dev/lotherk/kidstube/ui/TileView.kt @@ -39,7 +39,6 @@ class TileView @JvmOverloads constructor( private val pillPadH = 5f * density private val pillPadV = 2f * density private val textPad = 8f * density - private val scrimHeight = 34f * density private val bitmapPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG) private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { @@ -55,9 +54,13 @@ class TileView @JvmOverloads constructor( } private val titlePaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.WHITE - textSize = 12f * density + textSize = 14f * density typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD) } + + /** Fitted title size; 0 means "not computed for this height yet". */ + private var titleSize = 0f + private var titleLines = 2 private val heartPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = ContextCompat.getColor(context, R.color.kt_red) } @@ -72,6 +75,7 @@ class TileView @JvmOverloads constructor( private val scrimPaint = Paint() private var scrimFor = 0 + private var scrimTop = 0f private var layout: StaticLayout? = null private var layoutFor: String? = null @@ -114,18 +118,22 @@ class TileView @JvmOverloads constructor( canvas.drawBitmap(bmp, scaleMatrix, bitmapPaint) } + fitTitle(h) val text = layoutFor(w, title) if (text != null) { - val heightKey = height - if (scrimFor != heightKey) { + // The scrim follows the text, never a fixed strip: a two-line title + // in a small tile would otherwise sit half outside its backing. + scrimTop = h - text.height - textPad + val shaderKey = (scrimTop.toInt() shl 16) or height + if (scrimFor != shaderKey) { scrimPaint.shader = LinearGradient( - 0f, h - scrimHeight, 0f, h, - intArrayOf(0x00000000, 0xB3000000.toInt()), + 0f, scrimTop - textPad, 0f, h, + intArrayOf(0x00000000, 0xC0000000.toInt()), null, Shader.TileMode.CLAMP ) - scrimFor = heightKey + scrimFor = shaderKey } - canvas.drawRect(0f, h - scrimHeight, w, h, scrimPaint) + canvas.drawRect(0f, scrimTop - textPad, w, h, scrimPaint) canvas.save() canvas.translate(textPad, h - text.height.toFloat() - textPad * 0.5f) text.draw(canvas) @@ -137,6 +145,21 @@ class TileView @JvmOverloads constructor( if (liked) drawHeart(canvas, w) } + /** + * The title is drawn inside the tile, so its size has to follow the tile + * height — but only downwards to a legible floor. A small tile gets one + * line instead of two, never microscopic type. + */ + private fun fitTitle(tileHeight: Float) { + val target = (tileHeight * 0.16f).coerceIn(11f * density, 17f * density) + val lines = if (tileHeight < 76f * density) 1 else 2 + if (target == titleSize && lines == titleLines) return + titleSize = target + titleLines = lines + titlePaint.textSize = target + layout = null + } + private fun layoutFor(width: Float, text: CharSequence?): StaticLayout? { if (text.isNullOrEmpty()) return null val available = (width - 2 * textPad).roundToInt() @@ -148,7 +171,7 @@ class TileView @JvmOverloads constructor( ?: text val built = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { StaticLayout.Builder.obtain(ellipsized, 0, ellipsized.length, titlePaint, available) - .setMaxLines(2) + .setMaxLines(titleLines) .setEllipsize(TextUtils.TruncateAt.END) .setAlignment(Layout.Alignment.ALIGN_NORMAL) .build()