Skip to content

Commit

Permalink
build: material module for jitpack.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Oct 17, 2023
1 parent c983f14 commit 68b0b93
Show file tree
Hide file tree
Showing 119 changed files with 745 additions and 511 deletions.
10 changes: 5 additions & 5 deletions androidApp/src/main/java/com/m3u/androidApp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import com.m3u.core.unspecified.UBoolean
import com.m3u.core.util.basic.rational
import com.m3u.core.util.context.isDarkMode
import com.m3u.core.util.context.isPortraitMode
import com.m3u.ui.model.Action
import com.m3u.ui.model.Fob
import com.m3u.ui.model.Helper
import com.m3u.ui.model.OnPipModeChanged
import com.m3u.ui.model.OnUserLeaveHint
import com.m3u.ui.Action
import com.m3u.ui.Fob
import com.m3u.ui.Helper
import com.m3u.ui.OnPipModeChanged
import com.m3u.ui.OnUserLeaveHint
import dagger.hilt.android.AndroidEntryPoint
import kotlin.reflect.KMutableProperty0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import com.m3u.core.util.basic.title
import com.m3u.material.components.NavigationSheet
import com.m3u.material.ktx.animateColor
import com.m3u.material.ktx.animated
import com.m3u.material.model.LocalTheme
import com.m3u.ui.Destination
import com.m3u.ui.Fob
import com.m3u.ui.Navigate
import com.m3u.ui.components.NavigationSheet
import com.m3u.ui.ktx.animateColor
import com.m3u.ui.ktx.animated
import com.m3u.ui.model.Fob
import com.m3u.ui.model.LocalTheme

@Composable
fun AppBottomSheet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import com.m3u.ui.model.LocalSpacing
import com.m3u.ui.model.LocalTheme
import com.m3u.material.model.LocalSpacing
import com.m3u.material.model.LocalTheme

@Composable
fun AppSnackHost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import com.m3u.features.console.navigation.consoleScreen
import com.m3u.features.feed.navigation.feedScreen
import com.m3u.features.live.navigation.livePlaylistScreen
import com.m3u.features.live.navigation.liveScreen
import com.m3u.i18n.R.string
import com.m3u.ui.Destination
import com.m3u.ui.LocalHelper
import com.m3u.ui.Navigate
import com.m3u.ui.model.LocalHelper
import com.m3u.i18n.R as I18R

@Composable
fun M3UNavHost(
Expand All @@ -42,7 +42,7 @@ fun M3UNavHost(
onCurrentPage = onCurrentPage,
navigateToFeed = { feed ->
helper.title = feed.title.ifEmpty {
if (feed.local) context.getString(I18R.string.feat_main_imported_feed_title)
if (feed.local) context.getString(string.feat_main_imported_feed_title)
else ""
}
navigate(Destination.Feed(feed.url))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.m3u.core.wrapper.Event
import com.m3u.core.wrapper.eventOf
import com.m3u.features.favorite.FavouriteRoute
import com.m3u.features.favorite.NavigateToLive
import com.m3u.features.main.MainRoute
import com.m3u.features.main.NavigateToFeed
import com.m3u.features.setting.NavigateToAbout
import com.m3u.features.setting.NavigateToConsole
import com.m3u.features.setting.SettingRoute
import com.m3u.material.ktx.Edge
import com.m3u.material.ktx.blurEdges
import com.m3u.material.model.LocalTheme
import com.m3u.ui.Destination
import com.m3u.ui.ktx.Edge
import com.m3u.ui.ktx.blurEdges
import com.m3u.ui.model.LocalTheme
import com.m3u.ui.ResumeEvent
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

Expand Down Expand Up @@ -112,15 +116,15 @@ private fun RootGraph(
Destination.Root.Main -> {
MainRoute(
navigateToFeed = navigateToFeed,
isCurrentPage = currentPage == pagerIndex,
resume = rememberResumeEvent(currentPage, pagerIndex),
modifier = Modifier.fillMaxSize()
)
}

Destination.Root.Favourite -> {
FavouriteRoute(
navigateToLive = navigateToLive,
isCurrentPage = currentPage == pagerIndex,
resume = rememberResumeEvent(currentPage, pagerIndex),
modifier = Modifier.fillMaxSize()
)
}
Expand All @@ -129,7 +133,7 @@ private fun RootGraph(
SettingRoute(
navigateToConsole = navigateToConsole,
navigateToAbout = navigateToAbout,
isCurrentPage = currentPage == pagerIndex,
resume = rememberResumeEvent(currentPage, pagerIndex),
modifier = Modifier.fillMaxSize()
)
}
Expand All @@ -142,4 +146,11 @@ private data class PagerStateSnapshot(
val target: Int,
val settled: Int,
val scrolling: Boolean
)
)

@Composable
private fun rememberResumeEvent(currentPage: Int, targetPage: Int): ResumeEvent =
remember(currentPage, targetPage) {
if (currentPage == targetPage) eventOf(Unit)
else Event.Handled()
}
6 changes: 3 additions & 3 deletions androidApp/src/main/java/com/m3u/androidApp/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.m3u.androidApp.navigation.M3UNavHost
import com.m3u.ui.ktx.EventHandler
import com.m3u.ui.model.EmptyHelper
import com.m3u.ui.model.Helper
import com.m3u.ui.EmptyHelper
import com.m3u.ui.EventHandler
import com.m3u.ui.Helper

@Composable
fun App(
Expand Down
8 changes: 4 additions & 4 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppDefaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ 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.material.model.ABlackTheme
import com.m3u.material.model.DayTheme
import com.m3u.material.model.NightTheme
import com.m3u.material.model.Theme
import com.m3u.ui.Destination
import com.m3u.ui.model.ABlackTheme
import com.m3u.ui.model.DayTheme
import com.m3u.ui.model.NightTheme
import com.m3u.ui.model.Theme

object AppDefaults {
@Composable
Expand Down
17 changes: 10 additions & 7 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppScaffold.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.m3u.androidApp.components.AppBottomSheet
import com.m3u.androidApp.components.AppSnackHost
import com.m3u.core.util.withEach
import com.m3u.i18n.R.string
import com.m3u.material.components.AppTopBar
import com.m3u.material.components.IconButton
import com.m3u.material.model.LocalSpacing
import com.m3u.material.model.Theme
import com.m3u.ui.Action
import com.m3u.ui.Destination
import com.m3u.ui.Fob
import com.m3u.ui.Helper
import com.m3u.ui.M3ULocalProvider
import com.m3u.ui.Navigate
import com.m3u.ui.components.AppTopBar
import com.m3u.ui.components.IconButton
import com.m3u.ui.model.Action
import com.m3u.ui.model.Fob
import com.m3u.ui.model.Helper
import com.m3u.ui.model.LocalSpacing
import com.m3u.ui.model.Theme
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -89,6 +91,7 @@ internal fun AppScaffold(
}
},
onBackPressed = onBackPressed,
onBackPressedContentDescription = stringResource(string.ui_cd_top_bar_on_back_pressed),
modifier = modifier
) { padding ->
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.m3u.core.wrapper.Event
import com.m3u.core.wrapper.eventOf
import com.m3u.core.wrapper.handledEvent
import com.m3u.data.service.UiService
import com.m3u.ui.Action
import com.m3u.ui.Destination
import com.m3u.ui.model.Action
import com.m3u.ui.model.Fob
import com.m3u.ui.Fob
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
Expand Down
21 changes: 19 additions & 2 deletions core/src/main/java/com/m3u/core/unspecified/UBoolean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@ enum class UBoolean {
True, False, Unspecified
}

val Boolean.u: UBoolean get() = if (this) UBoolean.True else UBoolean.False
@Deprecated(
"Replace with Boolean.unspecifiable",
replaceWith = ReplaceWith(
"this.unspecifiable",
"com.m3u.core.unspecified.unspecifiable"
)
)
val Boolean.u: UBoolean get() = unspecifiable
val Boolean.unspecifiable: UBoolean get() = if (this) UBoolean.True else UBoolean.False

val UBoolean.actual: Boolean?
@Deprecated(
"Replace with UBoolean.specified",
replaceWith = ReplaceWith(
"this.specified",
"com.m3u.core.unspecified.specified"
)
)
val UBoolean.actual: Boolean? get() = specified

val UBoolean.specified: Boolean?
get() = when (this) {
UBoolean.True -> true
UBoolean.False -> false
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/com/m3u/core/util/Collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@ inline fun <E> List<E>.indexOf(start: Int = 0, predicate: (E) -> Boolean): Int {
index++
}
return -1
}
}

inline fun <E> Iterable<E>.contains(predicate: (E) -> Boolean): Boolean = find(predicate) != null
22 changes: 10 additions & 12 deletions core/src/main/java/com/m3u/core/util/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import androidx.core.net.toFile

fun Uri.readContentFilename(
contentResolver: ContentResolver
): String? = when (scheme) {
): String? = if (this == Uri.EMPTY) null
else when (scheme) {
ContentResolver.SCHEME_FILE -> toFile().name
ContentResolver.SCHEME_CONTENT -> {
contentResolver.query(
Expand All @@ -25,20 +26,17 @@ fun Uri.readContentFilename(
} else null
}
}

else -> null
}

fun Uri.readContentText(
contentResolver: ContentResolver
): String? {
return when (scheme) {
ContentResolver.SCHEME_FILE -> toFile().readText()
ContentResolver.SCHEME_CONTENT ->
contentResolver.openInputStream(this)?.use {
it.bufferedReader().readText()
}

else -> null
}
): String? = if (this == Uri.EMPTY) null
else when (scheme) {
ContentResolver.SCHEME_FILE -> toFile().readText()
ContentResolver.SCHEME_CONTENT ->
contentResolver.openInputStream(this)?.use {
it.bufferedReader().readText()
}
else -> null
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.snapshots.StateFactoryMarker

// TODO: Move to material/ui module.
@StateFactoryMarker
fun <T> observableStateOf(
delegate: MutableState<T>,
onChanged: (T) -> Unit
): MutableState<T> {
return ObservableState(delegate, onChanged)
}

@StateFactoryMarker
fun <T> observableStateOf(
value: T,
onChanged: (T) -> Unit
): MutableState<T> {
val delegate = mutableStateOf(value)
return ObservableState(value, delegate, onChanged)
return ObservableState(mutableStateOf(value), onChanged)
}

private class ObservableState<T>(
defaultValue: T,
private val delegate: MutableState<T>,
private val onChanged: (T) -> Unit
) : MutableState<T> {
override var value: T = defaultValue
override var value: T
get() = delegate.value
set(value) {
field = value
onChanged(value)
delegate.value = value
}

override fun component1(): T = delegate.component1()
Expand Down
21 changes: 3 additions & 18 deletions core/src/main/java/com/m3u/core/util/context/SharedPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.m3u.core.util.context
import android.content.SharedPreferences
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import com.m3u.core.util.compose.observableStateOf
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

Expand Down Expand Up @@ -76,23 +77,7 @@ private fun <T> SharedPreferences.delegateAsState(
defaultValue: T,
getter: SharedPreferences.(String, T) -> T,
setter: SharedPreferences.Editor.(String, T) -> SharedPreferences.Editor
): MutableState<T> = StateDelegator(
): MutableState<T> = observableStateOf(
delegate = mutableStateOf(getter(key, defaultValue)),
onUpdate = { edit().setter(key, it).apply() },
onChanged = { edit().setter(key, it).apply() }
)

private class StateDelegator<T>(
private val delegate: MutableState<T>,
private val onUpdate: (T) -> Unit
) : MutableState<T> {
override var value: T
get() = delegate.value
set(value) {
onUpdate(value)
delegate.value = value
}

override fun component1(): T = delegate.component1()

override fun component2(): (T) -> Unit = delegate.component2()
}
5 changes: 5 additions & 0 deletions core/src/main/java/com/m3u/core/wrapper/Event.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.m3u.core.wrapper

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable

@Stable
sealed class Event<out T> private constructor(
private val data: T? = null
) {
Expand All @@ -25,6 +28,7 @@ sealed class Event<out T> private constructor(
/**
* Event which cannot be consumed
*/
@Immutable
class Handled<out T> : Event<T>() {
override var isHandled: Boolean = true
}
Expand All @@ -34,6 +38,7 @@ sealed class Event<out T> private constructor(
* @see eventOf
* @hide
*/
@Stable
class Regular<out T>(data: T) : Event<T>(data)
}

Expand Down
Loading

0 comments on commit 68b0b93

Please sign in to comment.