First commit
This commit is contained in:
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
*.iml
|
||||
*.iws
|
||||
.idea/
|
||||
/out/
|
||||
!/.idea/assetWizardSettings.xml
|
||||
!/.idea/navEditor.xml
|
||||
|
||||
.gradle/
|
||||
/build/
|
||||
/*/build/
|
||||
|
||||
local.properties
|
||||
secrets.properties
|
||||
|
||||
*.apk
|
||||
*.ap_
|
||||
*.aab
|
||||
*.dex
|
||||
|
||||
*.jks
|
||||
*.keystore
|
||||
|
||||
.externalNativeBuild/
|
||||
.cxx/
|
||||
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
*.log
|
||||
captures/
|
||||
|
||||
*.hprof
|
||||
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
79
app/build.gradle.kts
Normal file
79
app/build.gradle.kts
Normal file
@@ -0,0 +1,79 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.ksp)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "net.tinsae.tv"
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "net.tinsae.tv"
|
||||
minSdk = 23
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
lint {
|
||||
disable.add("NullSafeMutableLiveData")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.compose.ui)
|
||||
implementation(libs.androidx.compose.ui.graphics)
|
||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
||||
implementation(libs.androidx.tv.foundation)
|
||||
implementation(libs.androidx.tv.material)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(libs.androidx.lifecycle.viewmodel.compose)
|
||||
implementation(libs.androidx.material3)
|
||||
|
||||
// Media3
|
||||
implementation(libs.androidx.media3.exoplayer)
|
||||
implementation(libs.androidx.media3.ui)
|
||||
implementation(libs.androidx.media3.hls)
|
||||
implementation(libs.androidx.media3.session)
|
||||
|
||||
// Room
|
||||
implementation(libs.androidx.room.runtime)
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.androidx.graphics.shapes)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
|
||||
implementation(libs.retrofit.core)
|
||||
implementation(libs.retrofit.scalars)
|
||||
implementation(libs.kotlinx.coroutines.android)
|
||||
implementation(libs.coil.compose)
|
||||
|
||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||
}
|
||||
21
app/proguard-rules.pro
vendored
Normal file
21
app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
BIN
app/release/baselineProfiles/0/app-release.dm
Normal file
BIN
app/release/baselineProfiles/0/app-release.dm
Normal file
Binary file not shown.
BIN
app/release/baselineProfiles/1/app-release.dm
Normal file
BIN
app/release/baselineProfiles/1/app-release.dm
Normal file
Binary file not shown.
37
app/release/output-metadata.json
Normal file
37
app/release/output-metadata.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "net.tinsae.tv",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File",
|
||||
"baselineProfiles": [
|
||||
{
|
||||
"minApi": 28,
|
||||
"maxApi": 30,
|
||||
"baselineProfiles": [
|
||||
"baselineProfiles/1/app-release.dm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"minApi": 31,
|
||||
"maxApi": 2147483647,
|
||||
"baselineProfiles": [
|
||||
"baselineProfiles/0/app-release.dm"
|
||||
]
|
||||
}
|
||||
],
|
||||
"minSdkVersionForDexing": 23
|
||||
}
|
||||
35
app/src/main/AndroidManifest.xml
Normal file
35
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.touchscreen"
|
||||
android:required="false" />
|
||||
<uses-feature
|
||||
android:name="android.software.leanback"
|
||||
android:required="false" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:banner="@mipmap/ic_launcher"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.TV"
|
||||
android:hardwareAccelerated="true"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
28
app/src/main/java/net/tinsae/tv/MainActivity.kt
Normal file
28
app/src/main/java/net/tinsae/tv/MainActivity.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.tinsae.tv
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import net.tinsae.tv.ui.screens.MainScreen
|
||||
import net.tinsae.tv.ui.theme.TVTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// Ensure the app starts in dark mode
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
|
||||
// Ensure the window background is transparent to allow SurfaceView (Video)
|
||||
// to be visible through the UI layers.
|
||||
window.setBackgroundDrawableResource(android.R.color.transparent)
|
||||
|
||||
setContent {
|
||||
TVTheme {
|
||||
MainScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
app/src/main/java/net/tinsae/tv/data/AppDatabase.kt
Normal file
28
app/src/main/java/net/tinsae/tv/data/AppDatabase.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.tinsae.tv.data
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [ChannelEntity::class], version = 1, exportSchema = false)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun channelDao(): ChannelDao
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: AppDatabase? = null
|
||||
|
||||
fun getDatabase(context: Context): AppDatabase {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
val instance = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
AppDatabase::class.java,
|
||||
"tv_database"
|
||||
).build()
|
||||
INSTANCE = instance
|
||||
instance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/src/main/java/net/tinsae/tv/data/ChannelDao.kt
Normal file
25
app/src/main/java/net/tinsae/tv/data/ChannelDao.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package net.tinsae.tv.data
|
||||
|
||||
import androidx.room.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ChannelDao {
|
||||
@Query("SELECT * FROM channels WHERE isFavorite = 1")
|
||||
fun getFavorites(): Flow<List<ChannelEntity>>
|
||||
|
||||
@Query("SELECT url FROM channels WHERE isFavorite = 1")
|
||||
suspend fun getFavoriteUrls(): List<String>
|
||||
|
||||
@Query("SELECT * FROM channels WHERE lastPlayedTimestamp > 0 ORDER BY lastPlayedTimestamp DESC LIMIT 20")
|
||||
fun getLastPlayed(): Flow<List<ChannelEntity>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertChannel(channel: ChannelEntity)
|
||||
|
||||
@Update
|
||||
suspend fun updateChannel(channel: ChannelEntity)
|
||||
|
||||
@Query("SELECT * FROM channels WHERE url = :url")
|
||||
suspend fun getChannelByUrl(url: String): ChannelEntity?
|
||||
}
|
||||
15
app/src/main/java/net/tinsae/tv/data/ChannelEntity.kt
Normal file
15
app/src/main/java/net/tinsae/tv/data/ChannelEntity.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package net.tinsae.tv.data
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "channels")
|
||||
data class ChannelEntity(
|
||||
@PrimaryKey val url: String,
|
||||
val name: String,
|
||||
val logoUrl: String?,
|
||||
val group: String?,
|
||||
val id: String?,
|
||||
val isFavorite: Boolean = false,
|
||||
val lastPlayedTimestamp: Long = 0
|
||||
)
|
||||
21
app/src/main/java/net/tinsae/tv/data/mapper/ChannelMapper.kt
Normal file
21
app/src/main/java/net/tinsae/tv/data/mapper/ChannelMapper.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.tinsae.tv.data.mapper
|
||||
|
||||
import net.tinsae.tv.data.ChannelEntity
|
||||
import net.tinsae.tv.model.Channel
|
||||
|
||||
fun Channel.toEntity() = ChannelEntity(
|
||||
url = url,
|
||||
name = name,
|
||||
logoUrl = logoUrl,
|
||||
group = group,
|
||||
id = id
|
||||
)
|
||||
|
||||
fun ChannelEntity.toChannel(forceFavorite: Boolean = false) = Channel(
|
||||
name = name,
|
||||
url = url,
|
||||
logoUrl = logoUrl,
|
||||
group = group,
|
||||
id = id,
|
||||
isFavorite = forceFavorite || isFavorite
|
||||
)
|
||||
11
app/src/main/java/net/tinsae/tv/model/Category.kt
Normal file
11
app/src/main/java/net/tinsae/tv/model/Category.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package net.tinsae.tv.model
|
||||
|
||||
data class Category(
|
||||
val name: String,
|
||||
val url: String,
|
||||
val type: CategoryType
|
||||
)
|
||||
|
||||
enum class CategoryType {
|
||||
COUNTRY, LANGUAGE, GENRE, FAVORITES, LAST_PLAYED, CHANNEL_LIST
|
||||
}
|
||||
10
app/src/main/java/net/tinsae/tv/model/Channel.kt
Normal file
10
app/src/main/java/net/tinsae/tv/model/Channel.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package net.tinsae.tv.model
|
||||
|
||||
data class Channel(
|
||||
val name: String,
|
||||
val url: String,
|
||||
val logoUrl: String? = null,
|
||||
val group: String? = null,
|
||||
val id: String? = null,
|
||||
val isFavorite: Boolean = false
|
||||
)
|
||||
26
app/src/main/java/net/tinsae/tv/network/M3uService.kt
Normal file
26
app/src/main/java/net/tinsae/tv/network/M3uService.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package net.tinsae.tv.network
|
||||
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Url
|
||||
|
||||
interface M3uService {
|
||||
@GET
|
||||
suspend fun fetchM3u(@Url url: String): String
|
||||
|
||||
companion object {
|
||||
private var instance: M3uService? = null
|
||||
|
||||
fun getInstance(): M3uService {
|
||||
if (instance == null) {
|
||||
val retrofit = Retrofit.Builder()
|
||||
.baseUrl("https://example.com/") // Base URL is required but overridden by @Url
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.build()
|
||||
instance = retrofit.create(M3uService::class.java)
|
||||
}
|
||||
return instance!!
|
||||
}
|
||||
}
|
||||
}
|
||||
70
app/src/main/java/net/tinsae/tv/parser/M3uParser.kt
Normal file
70
app/src/main/java/net/tinsae/tv/parser/M3uParser.kt
Normal file
@@ -0,0 +1,70 @@
|
||||
package net.tinsae.tv.parser
|
||||
|
||||
import net.tinsae.tv.model.Channel
|
||||
|
||||
object M3uParser {
|
||||
fun parse(content: String): List<Channel> {
|
||||
val channels = mutableListOf<Channel>()
|
||||
val lines = content.lines()
|
||||
|
||||
var currentName = ""
|
||||
var currentLogo: String? = null
|
||||
var currentGroup: String? = null
|
||||
var currentId: String? = null
|
||||
|
||||
for (line in lines) {
|
||||
val trimmedLine = line.trim()
|
||||
if (trimmedLine.startsWith("#EXTINF:", ignoreCase = true)) {
|
||||
// Reset metadata for a new entry
|
||||
currentName = ""
|
||||
currentLogo = null
|
||||
currentGroup = null
|
||||
currentId = null
|
||||
|
||||
val metadata = trimmedLine.substring(8) // After "#EXTINF:"
|
||||
|
||||
// M3U standard: #EXTINF:duration attributes,name
|
||||
// We look for the last comma to separate attributes from name
|
||||
val lastCommaIndex = metadata.lastIndexOf(',')
|
||||
if (lastCommaIndex != -1) {
|
||||
currentName = metadata.substring(lastCommaIndex + 1).trim()
|
||||
val attributesPart = metadata.substring(0, lastCommaIndex)
|
||||
|
||||
currentId = extractAttribute(attributesPart, "tvg-id")
|
||||
currentLogo = extractAttribute(attributesPart, "tvg-logo")
|
||||
currentGroup = extractAttribute(attributesPart, "group-title")
|
||||
} else {
|
||||
// Fallback for malformed or simple #EXTINF lines
|
||||
// Try to skip duration and take the rest as name
|
||||
val parts = metadata.split(Regex("\\s+"), limit = 2)
|
||||
if (parts.size >= 2) {
|
||||
currentName = parts[1].trim()
|
||||
} else {
|
||||
currentName = metadata.trim()
|
||||
}
|
||||
}
|
||||
} else if (trimmedLine.isNotEmpty() && !trimmedLine.startsWith("#")) {
|
||||
// This line is the URL
|
||||
if (currentName.isNotEmpty()) {
|
||||
channels.add(
|
||||
Channel(
|
||||
name = currentName,
|
||||
url = trimmedLine,
|
||||
logoUrl = currentLogo,
|
||||
group = currentGroup,
|
||||
id = currentId
|
||||
)
|
||||
)
|
||||
// Reset name after adding to avoid duplicates if multiple URLs follow
|
||||
currentName = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
return channels
|
||||
}
|
||||
|
||||
private fun extractAttribute(source: String, attributeName: String): String? {
|
||||
val pattern = """$attributeName="([^"]+)"""".toRegex()
|
||||
return pattern.find(source)?.groupValues?.get(1)
|
||||
}
|
||||
}
|
||||
86
app/src/main/java/net/tinsae/tv/repo/ChannelRepository.kt
Normal file
86
app/src/main/java/net/tinsae/tv/repo/ChannelRepository.kt
Normal file
@@ -0,0 +1,86 @@
|
||||
package net.tinsae.tv.repo
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import net.tinsae.tv.data.ChannelDao
|
||||
import net.tinsae.tv.data.mapper.toChannel
|
||||
import net.tinsae.tv.data.mapper.toEntity
|
||||
import net.tinsae.tv.model.Category
|
||||
import net.tinsae.tv.model.CategoryType
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.network.M3uService
|
||||
import net.tinsae.tv.parser.M3uParser
|
||||
import org.json.JSONArray
|
||||
|
||||
class ChannelRepository(private val channelDao: ChannelDao) {
|
||||
|
||||
fun getFavorites(): Flow<List<Channel>> = channelDao.getFavorites().map { entities ->
|
||||
entities.map { it.toChannel(true) }
|
||||
}
|
||||
|
||||
fun getLastPlayed(): Flow<List<Channel>> = channelDao.getLastPlayed().map { entities ->
|
||||
entities.map { it.toChannel() }
|
||||
}
|
||||
|
||||
suspend fun saveChannel(channel: Channel, isFavorite: Boolean? = null, lastPlayed: Boolean = false) {
|
||||
val existing = channelDao.getChannelByUrl(channel.url)
|
||||
val finalIsFavorite = isFavorite ?: existing?.isFavorite ?: false
|
||||
val finalLastPlayed = if (lastPlayed) System.currentTimeMillis() else existing?.lastPlayedTimestamp ?: 0L
|
||||
|
||||
val entity = channel.toEntity().copy(
|
||||
isFavorite = finalIsFavorite,
|
||||
lastPlayedTimestamp = finalLastPlayed
|
||||
)
|
||||
channelDao.insertChannel(entity)
|
||||
}
|
||||
|
||||
suspend fun fetchSubCategories(type: CategoryType): List<Category> {
|
||||
val apiUrl = when (type) {
|
||||
CategoryType.COUNTRY -> "https://iptv-org.github.io/api/countries.json"
|
||||
CategoryType.LANGUAGE -> "https://iptv-org.github.io/api/languages.json"
|
||||
CategoryType.GENRE -> "https://iptv-org.github.io/api/categories.json"
|
||||
else -> return emptyList()
|
||||
}
|
||||
|
||||
val jsonResponse = M3uService.getInstance().fetchM3u(apiUrl)
|
||||
val jsonArray = JSONArray(jsonResponse)
|
||||
val subCategories = mutableListOf<Category>()
|
||||
|
||||
for (i in 0 until jsonArray.length()) {
|
||||
val obj = jsonArray.getJSONObject(i)
|
||||
val name = obj.getString("name")
|
||||
|
||||
val m3uUrl = when (type) {
|
||||
CategoryType.COUNTRY -> {
|
||||
val code = obj.getString("code").lowercase()
|
||||
"https://iptv-org.github.io/iptv/countries/$code.m3u"
|
||||
}
|
||||
CategoryType.LANGUAGE -> {
|
||||
val code = obj.getString("code").lowercase()
|
||||
"https://iptv-org.github.io/iptv/languages/$code.m3u"
|
||||
}
|
||||
CategoryType.GENRE -> {
|
||||
val id = obj.getString("id")
|
||||
"https://iptv-org.github.io/iptv/categories/$id.m3u"
|
||||
}
|
||||
else -> ""
|
||||
}
|
||||
|
||||
subCategories.add(Category(name, m3uUrl, CategoryType.CHANNEL_LIST))
|
||||
}
|
||||
|
||||
return subCategories.sortedBy { it.name }
|
||||
}
|
||||
|
||||
suspend fun fetchChannels(category: Category): List<Channel> {
|
||||
val m3uContent = M3uService.getInstance().fetchM3u(category.url)
|
||||
val channels = M3uParser.parse(m3uContent)
|
||||
|
||||
// Batch lookup of all favorite URLs to avoid N+1 queries
|
||||
val favoriteUrls = channelDao.getFavoriteUrls().toSet()
|
||||
|
||||
return channels.map { channel ->
|
||||
channel.copy(isFavorite = favoriteUrls.contains(channel.url))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.tinsae.tv.ui.components.category
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.*
|
||||
import net.tinsae.tv.model.Category
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
@Composable
|
||||
fun CategoryCard(
|
||||
category: Category,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
onClick = onClick,
|
||||
modifier = modifier
|
||||
.padding(8.dp)
|
||||
.aspectRatio(30f / 10f)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = category.name,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 2
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.tinsae.tv.ui.components.category
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.tinsae.tv.model.Category
|
||||
import net.tinsae.tv.ui.components.common.SearchBar
|
||||
|
||||
@Composable
|
||||
fun CategoryGrid(
|
||||
categories: List<Category>,
|
||||
searchQuery: String,
|
||||
onSearchQueryChange: (String) -> Unit,
|
||||
onCategoryClick: (Category) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
initialSelectedCategory: Category? = null
|
||||
) {
|
||||
val gridState = rememberLazyGridState()
|
||||
|
||||
// Filter categories based on search query
|
||||
val filteredCategories = remember(categories, searchQuery) {
|
||||
if (searchQuery.isBlank()) {
|
||||
categories
|
||||
} else {
|
||||
categories.filter { it.name.contains(searchQuery, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
|
||||
val focusRequesters = remember(filteredCategories) {
|
||||
List(filteredCategories.size) { FocusRequester() }
|
||||
}
|
||||
|
||||
LaunchedEffect(filteredCategories, initialSelectedCategory) {
|
||||
val index = filteredCategories.indexOfFirst { it.url == initialSelectedCategory?.url }
|
||||
if (index != -1) {
|
||||
gridState.scrollToItem(index)
|
||||
focusRequesters[index].requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = modifier.fillMaxSize()) {
|
||||
SearchBar(
|
||||
query = searchQuery,
|
||||
onQueryChange = onSearchQueryChange,
|
||||
placeholder = "Search categories..."
|
||||
)
|
||||
|
||||
LazyVerticalGrid(
|
||||
state = gridState,
|
||||
columns = GridCells.Fixed(4),
|
||||
contentPadding = PaddingValues(32.dp),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
itemsIndexed(filteredCategories) { index, category ->
|
||||
CategoryCard(
|
||||
category = category,
|
||||
onClick = { onCategoryClick(category) },
|
||||
modifier = Modifier.focusRequester(focusRequesters[index])
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.tinsae.tv.ui.components.channel
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.nativeKeyCode
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.CompactCard
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import androidx.tv.material3.Icon
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Text
|
||||
import coil.compose.AsyncImage
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.util.Misc.makeName
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChannelCard(
|
||||
channel: Channel,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: (() -> Unit)? = null,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
CompactCard(
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
image = {
|
||||
Box {
|
||||
AsyncImage(
|
||||
model = channel.logoUrl,
|
||||
contentDescription = channel.name,
|
||||
modifier = Modifier.aspectRatio(16f / 9f)
|
||||
)
|
||||
if (channel.isFavorite) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Favorite,
|
||||
contentDescription = "Favorite",
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(8.dp),
|
||||
tint = Color.Red
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(
|
||||
text = channel.name.makeName(),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(5.dp)
|
||||
)
|
||||
},
|
||||
modifier = modifier
|
||||
.padding(8.dp)
|
||||
.onKeyEvent { keyEvent ->
|
||||
if (keyEvent.type == KeyEventType.KeyDown) {
|
||||
when (keyEvent.key.nativeKeyCode) {
|
||||
KeyEvent.KEYCODE_PROG_RED,
|
||||
KeyEvent.KEYCODE_PROG_GREEN,
|
||||
KeyEvent.KEYCODE_PROG_YELLOW,
|
||||
KeyEvent.KEYCODE_PROG_BLUE -> {
|
||||
onLongClick?.invoke()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.tinsae.tv.ui.components.channel
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.ui.components.common.SearchBar
|
||||
|
||||
@Composable
|
||||
fun ChannelGrid(
|
||||
channels: List<Channel>,
|
||||
searchQuery: String,
|
||||
onSearchQueryChange: (String) -> Unit,
|
||||
onChannelClick: (Channel) -> Unit,
|
||||
onToggleFavorite: (Channel) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
initialSelectedChannel: Channel? = null
|
||||
) {
|
||||
val gridState = rememberLazyGridState()
|
||||
|
||||
// Filter channels based on search query
|
||||
val filteredChannels = remember(channels, searchQuery) {
|
||||
if (searchQuery.isBlank()) {
|
||||
channels
|
||||
} else {
|
||||
channels.filter { it.name.contains(searchQuery, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
|
||||
val focusRequesters = remember(filteredChannels) {
|
||||
List(filteredChannels.size) { FocusRequester() }
|
||||
}
|
||||
|
||||
LaunchedEffect(filteredChannels, initialSelectedChannel) {
|
||||
val index = filteredChannels.indexOfFirst { it.url == initialSelectedChannel?.url }
|
||||
if (index != -1) {
|
||||
gridState.scrollToItem(index)
|
||||
focusRequesters[index].requestFocus()
|
||||
} else if (filteredChannels.isNotEmpty()) {
|
||||
// Only request focus if we aren't typing in the search bar
|
||||
// Actually, we usually want to keep focus on the search bar while typing
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = modifier.fillMaxSize()) {
|
||||
SearchBar(
|
||||
query = searchQuery,
|
||||
onQueryChange = onSearchQueryChange,
|
||||
placeholder = "Search channels..."
|
||||
)
|
||||
|
||||
LazyVerticalGrid(
|
||||
state = gridState,
|
||||
columns = GridCells.Fixed(5),
|
||||
contentPadding = PaddingValues(32.dp),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
itemsIndexed(filteredChannels) { index, channel ->
|
||||
ChannelCard(
|
||||
channel = channel,
|
||||
onClick = { onChannelClick(channel) },
|
||||
onLongClick = { onToggleFavorite(channel) },
|
||||
modifier = Modifier.focusRequester(focusRequesters[index])
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.tinsae.tv.ui.components.channel
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Text
|
||||
import net.tinsae.tv.model.Channel
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChannelRow(
|
||||
title: String,
|
||||
channels: List<Channel>,
|
||||
onChannelClick: (Channel) -> Unit,
|
||||
onToggleFavorite: (Channel) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
firstItemFocusRequester: FocusRequester? = null,
|
||||
initialSelectedChannel: Channel? = null
|
||||
) {
|
||||
val listState = rememberLazyListState()
|
||||
val focusRequesters = remember(channels) {
|
||||
List(channels.size) { FocusRequester() }
|
||||
}
|
||||
|
||||
LaunchedEffect(channels, initialSelectedChannel) {
|
||||
val index = channels.indexOfFirst { it.url == initialSelectedChannel?.url }
|
||||
if (index != -1) {
|
||||
listState.scrollToItem(index)
|
||||
focusRequesters[index].requestFocus()
|
||||
} else if (channels.isNotEmpty() && firstItemFocusRequester != null) {
|
||||
// This is for the video player overlay case
|
||||
firstItemFocusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = modifier.padding(vertical = 16.dp)) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = Modifier.padding(start = 32.dp, bottom = 8.dp)
|
||||
)
|
||||
|
||||
if (channels.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(150.dp)
|
||||
.padding(horizontal = 32.dp),
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
Text(
|
||||
text = "No channels here yet",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyRow(
|
||||
state = listState,
|
||||
contentPadding = PaddingValues(horizontal = 24.dp)
|
||||
) {
|
||||
itemsIndexed(channels, key = { _, channel -> channel.url }) { index, channel ->
|
||||
val itemFocusRequester = if (index == 0 && firstItemFocusRequester != null) {
|
||||
firstItemFocusRequester
|
||||
} else {
|
||||
focusRequesters[index]
|
||||
}
|
||||
|
||||
ChannelCard(
|
||||
channel = channel,
|
||||
onClick = { onChannelClick(channel) },
|
||||
onLongClick = { onToggleFavorite(channel) },
|
||||
modifier = Modifier
|
||||
.width(200.dp)
|
||||
.focusRequester(itemFocusRequester)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.tinsae.tv.ui.components.common
|
||||
|
||||
import android.graphics.Color
|
||||
import android.widget.TextClock
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import net.tinsae.tv.ui.theme.black
|
||||
|
||||
@Composable
|
||||
fun DigitalClock() {
|
||||
val shape = RoundedTrapezoidShape(15.dp, 7.dp)
|
||||
|
||||
Box(modifier = Modifier.fillMaxWidth().padding(16.dp, 0.dp), contentAlignment = Alignment.TopCenter){
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
TextClock(context).apply {
|
||||
format12Hour = "hh:mm a"
|
||||
textSize= 14f
|
||||
setTextColor(Color.WHITE)
|
||||
setPadding(5,0,5,0)
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(0.dp)
|
||||
.background(
|
||||
color = black,
|
||||
shape = shape
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.tinsae.tv.ui.components.common
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
|
||||
@Composable
|
||||
fun SearchBar(
|
||||
query: String,
|
||||
onQueryChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
placeholder: String = "Search..."
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = query,
|
||||
onValueChange = onQueryChange,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 32.dp, vertical = 16.dp),
|
||||
placeholder = { Text(text = placeholder, color = Color.Gray) },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Search,
|
||||
contentDescription = "Search Icon",
|
||||
tint = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
},
|
||||
singleLine = true,
|
||||
colors = OutlinedTextFieldDefaults.colors(
|
||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
||||
unfocusedBorderColor = Color.Gray,
|
||||
cursorColor = MaterialTheme.colorScheme.primary,
|
||||
focusedTextColor = Color.White,
|
||||
unfocusedTextColor = Color.White
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.tinsae.tv.ui.components.common
|
||||
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Outline
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
|
||||
class TrapezoidShape(private val angle: Float) : Shape {
|
||||
override fun createOutline(
|
||||
size: Size,
|
||||
layoutDirection: LayoutDirection,
|
||||
density: Density
|
||||
): Outline {
|
||||
val path = Path().apply {
|
||||
moveTo(angle, 0f)
|
||||
lineTo(size.width - angle, 0f)
|
||||
lineTo(size.width, size.height)
|
||||
lineTo(0f, size.height)
|
||||
close()
|
||||
}
|
||||
return Outline.Generic(path)
|
||||
}
|
||||
}
|
||||
|
||||
class RoundedTrapezoidShape(
|
||||
private val topOffset: Dp,
|
||||
private val cornerRadius: Dp
|
||||
) : Shape {
|
||||
override fun createOutline(
|
||||
size: Size,
|
||||
layoutDirection: LayoutDirection,
|
||||
density: Density
|
||||
): Outline {
|
||||
val offset = with(density) { topOffset.toPx() }
|
||||
val radius = with(density) { cornerRadius.toPx() }
|
||||
|
||||
val path = Path().apply {
|
||||
// Start at top-left (no radius)
|
||||
moveTo(0f - offset, 0f)
|
||||
// Line to top-right (no radius)
|
||||
lineTo(size.width + offset, 0f)
|
||||
|
||||
// Line towards bottom-right corner, then curve
|
||||
lineTo(size.width + radius * 0.5f, size.height - radius * 0.5f)
|
||||
quadraticTo(size.width, size.height, size.width - radius, size.height )
|
||||
|
||||
// Line towards bottom-left corner, then curve
|
||||
lineTo( radius, size.height)
|
||||
quadraticTo(0f, size.height, -radius * 0.5f, size.height - radius * 0.5f)
|
||||
|
||||
close()
|
||||
}
|
||||
return Outline.Generic(path)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.tinsae.tv.ui.components.player
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.ui.components.channel.ChannelRow
|
||||
import net.tinsae.tv.ui.theme.translucent
|
||||
|
||||
@Composable
|
||||
fun ChannelOverlay(
|
||||
visible: Boolean,
|
||||
channels: List<Channel>,
|
||||
onChannelChange: (Channel) -> Unit,
|
||||
onToggleFavorite: (Channel) -> Unit,
|
||||
firstItemFocusRequester: FocusRequester,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
modifier = modifier
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(translucent)
|
||||
.padding(vertical = 6.dp)
|
||||
) {
|
||||
ChannelRow(
|
||||
title = "Channels",
|
||||
channels = channels,
|
||||
onChannelClick = onChannelChange,
|
||||
onToggleFavorite = onToggleFavorite,
|
||||
firstItemFocusRequester = firstItemFocusRequester
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.tinsae.tv.ui.components.player
|
||||
|
||||
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.input.key.KeyEvent
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.type
|
||||
import android.view.KeyEvent as NativeKeyEvent
|
||||
|
||||
fun eventHandler( keyEvent: KeyEvent,
|
||||
onToggleOverlay: (showOverlay: Boolean) -> Unit,
|
||||
playerFocusRequester: FocusRequester
|
||||
): Boolean
|
||||
{
|
||||
|
||||
if(keyEvent.type == KeyEventType.KeyDown){
|
||||
when(keyEvent.nativeKeyEvent.keyCode){
|
||||
// up show overlay
|
||||
NativeKeyEvent.KEYCODE_DPAD_UP -> {
|
||||
onToggleOverlay(true)
|
||||
return true
|
||||
}
|
||||
|
||||
// down hide overlay
|
||||
NativeKeyEvent.KEYCODE_DPAD_DOWN -> {
|
||||
onToggleOverlay(false)
|
||||
playerFocusRequester.requestFocus()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.tinsae.tv.ui.components.player
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Text
|
||||
|
||||
@Composable
|
||||
fun PlaybackErrorMessage(message: String) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black.copy(alpha = 0.5f)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = message,
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
modifier = Modifier.padding(32.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package net.tinsae.tv.ui.components.player
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.ui.PlayerView
|
||||
import net.tinsae.tv.ui.theme.cyan
|
||||
|
||||
|
||||
@Composable
|
||||
fun PlayerContainer(isLoading: Boolean, exoPlayer: ExoPlayer, playerFocusRequester: FocusRequester){
|
||||
AndroidView(
|
||||
factory = { ctx ->
|
||||
playerView(ctx, exoPlayer)
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.focusRequester(playerFocusRequester)
|
||||
.focusable()
|
||||
)
|
||||
|
||||
if (isLoading) {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
color = cyan
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OptIn(UnstableApi::class)
|
||||
fun playerView(ctx: Context, exoPlayer: ExoPlayer): View {
|
||||
return PlayerView(ctx).apply {
|
||||
player = exoPlayer
|
||||
useController = false
|
||||
// Keep the screen awake while the video player is visible
|
||||
keepScreenOn = true
|
||||
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package net.tinsae.tv.ui.components.player
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.session.MediaSession
|
||||
import kotlinx.coroutines.delay
|
||||
import net.tinsae.tv.model.Channel
|
||||
|
||||
@OptIn(UnstableApi::class)
|
||||
@Composable
|
||||
fun VideoPlayer(
|
||||
url: String,
|
||||
channels: List<Channel>,
|
||||
onChannelChange: (Channel) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
onToggleFavorite: (Channel) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var isLoading by remember { mutableStateOf(true) }
|
||||
var errorMessage by remember { mutableStateOf<String?>(null) }
|
||||
var showChannelList by remember { mutableStateOf(false) }
|
||||
val playerFocusRequester = remember { FocusRequester() }
|
||||
val firstItemFocusRequester = remember { FocusRequester() }
|
||||
|
||||
val exoPlayer = remember {
|
||||
ExoPlayer.Builder(context).build().apply {
|
||||
setMediaItem(MediaItem.fromUri(url))
|
||||
prepare()
|
||||
playWhenReady = true
|
||||
|
||||
addListener(object : Player.Listener {
|
||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||
isLoading = playbackState == Player.STATE_BUFFERING ||
|
||||
playbackState == Player.STATE_IDLE
|
||||
if (playbackState == Player.STATE_READY) {
|
||||
errorMessage = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPlayerError(error: PlaybackException) {
|
||||
isLoading = false
|
||||
errorMessage = "Playback Error: ${error.localizedMessage}"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// MediaSession
|
||||
DisposableEffect(exoPlayer) {
|
||||
val mediaSession = MediaSession.Builder(context, exoPlayer).build()
|
||||
onDispose {
|
||||
mediaSession.release()
|
||||
exoPlayer.release()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
playerFocusRequester.requestFocus()
|
||||
}
|
||||
|
||||
// Update media item if URL changes
|
||||
LaunchedEffect(url) {
|
||||
errorMessage = null
|
||||
isLoading = true
|
||||
exoPlayer.setMediaItem(MediaItem.fromUri(url))
|
||||
exoPlayer.prepare()
|
||||
exoPlayer.playWhenReady = true
|
||||
showChannelList = false
|
||||
playerFocusRequester.requestFocus()
|
||||
}
|
||||
|
||||
// Focus to list when it appears
|
||||
LaunchedEffect(showChannelList) {
|
||||
if (showChannelList) {
|
||||
delay(200)
|
||||
firstItemFocusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler(onBack = {
|
||||
if (showChannelList) {
|
||||
showChannelList = false
|
||||
playerFocusRequester.requestFocus()
|
||||
} else {
|
||||
onBack()
|
||||
}
|
||||
})
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.onKeyEvent { event ->
|
||||
eventHandler(
|
||||
keyEvent = event,
|
||||
onToggleOverlay = { showChannelList = it },
|
||||
playerFocusRequester = playerFocusRequester
|
||||
)
|
||||
}
|
||||
) {
|
||||
PlayerContainer(isLoading, exoPlayer, playerFocusRequester)
|
||||
|
||||
errorMessage?.let { msg ->
|
||||
PlaybackErrorMessage(message = msg)
|
||||
}
|
||||
|
||||
ChannelOverlay(
|
||||
visible = showChannelList,
|
||||
channels = channels,
|
||||
onChannelChange = onChannelChange,
|
||||
onToggleFavorite = onToggleFavorite,
|
||||
firstItemFocusRequester = firstItemFocusRequester,
|
||||
modifier = Modifier.align(Alignment.BottomCenter)
|
||||
)
|
||||
}
|
||||
}
|
||||
94
app/src/main/java/net/tinsae/tv/ui/screens/HomeScreen.kt
Normal file
94
app/src/main/java/net/tinsae/tv/ui/screens/HomeScreen.kt
Normal file
@@ -0,0 +1,94 @@
|
||||
package net.tinsae.tv.ui.screens
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Text
|
||||
import net.tinsae.tv.model.Category
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.ui.components.category.CategoryCard
|
||||
import net.tinsae.tv.ui.components.channel.ChannelRow
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
favorites: List<Channel>,
|
||||
lastPlayed: List<Channel>,
|
||||
filterCategories: List<Category>,
|
||||
onChannelClick: (Channel, List<Channel>) -> Unit,
|
||||
onFilterClick: (Category) -> Unit,
|
||||
onToggleFavorite: (Channel) -> Unit,
|
||||
initialSelectedChannel: Channel? = null,
|
||||
initialSelectedCategory: Category? = null
|
||||
) {
|
||||
val filterFocusRequesters = remember { List(filterCategories.size) { FocusRequester() } }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (initialSelectedCategory != null) {
|
||||
val index = filterCategories.indexOfFirst { it.name == initialSelectedCategory.name }
|
||||
if (index != -1) {
|
||||
filterFocusRequesters[index].requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(bottom = 32.dp)
|
||||
) {
|
||||
item {
|
||||
ChannelRow(
|
||||
title = "Favorites",
|
||||
channels = favorites,
|
||||
onChannelClick = { onChannelClick(it, favorites) },
|
||||
onToggleFavorite = onToggleFavorite,
|
||||
initialSelectedChannel = initialSelectedChannel
|
||||
)
|
||||
}
|
||||
item {
|
||||
ChannelRow(
|
||||
title = "Recently Played",
|
||||
channels = lastPlayed,
|
||||
onChannelClick = { onChannelClick(it, lastPlayed) },
|
||||
onToggleFavorite = onToggleFavorite,
|
||||
initialSelectedChannel = initialSelectedChannel
|
||||
)
|
||||
}
|
||||
item {
|
||||
Column(modifier = Modifier.padding(vertical = 16.dp)) {
|
||||
Text(
|
||||
text = "Filter",
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
modifier = Modifier.padding(start = 32.dp, bottom = 8.dp)
|
||||
)
|
||||
LazyRow(
|
||||
contentPadding = PaddingValues(horizontal = 34.dp)
|
||||
) {
|
||||
itemsIndexed(filterCategories) { index, category ->
|
||||
CategoryCard(
|
||||
category = category,
|
||||
onClick = { onFilterClick(category) },
|
||||
modifier = Modifier
|
||||
.width(280.dp)
|
||||
.focusRequester(filterFocusRequesters[index])
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
152
app/src/main/java/net/tinsae/tv/ui/screens/MainScreen.kt
Normal file
152
app/src/main/java/net/tinsae/tv/ui/screens/MainScreen.kt
Normal file
@@ -0,0 +1,152 @@
|
||||
package net.tinsae.tv.ui.screens
|
||||
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Surface
|
||||
import androidx.tv.material3.Text
|
||||
import net.tinsae.tv.model.Category
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.ui.components.category.CategoryGrid
|
||||
import net.tinsae.tv.ui.components.channel.ChannelGrid
|
||||
import net.tinsae.tv.ui.components.common.DigitalClock
|
||||
import net.tinsae.tv.ui.components.player.VideoPlayer
|
||||
import net.tinsae.tv.ui.viewmodel.ChannelUiState
|
||||
import net.tinsae.tv.ui.viewmodel.ChannelViewModel
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
@Composable
|
||||
fun MainScreen(viewModel: ChannelViewModel = viewModel()) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val favorites by viewModel.favorites.collectAsState()
|
||||
val lastPlayed by viewModel.lastPlayed.collectAsState()
|
||||
val searchQuery by viewModel.searchQuery.collectAsState()
|
||||
|
||||
var playingChannel by remember { mutableStateOf<Channel?>(null) }
|
||||
var lastSelectedChannel by remember { mutableStateOf<Channel?>(null) }
|
||||
var currentChannelList by remember { mutableStateOf<List<Channel>>(emptyList()) }
|
||||
var lastSelectedCategory by remember { mutableStateOf<Category?>(null) }
|
||||
|
||||
// When video is playing, background must be transparent
|
||||
// so the SurfaceView hardware layer behind the window can be seen.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(if (playingChannel != null) Color.Transparent else MaterialTheme.colorScheme.background)
|
||||
) {
|
||||
if (playingChannel != null) {
|
||||
VideoPlayer(
|
||||
url = playingChannel!!.url,
|
||||
channels = currentChannelList,
|
||||
onChannelChange = {
|
||||
playingChannel = it
|
||||
lastSelectedChannel = it
|
||||
},
|
||||
onBack = { playingChannel = null },
|
||||
onToggleFavorite = { viewModel.toggleFavorite(it) }
|
||||
)
|
||||
LaunchedEffect(playingChannel) {
|
||||
viewModel.onChannelPlayed(playingChannel!!)
|
||||
}
|
||||
} else {
|
||||
BackHandler(enabled = uiState !is ChannelUiState.Home) {
|
||||
viewModel.goBack()
|
||||
}
|
||||
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
when (val state = uiState) {
|
||||
is ChannelUiState.Home -> {
|
||||
HomeScreen(
|
||||
favorites = favorites,
|
||||
lastPlayed = lastPlayed,
|
||||
filterCategories = viewModel.filterCategories,
|
||||
onChannelClick = { channel, list ->
|
||||
currentChannelList = list
|
||||
lastSelectedChannel = channel
|
||||
playingChannel = channel
|
||||
Log.d("PLAYING", "url ${channel.url}")
|
||||
},
|
||||
onFilterClick = { category ->
|
||||
lastSelectedCategory = category
|
||||
viewModel.fetchSubCategories(category)
|
||||
},
|
||||
onToggleFavorite = { viewModel.toggleFavorite(it) },
|
||||
initialSelectedChannel = lastSelectedChannel,
|
||||
initialSelectedCategory = lastSelectedCategory
|
||||
)
|
||||
}
|
||||
is ChannelUiState.Categories -> {
|
||||
Column {
|
||||
Text(
|
||||
text = state.title,
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
modifier = Modifier.padding(32.dp)
|
||||
)
|
||||
CategoryGrid(
|
||||
categories = state.categories,
|
||||
searchQuery = searchQuery,
|
||||
onSearchQueryChange = { viewModel.onSearchQueryChange(it) },
|
||||
onCategoryClick = { category ->
|
||||
lastSelectedCategory = category
|
||||
viewModel.fetchChannels(category)
|
||||
},
|
||||
initialSelectedCategory = lastSelectedCategory
|
||||
)
|
||||
}
|
||||
}
|
||||
is ChannelUiState.Success -> {
|
||||
Column {
|
||||
Text(
|
||||
text = state.title,
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
modifier = Modifier.padding(32.dp)
|
||||
)
|
||||
ChannelGrid(
|
||||
channels = state.channels,
|
||||
searchQuery = searchQuery,
|
||||
onSearchQueryChange = { viewModel.onSearchQueryChange(it) },
|
||||
onChannelClick = {
|
||||
currentChannelList = state.channels
|
||||
lastSelectedChannel = it
|
||||
playingChannel = it
|
||||
},
|
||||
onToggleFavorite = { viewModel.toggleFavorite(it) },
|
||||
initialSelectedChannel = lastSelectedChannel
|
||||
)
|
||||
}
|
||||
}
|
||||
is ChannelUiState.Loading -> {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
is ChannelUiState.Error -> {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Text(text = "Error: ${state.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DigitalClock()
|
||||
}
|
||||
}
|
||||
19
app/src/main/java/net/tinsae/tv/ui/theme/Color.kt
Normal file
19
app/src/main/java/net/tinsae/tv/ui/theme/Color.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package net.tinsae.tv.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
|
||||
val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
|
||||
val cyan = Color(0xFF03A9F4)
|
||||
val gray = Color(0xFF424242)
|
||||
val black = Color(0xFF000000)
|
||||
|
||||
val clear = Color(0x00000000)
|
||||
|
||||
val translucent = Color(0x60000000)
|
||||
23
app/src/main/java/net/tinsae/tv/ui/theme/Theme.kt
Normal file
23
app/src/main/java/net/tinsae/tv/ui/theme/Theme.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package net.tinsae.tv.ui.theme
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.darkColorScheme
|
||||
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
@Composable
|
||||
fun TVTheme(
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val colorScheme = darkColorScheme(
|
||||
primary = Purple80,
|
||||
secondary = PurpleGrey80,
|
||||
tertiary = Pink80
|
||||
)
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
36
app/src/main/java/net/tinsae/tv/ui/theme/Type.kt
Normal file
36
app/src/main/java/net/tinsae/tv/ui/theme/Type.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package net.tinsae.tv.ui.theme
|
||||
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||
import androidx.tv.material3.Typography
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
@OptIn(ExperimentalTvMaterial3Api::class)
|
||||
val Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
/* Other default text styles to override
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 22.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
labelSmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
*/
|
||||
)
|
||||
118
app/src/main/java/net/tinsae/tv/ui/viewmodel/ChannelViewModel.kt
Normal file
118
app/src/main/java/net/tinsae/tv/ui/viewmodel/ChannelViewModel.kt
Normal file
@@ -0,0 +1,118 @@
|
||||
package net.tinsae.tv.ui.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import net.tinsae.tv.data.AppDatabase
|
||||
import net.tinsae.tv.model.Category
|
||||
import net.tinsae.tv.model.CategoryType
|
||||
import net.tinsae.tv.model.Channel
|
||||
import net.tinsae.tv.repo.ChannelRepository
|
||||
|
||||
sealed class ChannelUiState {
|
||||
data object Loading : ChannelUiState()
|
||||
data object Home : ChannelUiState()
|
||||
data class Categories(val categories: List<Category>, val title: String) : ChannelUiState()
|
||||
data class Success(val channels: List<Channel>, val title: String) : ChannelUiState()
|
||||
data class Error(val message: String) : ChannelUiState()
|
||||
}
|
||||
|
||||
class ChannelViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val repository = ChannelRepository(AppDatabase.getDatabase(application).channelDao())
|
||||
|
||||
private val _uiState = MutableStateFlow<ChannelUiState>(ChannelUiState.Home)
|
||||
val uiState: StateFlow<ChannelUiState> = _uiState.asStateFlow()
|
||||
|
||||
private val _searchQuery = MutableStateFlow("")
|
||||
val searchQuery: StateFlow<String> = _searchQuery.asStateFlow()
|
||||
|
||||
private val navigationStack = mutableListOf<ChannelUiState>()
|
||||
|
||||
val favorites: StateFlow<List<Channel>> = repository.getFavorites()
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
|
||||
|
||||
val lastPlayed: StateFlow<List<Channel>> = repository.getLastPlayed()
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
|
||||
|
||||
val filterCategories = listOf(
|
||||
Category("By Country", "", CategoryType.COUNTRY),
|
||||
Category("By Language", "", CategoryType.LANGUAGE),
|
||||
Category("By Category", "", CategoryType.GENRE)
|
||||
)
|
||||
|
||||
fun onSearchQueryChange(query: String) {
|
||||
_searchQuery.value = query
|
||||
}
|
||||
|
||||
fun showHome() {
|
||||
navigationStack.clear()
|
||||
_searchQuery.value = ""
|
||||
_uiState.value = ChannelUiState.Home
|
||||
}
|
||||
|
||||
fun goBack(): Boolean {
|
||||
_searchQuery.value = ""
|
||||
return if (navigationStack.isNotEmpty()) {
|
||||
_uiState.value = navigationStack.removeAt(navigationStack.size - 1)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchSubCategories(category: Category) {
|
||||
viewModelScope.launch {
|
||||
val previousState = _uiState.value
|
||||
_uiState.value = ChannelUiState.Loading
|
||||
_searchQuery.value = "" // Clear search when navigating
|
||||
try {
|
||||
val subCategories = repository.fetchSubCategories(category.type)
|
||||
navigationStack.add(previousState)
|
||||
_uiState.value = ChannelUiState.Categories(subCategories, category.name)
|
||||
} catch (e: Exception) {
|
||||
_uiState.value = ChannelUiState.Error(e.message ?: "Unknown error occurred")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchChannels(category: Category) {
|
||||
viewModelScope.launch {
|
||||
val previousState = _uiState.value
|
||||
_uiState.value = ChannelUiState.Loading
|
||||
_searchQuery.value = "" // Clear search when navigating
|
||||
try {
|
||||
val channels = repository.fetchChannels(category)
|
||||
if (channels.isEmpty()) {
|
||||
throw Exception("No channels found for ${category.name}")
|
||||
}
|
||||
navigationStack.add(previousState)
|
||||
_uiState.value = ChannelUiState.Success(channels, category.name)
|
||||
} catch (e: Exception) {
|
||||
_uiState.value = ChannelUiState.Error(e.message ?: "Unknown error occurred")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onChannelPlayed(channel: Channel) {
|
||||
viewModelScope.launch {
|
||||
repository.saveChannel(channel, lastPlayed = true)
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleFavorite(channel: Channel) {
|
||||
viewModelScope.launch {
|
||||
val isFavorite = !channel.isFavorite
|
||||
repository.saveChannel(channel, isFavorite = isFavorite)
|
||||
|
||||
val currentState = _uiState.value
|
||||
if (currentState is ChannelUiState.Success) {
|
||||
val updatedList = currentState.channels.map {
|
||||
if (it.url == channel.url) it.copy(isFavorite = isFavorite) else it
|
||||
}
|
||||
_uiState.value = currentState.copy(channels = updatedList)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
app/src/main/java/net/tinsae/tv/util/Misc.kt
Normal file
20
app/src/main/java/net/tinsae/tv/util/Misc.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
package net.tinsae.tv.util
|
||||
|
||||
object Misc {
|
||||
|
||||
fun String.makeName(): String {
|
||||
// there are some strings that start wit a .
|
||||
val name = if (this.startsWith(".", ignoreCase = true)) {
|
||||
this.replace(".", "")
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
|
||||
if (name.contains("(")) {
|
||||
return name.substringBefore("(").trim()
|
||||
}
|
||||
|
||||
return name.trim()
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 982 B |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
3
app/src/main/res/values/strings.xml
Normal file
3
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">TV</string>
|
||||
</resources>
|
||||
4
app/src/main/res/values/themes.xml
Normal file
4
app/src/main/res/values/themes.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
|
||||
<style name="Theme.TV" parent="Theme.AppCompat.DayNight.NoActionBar" />
|
||||
</resources>
|
||||
7
build.gradle.kts
Normal file
7
build.gradle.kts
Normal file
@@ -0,0 +1,7 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
alias(libs.plugins.android.application) apply false
|
||||
alias(libs.plugins.kotlin.android) apply false
|
||||
alias(libs.plugins.kotlin.compose) apply false
|
||||
alias(libs.plugins.ksp) apply false
|
||||
}
|
||||
18
gradle.properties
Normal file
18
gradle.properties
Normal file
@@ -0,0 +1,18 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. For more details, visit
|
||||
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
|
||||
# org.gradle.parallel=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
android.disallowKotlinSourceSets=false
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
12
gradle/gradle-daemon-jvm.properties
Normal file
12
gradle/gradle-daemon-jvm.properties
Normal file
@@ -0,0 +1,12 @@
|
||||
#This file is generated by updateDaemonJvm
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/ec7520a1e057cd116f9544c42142a16b/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/4c4f879899012ff0a8b2e2117df03b0e/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/ec7520a1e057cd116f9544c42142a16b/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/4c4f879899012ff0a8b2e2117df03b0e/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/73bcfb608d1fde9fb62e462f834a3299/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/846ee0d876d26a26f37aa1ce8de73224/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/ec7520a1e057cd116f9544c42142a16b/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/4c4f879899012ff0a8b2e2117df03b0e/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/9482ddec596298c84656d31d16652665/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/39701d92e1756bb2f141eb67cd4c660e/redirect
|
||||
toolchainVersion=21
|
||||
55
gradle/libs.versions.toml
Normal file
55
gradle/libs.versions.toml
Normal file
@@ -0,0 +1,55 @@
|
||||
[versions]
|
||||
agp = "8.7.3"
|
||||
coreKtx = "1.15.0"
|
||||
appcompat = "1.7.0"
|
||||
kotlin = "2.0.21"
|
||||
composeBom = "2024.12.01"
|
||||
tvFoundation = "1.0.0-beta01"
|
||||
tvMaterial = "1.0.0"
|
||||
lifecycleRuntimeKtx = "2.8.7"
|
||||
activityCompose = "1.9.3"
|
||||
retrofit = "2.11.0"
|
||||
coroutines = "1.10.1"
|
||||
lifecycleViewmodelCompose = "2.8.7"
|
||||
coil = "2.7.0"
|
||||
material3 = "1.3.1"
|
||||
media3 = "1.5.0"
|
||||
room = "2.7.0-alpha11"
|
||||
ksp = "2.0.21-1.0.26"
|
||||
graphicsShapes = "1.1.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
|
||||
androidx-compose-ui = { group = "androidx.compose.ui" , name = "ui" }
|
||||
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
|
||||
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
|
||||
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
|
||||
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
|
||||
androidx-tv-foundation = { group = "androidx.tv", name = "tv-foundation", version.ref = "tvFoundation" }
|
||||
androidx-tv-material = { group = "androidx.tv", name = "tv-material", version.ref = "tvMaterial" }
|
||||
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
|
||||
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
|
||||
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
|
||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
|
||||
androidx-media3-exoplayer = { group = "androidx.media3", name = "media3-exoplayer", version.ref = "media3" }
|
||||
androidx-media3-ui = { group = "androidx.media3", name = "media3-ui", version.ref = "media3" }
|
||||
androidx-media3-hls = { group = "androidx.media3", name = "media3-exoplayer-hls", version.ref = "media3" }
|
||||
androidx-media3-session = { group = "androidx.media3", name = "media3-session", version.ref = "media3" }
|
||||
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
|
||||
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
|
||||
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
|
||||
retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
|
||||
retrofit-scalars = { group = "com.squareup.retrofit2", name = "converter-scalars", version.ref = "retrofit" }
|
||||
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
|
||||
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
|
||||
androidx-graphics-shapes = { group = "androidx.graphics", name = "graphics-shapes", version.ref = "graphicsShapes" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
9
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
9
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#Fri Mar 20 15:56:34 CET 2026
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=b266d5ff6b90eada6dc3b20cb090e3731302e553a27c5d3e4df1f0d76beaff06
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
251
gradlew
vendored
Executable file
251
gradlew
vendored
Executable file
@@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 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="\\\"\\\""
|
||||
|
||||
|
||||
# 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" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# 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" "$@"
|
||||
94
gradlew.bat
vendored
Normal file
94
gradlew.bat
vendored
Normal file
@@ -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=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
: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
|
||||
27
settings.gradle.kts
Normal file
27
settings.gradle.kts
Normal file
@@ -0,0 +1,27 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google {
|
||||
content {
|
||||
includeGroupByRegex("com\\.android.*")
|
||||
includeGroupByRegex("com\\.google.*")
|
||||
includeGroupByRegex("androidx.*")
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "TV"
|
||||
include(":app")
|
||||
|
||||
Reference in New Issue
Block a user