Skip to content

Commit 989f79a

Browse files
authored
Merge pull request #2 from TypeType-Video/release/0.2.0-beta.1
chore: release 0.2.0-beta.1
2 parents 296112e + 3adf766 commit 989f79a

35 files changed

Lines changed: 1607 additions & 14 deletions

File tree

‎app/build.gradle.kts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
// The release workflow reads this line: "x.y.z-beta.n" is published from the beta branch, "x.y.z" from main.
8-
val appVersion = "0.1.1-beta.1"
8+
val appVersion = "0.2.0-beta.1"
99

1010
// The version code follows from the name, so each release installs over the one before, and a beta sits under the
1111
// stable release that ends it: 0.3.0-beta.2 is 30002 and 0.3.0 is 30099.
@@ -81,6 +81,7 @@ dependencies {
8181
implementation(project(":feature:collections"))
8282
implementation(project(":feature:detail"))
8383
implementation(project(":feature:player"))
84+
implementation(project(":feature:update"))
8485
implementation(libs.androidx.media3.exoplayer)
8586
implementation(libs.androidx.media3.exoplayer.hls)
8687
implementation(libs.androidx.media3.datasource.okhttp)

‎app/src/main/java/video/typetype/tv/AppContainer.kt‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package video.typetype.tv
22

33
import android.content.Context
4+
import android.content.pm.ApplicationInfo
5+
import androidx.core.content.pm.PackageInfoCompat
46
import androidx.media3.common.util.UnstableApi
7+
import kotlinx.coroutines.CoroutineScope
8+
import kotlinx.coroutines.Dispatchers
9+
import kotlinx.coroutines.SupervisorJob
510
import video.typetype.tv.data.ContentRepository
611
import video.typetype.tv.data.PresenceReport
712
import video.typetype.tv.data.device.PerformanceSettings
813
import video.typetype.tv.data.device.PreferencesDeviceStore
14+
import video.typetype.tv.data.device.UpdateSettings
915
import video.typetype.tv.data.dto.UserProfileDto
1016
import video.typetype.tv.data.net.AndroidConnectivity
1117
import video.typetype.tv.data.net.Connectivity
18+
import video.typetype.tv.data.net.HttpClients
1219
import video.typetype.tv.data.net.LazySecretStore
1320
import video.typetype.tv.data.net.TinkSecretStore
1421
import video.typetype.tv.data.remote.AndroidTextProvider
@@ -20,12 +27,18 @@ import video.typetype.tv.data.session.Backend
2027
import video.typetype.tv.data.session.DeviceProfileStore
2128
import video.typetype.tv.data.session.SessionManager
2229
import video.typetype.tv.data.session.StreamAccess
30+
import video.typetype.tv.data.update.ReleaseFeed
31+
import video.typetype.tv.data.update.UpdateDownloader
2332
import video.typetype.tv.playback.CodecSupport
2433
import video.typetype.tv.playback.DecoderFailures
2534
import video.typetype.tv.playback.DeviceCodecSupport
2635
import video.typetype.tv.playback.LearnedCodecSupport
2736
import video.typetype.tv.playback.PlaybackProvider
2837
import video.typetype.tv.playback.RoutingPlaybackProvider
38+
import video.typetype.tv.ui.update.InstalledApp
39+
import video.typetype.tv.ui.update.SessionUpdateInstaller
40+
import video.typetype.tv.ui.update.UpdateController
41+
import java.io.File
2942

3043
class AppContainer(context: Context) {
3144
private val appContext = context.applicationContext
@@ -39,6 +52,7 @@ class AppContainer(context: Context) {
3952

4053
private val deviceProfile by lazy { DeviceProfileStore(appContext, appVersion) }
4154
val performance by lazy { PerformanceSettings(PreferencesDeviceStore(appContext)) }
55+
val updateSettings by lazy { UpdateSettings(PreferencesDeviceStore(appContext, PreferencesDeviceStore.UPDATES)) }
4256

4357
fun warmUp() {
4458
Thread({ secrets.warmUp() }, "secrets-warmup").start()
@@ -77,7 +91,7 @@ class AppContainer(context: Context) {
7791
watch = backend.watch,
7892
userSettings = userSettings,
7993
access = access,
80-
performance = performance,
94+
deviceSections = listOf(performance, updateSettings),
8195
)
8296

8397
private val codecs: CodecSupport by lazy { deviceCodecs() }
@@ -91,6 +105,22 @@ class AppContainer(context: Context) {
91105
@androidx.annotation.OptIn(UnstableApi::class)
92106
private fun deviceCodecs(): CodecSupport = LearnedCodecSupport(DeviceCodecSupport(appContext), decoderFailures)
93107

108+
val updates by lazy {
109+
val info = appContext.packageManager.getPackageInfo(appContext.packageName, 0)
110+
val http = HttpClients.updates()
111+
val feed = ReleaseFeed(http)
112+
UpdateController(
113+
releases = feed,
114+
download = UpdateDownloader(http),
115+
installer = SessionUpdateInstaller(appContext),
116+
settings = updateSettings,
117+
installed = InstalledApp(appContext.packageName, info.versionName.orEmpty(), PackageInfoCompat.getLongVersionCode(info)),
118+
apkFile = File(appContext.cacheDir, "update/TypeType-TV.apk"),
119+
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate),
120+
automatic = appContext.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE == 0,
121+
)
122+
}
123+
94124
val decoderFailures by lazy { DecoderFailures(PreferencesDeviceStore(appContext, PreferencesDeviceStore.DECODERS)) }
95125
}
96126

‎app/src/main/java/video/typetype/tv/ui/AppEntry.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
3737
import androidx.media3.common.util.UnstableApi
3838
import kotlinx.coroutines.launch
3939
import video.typetype.tv.AppContainer
40+
import video.typetype.tv.data.device.UpdateSettings
4041
import video.typetype.tv.data.session.SessionState
4142
import video.typetype.tv.ui.auth.LoginScreen
4243
import video.typetype.tv.ui.auth.ReconnectScreen
@@ -144,10 +145,12 @@ private fun AppState(container: AppContainer, state: SessionState, scope: Corout
144145
"forget-certificate" -> session.forgetCertificate()
145146
"mark-notifications-read" -> tryLoad({}) { repository.markNotificationsRead() }
146147
"forget-decoders" -> container.decoderFailures.forget()
148+
UpdateSettings.CHECK_NOW -> container.updates.checkNow()
147149
}
148150
}
149151
},
150152
performance = performance,
153+
updates = container.updates,
151154
)
152155
}
153156
}

‎app/src/main/java/video/typetype/tv/ui/AppRoot.kt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import video.typetype.tv.navigation.topTab
4444
import video.typetype.tv.theme.Dimens
4545
import video.typetype.tv.theme.Palette
4646
import video.typetype.tv.ui.components.TopNav
47+
import video.typetype.tv.ui.update.UpdateController
48+
import video.typetype.tv.ui.update.UpdateHost
49+
import video.typetype.tv.ui.update.offer
50+
import androidx.compose.runtime.collectAsState
4751
import video.typetype.tv.ui.home.HomeScreen
4852
import video.typetype.tv.ui.channel.ChannelScreen
4953
import video.typetype.tv.ui.playlist.CollectionKind
@@ -85,8 +89,10 @@ fun AppRoot(
8589
account: AccountBadge,
8690
onSettingsAction: (String) -> Unit,
8791
performance: Performance = Performance(),
92+
updates: UpdateController,
8893
) {
8994
val navigator = remember { MockNavigator() }
95+
val updateState by updates.state.collectAsState()
9096
val homeSession = remember { HomeSession() }
9197
val searchSession = remember { SearchSession() }
9298
val librarySession = remember { LibrarySession() }
@@ -281,6 +287,8 @@ fun AppRoot(
281287
contentEntry = homeSession.heroEntry.takeIf { activeTab == TopTab.Home },
282288
navEntry = navEntry,
283289
onNavFocusChange = { navFocused = it },
290+
updateVersion = updateState.offer?.target?.version?.toString(),
291+
onUpdate = updates::openPanel,
284292
)
285293
}
286294
}
@@ -296,6 +304,7 @@ fun AppRoot(
296304
},
297305
)
298306
}
307+
UpdateHost(updates)
299308
}
300309
}
301310
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package video.typetype.tv.data.device
2+
3+
import video.typetype.tv.data.SettingsGroup
4+
import video.typetype.tv.data.remote.TextProvider
5+
6+
// A settings section kept on this box, shown among the account's sections.
7+
interface DeviceSection {
8+
fun addTo(groups: List<SettingsGroup>, texts: TextProvider): List<SettingsGroup>
9+
10+
// Returns false for a setting this section does not keep.
11+
fun update(id: String, value: String): Boolean
12+
}
13+
14+
internal fun List<SettingsGroup>.insertBefore(groupId: String, group: SettingsGroup): List<SettingsGroup> {
15+
val at = indexOfFirst { it.id == groupId }.takeIf { it >= 0 } ?: size
16+
return take(at) + group + drop(at)
17+
}

‎core/data/src/main/java/video/typetype/tv/data/device/DeviceStore.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ class PreferencesDeviceStore(context: Context, name: String = PERFORMANCE) : Dev
2727
companion object {
2828
const val PERFORMANCE = "performance"
2929
const val DECODERS = "decoders"
30+
const val UPDATES = "updates"
3031
}
3132
}

‎core/data/src/main/java/video/typetype/tv/data/device/PerformanceSettings.kt‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ data class Performance(
2020

2121
// What a slow box can turn off to stay smooth. The choice belongs to the box, not to the account: a strong
2222
// television and a small stick signed in to the same account each keep their own.
23-
class PerformanceSettings(private val store: DeviceStore) {
23+
class PerformanceSettings(private val store: DeviceStore) : DeviceSection {
2424
private val state = MutableStateFlow(read())
2525
val current: StateFlow<Performance> = state.asStateFlow()
2626

2727
// The section sits with the everyday ones, before the account and the server.
28-
fun addTo(groups: List<SettingsGroup>, texts: TextProvider): List<SettingsGroup> {
29-
val at = groups.indexOfFirst { it.id == BEFORE_GROUP }.takeIf { it >= 0 } ?: groups.size
30-
return groups.take(at) + group(texts) + groups.drop(at)
31-
}
28+
override fun addTo(groups: List<SettingsGroup>, texts: TextProvider): List<SettingsGroup> =
29+
groups.insertBefore(BEFORE_GROUP, group(texts))
3230

33-
// Returns false for a setting kept on the server.
34-
fun update(id: String, value: String): Boolean {
31+
override fun update(id: String, value: String): Boolean {
3532
when (id) {
3633
in FLAGS -> store.putFlag(id, value.toBoolean())
3734
INTRO -> store.putText(id, Intro.entries.firstOrNull { it.wire == value }?.wire ?: return false)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package video.typetype.tv.data.device
2+
3+
import kotlinx.coroutines.flow.MutableStateFlow
4+
import kotlinx.coroutines.flow.StateFlow
5+
import kotlinx.coroutines.flow.asStateFlow
6+
import video.typetype.tv.data.SettingItem
7+
import video.typetype.tv.data.SettingsGroup
8+
import video.typetype.tv.data.remote.TextProvider
9+
import video.typetype.tv.data.update.UpdateChannel
10+
import video.typetype.tv.resources.R
11+
12+
data class UpdatePreferences(
13+
val channel: UpdateChannel = UpdateChannel.Stable,
14+
val checkOnStart: Boolean = true,
15+
)
16+
17+
// How this box follows new versions of the app. The choice belongs to the box: a test box can follow the betas
18+
// while the living-room TV stays on stable releases.
19+
class UpdateSettings(private val store: DeviceStore) : DeviceSection {
20+
private val state = MutableStateFlow(read())
21+
val current: StateFlow<UpdatePreferences> = state.asStateFlow()
22+
23+
override fun addTo(groups: List<SettingsGroup>, texts: TextProvider): List<SettingsGroup> =
24+
groups.insertBefore(BEFORE_GROUP, group(texts))
25+
26+
override fun update(id: String, value: String): Boolean {
27+
when (id) {
28+
CHECK_ON_START -> store.putFlag(id, value.toBoolean())
29+
CHANNEL -> store.putText(id, UpdateChannel.entries.firstOrNull { it.wire == value }?.wire ?: return false)
30+
else -> return false
31+
}
32+
state.value = read()
33+
return true
34+
}
35+
36+
private fun group(texts: TextProvider): SettingsGroup {
37+
val now = state.value
38+
return SettingsGroup(
39+
id = GROUP,
40+
titleRes = R.string.settings_group_updates,
41+
items = listOf(
42+
SettingItem.Action(CHECK_NOW, R.string.settings_check_updates, R.string.settings_check_updates_summary),
43+
SettingItem.Choice(
44+
id = CHANNEL,
45+
titleRes = R.string.settings_update_channel,
46+
options = listOf(R.string.settings_update_channel_stable, R.string.settings_update_channel_beta).map(texts::text),
47+
defaultIndex = now.channel.ordinal,
48+
wireValues = UpdateChannel.entries.map { it.wire },
49+
summaryRes = R.string.settings_update_channel_summary,
50+
),
51+
SettingItem.Toggle(CHECK_ON_START, R.string.settings_update_on_start, R.string.settings_update_on_start_summary, now.checkOnStart),
52+
),
53+
)
54+
}
55+
56+
private fun read() = UpdatePreferences(
57+
channel = store.text(CHANNEL, UpdateChannel.Stable.wire).let { wire ->
58+
UpdateChannel.entries.firstOrNull { it.wire == wire } ?: UpdateChannel.Stable
59+
},
60+
checkOnStart = store.flag(CHECK_ON_START, true),
61+
)
62+
63+
companion object {
64+
const val CHECK_NOW = "check-updates"
65+
private const val GROUP = "updates"
66+
private const val BEFORE_GROUP = "about"
67+
private const val CHANNEL = "update-channel"
68+
private const val CHECK_ON_START = "update-on-start"
69+
}
70+
}

‎core/data/src/main/java/video/typetype/tv/data/net/HttpClients.kt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ object HttpClients {
8989
.addInterceptor(UserAgentInterceptor(USER_AGENT))
9090
.build()
9191

92+
// Release checks and downloads go to GitHub, never to the instance, so they carry no account and no pin.
93+
fun updates(): OkHttpClient = base(PinTrust())
94+
.addInterceptor(UserAgentInterceptor(USER_AGENT))
95+
.build()
96+
9297
fun subtitles(): OkHttpClient = base(PinTrust())
9398
.addInterceptor(UserAgentInterceptor(USER_AGENT))
9499
.build()

‎core/data/src/main/java/video/typetype/tv/data/remote/RemoteContentRepository.kt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import video.typetype.tv.data.dto.BlockChannelRequest
3535
import video.typetype.tv.data.dto.BlockVideoRequest
3636
import video.typetype.tv.data.dto.StreamDto
3737
import video.typetype.tv.data.net.ApiException
38-
import video.typetype.tv.data.device.PerformanceSettings
38+
import video.typetype.tv.data.device.DeviceSection
3939
import video.typetype.tv.data.net.ServerWatch
4040
import video.typetype.tv.data.session.StreamAccess
4141

@@ -49,7 +49,7 @@ class RemoteContentRepository(
4949
private val watch: ServerWatch,
5050
private val userSettings: RemoteUserSettings,
5151
access: StreamAccess,
52-
private val performance: PerformanceSettings,
52+
private val deviceSections: List<DeviceSection>,
5353
private val clock: () -> Long = System::currentTimeMillis,
5454
) : ContentRepository {
5555
private val streams = StreamStore({ url -> access.anonymousFirst { api.streamFor(url, it) } }, clock)
@@ -133,7 +133,8 @@ class RemoteContentRepository(
133133
.distinct()
134134
.take(IDEA_LIMIT)
135135

136-
override suspend fun settings(): List<SettingsGroup> = performance.addTo(watch.watch { settingsSource.groups(api) }, texts)
136+
override suspend fun settings(): List<SettingsGroup> =
137+
deviceSections.fold(watch.watch { settingsSource.groups(api) }) { groups, section -> section.addTo(groups, texts) }
137138

138139
override suspend fun startupPreferences(): StartupPreferences = userSettings.startupPreferences()
139140

@@ -174,7 +175,7 @@ class RemoteContentRepository(
174175
}
175176

176177
override suspend fun updateSetting(id: String, value: String) {
177-
if (performance.update(id, value)) return
178+
if (deviceSections.any { it.update(id, value) }) return
178179
settingsSource.update(api, id, value)
179180
userSettings.invalidate()
180181
}

0 commit comments

Comments
 (0)