|
|
@@ -9,16 +9,18 @@
|
|
|
package org.mjdev.tvapp.ui.pages
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.Home
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.MutableState
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.ui.Modifier
|
|
|
-import androidx.compose.ui.graphics.Color
|
|
|
import androidx.compose.ui.graphics.vector.ImageVector
|
|
|
+import androidx.compose.ui.layout.ContentScale
|
|
|
import org.mjdev.tvapp.R
|
|
|
import org.mjdev.tvlib.annotations.TvPreview
|
|
|
import org.mjdev.tvlib.extensions.HiltExt.appViewModel
|
|
|
@@ -36,6 +38,9 @@ import org.mjdev.tvapp.viewmodel.MainViewModel
|
|
|
import org.mjdev.tvlib.interfaces.ItemAudio
|
|
|
import org.mjdev.tvlib.interfaces.ItemPhoto
|
|
|
import org.mjdev.tvlib.interfaces.ItemVideo
|
|
|
+import org.mjdev.tvlib.interfaces.ItemWithBackground
|
|
|
+import org.mjdev.tvlib.interfaces.ItemWithImage
|
|
|
+import org.mjdev.tvlib.ui.components.tv.FadingPhotoImage
|
|
|
|
|
|
@SuppressLint("ComposableNaming")
|
|
|
class MainPage : Page() {
|
|
|
@@ -62,12 +67,10 @@ class MainPage : Page() {
|
|
|
val networkState = remember(viewModel.networkInfo.networkStatus) {
|
|
|
viewModel.networkInfo.networkStatus
|
|
|
}.collectAsState(null)
|
|
|
- val errorState = remember(viewModel.error) {
|
|
|
- mutableStateOf(viewModel.error.value)
|
|
|
- }
|
|
|
- val titleState = remember {
|
|
|
- mutableStateOf<Any?>(R.string.app_name)
|
|
|
- }
|
|
|
+
|
|
|
+ val errorState = remember(viewModel.error) { mutableStateOf(viewModel.error.value) }
|
|
|
+ val titleState = remember { mutableStateOf<Any?>(R.string.app_name) }
|
|
|
+ val backgroundState: MutableState<Any?> = remember { mutableStateOf(null) }
|
|
|
|
|
|
val onItemClick: (item: Any?) -> Unit = { item ->
|
|
|
val dataId = (item as? ItemWithId)?.id
|
|
|
@@ -79,13 +82,16 @@ class MainPage : Page() {
|
|
|
val dataUri = (item as? ItemAudio)?.uri
|
|
|
navController?.open<PlayerScreen>(dataUri)
|
|
|
}
|
|
|
+
|
|
|
is ItemVideo -> {
|
|
|
val dataUri = (item as? ItemVideo)?.uri
|
|
|
navController?.open<PlayerScreen>(dataUri)
|
|
|
}
|
|
|
+
|
|
|
is ItemPhoto -> {
|
|
|
navController?.open<DetailScreen>(item)
|
|
|
}
|
|
|
+
|
|
|
else -> {
|
|
|
navController?.open<DetailScreen>(item)
|
|
|
}
|
|
|
@@ -93,56 +99,79 @@ class MainPage : Page() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ val onItemSelect: (item: Any?) -> Unit = { item ->
|
|
|
+ backgroundState.value = when (item) {
|
|
|
+ is ItemWithBackground<*> -> item.background
|
|
|
+ is ItemWithImage<*> -> item.image
|
|
|
+ else -> {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
viewModel.handleError { error ->
|
|
|
errorState.value = error
|
|
|
}
|
|
|
|
|
|
- BrowseView(
|
|
|
+ Box(
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
- appIcon = R.mipmap.ic_launcher,
|
|
|
- userIcon = R.drawable.milanj,
|
|
|
- title = titleState.value,
|
|
|
- messages = messages.value,
|
|
|
- categories = categoryList.value.map { it.key }.distinct(),
|
|
|
- featuredItems = featuredMovieList.value,
|
|
|
- categoriesAndItemsMap = categoryList.value,
|
|
|
- networkState = networkState,
|
|
|
- errorState = errorState,
|
|
|
- backgroundColor = Color.DarkGray,
|
|
|
- onTitleClicked = {
|
|
|
- navController?.openMenu()
|
|
|
- },
|
|
|
- onItemClicked = onItemClick,
|
|
|
- customRows = mutableListOf<@Composable () -> Unit>().apply {
|
|
|
- if (viewModel.appsList.size > 0) {
|
|
|
- add { AppsRow(apps = viewModel.appsList) }
|
|
|
- }
|
|
|
- if (viewModel.localAudioCursor.count > 0) {
|
|
|
- add {
|
|
|
- LocalAudioRow(
|
|
|
- cursor = viewModel.localAudioCursor,
|
|
|
- openItem = { item -> onItemClick(item) }
|
|
|
- )
|
|
|
+ ) {
|
|
|
+ FadingPhotoImage(
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
+ fadingImageState = backgroundState,
|
|
|
+ contrast = 4f,
|
|
|
+ alpha = 0.7f,
|
|
|
+ brightness = -255f,
|
|
|
+ contentScale = ContentScale.Crop
|
|
|
+ )
|
|
|
+ BrowseView(
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
+ appIcon = R.mipmap.ic_launcher,
|
|
|
+ userIcon = R.drawable.milanj,
|
|
|
+ title = titleState.value,
|
|
|
+ messages = messages.value,
|
|
|
+ categories = categoryList.value.map { it.key }.distinct(),
|
|
|
+ featuredItems = featuredMovieList.value,
|
|
|
+ categoriesAndItemsMap = categoryList.value,
|
|
|
+ networkState = networkState,
|
|
|
+ errorState = errorState,
|
|
|
+ onTitleClicked = {
|
|
|
+ navController?.openMenu()
|
|
|
+ },
|
|
|
+ onItemFocused = onItemSelect,
|
|
|
+ onItemClicked = onItemClick,
|
|
|
+ customRows = mutableListOf<@Composable () -> Unit>().apply {
|
|
|
+ if (viewModel.appsList.size > 0) {
|
|
|
+ add { AppsRow(apps = viewModel.appsList) }
|
|
|
}
|
|
|
- }
|
|
|
- if (viewModel.localVideoCursor.count > 0) {
|
|
|
- add {
|
|
|
- LocalVideoRow(
|
|
|
- cursor = viewModel.localVideoCursor,
|
|
|
- openItem = { item -> onItemClick(item) }
|
|
|
- )
|
|
|
+ if (viewModel.localAudioCursor.count > 0) {
|
|
|
+ add {
|
|
|
+ LocalAudioRow(
|
|
|
+ cursor = viewModel.localAudioCursor,
|
|
|
+ openItem = { item -> onItemClick(item) },
|
|
|
+ onItemFocus = onItemSelect,
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (viewModel.localPhotoCursor.count > 0) {
|
|
|
- add {
|
|
|
- LocalPhotosRow(
|
|
|
- cursor = viewModel.localPhotoCursor,
|
|
|
- openItem = { item -> onItemClick(item) }
|
|
|
- )
|
|
|
+ if (viewModel.localVideoCursor.count > 0) {
|
|
|
+ add {
|
|
|
+ LocalVideoRow(
|
|
|
+ cursor = viewModel.localVideoCursor,
|
|
|
+ openItem = { item -> onItemClick(item) },
|
|
|
+ onItemFocus = onItemSelect,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (viewModel.localPhotoCursor.count > 0) {
|
|
|
+ add {
|
|
|
+ LocalPhotosRow(
|
|
|
+ cursor = viewModel.localPhotoCursor,
|
|
|
+ openItem = { item -> onItemClick(item) },
|
|
|
+ onItemFocus = onItemSelect,
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- )
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|