Skip to content

Commit

Permalink
fix: tv provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jan 19, 2024
1 parent e4683a4 commit 45c8d60
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions features/playlist/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation(libs.androidx.work.work.runtime.ktx)

implementation(libs.com.google.accompanist.accompanist.permissions)
implementation(libs.androidx.tvprovider.tvprovider)
}

tasks.withType<KotlinCompile>().configureEach {
Expand Down
1 change: 1 addition & 0 deletions features/playlist/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.m3u.features.playlist

import android.content.ContentResolver
import android.content.Context

sealed interface PlaylistEvent {
Expand All @@ -10,4 +11,5 @@ sealed interface PlaylistEvent {
data object ScrollUp : PlaylistEvent
data class Query(val text: String) : PlaylistEvent
data class CreateShortcut(val context: Context, val id: Int) : PlaylistEvent
data class CreateTvRecommend(val contentResolver: ContentResolver, val id: Int) : PlaylistEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PlaylistViewModel @Inject constructor(
is PlaylistEvent.SavePicture -> savePicture(event)
is PlaylistEvent.Query -> query(event)
is PlaylistEvent.CreateShortcut -> createShortcut(event.context, event.id)
is PlaylistEvent.CreateTvRecommend -> createTvRecommend(event.contentResolver, event.id)
}
}

Expand Down Expand Up @@ -204,6 +205,23 @@ class PlaylistViewModel @Inject constructor(
}
}

private fun createTvRecommend(contentResolver: ContentResolver, id: Int) {
viewModelScope.launch {
val stream = streamRepository.get(id) ?: return@launch
val bitmap = stream.cover?.let { mediaRepository.loadDrawable(it)?.toBitmap() }
val channel = TvChannel.Builder()
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
.setDisplayName(stream.title)
.setInternalProviderId(id.toString())
.setAppLinkIntentUri("content://channelsample.com/category/$id".toUri())
.build()
contentResolver.insert(
TvContractCompat.Channels.CONTENT_URI,
channel.toContentValues()
)
}
}

private val _query: MutableStateFlow<String> = MutableStateFlow("")
internal val query: StateFlow<String> = _query.asStateFlow()
private fun query(event: PlaylistEvent.Query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal fun PlaylistDrawer(

internal object PlaylistDrawerDefaults {
@Composable
fun rememberStreamItems(
fun rememberStreamMenuItems(
stream: Stream?,
onFavorite: (streamId: Int, target: Boolean) -> Unit,
ban: (streamId: Int) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import com.m3u.features.playlist.components.PlaylistDrawerDefaults
import com.m3u.features.playlist.components.TvStreamGallery
import com.m3u.material.ktx.Edge
import com.m3u.material.ktx.blurEdge
import com.m3u.ui.helper.LocalHelper
import com.m3u.ui.Sort
import com.m3u.ui.helper.LocalHelper
import kotlinx.collections.immutable.ImmutableList

@Composable
Expand Down Expand Up @@ -81,7 +81,7 @@ internal fun TvPlaylistScreenImpl(

PlaylistDrawer(
drawerState = drawerState,
items = PlaylistDrawerDefaults.rememberStreamItems(
items = PlaylistDrawerDefaults.rememberStreamMenuItems(
stream = pressStream,
onFavorite = onFavorite,
ban = ban,
Expand Down

0 comments on commit 45c8d60

Please sign in to comment.