mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Fix bugs with switching users
This commit is contained in:
parent
833e1d2ea1
commit
dd08bb3e13
6 changed files with 55 additions and 45 deletions
|
|
@ -65,11 +65,11 @@ data class HomeRow(
|
|||
)
|
||||
|
||||
@Composable
|
||||
fun MainPage(
|
||||
fun HomePage(
|
||||
preferences: UserPreferences,
|
||||
navigationManager: NavigationManager,
|
||||
modifier: Modifier,
|
||||
viewModel: MainViewModel = hiltViewModel(),
|
||||
viewModel: HomeViewModel = hiltViewModel(),
|
||||
) {
|
||||
OneTimeLaunchedEffect {
|
||||
viewModel.init(preferences)
|
||||
|
|
@ -27,7 +27,7 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MainViewModel
|
||||
class HomeViewModel
|
||||
@Inject
|
||||
constructor(
|
||||
val api: ApiClient,
|
||||
|
|
@ -135,7 +135,7 @@ class MainViewModel
|
|||
.getNextUp(request)
|
||||
.content
|
||||
.items
|
||||
.map { BaseItem.Companion.from(it, api) }
|
||||
.map { BaseItem.Companion.from(it, api, true) }
|
||||
listOf(
|
||||
HomeRow(
|
||||
section = section,
|
||||
|
|
@ -158,7 +158,7 @@ class MainViewModel
|
|||
}.flatten()
|
||||
.filter { it.items.isNotEmpty() }
|
||||
withContext(Dispatchers.Main) {
|
||||
this@MainViewModel.homeRows.value = homeRows
|
||||
this@HomeViewModel.homeRows.value = homeRows
|
||||
loadingState.value = LoadingState.Success
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,8 @@ fun ApplicationContent(
|
|||
preferences = preferences,
|
||||
navigationManager = navigationManager,
|
||||
deviceProfile = deviceProfile,
|
||||
user = user,
|
||||
server = server,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import com.github.damontecres.dolphin.ui.detail.SeriesDetails
|
|||
import com.github.damontecres.dolphin.ui.detail.VideoDetails
|
||||
import com.github.damontecres.dolphin.ui.detail.movie.MovieDetails
|
||||
import com.github.damontecres.dolphin.ui.detail.series.SeriesOverview
|
||||
import com.github.damontecres.dolphin.ui.main.MainPage
|
||||
import com.github.damontecres.dolphin.ui.main.HomePage
|
||||
import com.github.damontecres.dolphin.ui.playback.PlaybackContent
|
||||
import com.github.damontecres.dolphin.ui.preferences.PreferenceScreenOption
|
||||
import com.github.damontecres.dolphin.ui.preferences.PreferencesPage
|
||||
|
|
@ -31,7 +31,7 @@ fun DestinationContent(
|
|||
) {
|
||||
when (destination) {
|
||||
is Destination.Main ->
|
||||
MainPage(
|
||||
HomePage(
|
||||
preferences = preferences,
|
||||
navigationManager = navigationManager,
|
||||
modifier = modifier,
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ import androidx.tv.material3.Text
|
|||
import androidx.tv.material3.rememberDrawerState
|
||||
import androidx.tv.material3.surfaceColorAtElevation
|
||||
import com.github.damontecres.dolphin.R
|
||||
import com.github.damontecres.dolphin.data.JellyfinServer
|
||||
import com.github.damontecres.dolphin.data.JellyfinUser
|
||||
import com.github.damontecres.dolphin.data.ServerRepository
|
||||
import com.github.damontecres.dolphin.data.model.Library
|
||||
import com.github.damontecres.dolphin.preferences.UserPreferences
|
||||
|
|
@ -89,9 +91,15 @@ fun NavDrawer(
|
|||
destination: Destination,
|
||||
preferences: UserPreferences,
|
||||
navigationManager: NavigationManager,
|
||||
user: JellyfinUser?,
|
||||
server: JellyfinServer?,
|
||||
deviceProfile: DeviceProfile,
|
||||
modifier: Modifier = Modifier,
|
||||
viewModel: NavDrawerViewModel = hiltViewModel(LocalView.current.findViewTreeViewModelStoreOwner()!!),
|
||||
viewModel: NavDrawerViewModel =
|
||||
hiltViewModel(
|
||||
LocalView.current.findViewTreeViewModelStoreOwner()!!,
|
||||
key = "${server?.id}_${user?.id}",
|
||||
),
|
||||
) {
|
||||
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
||||
val listState = rememberLazyListState()
|
||||
|
|
@ -102,8 +110,6 @@ fun NavDrawer(
|
|||
drawerState.setValue(DrawerValue.Open)
|
||||
drawerFocusRequester.requestFocus()
|
||||
}
|
||||
|
||||
val user = viewModel.serverRepository.currentUser
|
||||
val libraries by viewModel.libraries.observeAsState(listOf())
|
||||
|
||||
NavigationDrawer(
|
||||
|
|
@ -125,6 +131,7 @@ fun NavDrawer(
|
|||
) {
|
||||
IconNavItem(
|
||||
text = user?.name ?: "",
|
||||
subtext = server?.name ?: server?.url,
|
||||
icon = Icons.Default.AccountCircle,
|
||||
onClick = { navigationManager.navigateTo(Destination.UserList) },
|
||||
)
|
||||
|
|
@ -194,6 +201,7 @@ fun NavigationDrawerScope.IconNavItem(
|
|||
icon: ImageVector,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
subtext: String? = null,
|
||||
) {
|
||||
NavigationDrawerItem(
|
||||
modifier = modifier,
|
||||
|
|
@ -205,6 +213,15 @@ fun NavigationDrawerScope.IconNavItem(
|
|||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
supportingContent =
|
||||
subtext?.let {
|
||||
{
|
||||
Text(
|
||||
text = it,
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
},
|
||||
interactionSource = null,
|
||||
) {
|
||||
Text(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue