KidsTube: offline iOS-look kids player for local videos
Scaffold and first working build of an Android app that reproduces the iOS YouTube Kids interface over a local folder: shelves of 16:9 rounded thumbnails, fullscreen player, bottom bar, search grid and a parent gate. - minSdk 21, AGP 8.13.2 / Gradle 8.13 / Kotlin 2.1.20, compileSdk 35 - library from Movies/KidsTube via MediaStore, or a SAF tree the parent picks - no INTERNET permission: verified against the built APK with aapt2 - thumbnails decoded once into filesDir and cached, never on the bind path - player: VideoView, immersive, chrome auto-hides, tap_catcher restores it Verified on the AGS2-W09 (API 30): shelves with real frames, playback, search filtering, parent gate, back navigation.
This commit is contained in:
commit
ec3fd61756
39 files changed
+2054
No files matched your search
+11
@@ -0,0 +1,11 @@
|
||||
*.iml
|
||||
.gradle/
|
||||
/local.properties
|
||||
/.idea/
|
||||
.DS_Store
|
||||
/build
|
||||
/app/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
@@ -0,0 +1,106 @@
|
||||
# KidsTube
|
||||
|
||||
Android app that reproduces the **iOS** YouTube Kids interface — thumbnail
|
||||
shelves, fullscreen player, bottom bar — while playing video from a **local
|
||||
folder only**. No network, no account, no recommendations. It exists because the
|
||||
son accepts the iOS kids UI and rejects the Android one, so this is a convincing
|
||||
shell around local files. Floor: Android 5.0 / API 21. App name: KidsTube.
|
||||
|
||||
State 2026-10-28: builds, installs and plays on the target tablet; shelves,
|
||||
search, player and the parent gate were verified on the device.
|
||||
|
||||
## Non-negotiables
|
||||
|
||||
- No network. The APK must carry no `INTERNET` permission and no HTTP client:
|
||||
`unzip -p app/build/outputs/apk/debug/app-debug.apk AndroidManifest.xml | strings | grep -ci internet`
|
||||
must print `0`, and
|
||||
`/home/lotherk/android-sdk/build-tools/35.0.0/aapt2 dump permissions app/build/outputs/apk/debug/app-debug.apk`
|
||||
must list only the two storage permissions.
|
||||
- `minSdk` stays 21. Check any new AAR's `minSdk` before adding it — much of
|
||||
current androidx sits at 23+.
|
||||
- When the choice is "Material default" vs "the iOS app's proportions", take iOS.
|
||||
|
||||
## Environment (this machine, verified)
|
||||
|
||||
- JDK 21 (`/usr/lib/jvm/java-21-openjdk-amd64`); no JDK 8 or 17 installed.
|
||||
- SDK lives in `/home/lotherk/android-sdk` (user-local). The distro's
|
||||
`/usr/lib/android-sdk` has no `platforms/` or `build-tools/`, and its bundled
|
||||
`sdkmanager`/`apkanalyzer` die on JDK 21 with `NoClassDefFoundError:
|
||||
javax/xml/bind/annotation/XmlSchema` (JAXB removed in JDK 11) — do not use it.
|
||||
- `gradle` is not on PATH; the standalone distribution is
|
||||
`/home/lotherk/android-tools/gradle-8.13`. The wrapper is pinned to 8.13 and
|
||||
`local.properties` points at the SDK.
|
||||
- AGP 8.13.2, Kotlin 2.1.20, compileSdk 35, build-tools 35.0.0. AGP 8.13 requires
|
||||
Gradle >= 8.13, Build-Tools >= 35.0.0, JDK >= 17.
|
||||
|
||||
## Build, install, run
|
||||
|
||||
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
|
||||
export ANDROID_HOME=/home/lotherk/android-sdk
|
||||
|
||||
./gradlew :app:assembleDebug # apk -> app/build/outputs/apk/debug/
|
||||
./gradlew :app:lintDebug # must stay green; abortOnError = true
|
||||
adb install -r app/build/outputs/apk/debug/app-debug.apk
|
||||
adb shell pm grant dev.lotherk.kidstube android.permission.READ_EXTERNAL_STORAGE
|
||||
adb shell am start -n dev.lotherk.kidstube/.ui.MainActivity
|
||||
adb exec-out screencap -p > /tmp/kt.png
|
||||
adb logcat -d | grep -E 'kidstube|AndroidRuntime'
|
||||
|
||||
Target device: Huawei AGS2-W09, LineageOS 18.1 (`18.1-20220523-UNOFFICIAL-prague`),
|
||||
Android 11 / API 30, arm64-v8a, 1200x1920 at 480 dpi = 400dp wide. API 21 cannot
|
||||
be exercised here — that needs an emulator image and none is installed.
|
||||
|
||||
## Content
|
||||
|
||||
The library is `Movies/KidsTube` (`/storage/emulated/0/Movies/KidsTube`), scanned
|
||||
through MediaStore; a SAF tree picked from the Profile screen takes precedence.
|
||||
Copy files with
|
||||
|
||||
adb push video.mp4 /sdcard/Movies/KidsTube/
|
||||
adb shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Movies/KidsTube/video.mp4
|
||||
|
||||
The broadcast is not optional: a pushed file stays invisible until MediaStore
|
||||
indexes it, and from API 29 scoped storage forbids directory listing (the app uid
|
||||
gets `EACCES`), so there is no fallback route.
|
||||
|
||||
## Layout and conventions
|
||||
|
||||
- `data/` — `Library` (SAF tree, else MediaStore; folder grouping; `MediaItem`
|
||||
carries a sha1 `key`), `MediaItem`.
|
||||
- `media/ThumbCache` — decode via `MediaMetadataRetriever`, write JPEGs to
|
||||
`filesDir/thumbs`, `LruCache` in memory, 3-thread pool, tag-guarded binds.
|
||||
- `ui/` — `MainActivity` (shelves, search grid, parent gate), `SectionAdapter`
|
||||
(vertical shelves, each a horizontal RecyclerView), `VideoAdapter` (modes HERO /
|
||||
CAROUSEL / GRID), `PlayerActivity` (VideoView, immersive, auto-hiding chrome),
|
||||
`ThumbView`.
|
||||
- `ThumbView` owns the two numbers the look depends on — 16:9 and 12dp corner
|
||||
radius — plus the duration pill. Never re-implement them per layout.
|
||||
- Kotlin + Views + AppCompat, single `:app` module, viewBinding, no Compose.
|
||||
Every dimension in dp/sp, designed against 400dp width.
|
||||
|
||||
## Pitfalls
|
||||
|
||||
- `reload()` must treat "no SAF tree, storage permission granted" as a valid
|
||||
source. Gating on the tree alone silently shows an empty home screen.
|
||||
- `VideoView` swallows touches, so its `OnClickListener` never fires; the player
|
||||
uses a transparent `tap_catcher` view above it to bring the chrome back.
|
||||
- Tint AppCompat widgets with `app:tint`, never `android:tint` — lint fails the
|
||||
build on `UseAppTint`, and the vector drawables are white by default, so a
|
||||
missing tint makes an icon invisible rather than obviously wrong.
|
||||
- The system "Viewing full screen" confirmation appears on first launch and holds
|
||||
focus — dismiss it before trusting any UI dump.
|
||||
- `uiautomator dump` takes seconds here, longer than the 4s chrome timeout, so a
|
||||
dump right after a tap shows stale state. Screenshot instead.
|
||||
- adbd on the device crash-loops (`Could not install *smartsocket* listener`); a
|
||||
dropped `adb` connection is the device, not the app. Reconnect and check
|
||||
`sys.boot_completed`.
|
||||
- The tablet randomly brings up the camera app between commands. Force-stop
|
||||
`com.android.camera2` and restart the activity if the focus looks wrong.
|
||||
- File paths: `/storage/emulated/0` is the real mount; `/sdcard` works for `ls`
|
||||
but not for `df`.
|
||||
|
||||
## Repo
|
||||
|
||||
Initialised locally (one commit), no remote yet; Konrad's convention is `origin`
|
||||
= hiddenbox when one is added. Short imperative commit subjects, no
|
||||
conventional-commit prefixes.
|
||||
@@ -0,0 +1,48 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "dev.lotherk.kidstube"
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "dev.lotherk.kidstube"
|
||||
minSdk = 21
|
||||
targetSdk = 35
|
||||
versionCode = 1
|
||||
versionName = "0.1"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
|
||||
lint {
|
||||
// Hard floor check: an API-24 call must fail here, not on the tablet.
|
||||
abortOnError = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
implementation("androidx.appcompat:appcompat:1.7.0")
|
||||
implementation("androidx.recyclerview:recyclerview:1.3.2")
|
||||
implementation("androidx.documentfile:documentfile:1.0.1")
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- Storage read only, both regimes: READ_EXTERNAL_STORAGE up to API 32,
|
||||
READ_MEDIA_VIDEO from API 33. Never INTERNET - the app is offline by
|
||||
construction, and the built APK is checked for that. -->
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.KidsTube">
|
||||
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.PlayerActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:theme="@style/Theme.KidsTube.Player" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,201 @@
|
||||
package dev.lotherk.kidstube.data
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
|
||||
/**
|
||||
* Video sources, in order of precedence:
|
||||
* 1. a SAF tree the parent picked (any folder, no permission needed),
|
||||
* 2. the default folder Movies/KidsTube via MediaStore.
|
||||
*
|
||||
* Nothing else: no network, no cloud, no second app.
|
||||
*/
|
||||
object Library {
|
||||
|
||||
const val PREFS = "kidstube"
|
||||
const val DEFAULT_FOLDER = "KidsTube"
|
||||
private const val KEY_TREE = "tree_uri"
|
||||
|
||||
fun treeUri(context: Context): Uri? =
|
||||
prefs(context).getString(KEY_TREE, null)?.let(Uri::parse)
|
||||
|
||||
fun setTree(context: Context, uri: Uri) {
|
||||
try {
|
||||
context.contentResolver.takePersistableUriPermission(
|
||||
uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
} catch (e: SecurityException) {
|
||||
// Already persisted or the provider refuses; remember the URI anyway.
|
||||
}
|
||||
prefs(context).edit().putString(KEY_TREE, uri.toString()).apply()
|
||||
}
|
||||
|
||||
fun folderName(context: Context): String? =
|
||||
treeUri(context)?.let { DocumentFile.fromTreeUri(context, it)?.name }
|
||||
?: defaultFolderPath()
|
||||
|
||||
/** The runtime permission that applies to this API level. */
|
||||
fun readPermission(): String =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
Manifest.permission.READ_MEDIA_VIDEO
|
||||
} else {
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
}
|
||||
|
||||
fun hasReadPermission(context: Context): Boolean =
|
||||
ContextCompat.checkSelfPermission(context, readPermission()) ==
|
||||
PackageManager.PERMISSION_GRANTED
|
||||
|
||||
fun scan(context: Context): List<MediaItem> {
|
||||
val tree = treeUri(context)
|
||||
Log.d("kidstube", "scan tree=" + (tree != null) + " perm=" + hasReadPermission(context))
|
||||
val items = if (tree != null) scanTree(context, tree) else scanDefaultFolder(context)
|
||||
return items.sortedWith(compareBy({ it.folder.lowercase() }, { it.title.lowercase() }))
|
||||
}
|
||||
|
||||
fun defaultFolderPath(): String =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
|
||||
.absolutePath + "/" + DEFAULT_FOLDER
|
||||
|
||||
// --- SAF tree -----------------------------------------------------------
|
||||
|
||||
private fun scanTree(context: Context, tree: Uri): List<MediaItem> {
|
||||
val root = DocumentFile.fromTreeUri(context, tree) ?: return emptyList()
|
||||
val out = ArrayList<MediaItem>()
|
||||
walk(root, root.name ?: "", out, 0)
|
||||
return out
|
||||
}
|
||||
|
||||
private fun walk(dir: DocumentFile, folder: String, out: MutableList<MediaItem>, depth: Int) {
|
||||
if (depth > 6) return
|
||||
for (child in dir.listFiles()) {
|
||||
if (child.isDirectory) {
|
||||
walk(child, child.name ?: folder, out, depth + 1)
|
||||
} else if (child.isFile) {
|
||||
addFile(child.name ?: continue, child.uri, folder, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- default folder via MediaStore -------------------------------------
|
||||
|
||||
private fun scanDefaultFolder(context: Context): List<MediaItem> {
|
||||
if (!hasReadPermission(context)) return emptyList()
|
||||
val out = ArrayList<MediaItem>()
|
||||
val prefix = Environment.DIRECTORY_MOVIES + "/" + DEFAULT_FOLDER
|
||||
val collection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL)
|
||||
} else {
|
||||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
||||
}
|
||||
|
||||
val projection: Array<String>
|
||||
val selection: String?
|
||||
val args: Array<String>?
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
projection = arrayOf(
|
||||
MediaStore.Video.Media._ID,
|
||||
MediaStore.Video.Media.DISPLAY_NAME,
|
||||
MediaStore.Video.Media.RELATIVE_PATH
|
||||
)
|
||||
selection = "${MediaStore.Video.Media.RELATIVE_PATH} LIKE ?"
|
||||
args = arrayOf("$prefix%")
|
||||
} else {
|
||||
projection = arrayOf(
|
||||
MediaStore.Video.Media._ID,
|
||||
MediaStore.Video.Media.DISPLAY_NAME,
|
||||
MediaStore.Video.Media.DATA
|
||||
)
|
||||
selection = "${MediaStore.Video.Media.DATA} LIKE ?"
|
||||
args = arrayOf("%/$prefix/%")
|
||||
}
|
||||
|
||||
try {
|
||||
context.contentResolver.query(collection, projection, selection, args, null)
|
||||
?.use { cursor ->
|
||||
val idIndex = cursor.getColumnIndex(MediaStore.Video.Media._ID)
|
||||
val nameIndex = cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME)
|
||||
val pathIndex = cursor.getColumnIndex(projection[2])
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(idIndex)
|
||||
val name = cursor.getString(nameIndex) ?: continue
|
||||
val path = cursor.getString(pathIndex).orEmpty()
|
||||
val folder = folderOf(path, prefix)
|
||||
val uri = Uri.withAppendedPath(collection, id.toString())
|
||||
addFile(name, uri, folder, out)
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
Log.w("kidstube", "mediastore query failed", t)
|
||||
return emptyList()
|
||||
}
|
||||
Log.d("kidstube", "mediastore rows=" + out.size + " pathIndex=" + projection[2])
|
||||
// Below API 29 the raw file path is readable and catches files that were
|
||||
// never indexed. From 29 on scoped storage forbids directory listing
|
||||
// (verified: the app uid gets EACCES on this folder), so MediaStore is
|
||||
// the only route and a non-indexed file is simply invisible until the
|
||||
// media scanner sees it.
|
||||
if (out.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
return scanDefaultByFile()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
private fun scanDefaultByFile(): List<MediaItem> {
|
||||
val root = File(defaultFolderPath())
|
||||
if (!root.isDirectory) return emptyList()
|
||||
val out = ArrayList<MediaItem>()
|
||||
walkFiles(root, DEFAULT_FOLDER, out, 0)
|
||||
return out
|
||||
}
|
||||
|
||||
private fun walkFiles(dir: File, folder: String, out: MutableList<MediaItem>, depth: Int) {
|
||||
if (depth > 6) return
|
||||
val children = dir.listFiles() ?: return
|
||||
for (child in children) {
|
||||
if (child.isDirectory) {
|
||||
walkFiles(child, child.name, out, depth + 1)
|
||||
} else if (child.isFile) {
|
||||
addFile(child.name, Uri.fromFile(child), folder, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** "Movies/KidsTube/Tiere/" -> "Tiere", the folder itself -> "KidsTube". */
|
||||
private fun folderOf(path: String, prefix: String): String {
|
||||
val tail = path.removePrefix(prefix).trim('/')
|
||||
return tail.substringBefore('/').ifEmpty { DEFAULT_FOLDER }
|
||||
}
|
||||
|
||||
private fun addFile(name: String, uri: Uri, folder: String, out: MutableList<MediaItem>) {
|
||||
val ext = name.substringAfterLast('.', "").lowercase()
|
||||
if (ext !in VIDEO_EXT) return
|
||||
out.add(MediaItem(uri = uri, title = titleOf(name), folder = folder, key = sha1(uri.toString())))
|
||||
}
|
||||
|
||||
private val VIDEO_EXT = setOf("mp4", "m4v", "webm", "mkv", "3gp", "ts")
|
||||
|
||||
private fun titleOf(fileName: String): String =
|
||||
fileName.substringBeforeLast('.').replace('_', ' ').trim().ifEmpty { fileName }
|
||||
|
||||
private fun sha1(value: String): String {
|
||||
val digest = MessageDigest.getInstance("SHA-1").digest(value.toByteArray())
|
||||
val sb = StringBuilder(digest.size * 2)
|
||||
for (b in digest) sb.append(String.format("%02x", b))
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun prefs(context: Context) = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.lotherk.kidstube.data
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
/** One video found under the chosen folder. */
|
||||
data class MediaItem(
|
||||
val uri: Uri,
|
||||
val title: String,
|
||||
val folder: String,
|
||||
val key: String
|
||||
)
|
||||
@@ -0,0 +1,141 @@
|
||||
package dev.lotherk.kidstube.media
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.LruCache
|
||||
import dev.lotherk.kidstube.data.Library
|
||||
import dev.lotherk.kidstube.data.MediaItem
|
||||
import dev.lotherk.kidstube.ui.ThumbView
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
/**
|
||||
* Thumbnails are decoded once, written to filesDir and read back from disk while
|
||||
* scrolling. Decoding on the bind path stutters on this tablet.
|
||||
*/
|
||||
object ThumbCache {
|
||||
|
||||
private const val THUMB_WIDTH = 640
|
||||
private val pool = Executors.newFixedThreadPool(3)
|
||||
private val main = Handler(Looper.getMainLooper())
|
||||
|
||||
private val memory = object : LruCache<String, Bitmap>(
|
||||
(Runtime.getRuntime().maxMemory() / 1024 / 8).toInt()
|
||||
) {
|
||||
override fun sizeOf(key: String, value: Bitmap): Int = value.byteCount / 1024
|
||||
}
|
||||
|
||||
fun label(context: Context, item: MediaItem): String? {
|
||||
val ms = Library.prefs(context).getLong("dur_" + item.key, 0L)
|
||||
return if (ms > 0) formatDuration(ms) else null
|
||||
}
|
||||
|
||||
fun load(context: Context, item: MediaItem, view: ThumbView) {
|
||||
val key = item.key
|
||||
view.tag = key
|
||||
|
||||
memory.get(key)?.let {
|
||||
view.setThumb(it, label(context, item))
|
||||
return
|
||||
}
|
||||
|
||||
val fromDisk = readDisk(context, item)
|
||||
if (fromDisk != null) {
|
||||
memory.put(key, fromDisk)
|
||||
view.setThumb(fromDisk, label(context, item))
|
||||
return
|
||||
}
|
||||
|
||||
view.setThumb(null, label(context, item))
|
||||
val app = context.applicationContext
|
||||
pool.execute {
|
||||
val data = generateThumb(app, item)
|
||||
main.post {
|
||||
if (data.bitmap != null) memory.put(key, data.bitmap)
|
||||
if (view.tag == key) view.setThumb(data.bitmap, data.label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ThumbData(val bitmap: Bitmap?, val label: String?)
|
||||
|
||||
private fun generateThumb(context: Context, item: MediaItem): ThumbData {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
try {
|
||||
val path = item.uri.path
|
||||
if (item.uri.scheme == "file" && path != null) {
|
||||
retriever.setDataSource(path)
|
||||
} else {
|
||||
retriever.setDataSource(context, item.uri)
|
||||
}
|
||||
val durationMs = retriever
|
||||
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
||||
?.toLongOrNull() ?: 0L
|
||||
val frame = retriever.getFrameAtTime(
|
||||
if (durationMs > 3000) 1_000_000L else 0L,
|
||||
MediaMetadataRetriever.OPTION_CLOSEST_SYNC
|
||||
)
|
||||
val scaled = frame?.let { scaleToWidth(it, THUMB_WIDTH) }
|
||||
if (scaled != null) writeDisk(context, item, scaled)
|
||||
if (durationMs > 0) {
|
||||
Library.prefs(context).edit().putLong("dur_" + item.key, durationMs).apply()
|
||||
}
|
||||
return ThumbData(scaled, if (durationMs > 0) formatDuration(durationMs) else null)
|
||||
} catch (t: Throwable) {
|
||||
return ThumbData(null, null)
|
||||
} finally {
|
||||
try {
|
||||
retriever.release()
|
||||
} catch (ignored: Throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun scaleToWidth(source: Bitmap, width: Int): Bitmap {
|
||||
if (source.width <= width) return source
|
||||
val height = (source.height.toFloat() * width / source.width).toInt().coerceAtLeast(1)
|
||||
return Bitmap.createScaledBitmap(source, width, height, true)
|
||||
}
|
||||
|
||||
private fun fileFor(context: Context, item: MediaItem): File =
|
||||
File(File(context.filesDir, "thumbs"), item.key + ".jpg")
|
||||
|
||||
private fun readDisk(context: Context, item: MediaItem): Bitmap? {
|
||||
val file = fileFor(context, item)
|
||||
if (!file.exists()) return null
|
||||
return try {
|
||||
BitmapFactory.decodeFile(file.absolutePath)
|
||||
} catch (t: Throwable) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeDisk(context: Context, item: MediaItem, bitmap: Bitmap) {
|
||||
try {
|
||||
val dir = File(context.filesDir, "thumbs")
|
||||
if (!dir.exists()) dir.mkdirs()
|
||||
fileFor(context, item).outputStream().use { out ->
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 82, out)
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
// A missing cache file only costs a later re-decode.
|
||||
}
|
||||
}
|
||||
|
||||
fun formatDuration(ms: Long): String {
|
||||
val totalSeconds = ms / 1000
|
||||
val hours = totalSeconds / 3600
|
||||
val minutes = (totalSeconds % 3600) / 60
|
||||
val seconds = totalSeconds % 60
|
||||
return if (hours > 0) {
|
||||
String.format(Locale.US, "%d:%02d:%02d", hours, minutes, seconds)
|
||||
} else {
|
||||
String.format(Locale.US, "%d:%02d", minutes, seconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package dev.lotherk.kidstube.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.InputType
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dev.lotherk.kidstube.R
|
||||
import dev.lotherk.kidstube.data.Library
|
||||
import dev.lotherk.kidstube.data.MediaItem
|
||||
import dev.lotherk.kidstube.databinding.ActivityMainBinding
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.random.Random
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private val sectionAdapter = SectionAdapter { openPlayer(it) }
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
|
||||
private lateinit var resultsAdapter: VideoAdapter
|
||||
private var all: List<MediaItem> = emptyList()
|
||||
private var scanning = false
|
||||
private var activeTab = 0
|
||||
|
||||
private val openFolder =
|
||||
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
|
||||
if (uri != null) {
|
||||
Library.setTree(this, uri)
|
||||
reload()
|
||||
}
|
||||
}
|
||||
|
||||
private val permission =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { reload() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.rows.layoutManager = LinearLayoutManager(this)
|
||||
binding.rows.adapter = sectionAdapter
|
||||
|
||||
resultsAdapter = VideoAdapter(VideoAdapter.Mode.GRID) { openPlayer(it) }
|
||||
binding.results.layoutManager = GridLayoutManager(this, 2)
|
||||
binding.results.adapter = resultsAdapter
|
||||
|
||||
binding.btnPick.setOnClickListener { pickFolder() }
|
||||
binding.btnTopSearch.setOnClickListener { selectTab(1) }
|
||||
binding.avatar.setOnClickListener { parentGate() }
|
||||
binding.tabHome.setOnClickListener { selectTab(0) }
|
||||
binding.tabSearch.setOnClickListener { selectTab(1) }
|
||||
binding.tabProfile.setOnClickListener { parentGate() }
|
||||
binding.btnSearchClose.setOnClickListener { selectTab(0) }
|
||||
|
||||
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())
|
||||
})
|
||||
|
||||
selectTab(0)
|
||||
start()
|
||||
}
|
||||
|
||||
/** Default folder needs a read permission once; a picked SAF tree does not. */
|
||||
private fun start() {
|
||||
if (Library.treeUri(this) == null && !Library.hasReadPermission(this)) {
|
||||
permission.launch(Library.readPermission())
|
||||
return
|
||||
}
|
||||
reload()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!scanning) reload()
|
||||
}
|
||||
|
||||
private fun reload() {
|
||||
if (scanning) return
|
||||
val hasSource = Library.treeUri(this) != null || Library.hasReadPermission(this)
|
||||
if (!hasSource) {
|
||||
all = emptyList()
|
||||
sectionAdapter.submit(emptyList())
|
||||
refreshEmptyState()
|
||||
return
|
||||
}
|
||||
scanning = true
|
||||
executor.execute {
|
||||
val items = Library.scan(this)
|
||||
runOnUiThread {
|
||||
scanning = false
|
||||
all = items
|
||||
buildSections(items)
|
||||
applyFilter(binding.searchInput.text?.toString().orEmpty())
|
||||
refreshEmptyState()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildSections(items: List<MediaItem>) {
|
||||
if (items.isEmpty()) {
|
||||
sectionAdapter.submit(emptyList())
|
||||
return
|
||||
}
|
||||
val sections = ArrayList<SectionAdapter.Section>()
|
||||
sections.add(SectionAdapter.Section(getString(R.string.shelf_recent), items.take(8), true))
|
||||
for ((folder, list) in items.groupBy { it.folder }) {
|
||||
if (list.size < 2 || sections.size >= 5) continue
|
||||
sections.add(SectionAdapter.Section(folder, list.take(20), false))
|
||||
}
|
||||
sections.add(SectionAdapter.Section(getString(R.string.shelf_all), items.take(30), false))
|
||||
sectionAdapter.submit(sections)
|
||||
}
|
||||
|
||||
private fun applyFilter(query: String) {
|
||||
val q = query.trim().lowercase()
|
||||
val list = if (q.isEmpty()) all else all.filter {
|
||||
it.title.lowercase().contains(q) || it.folder.lowercase().contains(q)
|
||||
}
|
||||
resultsAdapter.submit(list)
|
||||
}
|
||||
|
||||
private fun selectTab(index: Int) {
|
||||
activeTab = index
|
||||
val active = ContextCompat.getColor(this, R.color.kt_red)
|
||||
val idle = ContextCompat.getColor(this, R.color.kt_tab_idle)
|
||||
|
||||
binding.tabHomeIcon.imageTintList = ColorStateList.valueOf(if (index == 0) active else idle)
|
||||
binding.tabHomeLabel.setTextColor(if (index == 0) active else idle)
|
||||
binding.tabSearchIcon.imageTintList = ColorStateList.valueOf(if (index == 1) active else idle)
|
||||
binding.tabSearchLabel.setTextColor(if (index == 1) active else idle)
|
||||
binding.tabProfileIcon.imageTintList = ColorStateList.valueOf(idle)
|
||||
|
||||
binding.searchBar.visibility = if (index == 1) View.VISIBLE else View.GONE
|
||||
binding.results.visibility = if (index == 1) View.VISIBLE else View.GONE
|
||||
binding.rows.visibility = if (index == 0) View.VISIBLE else View.GONE
|
||||
|
||||
if (index == 1) {
|
||||
binding.searchInput.requestFocus()
|
||||
} else {
|
||||
binding.searchInput.setText("")
|
||||
}
|
||||
refreshEmptyState()
|
||||
}
|
||||
|
||||
private fun refreshEmptyState() {
|
||||
val show = all.isEmpty() && activeTab == 0
|
||||
binding.empty.visibility = if (show) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
private fun pickFolder() {
|
||||
openFolder.launch(Library.treeUri(this))
|
||||
}
|
||||
|
||||
/** Same idea as the iOS kids app: a small multiplication gate for parents. */
|
||||
private fun parentGate() {
|
||||
val a = Random.nextInt(3, 10)
|
||||
val b = Random.nextInt(3, 10)
|
||||
val input = EditText(this).apply {
|
||||
inputType = InputType.TYPE_CLASS_NUMBER
|
||||
hint = "?"
|
||||
setPadding(48, 24, 48, 24)
|
||||
}
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(R.string.parent_gate_title)
|
||||
.setMessage("${getString(R.string.parent_gate_body)}: $a x $b = ?")
|
||||
.setView(input)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create()
|
||||
dialog.setOnShowListener {
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
if (input.text.toString().trim().toIntOrNull() == a * b) {
|
||||
dialog.dismiss()
|
||||
showFolderInfo()
|
||||
} else {
|
||||
input.error = getString(R.string.parent_wrong)
|
||||
}
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun showFolderInfo() {
|
||||
val name = Library.folderName(this) ?: getString(R.string.folder_label)
|
||||
val message = "$name\n\n${getString(R.string.video_count, all.size)}"
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.folder_label)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(R.string.change_folder) { d, _ ->
|
||||
d.dismiss()
|
||||
pickFolder()
|
||||
}
|
||||
.setNegativeButton(R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun openPlayer(item: MediaItem) {
|
||||
startActivity(
|
||||
Intent(this, PlayerActivity::class.java)
|
||||
.putExtra(PlayerActivity.EXTRA_URI, item.uri.toString())
|
||||
.putExtra(PlayerActivity.EXTRA_TITLE, item.title)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package dev.lotherk.kidstube.ui
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowInsetsController
|
||||
import android.view.WindowManager
|
||||
import android.widget.SeekBar
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import dev.lotherk.kidstube.R
|
||||
import dev.lotherk.kidstube.databinding.ActivityPlayerBinding
|
||||
|
||||
/** Fullscreen local playback. No pre-roll, no controls until a tap. */
|
||||
class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
companion object {
|
||||
const val EXTRA_URI = "uri"
|
||||
const val EXTRA_TITLE = "title"
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityPlayerBinding
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var chromeVisible = true
|
||||
|
||||
private val hideChrome = Runnable { setChrome(false) }
|
||||
private val ticker = object : Runnable {
|
||||
override fun run() {
|
||||
binding.seek.progress = binding.video.currentPosition
|
||||
handler.postDelayed(this, 500)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityPlayerBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val rawUri = intent.getStringExtra(EXTRA_URI)
|
||||
if (rawUri == null) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
binding.title.text = intent.getStringExtra(EXTRA_TITLE).orEmpty()
|
||||
binding.btnBack.setOnClickListener { finish() }
|
||||
binding.tapCatcher.setOnClickListener { setChrome(!chromeVisible) }
|
||||
binding.chrome.setOnClickListener { setChrome(!chromeVisible) }
|
||||
|
||||
binding.seek.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(bar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
if (fromUser) binding.video.seekTo(progress)
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(bar: SeekBar?) {
|
||||
handler.removeCallbacks(hideChrome)
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(bar: SeekBar?) {
|
||||
handler.removeCallbacks(hideChrome)
|
||||
handler.postDelayed(hideChrome, 3000)
|
||||
}
|
||||
})
|
||||
|
||||
binding.video.setVideoURI(Uri.parse(rawUri))
|
||||
binding.video.setOnPreparedListener { player ->
|
||||
binding.spinner.visibility = View.GONE
|
||||
player.isLooping = true
|
||||
binding.seek.max = if (player.duration > 0) player.duration else 1
|
||||
binding.video.start()
|
||||
handler.post(ticker)
|
||||
setChrome(true)
|
||||
}
|
||||
binding.video.setOnErrorListener { _, _, _ ->
|
||||
binding.spinner.visibility = View.GONE
|
||||
Toast.makeText(this, R.string.error_play, Toast.LENGTH_LONG).show()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) immersive()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
binding.video.stopPlayback()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun setChrome(visible: Boolean) {
|
||||
chromeVisible = visible
|
||||
binding.chrome.visibility = if (visible) View.VISIBLE else View.INVISIBLE
|
||||
handler.removeCallbacks(hideChrome)
|
||||
if (visible) handler.postDelayed(hideChrome, 4000)
|
||||
}
|
||||
|
||||
private fun immersive() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
window.setDecorFitsSystemWindows(false)
|
||||
window.insetsController?.let {
|
||||
it.hide(WindowInsets.Type.systemBars())
|
||||
it.systemBarsBehavior =
|
||||
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
}
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
window.decorView.systemUiVisibility = (
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package dev.lotherk.kidstube.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.LinearSnapHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.lotherk.kidstube.data.MediaItem
|
||||
import dev.lotherk.kidstube.databinding.ItemSectionBinding
|
||||
|
||||
/** Vertical list of shelves; each shelf is its own horizontal RecyclerView. */
|
||||
class SectionAdapter(
|
||||
private val onTap: (MediaItem) -> Unit
|
||||
) : RecyclerView.Adapter<SectionAdapter.Holder>() {
|
||||
|
||||
class Section(val title: String, val items: List<MediaItem>, val hero: Boolean)
|
||||
|
||||
private val sections = ArrayList<Section>()
|
||||
|
||||
fun submit(list: List<Section>) {
|
||||
sections.clear()
|
||||
sections.addAll(list)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
class Holder(val binding: ItemSectionBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
var snap: LinearSnapHelper? = null
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
|
||||
val binding = ItemSectionBinding.inflate(
|
||||
LayoutInflater.from(parent.context), parent, false
|
||||
)
|
||||
return Holder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: Holder, position: Int) {
|
||||
val section = sections[position]
|
||||
val binding = holder.binding
|
||||
binding.sectionTitle.text = section.title
|
||||
|
||||
val row = binding.row
|
||||
val context = row.context
|
||||
if (row.layoutManager == null) {
|
||||
row.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
val adapter = VideoAdapter(
|
||||
if (section.hero) VideoAdapter.Mode.HERO else VideoAdapter.Mode.CAROUSEL,
|
||||
onTap
|
||||
)
|
||||
row.adapter = adapter
|
||||
adapter.submit(section.items)
|
||||
|
||||
// The wide top shelf snaps page by page like the iOS carousel; the
|
||||
// smaller shelves scroll freely.
|
||||
if (section.hero && holder.snap == null) {
|
||||
holder.snap = LinearSnapHelper().apply { attachToRecyclerView(row) }
|
||||
} else if (!section.hero && holder.snap != null) {
|
||||
holder.snap?.attachToRecyclerView(null)
|
||||
holder.snap = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: Holder) {
|
||||
holder.snap?.attachToRecyclerView(null)
|
||||
holder.snap = null
|
||||
super.onViewRecycled(holder)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = sections.size
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package dev.lotherk.kidstube.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Path
|
||||
import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import dev.lotherk.kidstube.R
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* 16:9 thumbnail with 12dp rounded corners and an optional duration pill.
|
||||
*
|
||||
* Keeps the aspect ratio and the corner radius in one place: the iOS kids app
|
||||
* is judged on exactly these two numbers, so they must not drift per layout.
|
||||
*/
|
||||
class ThumbView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0
|
||||
) : View(context, attrs, defStyle) {
|
||||
|
||||
private val density = resources.displayMetrics.density
|
||||
private val radiusPx = 12f * density
|
||||
private val pillMargin = 6f * density
|
||||
private val pillPadH = 5f * density
|
||||
private val pillPadV = 2f * density
|
||||
|
||||
private val bitmapPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
|
||||
private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = ContextCompat.getColor(context, R.color.kt_placeholder)
|
||||
}
|
||||
private val pillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = ContextCompat.getColor(context, R.color.kt_pill)
|
||||
}
|
||||
private val labelPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
textSize = 11f * resources.displayMetrics.scaledDensity
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
}
|
||||
|
||||
private val clip = Path()
|
||||
private val scaleMatrix = Matrix()
|
||||
|
||||
private var thumb: Bitmap? = null
|
||||
private var pillText: String? = null
|
||||
|
||||
fun setThumb(bitmap: Bitmap?, label: String?) {
|
||||
thumb = bitmap
|
||||
pillText = label
|
||||
invalidate()
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val height = if (width > 0) (width * 9f / 16f).roundToInt() else 0
|
||||
setMeasuredDimension(width, height)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val w = width.toFloat()
|
||||
val h = height.toFloat()
|
||||
if (w <= 0f || h <= 0f) return
|
||||
|
||||
clip.reset()
|
||||
clip.addRoundRect(0f, 0f, w, h, radiusPx, radiusPx, Path.Direction.CW)
|
||||
canvas.save()
|
||||
canvas.clipPath(clip)
|
||||
|
||||
val bmp = thumb
|
||||
if (bmp == null || bmp.isRecycled) {
|
||||
canvas.drawRect(0f, 0f, w, h, fillPaint)
|
||||
} else {
|
||||
val scale = max(w / bmp.width, h / bmp.height)
|
||||
scaleMatrix.reset()
|
||||
scaleMatrix.setScale(scale, scale)
|
||||
scaleMatrix.postTranslate((w - bmp.width * scale) / 2f, (h - bmp.height * scale) / 2f)
|
||||
canvas.drawBitmap(bmp, scaleMatrix, bitmapPaint)
|
||||
}
|
||||
canvas.restore()
|
||||
|
||||
val label = pillText
|
||||
if (label != null) drawPill(canvas, label, w, h)
|
||||
}
|
||||
|
||||
private fun drawPill(canvas: Canvas, label: String, w: Float, h: Float) {
|
||||
val textWidth = labelPaint.measureText(label)
|
||||
val pillH = labelPaint.textSize + 2 * pillPadV
|
||||
val pillW = textWidth + 2 * pillPadH
|
||||
val right = w - pillMargin
|
||||
val bottom = h - pillMargin
|
||||
val left = right - pillW
|
||||
val top = bottom - pillH
|
||||
val r = pillH / 2f
|
||||
canvas.drawRoundRect(left, top, right, bottom, r, r, pillPaint)
|
||||
val baseline = top + pillH / 2f - (labelPaint.descent() + labelPaint.ascent()) / 2f
|
||||
canvas.drawText(label, left + pillPadH, baseline, labelPaint)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package dev.lotherk.kidstube.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.lotherk.kidstube.R
|
||||
import dev.lotherk.kidstube.data.MediaItem
|
||||
import dev.lotherk.kidstube.media.ThumbCache
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* One tile row. HERO is the wide top shelf, CAROUSEL the smaller ones, GRID the
|
||||
* two-column search result list.
|
||||
*/
|
||||
class VideoAdapter(
|
||||
private val mode: Mode,
|
||||
private val onTap: (MediaItem) -> Unit
|
||||
) : RecyclerView.Adapter<VideoAdapter.Holder>() {
|
||||
|
||||
enum class Mode { HERO, CAROUSEL, GRID }
|
||||
|
||||
private val items = ArrayList<MediaItem>()
|
||||
|
||||
fun submit(list: List<MediaItem>) {
|
||||
items.clear()
|
||||
items.addAll(list)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
class Holder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val thumb: ThumbView = view.findViewById(R.id.thumb)
|
||||
val title: TextView = view.findViewById(R.id.title)
|
||||
val meta: TextView = view.findViewById(R.id.meta)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
|
||||
val layout = if (mode == Mode.HERO) R.layout.item_hero else R.layout.item_video
|
||||
val view = LayoutInflater.from(parent.context).inflate(layout, parent, false)
|
||||
val density = parent.resources.displayMetrics.density
|
||||
val params = view.layoutParams as RecyclerView.LayoutParams
|
||||
when (mode) {
|
||||
Mode.HERO ->
|
||||
params.width = parent.resources.displayMetrics.widthPixels -
|
||||
(56 * density).roundToInt()
|
||||
Mode.CAROUSEL -> params.width = (210 * density).roundToInt()
|
||||
Mode.GRID -> params.width = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
}
|
||||
params.marginEnd = (12 * density).roundToInt()
|
||||
params.bottomMargin = if (mode == Mode.GRID) (16 * density).roundToInt() else 0
|
||||
view.layoutParams = params
|
||||
return Holder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: Holder, position: Int) {
|
||||
val item = items[position]
|
||||
holder.title.text = item.title
|
||||
holder.meta.text = item.folder
|
||||
ThumbCache.load(holder.itemView.context, item, holder.thumb)
|
||||
holder.itemView.setOnClickListener {
|
||||
val current = holder.bindingAdapterPosition
|
||||
if (current != RecyclerView.NO_POSITION && current < items.size) onTap(items[current])
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/kt_red" />
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/kt_red" />
|
||||
<corners android:radius="24dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/kt_scrim" />
|
||||
</shape>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zm0,2c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zm-6,0C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,261 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/kt_bg">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Top bar: wordmark left, search + avatar right (iOS Kids layout). -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="@string/wordmark_1"
|
||||
android:textColor="@color/kt_text"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="@string/wordmark_2"
|
||||
android:textColor="@color/kt_red"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_top_search"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/tab_search"
|
||||
android:padding="8dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_search"
|
||||
app:tint="@color/kt_text" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:background="@drawable/bg_avatar"
|
||||
android:contentDescription="@string/tab_profile"
|
||||
android:padding="7dp"
|
||||
android:src="@drawable/ic_person"
|
||||
app:tint="@android:color/white" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rows"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:scrollbars="none" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/empty_title"
|
||||
android:textColor="@color/kt_text"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/empty_body"
|
||||
android:textColor="@color/kt_text_sub"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_pick"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/bg_button"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
android:text="@string/pick_folder"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="15sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Search results, a 2-column grid like the iOS kids app. -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/results"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/kt_divider" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tabbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:background="@color/kt_bg"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tab_home"
|
||||
style="@style/KtTab"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tab_home_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/tab_home"
|
||||
android:src="@drawable/ic_home"
|
||||
app:tint="@color/kt_red" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tab_home_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/tab_home"
|
||||
android:textColor="@color/kt_red"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tab_search"
|
||||
style="@style/KtTab"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tab_search_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/tab_search"
|
||||
android:src="@drawable/ic_search"
|
||||
app:tint="@color/kt_tab_idle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tab_search_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/tab_search"
|
||||
android:textColor="@color/kt_tab_idle"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tab_profile"
|
||||
style="@style/KtTab"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tab_profile_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/tab_profile"
|
||||
android:src="@drawable/ic_person"
|
||||
app:tint="@color/kt_tab_idle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tab_profile_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/tab_profile"
|
||||
android:textColor="@color/kt_tab_idle"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Search overlay, hidden until the Search tab is tapped. -->
|
||||
<LinearLayout
|
||||
android:id="@+id/search_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="@color/kt_bg"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:visibility="gone"
|
||||
android:elevation="4dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_search_close"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/cancel"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_back"
|
||||
app:tint="@color/kt_text" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/search_input"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:hint="@string/search_hint"
|
||||
android:imeOptions="actionSearch"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="text"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/kt_text"
|
||||
android:textColorHint="@color/kt_tab_idle"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/black">
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/video"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminateTint="@android:color/white" />
|
||||
|
||||
<!-- VideoView swallows touches, so a transparent catcher sits above it to
|
||||
bring the controls back. The chrome itself is above this. -->
|
||||
<View
|
||||
android:id="@+id/tap_catcher"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="false" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/chrome"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_back"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_gravity="top|start"
|
||||
android:layout_margin="12dp"
|
||||
android:background="@drawable/bg_scrim_circle"
|
||||
android:contentDescription="@string/back"
|
||||
android:padding="10dp"
|
||||
android:src="@drawable/ic_back"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bottom_panel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/kt_scrim"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingBottom="12dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seek"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="32dp"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="0dp" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<dev.lotherk.kidstube.ui.ThumbView
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textColor="@color/kt_text"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/meta"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="@color/kt_text_sub"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/section_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:textColor="@color/kt_text"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:clipToPadding="false"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:scrollbars="none" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<dev.lotherk.kidstube.ui.ThumbView
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textColor="@color/kt_text"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/meta"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="@color/kt_text_sub"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 678 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- iOS YouTube Kids metrics: white canvas, near-black text, red accent. -->
|
||||
<color name="kt_bg">#FFFFFFFF</color>
|
||||
<color name="kt_red">#FFFF0000</color>
|
||||
<color name="kt_text">#FF212121</color>
|
||||
<color name="kt_text_sub">#FF606060</color>
|
||||
<color name="kt_tab_idle">#FF9E9E9E</color>
|
||||
<color name="kt_divider">#FFE6E6E6</color>
|
||||
<color name="kt_placeholder">#FFE8E8E8</color>
|
||||
<color name="kt_pill">#B3000000</color>
|
||||
<color name="kt_scrim">#66000000</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">KidsTube</string>
|
||||
<string name="wordmark_1">Kids</string>
|
||||
<string name="wordmark_2">Tube</string>
|
||||
|
||||
<string name="tab_home">Home</string>
|
||||
<string name="tab_search">Search</string>
|
||||
<string name="tab_profile">Profile</string>
|
||||
|
||||
<string name="empty_title">No videos yet</string>
|
||||
<string name="empty_body">Put the videos into the folder Movies/KidsTube, or pick another folder. The app only reads that folder and never goes online.</string>
|
||||
<string name="pick_folder">Choose folder</string>
|
||||
<string name="change_folder">Change folder</string>
|
||||
<string name="folder_label">Folder</string>
|
||||
<string name="video_count">%1$d videos</string>
|
||||
<string name="search_hint">Search videos</string>
|
||||
<string name="shelf_all">All videos</string>
|
||||
<string name="shelf_recent">Watch again</string>
|
||||
<string name="parent_gate_title">For parents</string>
|
||||
<string name="parent_gate_body">Solve to continue</string>
|
||||
<string name="parent_wrong">Not quite, try again</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="back">Back</string>
|
||||
<string name="error_play">This video cannot be played on this device</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.KidsTube" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorPrimary">@color/kt_red</item>
|
||||
<item name="colorPrimaryDark">@color/kt_red</item>
|
||||
<item name="colorAccent">@color/kt_red</item>
|
||||
<item name="android:windowBackground">@color/kt_bg</item>
|
||||
<item name="android:statusBarColor">@color/kt_bg</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.KidsTube.Player" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="android:windowBackground">@android:color/black</item>
|
||||
<item name="android:statusBarColor">@android:color/black</item>
|
||||
<item name="android:navigationBarColor">@android:color/black</item>
|
||||
</style>
|
||||
|
||||
<style name="KtTab">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_height">match_parent</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
plugins {
|
||||
id("com.android.application") version "8.13.2" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.1.20" apply false
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
kotlin.code.style=official
|
||||
Vendored
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,18 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "kidstube"
|
||||
include(":app")
|
||||
Reference in new issue
Block a user