Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PictureViewerFragment crashing when opening photo from latest row #2156

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ object Destinations {
// Playback
val nowPlaying = fragmentDestination<AudioNowPlayingFragment>()
val photoPlayer = activityDestination<PhotoPlayerActivity>()
fun pictureViewer(item: UUID, autoPlay: Boolean, albumSortBy: String, albumSortOrder: SortOrder) =
fun pictureViewer(item: UUID, autoPlay: Boolean, albumSortBy: String?, albumSortOrder: SortOrder?) =
fragmentDestination<PictureViewerFragment>(
PictureViewerFragment.ARGUMENT_ITEM_ID to item.toString(),
PictureViewerFragment.ARGUMENT_ALBUM_SORT_BY to albumSortBy,
PictureViewerFragment.ARGUMENT_ALBUM_SORT_ORDER to Json.Default.encodeToString(albumSortOrder),
PictureViewerFragment.ARGUMENT_ALBUM_SORT_ORDER to albumSortOrder?.let { Json.Default.encodeToString(it) },
PictureViewerFragment.ARGUMENT_AUTO_PLAY to autoPlay,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.jellyfin.sdk.api.client.extensions.imageApi
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.ImageType
import org.jellyfin.sdk.model.api.SortOrder
import org.jellyfin.sdk.model.constant.ItemSortBy
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
Expand All @@ -46,10 +47,10 @@ class PictureViewerFragment : Fragment(), View.OnKeyListener {
// Load requested item in viewmodel
lifecycleScope.launch {
val itemId = requireNotNull(arguments?.getString(ARGUMENT_ITEM_ID)?.toUUIDOrNull())
val albumSortBy = requireNotNull(arguments?.getString(ARGUMENT_ALBUM_SORT_BY))
val albumSortOrder = requireNotNull(arguments?.getString(ARGUMENT_ALBUM_SORT_ORDER)).let {
val albumSortBy = arguments?.getString(ARGUMENT_ALBUM_SORT_BY) ?: ItemSortBy.SortName
val albumSortOrder = arguments?.getString(ARGUMENT_ALBUM_SORT_ORDER)?.let {
Json.Default.decodeFromString<SortOrder>(it)
}
} ?: SortOrder.ASCENDING
pictureViewerViewModel.loadItem(itemId, albumSortBy, albumSortOrder)

val autoPlay = arguments?.getBoolean(ARGUMENT_AUTO_PLAY) == true
Expand Down