-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
androidApp/src/main/java/com/m3u/androidApp/glance/GlanceReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.m3u.androidApp.glance | ||
|
||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.GlanceAppWidgetReceiver | ||
import com.m3u.data.repository.channel.ChannelRepository | ||
import com.m3u.data.repository.media.MediaRepository | ||
import dagger.hilt.EntryPoint | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
class GlanceReceiver : GlanceAppWidgetReceiver() { | ||
override val glanceAppWidget: GlanceAppWidget = PlayRandomlyWidget() | ||
|
||
} | ||
|
||
@EntryPoint | ||
@InstallIn(SingletonComponent::class) | ||
interface GlanceAccessor { | ||
val channelRepository: ChannelRepository | ||
val mediaRepository: MediaRepository | ||
} |
101 changes: 101 additions & 0 deletions
101
androidApp/src/main/java/com/m3u/androidApp/glance/PlayRandomlyWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.m3u.androidApp.glance | ||
|
||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.Bitmap | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.core.graphics.drawable.toBitmap | ||
import androidx.glance.GlanceId | ||
import androidx.glance.GlanceModifier | ||
import androidx.glance.GlanceTheme | ||
import androidx.glance.Image | ||
import androidx.glance.ImageProvider | ||
import androidx.glance.action.clickable | ||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.action.actionStartActivity | ||
import androidx.glance.appwidget.cornerRadius | ||
import androidx.glance.appwidget.provideContent | ||
import androidx.glance.background | ||
import androidx.glance.layout.Alignment | ||
import androidx.glance.layout.Box | ||
import androidx.glance.layout.ContentScale | ||
import androidx.glance.layout.fillMaxSize | ||
import androidx.glance.layout.padding | ||
import androidx.glance.text.FontWeight | ||
import androidx.glance.text.Text | ||
import androidx.glance.text.TextDefaults | ||
import androidx.glance.unit.ColorProvider | ||
import com.m3u.core.Contracts | ||
import dagger.hilt.android.EntryPointAccessors | ||
|
||
class PlayRandomlyWidget : GlanceAppWidget() { | ||
override suspend fun provideGlance(context: Context, id: GlanceId) { | ||
val accessor: GlanceAccessor by lazy { | ||
EntryPointAccessors.fromApplication(context.applicationContext) | ||
} | ||
val playedRecently = accessor.channelRepository.observePlayedRecently() | ||
provideContent { | ||
val channel by playedRecently.collectAsState(initial = null) | ||
GlanceTheme { | ||
val bitmap: Bitmap? by produceState<Bitmap?>( | ||
initialValue = null, | ||
key1 = channel?.cover | ||
) { | ||
value = accessor.mediaRepository | ||
.loadDrawable(channel?.cover.orEmpty()) | ||
?.toBitmap() | ||
} | ||
Box( | ||
contentAlignment = Alignment.BottomStart, | ||
modifier = GlanceModifier | ||
.fillMaxSize() | ||
.cornerRadius(16.dp) | ||
.clickable( | ||
actionStartActivity( | ||
Intent(Intent.ACTION_VIEW).apply { | ||
component = ComponentName.createRelative( | ||
context, | ||
Contracts.PLAYER_ACTIVITY | ||
) | ||
putExtra( | ||
Contracts.PLAYER_SHORTCUT_CHANNEL_RECENTLY, | ||
true | ||
) | ||
} | ||
) | ||
) | ||
.background(GlanceTheme.colors.background) | ||
.padding(4.dp) | ||
) { | ||
val currentBitmap = bitmap | ||
if (currentBitmap != null) { | ||
Image( | ||
provider = ImageProvider(currentBitmap), | ||
contentDescription = channel?.title, | ||
contentScale = ContentScale.Crop, | ||
modifier = GlanceModifier | ||
.fillMaxSize() | ||
.cornerRadius(16.dp) | ||
) | ||
} | ||
Text( | ||
text = channel?.title.orEmpty(), | ||
style = TextDefaults.defaultTextStyle.copy( | ||
fontSize = 18.sp, | ||
fontWeight = FontWeight.Bold, | ||
color = ColorProvider(Color.White) | ||
), | ||
maxLines = 1, | ||
modifier = GlanceModifier.padding(12.dp) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialLayout="@layout/glance_default_loading_layout" | ||
android:targetCellWidth="2" | ||
android:targetCellHeight="1" | ||
android:updatePeriodMillis="86400000" | ||
android:resizeMode="horizontal|vertical" | ||
android:widgetCategory="home_screen" | ||
android:widgetFeatures="reconfigurable|configuration_optional"> | ||
</appwidget-provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters