Skip to content

Commit

Permalink
✨ 历史直播源、历史节目单
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed Apr 23, 2024
1 parent d21fb6f commit e6a41cf
Show file tree
Hide file tree
Showing 9 changed files with 1,172 additions and 187 deletions.
757 changes: 757 additions & 0 deletions app/src/main/java/top/yogiczy/mytv/tvmaterial/Dialog.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import top.yogiczy.mytv.data.entities.IptvGroupList
import top.yogiczy.mytv.data.repositories.EpgRepository
import top.yogiczy.mytv.data.repositories.IptvRepository
import top.yogiczy.mytv.data.utils.Constants
import top.yogiczy.mytv.ui.utils.SP

class HomeScreeViewModel : ViewModel() {
private val iptvRepository = IptvRepository()
Expand All @@ -39,9 +40,13 @@ class HomeScreeViewModel : ViewModel() {
delay(Constants.HTTP_RETRY_INTERVAL)
true
}
.catch { _uiState.value = HomeScreenUiState.Error(it.message) }
.catch {
_uiState.value = HomeScreenUiState.Error(it.message)
SP.iptvSourceUrlHistoryList -= SP.iptvSourceUrl
}
.map {
_uiState.value = HomeScreenUiState.Ready(iptvGroupList = it)
SP.iptvSourceUrlHistoryList += SP.iptvSourceUrl
it
}
.collect()
Expand All @@ -54,7 +59,10 @@ class HomeScreeViewModel : ViewModel() {

flow { emit(epgRepository.getEpgs(channels)) }
.retry(Constants.HTTP_RETRY_COUNT) { delay(Constants.HTTP_RETRY_INTERVAL); true }
.catch { emit(EpgList()) }
.catch {
emit(EpgList())
SP.epgXmlUrlHistoryList -= SP.epgXmlUrl
}
.map { epgList ->
// 移除过期节目
epgList.copy(value = epgList.map { epg ->
Expand All @@ -70,6 +78,7 @@ class HomeScreeViewModel : ViewModel() {
.map { epgList ->
_uiState.value =
(_uiState.value as HomeScreenUiState.Ready).copy(epgList = epgList)
SP.epgXmlUrlHistoryList += SP.epgXmlUrl
}
.collect()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -28,7 +27,6 @@ import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
Expand Down Expand Up @@ -72,7 +70,7 @@ import top.yogiczy.mytv.ui.screens.video.rememberExoPlayerState
import top.yogiczy.mytv.ui.utils.Loggable
import top.yogiczy.mytv.ui.utils.SP
import top.yogiczy.mytv.ui.utils.handleDPadKeyEvents
import top.yogiczy.mytv.ui.utils.handleVerticalDragGestures
import top.yogiczy.mytv.ui.utils.handleDragGestures
import kotlin.math.max

@androidx.annotation.OptIn(UnstableApi::class)
Expand Down Expand Up @@ -153,34 +151,34 @@ fun HomeContent(
state.changeCurrentIptv(state.currentIptv, state.currentIptvUrlIdx + 1)
}
},
onEnter = { state.changePanelVisible(true) },
onLongEnter = { state.changeSettingsVisible(true) },
onSelect = { state.changePanelVisible(true) },
onLongSelect = { state.changeSettingsVisible(true) },
onSettings = { state.changeSettingsVisible(true) },
onNumber = {
state.changeTempPanelVisible(false)
channelNoInputState.input(it)
},
)
.handleVerticalDragGestures(
onSwipeUp = { state.changeCurrentIptvToNext() },
onSwipeDown = { state.changeCurrentIptvToPrev() },
onSwipeLeft = {
if (state.currentIptv.urlList.size > 1) {
state.changeCurrentIptv(state.currentIptv, state.currentIptvUrlIdx + 1)
}
.handleDragGestures(
onSwipeDown = {
if (SP.iptvChannelChangeFlip) state.changeCurrentIptvToNext()
else state.changeCurrentIptvToPrev()
},
onSwipeUp = {
if (SP.iptvChannelChangeFlip) state.changeCurrentIptvToPrev()
else state.changeCurrentIptvToNext()
},
onSwipeRight = {
if (state.currentIptv.urlList.size > 1) {
state.changeCurrentIptv(state.currentIptv, state.currentIptvUrlIdx - 1)
}
},
onSwipeLeft = {
if (state.currentIptv.urlList.size > 1) {
state.changeCurrentIptv(state.currentIptv, state.currentIptvUrlIdx + 1)
}
},
)
.pointerInput(Unit) {
detectTapGestures(
onTap = { state.changePanelVisible(true) },
onDoubleTap = { state.changeSettingsVisible(true) },
)
}
.focusRequester(focusRequester)
.focusable(),
) {
Expand Down Expand Up @@ -237,16 +235,19 @@ private fun BackPressHandledArea(
onBackPressed: () -> Unit,
modifier: Modifier = Modifier,
content: @Composable BoxScope.() -> Unit,
) = Box(modifier = Modifier
.onPreviewKeyEvent {
if (it.key == Key.Back && it.type == KeyEventType.KeyUp) {
onBackPressed()
true
} else {
false
) = Box(
modifier = Modifier
.onPreviewKeyEvent {
if (it.key == Key.Back && it.type == KeyEventType.KeyUp) {
onBackPressed()
true
} else {
false
}
}
}
.then(modifier), content = content)
.then(modifier),
content = content,
)

@UnstableApi
class HomeContentState(
Expand Down Expand Up @@ -304,9 +305,8 @@ class HomeContentState(
}

// 记忆可播放的域名
SP.iptvPlayableHostList = SP.iptvPlayableHostList.plus(
Uri.parse(_currentIptv.urlList[_currentIptvUrlIdx]).host ?: ""
)
SP.iptvPlayableHostList += Uri.parse(_currentIptv.urlList[_currentIptvUrlIdx]).host
?: ""
}
}

Expand All @@ -316,9 +316,8 @@ class HomeContentState(
}

// 从记忆中删除不可播放的域名
SP.iptvPlayableHostList = SP.iptvPlayableHostList.minus(
Uri.parse(_currentIptv.urlList[_currentIptvUrlIdx]).host ?: ""
)
SP.iptvPlayableHostList -= Uri.parse(_currentIptv.urlList[_currentIptvUrlIdx]).host
?: ""
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package top.yogiczy.mytv.ui.screens.panel.components

import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -20,7 +19,6 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.material3.Card
Expand All @@ -31,6 +29,7 @@ import androidx.tv.material3.Text
import top.yogiczy.mytv.data.entities.EpgProgrammeCurrent
import top.yogiczy.mytv.data.entities.Iptv
import top.yogiczy.mytv.ui.theme.MyTVTheme
import top.yogiczy.mytv.ui.utils.handleDPadKeyEvents

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -58,22 +57,20 @@ fun PanelIptvItem(
.height(54.dp)
.focusRequester(focusRequester)
.onFocusChanged { isFocused = it.isFocused || it.hasFocus }
.pointerInput(Unit) {
detectTapGestures(
onTap = {
isFocused = true
onIptvSelected()
},
)
},
.handleDPadKeyEvents(
onSelect = {
focusRequester.requestFocus()
onIptvSelected()
}
),
scale = CardDefaults.scale(focusedScale = 1.1f),
colors = CardDefaults.colors(
containerColor = MaterialTheme.colorScheme.surface.copy(alpha = 0.8f),
contentColor = MaterialTheme.colorScheme.onSurface,
focusedContainerColor = MaterialTheme.colorScheme.onSurface,
focusedContentColor = MaterialTheme.colorScheme.surface,
),
onClick = { onIptvSelected() },
onClick = { },
) {
Column(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package top.yogiczy.mytv.ui.screens.settings.components

import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -20,7 +19,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.material3.Card
Expand All @@ -29,6 +27,7 @@ import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import top.yogiczy.mytv.ui.theme.MyTVTheme
import top.yogiczy.mytv.ui.utils.handleDPadKeyEvents

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -58,27 +57,24 @@ fun SettingsItem(
.height(90.dp)
.focusRequester(focusRequester)
.onFocusChanged { isFocused = it.isFocused || it.hasFocus }
.pointerInput(Unit) {
detectTapGestures(
onTap = {
isFocused = true
onClick()
},
onLongPress = {
isFocused = true
onLongClick()
},
)
},
.handleDPadKeyEvents(
onSelect = {
focusRequester.requestFocus()
onClick()
},
onLongSelect = {
focusRequester.requestFocus()
onLongClick()
},
),
scale = CardDefaults.scale(focusedScale = 1.05f),
colors = CardDefaults.colors(
containerColor = MaterialTheme.colorScheme.surface.copy(alpha = 0.8f),
contentColor = MaterialTheme.colorScheme.onSurface,
focusedContainerColor = MaterialTheme.colorScheme.onSurface,
focusedContentColor = MaterialTheme.colorScheme.surface,
),
onClick = onClick,
onLongClick = onLongClick,
onClick = {}
) {
Column(
modifier = Modifier
Expand Down
Loading

0 comments on commit e6a41cf

Please sign in to comment.