KidsTube: readable tiles, likes-only "Your stuff"

Three fixes from looking at the running app.

- Tiles take their full grid cell again. Sizing them from the available height
  to force three rows made them half a cell wide, and the wide gaps read as a
  zoomed-out page with tiny type. Full-width tiles, third row by scrolling.
- Tile title size now follows the tile height between 11sp and 17sp, with one
  line on short tiles, so the type can never collapse.
- "Your stuff" listed the whole library: selectTab cleared the search field, the
  watcher fired applyFilter("") and refilled the result list after the likes had
  been submitted. The watcher now only acts on the search tab, and the field is
  cleared before the tab's own list is submitted.

Verified on the device: grid is 3 columns filling the cells (22px gaps, titles
readable, confirmed by measurement and by reading the screenshot), and "Your
stuff" shows exactly the one liked video while the likes table holds one row.
The heart-toggle round trip is not re-verified yet: the tablet dropped off the
USB bus again before that tap sequence finished.
This commit is contained in:
lotherk committed 2026-10-28 15:38:03 +00:00
1 parent d9f7f3dc30
commit 2b5505578a
4 files changed
+60 -32

No files matched your search

+9 -3
View File
@@ -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
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 837 KiB

@@ -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() }
}
@@ -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()