commit 82aa207f9ab5bc6a5b6ee04b217f433ea9c0442e Author: omigamedev Date: Tue Feb 24 12:03:43 2026 +0100 Initial commit: LCK Control Android app Multi-module Android app (app/shared/sdk) with backend-driven auth, Quest Platform SDK login, YouTube/Twitch OAuth linking, stream management via AIDL service. Compose UI with Hilt DI. diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..f1caee7 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,14 @@ +{ + "permissions": { + "allow": [ + "WebSearch", + "WebFetch(domain:developers.google.com)", + "WebFetch(domain:dev.twitch.tv)", + "WebFetch(domain:dev.epicgames.com)", + "WebFetch(domain:mvnrepository.com)", + "WebFetch(domain:developers.meta.com)", + "WebFetch(domain:central.sonatype.com)", + "Bash(javap:*)" + ] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..076da46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +**/build/ +/captures +.externalNativeBuild +.cxx +.kotlin +local.properties + +# Platform tools +ovr-platform-util.exe diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..93cfd14 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +LCK Control \ No newline at end of file diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..617e481 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7061a0d --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,61 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..6b5a3ed --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,158 @@ +import java.io.ByteArrayOutputStream + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.compose) + alias(libs.plugins.kotlin.parcelize) + alias(libs.plugins.hilt) + alias(libs.plugins.ksp) +} + +// ── Git-based versioning ──────────────────────────────────── +fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0") + .removePrefix("v") + .ifEmpty { "0.1.0" } + +fun gitCommitCount(): Int = runGit("rev-list", "--count", "HEAD") + .toIntOrNull() ?: 1 + +fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD") + .ifEmpty { "unknown" } + +fun gitDisplayVersion(): String { + val base = gitVersionName() + val count = gitCommitCount() + val hash = gitShortHash() + return "$base+$count.$hash" +} + +fun runGit(vararg args: String): String = try { + val out = ByteArrayOutputStream() + project.exec { + commandLine("git", *args) + standardOutput = out + isIgnoreExitValue = true + } + out.toString().trim() +} catch (_: Exception) { "" } + +// ───────────────────────────────────────────────────────────── + +android { + namespace = "com.omixlab.lckcontrol" + compileSdk { + version = release(36) { + minorApiLevel = 1 + } + } + + signingConfigs { + create("release") { + storeFile = rootProject.file("lck-control.keystore") + storePassword = "4gx%wx4NOhS6" + keyAlias = "lck-control" + keyPassword = "4gx%wx4NOhS6" + } + } + + defaultConfig { + applicationId = "com.omixlab.lckcontrol" + minSdk = 32 + targetSdk = 34 + versionCode = gitCommitCount() + versionName = gitVersionName() + + buildConfigField("String", "DISPLAY_VERSION", "\"${gitDisplayVersion()}\"") + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + debug { + signingConfig = signingConfigs.getByName("release") + } + release { + signingConfig = signingConfigs.getByName("release") + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + buildFeatures { + compose = true + buildConfig = true + } + packaging { + resources { + excludes += setOf( + "META-INF/DEPENDENCIES", + "META-INF/LICENSE", + "META-INF/LICENSE.txt", + "META-INF/NOTICE", + "META-INF/NOTICE.txt", + ) + } + } +} + +dependencies { + implementation(project(":shared")) + + // Core + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.lifecycle.viewmodel.compose) + implementation(libs.androidx.lifecycle.runtime.compose) + implementation(libs.kotlinx.coroutines.android) + + // Compose + implementation(libs.androidx.activity.compose) + 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.compose.material3) + implementation(libs.androidx.compose.material.icons.extended) + implementation(libs.androidx.navigation.compose) + + // Hilt + implementation(libs.hilt.android) + ksp(libs.hilt.compiler) + implementation(libs.androidx.hilt.navigation.compose) + + // Room + implementation(libs.room.runtime) + implementation(libs.room.ktx) + ksp(libs.room.compiler) + + // Networking + implementation(libs.retrofit) + implementation(libs.retrofit.converter.moshi) + implementation(libs.moshi.kotlin) + implementation(libs.okhttp) + implementation(libs.okhttp.logging) + + // Security + implementation(libs.androidx.security.crypto) + + // Meta Quest Platform SDK + implementation("com.meta.horizon.platform.ovr:android-platform-sdk:77.0.1") + + // Browser (Custom Tabs for OAuth flows) + implementation(libs.androidx.browser) + + // Test + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + 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) +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/omixlab/lckcontrol/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/omixlab/lckcontrol/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..63d4701 --- /dev/null +++ b/app/src/androidTest/java/com/omixlab/lckcontrol/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.omixlab.lckcontrol + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.omixlab.lckcontrol", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6df87a4 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/omixlab/lckcontrol/LckControlApp.kt b/app/src/main/java/com/omixlab/lckcontrol/LckControlApp.kt new file mode 100644 index 0000000..ae9327f --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/LckControlApp.kt @@ -0,0 +1,7 @@ +package com.omixlab.lckcontrol + +import android.app.Application +import dagger.hilt.android.HiltAndroidApp + +@HiltAndroidApp +class LckControlApp : Application() diff --git a/app/src/main/java/com/omixlab/lckcontrol/MainActivity.kt b/app/src/main/java/com/omixlab/lckcontrol/MainActivity.kt new file mode 100644 index 0000000..e74ab42 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/MainActivity.kt @@ -0,0 +1,27 @@ +package com.omixlab.lckcontrol + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import com.omixlab.lckcontrol.data.local.TokenStore +import com.omixlab.lckcontrol.ui.navigation.AppNavigation +import com.omixlab.lckcontrol.ui.theme.LCKControlTheme +import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject + +@AndroidEntryPoint +class MainActivity : ComponentActivity() { + + @Inject lateinit var tokenStore: TokenStore + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { + LCKControlTheme { + AppNavigation(tokenStore) + } + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/auth/TwitchAuthRedirectActivity.kt b/app/src/main/java/com/omixlab/lckcontrol/auth/TwitchAuthRedirectActivity.kt new file mode 100644 index 0000000..b2bd6b7 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/auth/TwitchAuthRedirectActivity.kt @@ -0,0 +1,41 @@ +package com.omixlab.lckcontrol.auth + +import android.content.Intent +import android.os.Bundle +import androidx.activity.ComponentActivity +import com.omixlab.lckcontrol.MainActivity +import com.omixlab.lckcontrol.data.remote.LckApiService +import com.omixlab.lckcontrol.data.remote.ProviderCallbackRequest +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import javax.inject.Inject + +@AndroidEntryPoint +class TwitchAuthRedirectActivity : ComponentActivity() { + + @Inject lateinit var apiService: LckApiService + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + val code = intent?.data?.getQueryParameter("code") + val state = intent?.data?.getQueryParameter("state") + if (code != null && state != null) { + CoroutineScope(Dispatchers.IO).launch { + try { + apiService.twitchCallback(ProviderCallbackRequest(code = code, state = state)) + } catch (e: Exception) { + // Error will be surfaced when accounts screen refreshes + } + } + } + + val mainIntent = Intent(this, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + } + startActivity(mainIntent) + finish() + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/auth/YouTubeAuthRedirectActivity.kt b/app/src/main/java/com/omixlab/lckcontrol/auth/YouTubeAuthRedirectActivity.kt new file mode 100644 index 0000000..2df021b --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/auth/YouTubeAuthRedirectActivity.kt @@ -0,0 +1,41 @@ +package com.omixlab.lckcontrol.auth + +import android.content.Intent +import android.os.Bundle +import androidx.activity.ComponentActivity +import com.omixlab.lckcontrol.MainActivity +import com.omixlab.lckcontrol.data.remote.LckApiService +import com.omixlab.lckcontrol.data.remote.ProviderCallbackRequest +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import javax.inject.Inject + +@AndroidEntryPoint +class YouTubeAuthRedirectActivity : ComponentActivity() { + + @Inject lateinit var apiService: LckApiService + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + val code = intent?.data?.getQueryParameter("code") + val state = intent?.data?.getQueryParameter("state") + if (code != null && state != null) { + CoroutineScope(Dispatchers.IO).launch { + try { + apiService.youtubeCallback(ProviderCallbackRequest(code = code, state = state)) + } catch (e: Exception) { + // Error will be surfaced when accounts screen refreshes + } + } + } + + val mainIntent = Intent(this, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + } + startActivity(mainIntent) + finish() + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/LckDatabase.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/LckDatabase.kt new file mode 100644 index 0000000..dbb89b7 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/LckDatabase.kt @@ -0,0 +1,73 @@ +package com.omixlab.lckcontrol.data.local + +import androidx.room.Database +import androidx.room.RoomDatabase +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase +import com.omixlab.lckcontrol.data.local.dao.LinkedAccountDao +import com.omixlab.lckcontrol.data.local.dao.StreamPlanDao +import com.omixlab.lckcontrol.data.local.entity.LinkedAccountEntity +import com.omixlab.lckcontrol.data.local.entity.StreamDestinationEntity +import com.omixlab.lckcontrol.data.local.entity.StreamPlanEntity + +@Database( + entities = [ + LinkedAccountEntity::class, + StreamPlanEntity::class, + StreamDestinationEntity::class, + ], + version = 2, + exportSchema = false, +) +abstract class LckDatabase : RoomDatabase() { + abstract fun linkedAccountDao(): LinkedAccountDao + abstract fun streamPlanDao(): StreamPlanDao + + companion object { + val MIGRATION_1_2 = object : Migration(1, 2) { + override fun migrate(db: SupportSQLiteDatabase) { + // 1. Remove token columns from linked_accounts + db.execSQL(""" + CREATE TABLE linked_accounts_new ( + serviceId TEXT NOT NULL PRIMARY KEY, + displayName TEXT NOT NULL, + accountId TEXT NOT NULL, + avatarUrl TEXT + ) + """.trimIndent()) + db.execSQL(""" + INSERT INTO linked_accounts_new (serviceId, displayName, accountId, avatarUrl) + SELECT serviceId, displayName, accountId, avatarUrl FROM linked_accounts + """.trimIndent()) + db.execSQL("DROP TABLE linked_accounts") + db.execSQL("ALTER TABLE linked_accounts_new RENAME TO linked_accounts") + + // 2. Change stream_destinations.id from INTEGER to TEXT + db.execSQL(""" + CREATE TABLE stream_destinations_new ( + id TEXT NOT NULL PRIMARY KEY, + planId TEXT NOT NULL, + service TEXT NOT NULL, + title TEXT NOT NULL, + description TEXT NOT NULL DEFAULT '', + privacyStatus TEXT NOT NULL DEFAULT 'public', + gameId TEXT NOT NULL DEFAULT '', + tags TEXT NOT NULL DEFAULT '', + rtmpUrl TEXT NOT NULL DEFAULT '', + streamKey TEXT NOT NULL DEFAULT '', + broadcastId TEXT NOT NULL DEFAULT '', + status TEXT NOT NULL DEFAULT 'PENDING', + FOREIGN KEY (planId) REFERENCES stream_plans(planId) ON DELETE CASCADE + ) + """.trimIndent()) + db.execSQL("CREATE INDEX index_stream_destinations_planId ON stream_destinations_new(planId)") + db.execSQL(""" + INSERT INTO stream_destinations_new (id, planId, service, title, description, privacyStatus, gameId, tags, rtmpUrl, streamKey, broadcastId, status) + SELECT CAST(id AS TEXT), planId, service, title, description, privacyStatus, gameId, tags, rtmpUrl, streamKey, broadcastId, status FROM stream_destinations + """.trimIndent()) + db.execSQL("DROP TABLE stream_destinations") + db.execSQL("ALTER TABLE stream_destinations_new RENAME TO stream_destinations") + } + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/TokenStore.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/TokenStore.kt new file mode 100644 index 0000000..c866de9 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/TokenStore.kt @@ -0,0 +1,50 @@ +package com.omixlab.lckcontrol.data.local + +import android.content.Context +import androidx.security.crypto.EncryptedSharedPreferences +import androidx.security.crypto.MasterKeys +import dagger.hilt.android.qualifiers.ApplicationContext +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class TokenStore @Inject constructor( + @ApplicationContext context: Context, +) { + private val masterKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC) + + private val prefs = EncryptedSharedPreferences.create( + "lck_control_tokens", + masterKey, + context, + EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, + EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM, + ) + + fun getJwt(): String? = + prefs.getString(KEY_JWT, null) + + fun getRefreshToken(): String? = + prefs.getString(KEY_REFRESH_TOKEN, null) + + fun saveSession(jwt: String, refreshToken: String) { + prefs.edit() + .putString(KEY_JWT, jwt) + .putString(KEY_REFRESH_TOKEN, refreshToken) + .apply() + } + + fun clearSession() { + prefs.edit() + .remove(KEY_JWT) + .remove(KEY_REFRESH_TOKEN) + .apply() + } + + fun isLoggedIn(): Boolean = getJwt() != null + + companion object { + private const val KEY_JWT = "session_jwt" + private const val KEY_REFRESH_TOKEN = "session_refresh_token" + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/dao/LinkedAccountDao.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/dao/LinkedAccountDao.kt new file mode 100644 index 0000000..475f523 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/dao/LinkedAccountDao.kt @@ -0,0 +1,30 @@ +package com.omixlab.lckcontrol.data.local.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import com.omixlab.lckcontrol.data.local.entity.LinkedAccountEntity +import kotlinx.coroutines.flow.Flow + +@Dao +interface LinkedAccountDao { + @Query("SELECT * FROM linked_accounts") + fun observeAll(): Flow> + + @Query("SELECT * FROM linked_accounts") + suspend fun getAll(): List + + @Query("SELECT * FROM linked_accounts WHERE serviceId = :serviceId") + suspend fun getByService(serviceId: String): LinkedAccountEntity? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun upsert(account: LinkedAccountEntity) + + @Delete + suspend fun delete(account: LinkedAccountEntity) + + @Query("DELETE FROM linked_accounts WHERE serviceId = :serviceId") + suspend fun deleteByService(serviceId: String) +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/dao/StreamPlanDao.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/dao/StreamPlanDao.kt new file mode 100644 index 0000000..601c1d4 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/dao/StreamPlanDao.kt @@ -0,0 +1,58 @@ +package com.omixlab.lckcontrol.data.local.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Transaction +import com.omixlab.lckcontrol.data.local.entity.StreamDestinationEntity +import com.omixlab.lckcontrol.data.local.entity.StreamPlanEntity +import com.omixlab.lckcontrol.data.local.entity.StreamPlanWithDestinations +import kotlinx.coroutines.flow.Flow + +@Dao +interface StreamPlanDao { + @Transaction + @Query("SELECT * FROM stream_plans ORDER BY createdAt DESC") + fun observeAll(): Flow> + + @Transaction + @Query("SELECT * FROM stream_plans ORDER BY createdAt DESC") + suspend fun getAll(): List + + @Transaction + @Query("SELECT * FROM stream_plans WHERE planId = :planId") + suspend fun getById(planId: String): StreamPlanWithDestinations? + + @Transaction + @Query("SELECT * FROM stream_plans WHERE planId = :planId") + fun observeById(planId: String): Flow + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun upsertPlan(plan: StreamPlanEntity) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun upsertDestination(destination: StreamDestinationEntity) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun upsertDestinations(destinations: List) + + @Query("DELETE FROM stream_destinations WHERE planId = :planId") + suspend fun deleteDestinations(planId: String) + + @Query("DELETE FROM stream_plans WHERE planId = :planId") + suspend fun deletePlan(planId: String) + + @Query("UPDATE stream_plans SET status = :status WHERE planId = :planId") + suspend fun updateStatus(planId: String, status: String) + + @Query("UPDATE stream_destinations SET rtmpUrl = :rtmpUrl, streamKey = :streamKey, broadcastId = :broadcastId, status = :status WHERE id = :id") + suspend fun updateDestinationStream(id: String, rtmpUrl: String, streamKey: String, broadcastId: String, status: String) + + @Transaction + suspend fun insertPlanWithDestinations(plan: StreamPlanEntity, destinations: List) { + upsertPlan(plan) + deleteDestinations(plan.planId) + upsertDestinations(destinations) + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/LinkedAccountEntity.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/LinkedAccountEntity.kt new file mode 100644 index 0000000..837663a --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/LinkedAccountEntity.kt @@ -0,0 +1,12 @@ +package com.omixlab.lckcontrol.data.local.entity + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "linked_accounts") +data class LinkedAccountEntity( + @PrimaryKey val serviceId: String, + val displayName: String, + val accountId: String, + val avatarUrl: String? = null, +) diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamDestinationEntity.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamDestinationEntity.kt new file mode 100644 index 0000000..0d89106 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamDestinationEntity.kt @@ -0,0 +1,34 @@ +package com.omixlab.lckcontrol.data.local.entity + +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.Index +import androidx.room.PrimaryKey +import java.util.UUID + +@Entity( + tableName = "stream_destinations", + foreignKeys = [ + ForeignKey( + entity = StreamPlanEntity::class, + parentColumns = ["planId"], + childColumns = ["planId"], + onDelete = ForeignKey.CASCADE, + ) + ], + indices = [Index("planId")], +) +data class StreamDestinationEntity( + @PrimaryKey val id: String = UUID.randomUUID().toString(), + val planId: String, + val service: String, + val title: String, + val description: String = "", + val privacyStatus: String = "public", + val gameId: String = "", + val tags: String = "", + val rtmpUrl: String = "", + val streamKey: String = "", + val broadcastId: String = "", + val status: String = "PENDING", +) diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamPlanEntity.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamPlanEntity.kt new file mode 100644 index 0000000..3bebbe5 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamPlanEntity.kt @@ -0,0 +1,12 @@ +package com.omixlab.lckcontrol.data.local.entity + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "stream_plans") +data class StreamPlanEntity( + @PrimaryKey val planId: String, + val name: String, + val status: String = "DRAFT", + val createdAt: Long = System.currentTimeMillis(), +) diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamPlanWithDestinations.kt b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamPlanWithDestinations.kt new file mode 100644 index 0000000..37bb649 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/local/entity/StreamPlanWithDestinations.kt @@ -0,0 +1,13 @@ +package com.omixlab.lckcontrol.data.local.entity + +import androidx.room.Embedded +import androidx.room.Relation + +data class StreamPlanWithDestinations( + @Embedded val plan: StreamPlanEntity, + @Relation( + parentColumn = "planId", + entityColumn = "planId", + ) + val destinations: List, +) diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/remote/ApiModels.kt b/app/src/main/java/com/omixlab/lckcontrol/data/remote/ApiModels.kt new file mode 100644 index 0000000..1b9b351 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/remote/ApiModels.kt @@ -0,0 +1,128 @@ +package com.omixlab.lckcontrol.data.remote + +import com.squareup.moshi.JsonClass + +// ── Auth ───────────────────────────────────────────────── + +@JsonClass(generateAdapter = true) +data class MetaCallbackRequest( + val userId: String, + val nonce: String, + val deviceInfo: String? = null, +) + +@JsonClass(generateAdapter = true) +data class RefreshRequest( + val refreshToken: String, +) + +@JsonClass(generateAdapter = true) +data class AuthTokensResponse( + val accessToken: String, + val refreshToken: String, + val expiresIn: Int, +) + +@JsonClass(generateAdapter = true) +data class UserProfileResponse( + val id: String, + val displayName: String, + val email: String?, + val avatarUrl: String?, +) + +// ── Providers ──────────────────────────────────────────── + +@JsonClass(generateAdapter = true) +data class AuthUrlResponse( + val url: String, + val state: String, +) + +@JsonClass(generateAdapter = true) +data class ProviderCallbackRequest( + val code: String, + val state: String, +) + +@JsonClass(generateAdapter = true) +data class LinkedAccountResponse( + val id: String, + val serviceId: String, + val displayName: String, + val accountId: String, + val avatarUrl: String?, +) + +// ── Streams ────────────────────────────────────────────── + +@JsonClass(generateAdapter = true) +data class CreateStreamPlanRequest( + val name: String, + val destinations: List, +) + +@JsonClass(generateAdapter = true) +data class CreateDestinationRequest( + val serviceId: String, + val title: String, + val description: String? = null, + val privacyStatus: String? = null, + val gameId: String? = null, + val tags: String? = null, +) + +@JsonClass(generateAdapter = true) +data class StreamPlanResponse( + val id: String, + val name: String, + val status: String, + val createdAt: String, + val updatedAt: String, + val destinations: List, +) + +@JsonClass(generateAdapter = true) +data class StreamDestinationResponse( + val id: String, + val serviceId: String, + val title: String, + val description: String, + val privacyStatus: String, + val gameId: String, + val tags: String, + val rtmpUrl: String, + val streamKey: String, + val broadcastId: String, + val status: String, +) + +@JsonClass(generateAdapter = true) +data class PrepareResponse( + val planId: String, + val destinations: List, +) + +@JsonClass(generateAdapter = true) +data class PreparedDestination( + val serviceId: String, + val rtmpUrl: String, + val streamKey: String, + val broadcastId: String, +) + +@JsonClass(generateAdapter = true) +data class SuccessResponse( + val success: Boolean, +) + +@JsonClass(generateAdapter = true) +data class StatusResponse( + val success: Boolean, + val status: String, +) + +@JsonClass(generateAdapter = true) +data class ErrorResponse( + val error: String, +) diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/remote/AuthInterceptor.kt b/app/src/main/java/com/omixlab/lckcontrol/data/remote/AuthInterceptor.kt new file mode 100644 index 0000000..b61b81c --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/remote/AuthInterceptor.kt @@ -0,0 +1,88 @@ +package com.omixlab.lckcontrol.data.remote + +import com.omixlab.lckcontrol.data.local.TokenStore +import okhttp3.Interceptor +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.Response +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AuthInterceptor @Inject constructor( + private val tokenStore: TokenStore, +) : Interceptor { + + override fun intercept(chain: Interceptor.Chain): Response { + val original = chain.request() + + // Don't add auth header to auth endpoints (login, refresh) + val path = original.url.encodedPath + if (path.contains("/auth/meta/callback") || path.contains("/auth/refresh")) { + return chain.proceed(original) + } + + val jwt = tokenStore.getJwt() + val request = if (jwt != null) { + original.newBuilder() + .header("Authorization", "Bearer $jwt") + .build() + } else { + original + } + + val response = chain.proceed(request) + + // If 401 and we have a refresh token, try to refresh + if (response.code == 401) { + val refreshToken = tokenStore.getRefreshToken() + if (refreshToken != null) { + response.close() + val newTokens = refreshTokenSync(chain, refreshToken) + if (newTokens != null) { + tokenStore.saveSession(newTokens.accessToken, newTokens.refreshToken) + // Retry original request with new token + val retryRequest = original.newBuilder() + .header("Authorization", "Bearer ${newTokens.accessToken}") + .build() + return chain.proceed(retryRequest) + } else { + // Refresh failed, clear session + tokenStore.clearSession() + } + } + } + + return response + } + + private fun refreshTokenSync(chain: Interceptor.Chain, refreshToken: String): AuthTokensResponse? { + return try { + val baseUrl = chain.request().url.newBuilder() + .encodedPath("/auth/refresh") + .build() + + val json = """{"refreshToken":"$refreshToken"}""" + val mediaType = "application/json".toMediaTypeOrNull() + val body = json.toRequestBody(mediaType) + + val refreshRequest = okhttp3.Request.Builder() + .url(baseUrl) + .post(body) + .build() + + val refreshResponse = chain.proceed(refreshRequest) + if (refreshResponse.isSuccessful) { + val responseBody = refreshResponse.body?.string() ?: return null + val moshi = com.squareup.moshi.Moshi.Builder().build() + val adapter = moshi.adapter(AuthTokensResponse::class.java) + adapter.fromJson(responseBody) + } else { + refreshResponse.close() + null + } + } catch (e: Exception) { + null + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/remote/LckApiService.kt b/app/src/main/java/com/omixlab/lckcontrol/data/remote/LckApiService.kt new file mode 100644 index 0000000..fbfb0cc --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/remote/LckApiService.kt @@ -0,0 +1,63 @@ +package com.omixlab.lckcontrol.data.remote + +import retrofit2.http.* + +interface LckApiService { + + // ── Auth ───────────────────────────────────────────── + + @POST("auth/meta/callback") + suspend fun metaCallback(@Body body: MetaCallbackRequest): AuthTokensResponse + + @POST("auth/refresh") + suspend fun refreshSession(@Body body: RefreshRequest): AuthTokensResponse + + @GET("auth/me") + suspend fun getMe(): UserProfileResponse + + @POST("auth/logout") + suspend fun logout(): SuccessResponse + + // ── Providers ──────────────────────────────────────── + + @GET("providers/accounts") + suspend fun getLinkedAccounts(): List + + @GET("providers/youtube/auth-url") + suspend fun getYouTubeAuthUrl(): AuthUrlResponse + + @POST("providers/youtube/callback") + suspend fun youtubeCallback(@Body body: ProviderCallbackRequest): LinkedAccountResponse + + @GET("providers/twitch/auth-url") + suspend fun getTwitchAuthUrl(): AuthUrlResponse + + @POST("providers/twitch/callback") + suspend fun twitchCallback(@Body body: ProviderCallbackRequest): LinkedAccountResponse + + @DELETE("providers/{serviceId}") + suspend fun unlinkAccount(@Path("serviceId") serviceId: String): SuccessResponse + + // ── Streams ────────────────────────────────────────── + + @GET("streams/plans") + suspend fun getStreamPlans(): List + + @POST("streams/plans") + suspend fun createStreamPlan(@Body body: CreateStreamPlanRequest): StreamPlanResponse + + @GET("streams/plans/{id}") + suspend fun getStreamPlan(@Path("id") id: String): StreamPlanResponse + + @DELETE("streams/plans/{id}") + suspend fun deleteStreamPlan(@Path("id") id: String): SuccessResponse + + @POST("streams/plans/{id}/prepare") + suspend fun prepareStreamPlan(@Path("id") id: String): PrepareResponse + + @POST("streams/plans/{id}/start") + suspend fun startStreamPlan(@Path("id") id: String): StatusResponse + + @POST("streams/plans/{id}/end") + suspend fun endStreamPlan(@Path("id") id: String): StatusResponse +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/repository/AccountRepository.kt b/app/src/main/java/com/omixlab/lckcontrol/data/repository/AccountRepository.kt new file mode 100644 index 0000000..a3bcd60 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/repository/AccountRepository.kt @@ -0,0 +1,88 @@ +package com.omixlab.lckcontrol.data.repository + +import com.omixlab.lckcontrol.data.local.dao.LinkedAccountDao +import com.omixlab.lckcontrol.data.local.entity.LinkedAccountEntity +import com.omixlab.lckcontrol.data.remote.LckApiService +import com.omixlab.lckcontrol.data.remote.ProviderCallbackRequest +import com.omixlab.lckcontrol.shared.LinkedAccount +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AccountRepository @Inject constructor( + private val accountDao: LinkedAccountDao, + private val apiService: LckApiService, +) { + fun observeAccounts(): Flow> = + accountDao.observeAll().map { entities -> + entities.map { it.toLinkedAccount() } + } + + suspend fun getAccounts(): List = + accountDao.getAll().map { it.toLinkedAccount() } + + /** Fetch accounts from backend and sync to Room cache */ + suspend fun syncAccounts() { + val remote = apiService.getLinkedAccounts() + // Clear local and replace with remote data + val entities = remote.map { account -> + LinkedAccountEntity( + serviceId = account.serviceId, + displayName = account.displayName, + accountId = account.accountId, + avatarUrl = account.avatarUrl, + ) + } + // Get current local accounts to detect removals + val local = accountDao.getAll() + val remoteServiceIds = entities.map { it.serviceId }.toSet() + for (localAccount in local) { + if (localAccount.serviceId !in remoteServiceIds) { + accountDao.deleteByService(localAccount.serviceId) + } + } + for (entity in entities) { + accountDao.upsert(entity) + } + } + + /** Get YouTube OAuth URL from backend (for Custom Tabs) */ + suspend fun getYouTubeAuthUrl(): String { + val response = apiService.getYouTubeAuthUrl() + return response.url + } + + /** Get Twitch OAuth URL from backend (for Custom Tabs) */ + suspend fun getTwitchAuthUrl(): String { + val response = apiService.getTwitchAuthUrl() + return response.url + } + + /** Send YouTube callback code to backend */ + suspend fun handleYouTubeCallback(code: String, state: String) { + apiService.youtubeCallback(ProviderCallbackRequest(code, state)) + syncAccounts() + } + + /** Send Twitch callback code to backend */ + suspend fun handleTwitchCallback(code: String, state: String) { + apiService.twitchCallback(ProviderCallbackRequest(code, state)) + syncAccounts() + } + + /** Unlink account via backend and update local cache */ + suspend fun unlinkAccount(serviceId: String) { + apiService.unlinkAccount(serviceId) + accountDao.deleteByService(serviceId) + } + + private fun LinkedAccountEntity.toLinkedAccount() = LinkedAccount( + serviceId = serviceId, + displayName = displayName, + accountId = accountId, + avatarUrl = avatarUrl, + isAuthenticated = true, // Backend manages auth state + ) +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/data/repository/StreamPlanRepository.kt b/app/src/main/java/com/omixlab/lckcontrol/data/repository/StreamPlanRepository.kt new file mode 100644 index 0000000..61c1cf2 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/data/repository/StreamPlanRepository.kt @@ -0,0 +1,143 @@ +package com.omixlab.lckcontrol.data.repository + +import com.omixlab.lckcontrol.data.local.dao.StreamPlanDao +import com.omixlab.lckcontrol.data.local.entity.StreamDestinationEntity +import com.omixlab.lckcontrol.data.local.entity.StreamPlanEntity +import com.omixlab.lckcontrol.data.local.entity.StreamPlanWithDestinations +import com.omixlab.lckcontrol.data.remote.CreateDestinationRequest +import com.omixlab.lckcontrol.data.remote.CreateStreamPlanRequest +import com.omixlab.lckcontrol.data.remote.LckApiService +import com.omixlab.lckcontrol.data.remote.PrepareResponse +import com.omixlab.lckcontrol.data.remote.StreamPlanResponse +import com.omixlab.lckcontrol.shared.StreamDestination +import com.omixlab.lckcontrol.shared.StreamPlan +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class StreamPlanRepository @Inject constructor( + private val planDao: StreamPlanDao, + private val apiService: LckApiService, +) { + fun observePlans(): Flow> = + planDao.observeAll().map { list -> list.map { it.toStreamPlan() } } + + fun observePlan(planId: String): Flow = + planDao.observeById(planId).map { it?.toStreamPlan() } + + suspend fun getPlans(): List = + planDao.getAll().map { it.toStreamPlan() } + + suspend fun getPlan(planId: String): StreamPlan? = + planDao.getById(planId)?.toStreamPlan() + + /** Sync plans from backend to local Room cache */ + suspend fun syncPlans() { + val remotePlans = apiService.getStreamPlans() + for (remote in remotePlans) { + cacheRemotePlan(remote) + } + } + + /** Create plan via backend and cache locally */ + suspend fun createPlan(name: String, destinations: List): StreamPlan { + val request = CreateStreamPlanRequest( + name = name, + destinations = destinations.map { dest -> + CreateDestinationRequest( + serviceId = dest.service, + title = dest.title, + description = dest.description, + privacyStatus = dest.privacyStatus, + gameId = dest.gameId, + tags = dest.tags.joinToString(","), + ) + }, + ) + val response = apiService.createStreamPlan(request) + cacheRemotePlan(response) + return planDao.getById(response.id)!!.toStreamPlan() + } + + /** Prepare plan via backend — returns RTMP info */ + suspend fun preparePlan(planId: String): PrepareResponse { + val response = apiService.prepareStreamPlan(planId) + // Update local cache with RTMP info + for (dest in response.destinations) { + // Find local destination by serviceId within this plan + val local = planDao.getById(planId)?.destinations + ?.find { it.service == dest.serviceId } + if (local != null) { + planDao.updateDestinationStream( + id = local.id, + rtmpUrl = dest.rtmpUrl, + streamKey = dest.streamKey, + broadcastId = dest.broadcastId, + status = "READY", + ) + } + } + planDao.updateStatus(planId, "READY") + return response + } + + /** Start plan via backend */ + suspend fun startPlan(planId: String) { + apiService.startStreamPlan(planId) + planDao.updateStatus(planId, "LIVE") + } + + /** End plan via backend */ + suspend fun endPlan(planId: String) { + apiService.endStreamPlan(planId) + planDao.updateStatus(planId, "ENDED") + } + + suspend fun deletePlan(planId: String) { + apiService.deleteStreamPlan(planId) + planDao.deletePlan(planId) + } + + private suspend fun cacheRemotePlan(remote: StreamPlanResponse) { + val planEntity = StreamPlanEntity(planId = remote.id, name = remote.name, status = remote.status) + val destEntities = remote.destinations.map { d -> + StreamDestinationEntity( + id = d.id, + planId = remote.id, + service = d.serviceId, + title = d.title, + description = d.description, + privacyStatus = d.privacyStatus, + gameId = d.gameId, + tags = d.tags, + rtmpUrl = d.rtmpUrl, + streamKey = d.streamKey, + broadcastId = d.broadcastId, + status = d.status, + ) + } + planDao.insertPlanWithDestinations(planEntity, destEntities) + } + + private fun StreamPlanWithDestinations.toStreamPlan() = StreamPlan( + planId = plan.planId, + name = plan.name, + status = plan.status, + destinations = destinations.map { it.toStreamDestination() }, + ) + + private fun StreamDestinationEntity.toStreamDestination() = StreamDestination( + service = service, + title = title, + description = description, + privacyStatus = privacyStatus, + gameId = gameId, + tags = tags.split(",").filter { it.isNotBlank() }, + rtmpUrl = rtmpUrl, + streamKey = streamKey, + broadcastId = broadcastId, + status = status, + ) +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/di/AppModule.kt b/app/src/main/java/com/omixlab/lckcontrol/di/AppModule.kt new file mode 100644 index 0000000..b697bd5 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/di/AppModule.kt @@ -0,0 +1,56 @@ +package com.omixlab.lckcontrol.di + +import com.omixlab.lckcontrol.data.remote.AuthInterceptor +import com.omixlab.lckcontrol.data.remote.LckApiService +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.moshi.MoshiConverterFactory +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object AppModule { + + // TODO: Set from BuildConfig or remote config + private const val BASE_URL = "http://192.168.1.60:3100/" + + @Provides + @Singleton + fun provideMoshi(): Moshi = + Moshi.Builder() + .addLast(KotlinJsonAdapterFactory()) + .build() + + @Provides + @Singleton + fun provideOkHttpClient(authInterceptor: AuthInterceptor): OkHttpClient = + OkHttpClient.Builder() + .addInterceptor(authInterceptor) + .addInterceptor( + HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY + } + ) + .build() + + @Provides + @Singleton + fun provideRetrofit(okHttpClient: OkHttpClient, moshi: Moshi): Retrofit = + Retrofit.Builder() + .baseUrl(BASE_URL) + .client(okHttpClient) + .addConverterFactory(MoshiConverterFactory.create(moshi)) + .build() + + @Provides + @Singleton + fun provideLckApiService(retrofit: Retrofit): LckApiService = + retrofit.create(LckApiService::class.java) +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/di/DatabaseModule.kt b/app/src/main/java/com/omixlab/lckcontrol/di/DatabaseModule.kt new file mode 100644 index 0000000..eab0780 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/di/DatabaseModule.kt @@ -0,0 +1,31 @@ +package com.omixlab.lckcontrol.di + +import android.content.Context +import androidx.room.Room +import com.omixlab.lckcontrol.data.local.LckDatabase +import com.omixlab.lckcontrol.data.local.dao.LinkedAccountDao +import com.omixlab.lckcontrol.data.local.dao.StreamPlanDao +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object DatabaseModule { + + @Provides + @Singleton + fun provideDatabase(@ApplicationContext context: Context): LckDatabase = + Room.databaseBuilder(context, LckDatabase::class.java, "lck_control.db") + .addMigrations(LckDatabase.MIGRATION_1_2) + .build() + + @Provides + fun provideLinkedAccountDao(db: LckDatabase): LinkedAccountDao = db.linkedAccountDao() + + @Provides + fun provideStreamPlanDao(db: LckDatabase): StreamPlanDao = db.streamPlanDao() +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/service/ClientTracker.kt b/app/src/main/java/com/omixlab/lckcontrol/service/ClientTracker.kt new file mode 100644 index 0000000..ecc56b6 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/service/ClientTracker.kt @@ -0,0 +1,41 @@ +package com.omixlab.lckcontrol.service + +import java.util.UUID +import java.util.concurrent.ConcurrentHashMap + +data class ConnectedClient( + val clientId: String, + val clientName: String, + val packageName: String, + val activePlanId: String? = null, + val connectedAt: Long = System.currentTimeMillis(), +) + +class ClientTracker { + + private val clients = ConcurrentHashMap() + + fun register(clientName: String, packageName: String): String { + val clientId = UUID.randomUUID().toString() + clients[clientId] = ConnectedClient( + clientId = clientId, + clientName = clientName, + packageName = packageName, + ) + return clientId + } + + fun unregister(clientId: String): ConnectedClient? = clients.remove(clientId) + + fun setActivePlan(clientId: String, planId: String?) { + clients.computeIfPresent(clientId) { _, client -> + client.copy(activePlanId = planId) + } + } + + fun getClient(clientId: String): ConnectedClient? = clients[clientId] + + fun getAll(): List = clients.values.toList() + + fun count(): Int = clients.size +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/service/LckControlService.kt b/app/src/main/java/com/omixlab/lckcontrol/service/LckControlService.kt new file mode 100644 index 0000000..d3dd0d8 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/service/LckControlService.kt @@ -0,0 +1,203 @@ +package com.omixlab.lckcontrol.service + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.Service +import android.content.Intent +import android.content.pm.ServiceInfo +import android.os.IBinder +import android.os.RemoteCallbackList +import com.omixlab.lckcontrol.R +import com.omixlab.lckcontrol.data.repository.AccountRepository +import com.omixlab.lckcontrol.data.repository.StreamPlanRepository +import com.omixlab.lckcontrol.shared.ILckControlCallback +import com.omixlab.lckcontrol.shared.ILckControlService +import com.omixlab.lckcontrol.shared.LinkedAccount +import com.omixlab.lckcontrol.shared.StreamPlan +import com.omixlab.lckcontrol.shared.StreamPlanConfig +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import javax.inject.Inject + +@AndroidEntryPoint +class LckControlService : Service() { + + companion object { + private const val CHANNEL_ID = "lck_control_service" + private const val NOTIFICATION_ID = 1 + } + + @Inject lateinit var accountRepository: AccountRepository + @Inject lateinit var streamPlanRepository: StreamPlanRepository + + private val serviceScope = CoroutineScope(SupervisorJob() + Dispatchers.Main) + private val clientTracker = ClientTracker() + private val callbacks = RemoteCallbackList() + + private val binder = object : ILckControlService.Stub() { + + override fun getLinkedAccounts(): List = runBlocking { + accountRepository.getAccounts() + } + + override fun createStreamPlan(config: StreamPlanConfig): StreamPlan = runBlocking { + val plan = streamPlanRepository.createPlan(config.name, config.destinations) + broadcastPlansChanged() + plan + } + + override fun prepareStreamPlan(planId: String): StreamPlan = runBlocking { + streamPlanRepository.preparePlan(planId) + val plan = streamPlanRepository.getPlan(planId) ?: error("Plan not found after prepare") + broadcastPlanUpdated(plan) + plan + } + + override fun getStreamPlans(): List = runBlocking { + streamPlanRepository.getPlans() + } + + override fun getStreamPlan(planId: String): StreamPlan? = runBlocking { + streamPlanRepository.getPlan(planId) + } + + override fun startStreamPlan(planId: String): Boolean = runBlocking { + val plan = streamPlanRepository.getPlan(planId) ?: return@runBlocking false + if (plan.status != "READY") return@runBlocking false + streamPlanRepository.startPlan(planId) + val updated = streamPlanRepository.getPlan(planId) + if (updated != null) broadcastPlanUpdated(updated) + true + } + + override fun endStreamPlan(planId: String): Boolean = runBlocking { + val plan = streamPlanRepository.getPlan(planId) ?: return@runBlocking false + if (plan.status != "LIVE") return@runBlocking false + streamPlanRepository.endPlan(planId) + val updated = streamPlanRepository.getPlan(planId) + if (updated != null) broadcastPlanUpdated(updated) + true + } + + override fun registerClient(clientName: String, packageName: String): String { + val clientId = clientTracker.register(clientName, packageName) + broadcastClientRegistered(clientId) + return clientId + } + + override fun unregisterClient(clientId: String) { + clientTracker.unregister(clientId) + broadcastClientUnregistered(clientId) + } + + override fun setClientActivePlan(clientId: String, planId: String) { + clientTracker.setActivePlan(clientId, planId) + } + + override fun registerCallback(callback: ILckControlCallback) { + callbacks.register(callback) + } + + override fun unregisterCallback(callback: ILckControlCallback) { + callbacks.unregister(callback) + } + } + + override fun onCreate() { + super.onCreate() + createNotificationChannel() + startForeground( + NOTIFICATION_ID, + buildNotification(), + ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE, + ) + } + + override fun onBind(intent: Intent?): IBinder = binder + + override fun onDestroy() { + serviceScope.cancel() + callbacks.kill() + super.onDestroy() + } + + private fun createNotificationChannel() { + val channel = NotificationChannel( + CHANNEL_ID, + "LCK Control Service", + NotificationManager.IMPORTANCE_LOW, + ).apply { + description = "Manages connected game clients and stream plans" + } + getSystemService(NotificationManager::class.java).createNotificationChannel(channel) + } + + private fun buildNotification(): Notification = + Notification.Builder(this, CHANNEL_ID) + .setContentTitle("LCK Control") + .setContentText("Managing stream connections") + .setSmallIcon(R.drawable.ic_launcher_foreground) + .setOngoing(true) + .build() + + private fun broadcastPlansChanged() { + serviceScope.launch { + val plans = streamPlanRepository.getPlans() + val count = callbacks.beginBroadcast() + try { + for (i in 0 until count) { + try { + callbacks.getBroadcastItem(i).onStreamPlansChanged(plans) + } catch (_: Exception) {} + } + } finally { + callbacks.finishBroadcast() + } + } + } + + private fun broadcastPlanUpdated(plan: StreamPlan) { + val count = callbacks.beginBroadcast() + try { + for (i in 0 until count) { + try { + callbacks.getBroadcastItem(i).onStreamPlanUpdated(plan) + } catch (_: Exception) {} + } + } finally { + callbacks.finishBroadcast() + } + } + + private fun broadcastClientRegistered(clientId: String) { + val count = callbacks.beginBroadcast() + try { + for (i in 0 until count) { + try { + callbacks.getBroadcastItem(i).onClientRegistered(clientId) + } catch (_: Exception) {} + } + } finally { + callbacks.finishBroadcast() + } + } + + private fun broadcastClientUnregistered(clientId: String) { + val count = callbacks.beginBroadcast() + try { + for (i in 0 until count) { + try { + callbacks.getBroadcastItem(i).onClientUnregistered(clientId) + } catch (_: Exception) {} + } + } finally { + callbacks.finishBroadcast() + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/accounts/AccountsScreen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/accounts/AccountsScreen.kt new file mode 100644 index 0000000..48cfbbb --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/accounts/AccountsScreen.kt @@ -0,0 +1,119 @@ +package com.omixlab.lckcontrol.ui.accounts + +import android.app.Activity +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.LinkOff +import androidx.compose.material3.ElevatedCard +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun AccountsScreen( + viewModel: AccountsViewModel = hiltViewModel(), +) { + val accounts by viewModel.accounts.collectAsStateWithLifecycle() + val linkError by viewModel.linkError.collectAsStateWithLifecycle() + val snackbarHostState = remember { SnackbarHostState() } + val context = LocalContext.current + + LaunchedEffect(linkError) { + linkError?.let { + snackbarHostState.showSnackbar(it) + viewModel.clearError() + } + } + + Scaffold( + topBar = { + TopAppBar(title = { Text("Linked Accounts") }) + }, + snackbarHost = { SnackbarHost(snackbarHostState) }, + ) { padding -> + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(padding) + .padding(horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(12.dp), + ) { + item { Spacer(Modifier.height(8.dp)) } + + items(accounts, key = { it.serviceId }) { account -> + ElevatedCard(modifier = Modifier.fillMaxWidth()) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f)) { + Text(account.displayName, style = MaterialTheme.typography.titleSmall) + Text(account.serviceId, style = MaterialTheme.typography.bodySmall) + } + IconButton(onClick = { viewModel.unlinkAccount(account.serviceId) }) { + Icon(Icons.Default.LinkOff, contentDescription = "Unlink") + } + } + } + } + + // Show link buttons for providers not yet linked + val linkedServiceIds = accounts.map { it.serviceId }.toSet() + val unlinked = viewModel.getUnlinkedProviders(linkedServiceIds) + + if (unlinked.isNotEmpty()) { + item { + Spacer(Modifier.height(8.dp)) + Text("Add Account", style = MaterialTheme.typography.titleMedium) + Spacer(Modifier.height(4.dp)) + } + + items(unlinked, key = { it.serviceId }) { provider -> + OutlinedButton( + onClick = { + val activity = context as? Activity ?: return@OutlinedButton + viewModel.linkAccount(activity, provider.serviceId) + }, + modifier = Modifier.fillMaxWidth(), + ) { + Icon(Icons.Default.Add, contentDescription = null) + Spacer(Modifier.padding(4.dp)) + Text("Link ${provider.displayName}") + } + } + } + + item { Spacer(Modifier.height(16.dp)) } + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/accounts/AccountsViewModel.kt new file mode 100644 index 0000000..05c45a9 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/accounts/AccountsViewModel.kt @@ -0,0 +1,84 @@ +package com.omixlab.lckcontrol.ui.accounts + +import android.app.Activity +import android.net.Uri +import androidx.browser.customtabs.CustomTabsIntent +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.omixlab.lckcontrol.data.repository.AccountRepository +import com.omixlab.lckcontrol.shared.LinkedAccount +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch +import javax.inject.Inject + +data class AvailableProvider( + val serviceId: String, + val displayName: String, +) + +val ALL_PROVIDERS = listOf( + AvailableProvider("YOUTUBE", "YouTube"), + AvailableProvider("TWITCH", "Twitch"), +) + +@HiltViewModel +class AccountsViewModel @Inject constructor( + private val accountRepository: AccountRepository, +) : ViewModel() { + + val accounts: StateFlow> = accountRepository.observeAccounts() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) + + private val _linkError = MutableStateFlow(null) + val linkError: StateFlow = _linkError.asStateFlow() + + init { + // Sync accounts from backend on load + viewModelScope.launch { + try { + accountRepository.syncAccounts() + } catch (e: Exception) { + // Offline — local cache still works + } + } + } + + fun getUnlinkedProviders(linkedServiceIds: Set): List = + ALL_PROVIDERS.filter { it.serviceId !in linkedServiceIds } + + fun linkAccount(activity: Activity, serviceId: String) { + viewModelScope.launch { + _linkError.value = null + try { + val url = when (serviceId) { + "YOUTUBE" -> accountRepository.getYouTubeAuthUrl() + "TWITCH" -> accountRepository.getTwitchAuthUrl() + else -> throw IllegalArgumentException("Unknown service: $serviceId") + } + val customTabsIntent = CustomTabsIntent.Builder().build() + customTabsIntent.launchUrl(activity, Uri.parse(url)) + } catch (e: Exception) { + _linkError.value = e.message ?: "Failed to start auth flow" + } + } + } + + fun unlinkAccount(serviceId: String) { + viewModelScope.launch { + try { + accountRepository.unlinkAccount(serviceId) + } catch (e: Exception) { + _linkError.value = e.message ?: "Failed to unlink account" + } + } + } + + fun clearError() { + _linkError.value = null + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/clients/ActiveClientsScreen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/clients/ActiveClientsScreen.kt new file mode 100644 index 0000000..191a457 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/clients/ActiveClientsScreen.kt @@ -0,0 +1,137 @@ +package com.omixlab.lckcontrol.ui.clients + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +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.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Circle +import androidx.compose.material.icons.filled.Devices +import androidx.compose.material3.ElevatedCard +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun ActiveClientsScreen( + viewModel: ActiveClientsViewModel = hiltViewModel(), +) { + val clients by viewModel.clients.collectAsStateWithLifecycle() + val isConnected by viewModel.isConnected.collectAsStateWithLifecycle() + + Scaffold( + topBar = { + TopAppBar(title = { Text("Active Clients") }) + }, + ) { padding -> + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(padding) + .padding(horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(12.dp), + ) { + item { + Spacer(Modifier.height(8.dp)) + + // Service status + ElevatedCard(modifier = Modifier.fillMaxWidth()) { + Row( + modifier = Modifier.padding(16.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Icon( + Icons.Default.Circle, + contentDescription = null, + tint = if (isConnected) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.error, + modifier = Modifier.height(12.dp).width(12.dp), + ) + Spacer(Modifier.width(8.dp)) + Text( + if (isConnected) "Service Running" else "Service Disconnected", + style = MaterialTheme.typography.titleSmall, + ) + } + } + } + + if (clients.isEmpty()) { + item { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 32.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Icon( + Icons.Default.Devices, + contentDescription = null, + modifier = Modifier.height(48.dp).width(48.dp), + tint = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Spacer(Modifier.height(12.dp)) + Text( + "No active clients", + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Text( + "Game clients will appear here when connected", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } + } else { + items(clients, key = { it.planId }) { client -> + ElevatedCard(modifier = Modifier.fillMaxWidth()) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f)) { + Text(client.planName, style = MaterialTheme.typography.titleSmall) + Text( + "${client.destinationCount} destination(s)", + style = MaterialTheme.typography.bodySmall, + ) + } + Text( + client.planStatus, + style = MaterialTheme.typography.labelMedium, + color = when (client.planStatus) { + "LIVE" -> MaterialTheme.colorScheme.error + "READY" -> MaterialTheme.colorScheme.primary + else -> MaterialTheme.colorScheme.onSurfaceVariant + }, + ) + } + } + } + } + + item { Spacer(Modifier.height(16.dp)) } + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/clients/ActiveClientsViewModel.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/clients/ActiveClientsViewModel.kt new file mode 100644 index 0000000..d3c138b --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/clients/ActiveClientsViewModel.kt @@ -0,0 +1,111 @@ +package com.omixlab.lckcontrol.ui.clients + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.ServiceConnection +import android.os.IBinder +import androidx.lifecycle.ViewModel +import com.omixlab.lckcontrol.service.ClientTracker +import com.omixlab.lckcontrol.service.ConnectedClient +import com.omixlab.lckcontrol.shared.ILckControlCallback +import com.omixlab.lckcontrol.shared.ILckControlService +import com.omixlab.lckcontrol.shared.StreamPlan +import dagger.hilt.android.lifecycle.HiltViewModel +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import javax.inject.Inject + +@HiltViewModel +class ActiveClientsViewModel @Inject constructor( + @ApplicationContext private val context: Context, +) : ViewModel() { + + private var service: ILckControlService? = null + + private val _clients = MutableStateFlow>(emptyList()) + val clients: StateFlow> = _clients.asStateFlow() + + private val _isConnected = MutableStateFlow(false) + val isConnected: StateFlow = _isConnected.asStateFlow() + + private val callback = object : ILckControlCallback.Stub() { + override fun onStreamPlansChanged(plans: List) { + refreshClients() + } + + override fun onStreamPlanUpdated(plan: StreamPlan) { + refreshClients() + } + + override fun onClientRegistered(clientId: String) { + refreshClients() + } + + override fun onClientUnregistered(clientId: String) { + refreshClients() + } + } + + private val connection = object : ServiceConnection { + override fun onServiceConnected(name: ComponentName?, binder: IBinder?) { + service = ILckControlService.Stub.asInterface(binder) + service?.registerCallback(callback) + _isConnected.value = true + refreshClients() + } + + override fun onServiceDisconnected(name: ComponentName?) { + service = null + _isConnected.value = false + _clients.value = emptyList() + } + } + + init { + bindToService() + } + + private fun bindToService() { + val intent = Intent().apply { + component = ComponentName( + context.packageName, + "com.omixlab.lckcontrol.service.LckControlService", + ) + } + context.bindService(intent, connection, Context.BIND_AUTO_CREATE) + } + + private fun refreshClients() { + // The service tracks clients internally; for the UI we present + // plans and their associated clients. This is a simplified view. + val plans = service?.streamPlans ?: emptyList() + _clients.value = plans + .filter { it.status == "LIVE" || it.status == "READY" } + .map { plan -> + ClientInfo( + planId = plan.planId, + planName = plan.name, + planStatus = plan.status, + destinationCount = plan.destinations.size, + ) + } + } + + override fun onCleared() { + service?.unregisterCallback(callback) + try { + context.unbindService(connection) + } catch (_: IllegalArgumentException) {} + super.onCleared() + } +} + +data class ClientInfo( + val planId: String, + val planName: String, + val planStatus: String, + val destinationCount: Int, +) diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/dashboard/DashboardScreen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/dashboard/DashboardScreen.kt new file mode 100644 index 0000000..cca7e40 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/dashboard/DashboardScreen.kt @@ -0,0 +1,177 @@ +package com.omixlab.lckcontrol.ui.dashboard + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +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.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.Circle +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.ElevatedCard +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.FloatingActionButton +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.omixlab.lckcontrol.shared.StreamPlan + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun DashboardScreen( + onNavigateToCreatePlan: () -> Unit, + onNavigateToPlan: (String) -> Unit, + viewModel: DashboardViewModel = hiltViewModel(), +) { + val accounts by viewModel.accounts.collectAsStateWithLifecycle() + val plans by viewModel.plans.collectAsStateWithLifecycle() + + Scaffold( + topBar = { + TopAppBar(title = { Text("LCK Control") }) + }, + floatingActionButton = { + FloatingActionButton(onClick = onNavigateToCreatePlan) { + Icon(Icons.Default.Add, contentDescription = "Create Plan") + } + }, + ) { padding -> + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(padding) + .padding(horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(12.dp), + ) { + item { + Spacer(Modifier.height(8.dp)) + Text("Linked Accounts", style = MaterialTheme.typography.titleMedium) + Spacer(Modifier.height(4.dp)) + } + + if (accounts.isEmpty()) { + item { + Card( + modifier = Modifier.fillMaxWidth(), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.surfaceVariant, + ), + ) { + Text( + "No accounts linked yet. Go to Accounts to get started.", + modifier = Modifier.padding(16.dp), + style = MaterialTheme.typography.bodyMedium, + ) + } + } + } else { + item { + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + accounts.forEach { account -> + ElevatedCard { + Column(modifier = Modifier.padding(12.dp)) { + Text(account.displayName, style = MaterialTheme.typography.labelLarge) + Text(account.serviceId, style = MaterialTheme.typography.bodySmall) + } + } + } + } + } + } + + item { + Spacer(Modifier.height(8.dp)) + Text("Stream Plans", style = MaterialTheme.typography.titleMedium) + Spacer(Modifier.height(4.dp)) + } + + if (plans.isEmpty()) { + item { + Card( + modifier = Modifier.fillMaxWidth(), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.surfaceVariant, + ), + ) { + Text( + "No stream plans yet. Tap + to create one.", + modifier = Modifier.padding(16.dp), + style = MaterialTheme.typography.bodyMedium, + ) + } + } + } else { + items(plans, key = { it.planId }) { plan -> + PlanCard(plan = plan, onClick = { onNavigateToPlan(plan.planId) }) + } + } + + item { Spacer(Modifier.height(80.dp)) } + } + } +} + +@Composable +private fun PlanCard(plan: StreamPlan, onClick: () -> Unit) { + ElevatedCard( + modifier = Modifier + .fillMaxWidth() + .clickable(onClick = onClick), + ) { + Column(modifier = Modifier.padding(16.dp)) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.fillMaxWidth(), + ) { + Text(plan.name, style = MaterialTheme.typography.titleSmall, modifier = Modifier.weight(1f)) + Spacer(Modifier.width(8.dp)) + StatusChip(plan.status) + } + Spacer(Modifier.height(4.dp)) + Text( + "${plan.destinations.size} destination(s)", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } +} + +@Composable +private fun StatusChip(status: String) { + val color = when (status) { + "LIVE" -> MaterialTheme.colorScheme.error + "READY" -> MaterialTheme.colorScheme.primary + "PREPARING" -> MaterialTheme.colorScheme.tertiary + "ENDED" -> MaterialTheme.colorScheme.outline + else -> MaterialTheme.colorScheme.onSurfaceVariant + } + Row(verticalAlignment = Alignment.CenterVertically) { + Icon( + Icons.Default.Circle, + contentDescription = null, + tint = color, + modifier = Modifier.height(8.dp).width(8.dp), + ) + Spacer(Modifier.width(4.dp)) + Text(status, style = MaterialTheme.typography.labelSmall, color = color) + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/dashboard/DashboardViewModel.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/dashboard/DashboardViewModel.kt new file mode 100644 index 0000000..4ec5c9a --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/dashboard/DashboardViewModel.kt @@ -0,0 +1,26 @@ +package com.omixlab.lckcontrol.ui.dashboard + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.omixlab.lckcontrol.data.repository.AccountRepository +import com.omixlab.lckcontrol.data.repository.StreamPlanRepository +import com.omixlab.lckcontrol.shared.LinkedAccount +import com.omixlab.lckcontrol.shared.StreamPlan +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.stateIn +import javax.inject.Inject + +@HiltViewModel +class DashboardViewModel @Inject constructor( + accountRepository: AccountRepository, + streamPlanRepository: StreamPlanRepository, +) : ViewModel() { + + val accounts: StateFlow> = accountRepository.observeAccounts() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) + + val plans: StateFlow> = streamPlanRepository.observePlans() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/login/LoginScreen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/login/LoginScreen.kt new file mode 100644 index 0000000..d8c49ab --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/login/LoginScreen.kt @@ -0,0 +1,91 @@ +package com.omixlab.lckcontrol.ui.login + +import android.app.Activity +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.omixlab.lckcontrol.BuildConfig + +@Composable +fun LoginScreen( + onLoginSuccess: () -> Unit = {}, + viewModel: LoginViewModel = hiltViewModel(), +) { + val isLoading by viewModel.isLoading.collectAsStateWithLifecycle() + val error by viewModel.error.collectAsStateWithLifecycle() + val context = LocalContext.current + + Box( + modifier = Modifier + .fillMaxSize() + .padding(32.dp), + ) { + Column( + modifier = Modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + Text( + text = "LCK Control", + style = MaterialTheme.typography.headlineLarge, + ) + + Spacer(Modifier.height(8.dp)) + + Text( + text = "Stream management for Quest", + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + + Spacer(Modifier.height(48.dp)) + + if (isLoading) { + CircularProgressIndicator() + } else { + Button( + onClick = { + val activity = context as? Activity ?: return@Button + viewModel.loginWithQuest(activity) + }, + modifier = Modifier.fillMaxWidth(), + ) { + Text("Sign in with Quest") + } + } + + error?.let { errorMsg -> + Spacer(Modifier.height(16.dp)) + Text( + text = errorMsg, + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall, + ) + } + } + + Text( + text = BuildConfig.DISPLAY_VERSION, + modifier = Modifier.align(Alignment.BottomCenter), + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f), + ) + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/login/LoginViewModel.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/login/LoginViewModel.kt new file mode 100644 index 0000000..5dd7dbe --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/login/LoginViewModel.kt @@ -0,0 +1,145 @@ +package com.omixlab.lckcontrol.ui.login + +import android.app.Activity +import android.util.Log +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.omixlab.lckcontrol.data.local.TokenStore +import com.omixlab.lckcontrol.data.remote.LckApiService +import com.omixlab.lckcontrol.data.remote.MetaCallbackRequest +import com.meta.horizon.platform.ovr.Core +import com.meta.horizon.platform.ovr.models.PlatformInitialize +import com.meta.horizon.platform.ovr.models.User +import com.meta.horizon.platform.ovr.models.UserProof +import com.meta.horizon.platform.ovr.requests.Request +import com.meta.horizon.platform.ovr.requests.Users +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine + +@HiltViewModel +class LoginViewModel @Inject constructor( + private val tokenStore: TokenStore, + private val apiService: LckApiService, +) : ViewModel() { + + private val _isLoading = MutableStateFlow(false) + val isLoading: StateFlow = _isLoading.asStateFlow() + + private val _error = MutableStateFlow(null) + val error: StateFlow = _error.asStateFlow() + + fun isLoggedIn(): Boolean = tokenStore.isLoggedIn() + + fun loginWithQuest(activity: Activity) { + viewModelScope.launch { + _isLoading.value = true + _error.value = null + try { + // Initialize Platform SDK + if (!Core.isInitialized()) { + Log.d(TAG, "Initializing Platform SDK with appId=$QUEST_APP_ID") + val initResult = Core.initialize(QUEST_APP_ID, activity.applicationContext) + Log.d(TAG, "Core.initialize returned: $initResult") + } + Log.d(TAG, "Core.isInitialized=${Core.isInitialized()}") + + // Check cached user ID first (synchronous) + val cachedUserId = Core.getLoggedInUserID() + Log.d(TAG, "Core.getLoggedInUserID() = $cachedUserId") + + if (cachedUserId == 0L) { + throw Exception("Platform SDK returned user ID 0. " + + "Make sure the app is installed from the Horizon store (not sideloaded) " + + "and your account is a test user for this app.") + } + + // Get full user via async call with manual message pump + val user = awaitWithPump { Users.getLoggedInUser() } + val userId = user.getID().toString() + Log.d(TAG, "User: id=$userId displayName=${user.displayName}") + + // Get user proof (nonce) + val proof = awaitWithPump { Users.getUserProof() } + val nonce = proof.value + Log.d(TAG, "UserProof nonce=$nonce") + + // Send to backend for verification + val response = apiService.metaCallback( + MetaCallbackRequest( + userId = userId, + nonce = nonce, + deviceInfo = android.os.Build.MODEL, + ) + ) + + // Save session tokens + tokenStore.saveSession(response.accessToken, response.refreshToken) + } catch (e: Exception) { + Log.e(TAG, "Quest login failed", e) + _error.value = e.message ?: "Login failed" + } finally { + _isLoading.value = false + } + } + } + + fun clearError() { + _error.value = null + } + + /** + * Awaits a Platform SDK request by manually pumping the message queue. + * The SDK requires Request.runCallbacks() to be called for callbacks to fire. + */ + private suspend fun awaitWithPump( + block: () -> Request, + ): T = suspendCoroutine { cont -> + var completed = false + block() + .onSuccess { result: T -> + if (!completed) { + completed = true + cont.resume(result) + } + } + .onError { error -> + if (!completed) { + completed = true + cont.resumeWithException(Exception(error.message)) + } + } + + // Pump messages on a background thread + Thread { + val timeout = System.currentTimeMillis() + 10_000 // 10s timeout + while (!completed && System.currentTimeMillis() < timeout) { + try { + val msg = Core.popSDKMessage() + if (msg != null) { + Request.handleMessage(msg) + } + } catch (e: Exception) { + Log.w(TAG, "Message pump error", e) + } + Thread.sleep(50) + } + if (!completed) { + completed = true + cont.resumeWithException(Exception("Platform SDK request timed out")) + } + }.start() + } + + companion object { + private const val TAG = "LoginViewModel" + const val QUEST_APP_ID = "25653777174321448" + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/navigation/AppNavigation.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/navigation/AppNavigation.kt new file mode 100644 index 0000000..6beebd9 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/navigation/AppNavigation.kt @@ -0,0 +1,121 @@ +package com.omixlab.lckcontrol.ui.navigation + +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Dashboard +import androidx.compose.material.icons.filled.Devices +import androidx.compose.material.icons.filled.Person +import androidx.compose.material3.Icon +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.NavType +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController +import androidx.navigation.navArgument +import com.omixlab.lckcontrol.data.local.TokenStore +import com.omixlab.lckcontrol.ui.accounts.AccountsScreen +import com.omixlab.lckcontrol.ui.clients.ActiveClientsScreen +import com.omixlab.lckcontrol.ui.dashboard.DashboardScreen +import com.omixlab.lckcontrol.ui.login.LoginScreen +import com.omixlab.lckcontrol.ui.plans.CreatePlanScreen +import com.omixlab.lckcontrol.ui.plans.PlanDetailScreen + +private data class BottomNavItem( + val screen: Screen, + val label: String, + val icon: ImageVector, +) + +private val bottomNavItems = listOf( + BottomNavItem(Screen.Dashboard, "Dashboard", Icons.Default.Dashboard), + BottomNavItem(Screen.Accounts, "Accounts", Icons.Default.Person), + BottomNavItem(Screen.ActiveClients, "Clients", Icons.Default.Devices), +) + +@Composable +fun AppNavigation(tokenStore: TokenStore) { + val navController = rememberNavController() + val navBackStackEntry by navController.currentBackStackEntryAsState() + val currentRoute = navBackStackEntry?.destination?.route + + val showBottomBar = currentRoute in bottomNavItems.map { it.screen.route } + val startDestination = if (tokenStore.isLoggedIn()) Screen.Dashboard.route else Screen.Login.route + + Scaffold( + bottomBar = { + if (showBottomBar) { + NavigationBar { + bottomNavItems.forEach { item -> + NavigationBarItem( + icon = { Icon(item.icon, contentDescription = item.label) }, + label = { Text(item.label) }, + selected = currentRoute == item.screen.route, + onClick = { + navController.navigate(item.screen.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + ) + } + } + } + }, + ) { innerPadding -> + NavHost( + navController = navController, + startDestination = startDestination, + modifier = Modifier.padding(innerPadding), + ) { + composable(Screen.Login.route) { + LoginScreen() + } + composable(Screen.Dashboard.route) { + DashboardScreen( + onNavigateToCreatePlan = { navController.navigate(Screen.CreatePlan.route) }, + onNavigateToPlan = { planId -> + navController.navigate(Screen.PlanDetail.createRoute(planId)) + }, + ) + } + composable(Screen.Accounts.route) { + AccountsScreen() + } + composable(Screen.CreatePlan.route) { + CreatePlanScreen( + onPlanCreated = { planId -> + navController.navigate(Screen.PlanDetail.createRoute(planId)) { + popUpTo(Screen.Dashboard.route) + } + }, + onBack = { navController.popBackStack() }, + ) + } + composable( + route = Screen.PlanDetail.route, + arguments = listOf(navArgument("planId") { type = NavType.StringType }), + ) { backStackEntry -> + val planId = backStackEntry.arguments?.getString("planId") ?: return@composable + PlanDetailScreen( + planId = planId, + onBack = { navController.popBackStack() }, + ) + } + composable(Screen.ActiveClients.route) { + ActiveClientsScreen() + } + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/navigation/Screen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/navigation/Screen.kt new file mode 100644 index 0000000..350b899 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/navigation/Screen.kt @@ -0,0 +1,12 @@ +package com.omixlab.lckcontrol.ui.navigation + +sealed class Screen(val route: String) { + data object Login : Screen("login") + data object Dashboard : Screen("dashboard") + data object Accounts : Screen("accounts") + data object CreatePlan : Screen("create_plan") + data object PlanDetail : Screen("plan_detail/{planId}") { + fun createRoute(planId: String) = "plan_detail/$planId" + } + data object ActiveClients : Screen("active_clients") +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/plans/CreatePlanScreen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/CreatePlanScreen.kt new file mode 100644 index 0000000..0a243c7 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/CreatePlanScreen.kt @@ -0,0 +1,249 @@ +package com.omixlab.lckcontrol.ui.plans + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material3.Button +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.ElevatedCard +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.ExposedDropdownMenuBox +import androidx.compose.material3.ExposedDropdownMenuDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.MenuAnchorType +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +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.Modifier +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun CreatePlanScreen( + onPlanCreated: (String) -> Unit, + onBack: () -> Unit, + viewModel: CreatePlanViewModel = hiltViewModel(), +) { + val planName by viewModel.planName.collectAsStateWithLifecycle() + val destinations by viewModel.destinations.collectAsStateWithLifecycle() + val linkedAccounts by viewModel.linkedAccounts.collectAsStateWithLifecycle() + val isCreating by viewModel.isCreating.collectAsStateWithLifecycle() + val error by viewModel.error.collectAsStateWithLifecycle() + val snackbarHostState = remember { SnackbarHostState() } + + LaunchedEffect(error) { + error?.let { + snackbarHostState.showSnackbar(it) + viewModel.clearError() + } + } + + Scaffold( + topBar = { + TopAppBar( + title = { Text("Create Stream Plan") }, + navigationIcon = { + IconButton(onClick = onBack) { + Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") + } + }, + ) + }, + snackbarHost = { SnackbarHost(snackbarHostState) }, + ) { padding -> + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(padding) + .padding(horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(12.dp), + ) { + item { + Spacer(Modifier.height(8.dp)) + OutlinedTextField( + value = planName, + onValueChange = viewModel::setPlanName, + label = { Text("Plan Name") }, + modifier = Modifier.fillMaxWidth(), + singleLine = true, + ) + } + + item { + Spacer(Modifier.height(8.dp)) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text("Destinations", style = MaterialTheme.typography.titleMedium) + OutlinedButton(onClick = viewModel::addDestination) { + Icon(Icons.Default.Add, contentDescription = null) + Spacer(Modifier.padding(4.dp)) + Text("Add") + } + } + } + + itemsIndexed(destinations) { index, dest -> + DestinationCard( + destination = dest, + availableServices = linkedAccounts.map { it.serviceId }, + onUpdate = { viewModel.updateDestination(index, it) }, + onRemove = { viewModel.removeDestination(index) }, + ) + } + + item { + Spacer(Modifier.height(16.dp)) + Button( + onClick = { viewModel.createPlan(onPlanCreated) }, + modifier = Modifier.fillMaxWidth(), + enabled = !isCreating, + ) { + Text(if (isCreating) "Creating..." else "Create Plan") + } + Spacer(Modifier.height(16.dp)) + } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +private fun DestinationCard( + destination: DestinationInput, + availableServices: List, + onUpdate: (DestinationInput) -> Unit, + onRemove: () -> Unit, +) { + var serviceExpanded by remember { mutableStateOf(false) } + var privacyExpanded by remember { mutableStateOf(false) } + + ElevatedCard(modifier = Modifier.fillMaxWidth()) { + Column( + modifier = Modifier.padding(16.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text("Destination", style = MaterialTheme.typography.labelLarge) + IconButton(onClick = onRemove) { + Icon(Icons.Default.Delete, contentDescription = "Remove") + } + } + + // Service picker + ExposedDropdownMenuBox( + expanded = serviceExpanded, + onExpandedChange = { serviceExpanded = it }, + ) { + OutlinedTextField( + value = destination.service, + onValueChange = {}, + readOnly = true, + label = { Text("Service") }, + trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(serviceExpanded) }, + modifier = Modifier + .fillMaxWidth() + .menuAnchor(MenuAnchorType.PrimaryNotEditable), + ) + ExposedDropdownMenu( + expanded = serviceExpanded, + onDismissRequest = { serviceExpanded = false }, + ) { + availableServices.forEach { service -> + DropdownMenuItem( + text = { Text(service) }, + onClick = { + onUpdate(destination.copy(service = service)) + serviceExpanded = false + }, + ) + } + } + } + + OutlinedTextField( + value = destination.title, + onValueChange = { onUpdate(destination.copy(title = it)) }, + label = { Text("Stream Title") }, + modifier = Modifier.fillMaxWidth(), + singleLine = true, + ) + + OutlinedTextField( + value = destination.description, + onValueChange = { onUpdate(destination.copy(description = it)) }, + label = { Text("Description") }, + modifier = Modifier.fillMaxWidth(), + minLines = 2, + ) + + // Privacy status + ExposedDropdownMenuBox( + expanded = privacyExpanded, + onExpandedChange = { privacyExpanded = it }, + ) { + OutlinedTextField( + value = destination.privacyStatus, + onValueChange = {}, + readOnly = true, + label = { Text("Privacy") }, + trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(privacyExpanded) }, + modifier = Modifier + .fillMaxWidth() + .menuAnchor(MenuAnchorType.PrimaryNotEditable), + ) + ExposedDropdownMenu( + expanded = privacyExpanded, + onDismissRequest = { privacyExpanded = false }, + ) { + listOf("public", "unlisted", "private").forEach { status -> + DropdownMenuItem( + text = { Text(status) }, + onClick = { + onUpdate(destination.copy(privacyStatus = status)) + privacyExpanded = false + }, + ) + } + } + } + + OutlinedTextField( + value = destination.tags, + onValueChange = { onUpdate(destination.copy(tags = it)) }, + label = { Text("Tags (comma-separated)") }, + modifier = Modifier.fillMaxWidth(), + singleLine = true, + ) + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/plans/CreatePlanViewModel.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/CreatePlanViewModel.kt new file mode 100644 index 0000000..6320fb1 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/CreatePlanViewModel.kt @@ -0,0 +1,112 @@ +package com.omixlab.lckcontrol.ui.plans + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.omixlab.lckcontrol.data.repository.AccountRepository +import com.omixlab.lckcontrol.data.repository.StreamPlanRepository +import com.omixlab.lckcontrol.shared.LinkedAccount +import com.omixlab.lckcontrol.shared.StreamDestination +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch +import javax.inject.Inject + +data class DestinationInput( + val service: String = "", + val title: String = "", + val description: String = "", + val privacyStatus: String = "public", + val gameId: String = "", + val tags: String = "", +) + +@HiltViewModel +class CreatePlanViewModel @Inject constructor( + accountRepository: AccountRepository, + private val streamPlanRepository: StreamPlanRepository, +) : ViewModel() { + + val linkedAccounts: StateFlow> = accountRepository.observeAccounts() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) + + private val _planName = MutableStateFlow("") + val planName: StateFlow = _planName.asStateFlow() + + private val _destinations = MutableStateFlow>(emptyList()) + val destinations: StateFlow> = _destinations.asStateFlow() + + private val _isCreating = MutableStateFlow(false) + val isCreating: StateFlow = _isCreating.asStateFlow() + + private val _error = MutableStateFlow(null) + val error: StateFlow = _error.asStateFlow() + + fun setPlanName(name: String) { + _planName.value = name + } + + fun addDestination() { + _destinations.value = _destinations.value + DestinationInput() + } + + fun updateDestination(index: Int, destination: DestinationInput) { + _destinations.value = _destinations.value.toMutableList().apply { + set(index, destination) + } + } + + fun removeDestination(index: Int) { + _destinations.value = _destinations.value.toMutableList().apply { + removeAt(index) + } + } + + fun createPlan(onCreated: (String) -> Unit) { + val name = _planName.value.trim() + val dests = _destinations.value + + if (name.isBlank()) { + _error.value = "Plan name is required" + return + } + if (dests.isEmpty()) { + _error.value = "Add at least one destination" + return + } + if (dests.any { it.service.isBlank() || it.title.isBlank() }) { + _error.value = "All destinations need a service and title" + return + } + + viewModelScope.launch { + _isCreating.value = true + _error.value = null + try { + val streamDests = dests.map { input -> + StreamDestination( + service = input.service, + title = input.title, + description = input.description, + privacyStatus = input.privacyStatus, + gameId = input.gameId, + tags = input.tags.split(",").map { it.trim() }.filter { it.isNotBlank() }, + ) + } + val plan = streamPlanRepository.createPlan(name, streamDests) + onCreated(plan.planId) + } catch (e: Exception) { + _error.value = e.message ?: "Failed to create plan" + } finally { + _isCreating.value = false + } + } + } + + fun clearError() { + _error.value = null + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/plans/PlanDetailScreen.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/PlanDetailScreen.kt new file mode 100644 index 0000000..620e0b5 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/PlanDetailScreen.kt @@ -0,0 +1,236 @@ +package com.omixlab.lckcontrol.ui.plans + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.filled.ContentCopy +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.ElevatedCard +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalClipboardManager +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.omixlab.lckcontrol.shared.StreamDestination + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun PlanDetailScreen( + planId: String, + onBack: () -> Unit, + viewModel: PlanDetailViewModel = hiltViewModel(), +) { + val plan by viewModel.plan.collectAsStateWithLifecycle() + val isLoading by viewModel.isLoading.collectAsStateWithLifecycle() + val error by viewModel.error.collectAsStateWithLifecycle() + val snackbarHostState = remember { SnackbarHostState() } + + LaunchedEffect(error) { + error?.let { + snackbarHostState.showSnackbar(it) + viewModel.clearError() + } + } + + Scaffold( + topBar = { + TopAppBar( + title = { Text(plan?.name ?: "Plan Detail") }, + navigationIcon = { + IconButton(onClick = onBack) { + Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") + } + }, + actions = { + if (plan?.status == "DRAFT" || plan?.status == "ENDED") { + IconButton(onClick = { viewModel.deletePlan(onBack) }) { + Icon(Icons.Default.Delete, contentDescription = "Delete") + } + } + }, + ) + }, + snackbarHost = { SnackbarHost(snackbarHostState) }, + ) { padding -> + val currentPlan = plan + if (currentPlan == null) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(padding), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + CircularProgressIndicator() + } + return@Scaffold + } + + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(padding) + .padding(horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(12.dp), + ) { + item { + Spacer(Modifier.height(8.dp)) + + // Status + ElevatedCard(modifier = Modifier.fillMaxWidth()) { + Column(modifier = Modifier.padding(16.dp)) { + Text("Status", style = MaterialTheme.typography.labelMedium) + Spacer(Modifier.height(4.dp)) + Text( + currentPlan.status, + style = MaterialTheme.typography.headlineSmall, + color = when (currentPlan.status) { + "LIVE" -> MaterialTheme.colorScheme.error + "READY" -> MaterialTheme.colorScheme.primary + else -> MaterialTheme.colorScheme.onSurface + }, + ) + } + } + } + + // Action buttons + item { + when (currentPlan.status) { + "DRAFT" -> { + Button( + onClick = viewModel::preparePlan, + modifier = Modifier.fillMaxWidth(), + enabled = !isLoading, + ) { + if (isLoading) CircularProgressIndicator() + else Text("Prepare Stream") + } + } + "READY" -> { + Button( + onClick = viewModel::startPlan, + modifier = Modifier.fillMaxWidth(), + enabled = !isLoading, + ) { + Text("Go Live") + } + } + "LIVE" -> { + OutlinedButton( + onClick = viewModel::endPlan, + modifier = Modifier.fillMaxWidth(), + colors = ButtonDefaults.outlinedButtonColors( + contentColor = MaterialTheme.colorScheme.error, + ), + enabled = !isLoading, + ) { + Text("End Stream") + } + } + } + } + + // Destinations + item { + Spacer(Modifier.height(8.dp)) + Text("Destinations", style = MaterialTheme.typography.titleMedium) + } + + items(currentPlan.destinations) { dest -> + DestinationDetailCard(dest) + } + + item { Spacer(Modifier.height(16.dp)) } + } + } +} + +@Composable +private fun DestinationDetailCard(destination: StreamDestination) { + val clipboardManager = LocalClipboardManager.current + + ElevatedCard(modifier = Modifier.fillMaxWidth()) { + Column( + modifier = Modifier.padding(16.dp), + verticalArrangement = Arrangement.spacedBy(4.dp), + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text(destination.service, style = MaterialTheme.typography.titleSmall) + Text( + destination.status, + style = MaterialTheme.typography.labelSmall, + color = if (destination.status == "READY") MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + + Text(destination.title, style = MaterialTheme.typography.bodyMedium) + + if (destination.rtmpUrl.isNotBlank()) { + Spacer(Modifier.height(4.dp)) + Text("RTMP URL", style = MaterialTheme.typography.labelSmall) + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + destination.rtmpUrl, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.weight(1f), + ) + IconButton(onClick = { + clipboardManager.setText(AnnotatedString(destination.rtmpUrl)) + }) { + Icon(Icons.Default.ContentCopy, contentDescription = "Copy", modifier = Modifier.padding(4.dp)) + } + } + } + + if (destination.streamKey.isNotBlank()) { + Text("Stream Key", style = MaterialTheme.typography.labelSmall) + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + destination.streamKey.take(8) + "...", + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.weight(1f), + ) + IconButton(onClick = { + clipboardManager.setText(AnnotatedString(destination.streamKey)) + }) { + Icon(Icons.Default.ContentCopy, contentDescription = "Copy", modifier = Modifier.padding(4.dp)) + } + } + } + } + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/plans/PlanDetailViewModel.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/PlanDetailViewModel.kt new file mode 100644 index 0000000..bfceccb --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/plans/PlanDetailViewModel.kt @@ -0,0 +1,90 @@ +package com.omixlab.lckcontrol.ui.plans + +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.omixlab.lckcontrol.data.repository.StreamPlanRepository +import com.omixlab.lckcontrol.shared.StreamPlan +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class PlanDetailViewModel @Inject constructor( + savedStateHandle: SavedStateHandle, + private val streamPlanRepository: StreamPlanRepository, +) : ViewModel() { + + private val planId: String = savedStateHandle["planId"] ?: "" + + val plan: StateFlow = streamPlanRepository.observePlan(planId) + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null) + + private val _isLoading = MutableStateFlow(false) + val isLoading: StateFlow = _isLoading.asStateFlow() + + private val _error = MutableStateFlow(null) + val error: StateFlow = _error.asStateFlow() + + fun preparePlan() { + viewModelScope.launch { + _isLoading.value = true + _error.value = null + try { + streamPlanRepository.preparePlan(planId) + } catch (e: Exception) { + _error.value = e.message ?: "Failed to prepare plan" + } finally { + _isLoading.value = false + } + } + } + + fun startPlan() { + viewModelScope.launch { + _isLoading.value = true + _error.value = null + try { + streamPlanRepository.startPlan(planId) + } catch (e: Exception) { + _error.value = e.message ?: "Failed to start plan" + } finally { + _isLoading.value = false + } + } + } + + fun endPlan() { + viewModelScope.launch { + _isLoading.value = true + _error.value = null + try { + streamPlanRepository.endPlan(planId) + } catch (e: Exception) { + _error.value = e.message ?: "Failed to end plan" + } finally { + _isLoading.value = false + } + } + } + + fun deletePlan(onDeleted: () -> Unit) { + viewModelScope.launch { + try { + streamPlanRepository.deletePlan(planId) + onDeleted() + } catch (e: Exception) { + _error.value = e.message ?: "Failed to delete plan" + } + } + } + + fun clearError() { + _error.value = null + } +} diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Color.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Color.kt new file mode 100644 index 0000000..e10daca --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.omixlab.lckcontrol.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) \ No newline at end of file diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Theme.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Theme.kt new file mode 100644 index 0000000..e9ef008 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package com.omixlab.lckcontrol.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun LCKControlTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Type.kt b/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Type.kt new file mode 100644 index 0000000..db069c5 --- /dev/null +++ b/app/src/main/java/com/omixlab/lckcontrol/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.omixlab.lckcontrol.ui.theme + +import androidx.compose.material3.Typography +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 + +// Set of Material typography styles to start with +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 + ) + */ +) \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..4e45e69 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + LCK Control + Allows game clients to manage stream plans and receive RTMP endpoints through the LCK Control service. + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..89d0450 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +