Skip to content

Commit

Permalink
Add dismissible notification for beta releases
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Nov 12, 2022
1 parent 04acbb9 commit 8e9d5ef
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package org.jellyfin.androidtv.data.model

data class AppNotification(
val message: String,
val dismiss: () -> Unit,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.content.Context
import android.content.res.Configuration
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import org.jellyfin.androidtv.BuildConfig
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.data.model.AppNotification
import org.jellyfin.androidtv.preference.SystemPreferences

interface NotificationsRepository {
val notifications: StateFlow<List<AppNotification>>
Expand All @@ -18,19 +20,22 @@ interface NotificationsRepository {
class NotificationsRepositoryImpl(
private val context: Context,
private val uiModeManager: UiModeManager,
private val systemPreferences: SystemPreferences,
) : NotificationsRepository {
override val notifications = MutableStateFlow(emptyList<AppNotification>())

override fun dismissNotification(item: AppNotification) {
notifications.value = notifications.value.filter { it != item }
item.dismiss()
}

override fun addDefaultNotifications() {
addUiModeNotification()
addBetaNotification()
}

private fun addNotification(message: String) {
notifications.value = notifications.value + AppNotification(message)
private fun addNotification(message: String, dismiss: () -> Unit = {}) {
notifications.value = notifications.value + AppNotification(message, dismiss)
}

private fun addUiModeNotification() {
Expand All @@ -43,4 +48,16 @@ class NotificationsRepositoryImpl(
addNotification(context.getString(R.string.app_notification_uimode_invalid))
}
}

private fun addBetaNotification() {
val dismissedVersion = systemPreferences[SystemPreferences.dismissedBetaNotificationVersion]
val currentVersion = BuildConfig.VERSION_NAME
val isBeta = currentVersion.lowercase().contains("beta")

if (isBeta && currentVersion != dismissedVersion) {
addNotification(context.getString(R.string.app_notification_beta, currentVersion)) {
systemPreferences[SystemPreferences.dismissedBetaNotificationVersion] = currentVersion
}
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/jellyfin/androidtv/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ val appModule = module {

single<UserRepository> { UserRepositoryImpl() }
single<UserViewsRepository> { UserViewsRepositoryImpl(get()) }
single<NotificationsRepository> { NotificationsRepositoryImpl(get(), get()) }
single<NotificationsRepository> { NotificationsRepositoryImpl(get(), get(), get()) }
single<ItemMutationRepository> { ItemMutationRepositoryImpl(get(), get()) }
single<CustomMessageRepository> { CustomMessageRepositoryImpl() }
single<NavigationRepository> { NavigationRepositoryImpl(Destinations.home) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ class SystemPreferences(context: Context) : SharedPreferenceStore(
* Chosen player for play with button. Changes every time user chooses a player with "play with" button.
*/
var chosenPlayer = enumPreference("chosen_player", PreferredVideoPlayer.VLC)

/**
* The version name for the latest dismissed beta notification or empty if none.
*/
val dismissedBetaNotificationVersion = stringPreference("dismissed_beta_notification_version", "")
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,5 @@
<string name="crash_report_toast">Oops! Something went wrong, a crash report was sent to your Jellyfin server.</string>
<string name="server_setup_incomplete">The setup of this server has not been completed. Open Jellyfin in a web browser to finish setup before signing in.</string>
<string name="episode_name_special">special</string>
<string name="app_notification_beta">App updated to %1$s\nThank you for participating in the Jellyfin beta program</string>
</resources>

0 comments on commit 8e9d5ef

Please sign in to comment.