Skip to content

Commit

Permalink
Show UI mode notification on startup screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Jul 1, 2023
1 parent bf4fa8e commit 1a8d821
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package org.jellyfin.androidtv.data.model
data class AppNotification(
val message: String,
val dismiss: () -> Unit,
val public: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class NotificationsRepositoryImpl(
addBetaNotification()
}

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

private fun addUiModeNotification() {
Expand All @@ -45,7 +45,7 @@ class NotificationsRepositoryImpl(
val hasHdmiCec = context.packageManager.hasSystemFeature("android.hardware.hdmi.cec")

if (invalidUiMode && isTouch && !hasHdmiCec) {
addNotification(context.getString(R.string.app_notification_uimode_invalid))
addNotification(context.getString(R.string.app_notification_uimode_invalid), public = true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.dp
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
Expand All @@ -23,13 +34,15 @@ import org.jellyfin.androidtv.auth.model.ConnectingState
import org.jellyfin.androidtv.auth.model.Server
import org.jellyfin.androidtv.auth.model.ServerAdditionState
import org.jellyfin.androidtv.auth.model.UnableToConnectState
import org.jellyfin.androidtv.data.repository.NotificationsRepository
import org.jellyfin.androidtv.databinding.FragmentSelectServerBinding
import org.jellyfin.androidtv.ui.ServerButtonView
import org.jellyfin.androidtv.ui.SpacingItemDecoration
import org.jellyfin.androidtv.ui.startup.StartupViewModel
import org.jellyfin.androidtv.util.ListAdapter
import org.jellyfin.androidtv.util.MenuBuilder
import org.jellyfin.androidtv.util.getSummary
import org.koin.androidx.compose.get
import org.koin.androidx.viewmodel.ext.android.sharedViewModel

class SelectServerFragment : Fragment() {
Expand Down Expand Up @@ -146,6 +159,32 @@ class SelectServerFragment : Fragment() {
}
}

// Notifications
binding.notifications.setContent {
val notificationsRepository = get<NotificationsRepository>()
val notifications by notificationsRepository.notifications.collectAsState()

Column(
verticalArrangement = Arrangement.spacedBy(5.dp)
) {
for (notification in notifications) {
if (!notification.public) continue

Card(
modifier = Modifier
.fillMaxWidth(),
backgroundColor = colorResource(id = R.color.lb_basic_card_info_bg_color),
contentColor = colorResource(id = R.color.white),
) {
Text(
text = notification.message,
modifier = Modifier.padding(10.dp)
)
}
}
}
}

// Manual
binding.enterServerAddress.setOnClickListener {
parentFragmentManager.commit {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/fragment_select_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
android:layout_weight="1"
android:orientation="vertical">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 1a8d821

Please sign in to comment.