Skip to content

Commit

Permalink
feat: theme selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jan 10, 2024
1 parent 610563e commit 72ff9d1
Show file tree
Hide file tree
Showing 94 changed files with 496 additions and 344 deletions.
2 changes: 1 addition & 1 deletion androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/ui_app_name"
android:label="@string/ui_title_foryou"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/Theme.M3U.Starting"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("unused")

package com.m3u.androidApp.di
package com.m3u.androidApp

import com.m3u.androidApp.AppPublisher
import com.m3u.core.architecture.Publisher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class MainActivity : AppCompatActivity() {
)
val scope = rememberCoroutineScope()
val darkMode = when {
pref.cinemaMode -> true
pref.darkMode -> true
else -> isSystemInDarkTheme()
}
DisposableEffect(darkMode, scope) {
Expand Down
6 changes: 1 addition & 5 deletions androidApp/src/main/java/com/m3u/androidApp/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.m3u.androidApp.navigation.AppNavHost

@Composable
fun App(
Expand All @@ -22,10 +21,7 @@ fun App(

val isBackPressedVisible = AppDefaults.isBackPressedVisible(navDestination)

val title: String by AppDefaults.title(
rootDestination = rootDestination,
defState = viewModel.title.collectAsStateWithLifecycle()
)
val title: String by viewModel.title.collectAsStateWithLifecycle()

AppScaffold(
title = title,
Expand Down
31 changes: 0 additions & 31 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppDefaults.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package com.m3u.androidApp.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavDestination
import com.m3u.core.util.basic.title
import com.m3u.ui.Destination

object AppDefaults {
Expand All @@ -16,29 +10,4 @@ object AppDefaults {
currentDestination ?: return false
return !(currentDestination destinationTo Destination.Root::class.java)
}

@Composable
fun title(
rootDestination: Destination.Root?,
defState: State<String>
): State<String> {
val context = LocalContext.current
val defaultValue by defState
return remember(rootDestination) {
derivedStateOf {
(rootDestination
?.titleTextId
?.let(context::getString)
?: defaultValue)
.title()
}
}
}

// @Composable
// fun theme(cinemaMode: Boolean): Theme = when {
// cinemaMode -> ABlackTheme
// isSystemInDarkTheme() -> NightTheme
// else -> DayTheme
// }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.m3u.androidApp.navigation
package com.m3u.androidApp.ui

import android.app.ActivityOptions
import android.content.Intent
Expand Down Expand Up @@ -85,7 +85,7 @@ fun AppNavHost(
navController.navigateToPlaylist(playlist.url, recommend)
},
navigateToSettingPlaylistManagement = {
navigateToRoot(Destination.Root.Setting(SettingFragment.Subscriptions))
navigateToRoot(Destination.Root.Setting(SettingFragment.Playlists))
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import com.m3u.androidApp.components.AppSnackHost
import com.m3u.ui.AppSnackHost
import com.m3u.core.wrapper.Message
import com.m3u.material.components.Background
import com.m3u.material.components.IconButton
Expand Down
2 changes: 0 additions & 2 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import androidx.navigation.NavDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.m3u.androidApp.navigation.ROOT_ROUTE
import com.m3u.androidApp.navigation.popupToRoot
import com.m3u.features.about.navigation.ABOUT_ROUTE
import com.m3u.features.console.navigation.CONSOLE_ROUTE
import com.m3u.features.playlist.navigation.PLAYLIST_ROUTE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.m3u.androidApp.navigation
package com.m3u.androidApp.ui

import android.util.Log
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -16,7 +16,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.m3u.core.wrapper.eventOf
import com.m3u.core.wrapper.handledEvent
import com.m3u.data.database.entity.Playlist
import com.m3u.data.database.model.Playlist
import com.m3u.features.favorite.FavouriteRoute
import com.m3u.features.foryou.ForyouRoute
import com.m3u.features.setting.SettingRoute
Expand Down Expand Up @@ -92,6 +92,7 @@ private fun RootGraph(

HorizontalPager(
state = pagerState,
// userScrollEnabled = false,
modifier = modifier
.fillMaxSize()
.blurEdge(
Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/com/m3u/core/architecture/pref/Pref.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Pref {
var rootDestination: Int
var noPictureMode: Boolean

var cinemaMode: Boolean
var darkMode: Boolean
var useDynamicColors: Boolean

var zappingMode: Boolean
Expand All @@ -48,6 +48,8 @@ interface Pref {

var compact: Boolean

var colorArgb: Int

companion object {
@PlaylistStrategy
const val DEFAULT_PLAYLIST_STRATEGY = PlaylistStrategy.SKIP_FAVORITE
Expand All @@ -65,7 +67,7 @@ interface Pref {
const val DEFAULT_FULL_INFO_PLAYER = false
const val DEFAULT_ROOT_DESTINATION = 0
const val DEFAULT_NO_PICTURE_MODE = true
const val DEFAULT_CINEMA_MODE = false
const val DEFAULT_DARK_MODE = false

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
val DEFAULT_USE_DYNAMIC_COLORS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
Expand All @@ -81,6 +83,7 @@ interface Pref {
const val DEFAULT_UNSEENS_MILLISECONDS = UnseensMilliseconds.DAYS_3
const val DEFAULT_AUTO_RECONNECT = false
const val DEFAULT_COMPACT = false
const val DEFAULT_COLOR_ARGB = 0xD0BCFF

const val PLAYLIST_STRATEGY = "playlist-strategy"
const val ROW_COUNT = "rowCount"
Expand All @@ -95,7 +98,7 @@ interface Pref {
const val FULL_INFO_PLAYER = "full-info-player"
const val ROOT_DESTINATION = "root-destination"
const val NO_PICTURE_MODE = "no-picture-mode"
const val CINEMA_MODE = "cinema-mode"
const val DARK_MODE = "dark-mode"
const val USE_DYNAMIC_COLORS = "use-dynamic-colors"
const val ZAPPING_MODE = "zapping-mode"
const val BRIGHTNESS_GESTURE = "brightness-gesture"
Expand All @@ -106,6 +109,7 @@ interface Pref {
const val UNSEENS_MILLISECONDS = "unseens-milliseconds"
const val AUTO_RECONNECT = "auto-reconnect"
const val COMPACT = "compact"
const val COLOR_ARGB = "color-argb"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal object MockPref : Pref {
override var rootDestination: Int = Pref.DEFAULT_ROOT_DESTINATION
override var noPictureMode: Boolean = Pref.DEFAULT_NO_PICTURE_MODE

override var cinemaMode: Boolean = Pref.DEFAULT_CINEMA_MODE
override var darkMode: Boolean = Pref.DEFAULT_DARK_MODE
override var useDynamicColors: Boolean = Pref.DEFAULT_USE_DYNAMIC_COLORS
override var zappingMode: Boolean = Pref.DEFAULT_ZAPPING_MODE
override var brightnessGesture: Boolean = Pref.DEFAULT_BRIGHTNESS_GESTURE
Expand All @@ -28,4 +28,5 @@ internal object MockPref : Pref {
override var unseensMilliseconds: Long = Pref.DEFAULT_UNSEENS_MILLISECONDS
override var autoReconnect: Boolean = Pref.DEFAULT_AUTO_RECONNECT
override var compact: Boolean = Pref.DEFAULT_COMPACT
override var colorArgb: Int = Pref.DEFAULT_COLOR_ARGB
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import com.m3u.core.architecture.pref.Pref
import com.m3u.core.architecture.pref.Pref.Companion.AUTO_RECONNECT
import com.m3u.core.architecture.pref.Pref.Companion.AUTO_REFRESH
import com.m3u.core.architecture.pref.Pref.Companion.BRIGHTNESS_GESTURE
import com.m3u.core.architecture.pref.Pref.Companion.CINEMA_MODE
import com.m3u.core.architecture.pref.Pref.Companion.DARK_MODE
import com.m3u.core.architecture.pref.Pref.Companion.CLIP_MODE
import com.m3u.core.architecture.pref.Pref.Companion.COMPACT
import com.m3u.core.architecture.pref.Pref.Companion.CONNECT_TIMEOUT
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_AUTO_RECONNECT
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_AUTO_REFRESH
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_BRIGHTNESS_GESTURE
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_CINEMA_MODE
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_DARK_MODE
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_CLIP_MODE
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_COMPACT
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_CONNECT_TIMEOUT
Expand All @@ -30,6 +30,7 @@ import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_ROW_COUNT
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_SCREENCAST
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_SCREEN_ROTATING
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_SSL_VERIFICATION
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_COLOR_ARGB
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_UNSEENS_MILLISECONDS
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_USE_DYNAMIC_COLORS
import com.m3u.core.architecture.pref.Pref.Companion.DEFAULT_VOLUME_GESTURE
Expand All @@ -45,6 +46,7 @@ import com.m3u.core.architecture.pref.Pref.Companion.ROW_COUNT
import com.m3u.core.architecture.pref.Pref.Companion.SCREENCAST
import com.m3u.core.architecture.pref.Pref.Companion.SCREEN_ROTATING
import com.m3u.core.architecture.pref.Pref.Companion.SSL_VERIFICATION
import com.m3u.core.architecture.pref.Pref.Companion.COLOR_ARGB
import com.m3u.core.architecture.pref.Pref.Companion.UNSEENS_MILLISECONDS
import com.m3u.core.architecture.pref.Pref.Companion.USE_DYNAMIC_COLORS
import com.m3u.core.architecture.pref.Pref.Companion.VOLUME_GESTURE
Expand Down Expand Up @@ -96,8 +98,8 @@ class SnapshotPref @Inject constructor(
override var noPictureMode: Boolean by
sharedPreferences.booleanAsState(DEFAULT_NO_PICTURE_MODE, NO_PICTURE_MODE)

override var cinemaMode: Boolean by
sharedPreferences.booleanAsState(DEFAULT_CINEMA_MODE, CINEMA_MODE)
override var darkMode: Boolean by
sharedPreferences.booleanAsState(DEFAULT_DARK_MODE, DARK_MODE)
override var useDynamicColors: Boolean by
sharedPreferences.booleanAsState(DEFAULT_USE_DYNAMIC_COLORS, USE_DYNAMIC_COLORS)

Expand Down Expand Up @@ -129,6 +131,9 @@ class SnapshotPref @Inject constructor(
override var compact: Boolean by
sharedPreferences.booleanAsState(DEFAULT_COMPACT, COMPACT)

override var colorArgb: Int by
sharedPreferences.intAsState(DEFAULT_COLOR_ARGB, COLOR_ARGB)

companion object {
private const val SHARED_SETTINGS = "shared_settings"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.m3u.data.contract
package com.m3u.data

import android.annotation.SuppressLint
import java.security.cert.X509Certificate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.m3u.data.contract
package com.m3u.data

import java.security.SecureRandom
import javax.net.ssl.SSLContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
@file:Suppress("unused")

package com.m3u.data.di
package com.m3u.data.api

import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.m3u.core.architecture.pref.impl.SnapshotPref
import com.m3u.data.api.GithubApi
import com.m3u.data.contract.Apis
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -64,7 +62,7 @@ internal object ApiModule {
fun provideGithubApi(
builder: Retrofit.Builder
): GithubApi = builder
.baseUrl(Apis.GITHUB_BASE_URL)
.baseUrl(Contracts.GITHUB_BASE_URL)
.build()
.create()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.m3u.data.contract
package com.m3u.data.api

object Apis {
object Contracts {
const val GITHUB_BASE_URL = "https://api.github.com"
}
29 changes: 29 additions & 0 deletions data/src/main/java/com/m3u/data/database/DatabaseMigrations.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.m3u.data.database

import androidx.room.RenameColumn
import androidx.room.RenameTable
import androidx.room.migration.AutoMigrationSpec
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

internal object DatabaseMigrations {
val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE lives ADD COLUMN banned INTEGER NOT NULL DEFAULT 0")
}
}
val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("DROP TABLE posts")
}
}

@RenameColumn(
tableName = "lives",
fromColumnName = "feedUrl",
toColumnName = "playlistUrl"
)
@RenameTable(fromTableName = "feeds", toTableName = "playlists")
@RenameTable(fromTableName = "lives", toTableName = "streams")
class AutoMigration3To4 : AutoMigrationSpec
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@file:Suppress("unused")

package com.m3u.data.di
package com.m3u.data.database

import android.content.Context
import androidx.room.Room
import com.m3u.data.database.M3UDatabase
import com.m3u.data.database.dao.PlaylistDao
import com.m3u.data.database.dao.StreamDao
import dagger.Module
Expand All @@ -26,8 +25,8 @@ object DatabaseModule {
M3UDatabase::class.java,
"m3u-database"
)
.addMigrations(M3UDatabase.MIGRATION_1_2)
.addMigrations(M3UDatabase.MIGRATION_2_3)
.addMigrations(DatabaseMigrations.MIGRATION_1_2)
.addMigrations(DatabaseMigrations.MIGRATION_2_3)
.build()

@Provides
Expand Down
Loading

0 comments on commit 72ff9d1

Please sign in to comment.