Fix last media preview V2 UI glitches.
This commit is contained in:
parent
3826ac553d
commit
7088b1a302
5 changed files with 57 additions and 20 deletions
|
@ -261,6 +261,19 @@ public class MediaDatabase extends Database {
|
|||
public boolean isRelatedToFileSize() {
|
||||
return this == Largest;
|
||||
}
|
||||
|
||||
public static @NonNull Sorting deserialize(int code) {
|
||||
switch (code) {
|
||||
case 0:
|
||||
return Newest;
|
||||
case 1:
|
||||
return Oldest;
|
||||
case 2:
|
||||
return Largest;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final static class StorageBreakdown {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package org.thoughtcrime.securesms.mediapreview
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.commit
|
||||
import org.thoughtcrime.securesms.R
|
||||
|
||||
|
@ -17,6 +19,11 @@ class MediaPreviewV2Activity : AppCompatActivity(R.layout.activity_mediapreview_
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setTheme(R.style.TextSecure_MediaPreview)
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
val systemBarColor = ContextCompat.getColor(this, R.color.media_preview_bar_background)
|
||||
window.statusBarColor = systemBarColor
|
||||
window.navigationBarColor = systemBarColor
|
||||
}
|
||||
if (savedInstanceState == null) {
|
||||
val bundle = Bundle()
|
||||
val args = MediaIntentFactory.requireArguments(intent.extras!!)
|
||||
|
|
|
@ -79,6 +79,22 @@ class MediaPreviewV2Fragment : Fragment(R.layout.fragment_media_preview_v2), Med
|
|||
}
|
||||
}
|
||||
|
||||
private fun initializeViewModel(args: MediaIntentFactory.MediaPreviewArgs) {
|
||||
if (!MediaUtil.isImageType(args.initialMediaType) && !MediaUtil.isVideoType(args.initialMediaType)) {
|
||||
Log.w(TAG, "Unsupported media type sent to MediaPreviewV2Fragment, finishing.")
|
||||
Snackbar.make(binding.root, R.string.MediaPreviewActivity_unssuported_media_type, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.MediaPreviewActivity_dismiss_due_to_error) {
|
||||
requireActivity().finish()
|
||||
}.show()
|
||||
}
|
||||
|
||||
viewModel.setShowThread(args.showThread)
|
||||
viewModel.setAlwaysShowAlbumRail(args.allMediaInRail)
|
||||
viewModel.setLeftIsRecent(args.leftIsRecent)
|
||||
val sorting = MediaDatabase.Sorting.deserialize(args.sorting)
|
||||
viewModel.fetchAttachments(PartAuthority.requireAttachmentId(args.initialMediaUri), args.threadId, sorting)
|
||||
}
|
||||
|
||||
private fun initializeToolbar(toolbar: MaterialToolbar, args: MediaIntentFactory.MediaPreviewArgs) {
|
||||
toolbar.setNavigationOnClickListener {
|
||||
requireActivity().onBackPressed()
|
||||
|
@ -132,20 +148,6 @@ class MediaPreviewV2Fragment : Fragment(R.layout.fragment_media_preview_v2), Med
|
|||
fullscreenHelper.showAndHideWithSystemUI(requireActivity().window, binding.toolbarLayout, binding.mediaPreviewDetailsContainer)
|
||||
}
|
||||
|
||||
private fun initializeViewModel(args: MediaIntentFactory.MediaPreviewArgs) {
|
||||
if (!MediaUtil.isImageType(args.initialMediaType) && !MediaUtil.isVideoType(args.initialMediaType)) {
|
||||
Log.w(TAG, "Unsupported media type sent to MediaPreviewV2Fragment, finishing.")
|
||||
Snackbar.make(binding.root, R.string.MediaPreviewActivity_unssuported_media_type, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.MediaPreviewActivity_dismiss_due_to_error) {
|
||||
requireActivity().finish()
|
||||
}.show()
|
||||
}
|
||||
viewModel.setShowThread(args.showThread)
|
||||
viewModel.setAlwaysShowAlbumRail(args.allMediaInRail)
|
||||
val sorting = MediaDatabase.Sorting.values()[args.sorting]
|
||||
viewModel.fetchAttachments(PartAuthority.requireAttachmentId(args.initialMediaUri), args.threadId, sorting)
|
||||
}
|
||||
|
||||
private fun bindCurrentState(currentState: MediaPreviewV2State) {
|
||||
if (currentState.position == -1 && currentState.mediaRecords.isEmpty()) {
|
||||
onMediaNotAvailable()
|
||||
|
|
|
@ -7,7 +7,8 @@ data class MediaPreviewV2State(
|
|||
val loadState: LoadState = LoadState.INIT,
|
||||
val position: Int = 0,
|
||||
val showThread: Boolean = false,
|
||||
val allMediaInAlbumRail: Boolean = false
|
||||
val allMediaInAlbumRail: Boolean = false,
|
||||
val leftIsRecent: Boolean = false
|
||||
) {
|
||||
enum class LoadState { INIT, READY, LOADED }
|
||||
}
|
||||
|
|
|
@ -27,11 +27,19 @@ class MediaPreviewV2ViewModel : ViewModel() {
|
|||
fun fetchAttachments(startingAttachmentId: AttachmentId, threadId: Long, sorting: MediaDatabase.Sorting) {
|
||||
disposables += store.update(repository.getAttachments(startingAttachmentId, threadId, sorting)) {
|
||||
result: MediaPreviewRepository.Result, oldState: MediaPreviewV2State ->
|
||||
oldState.copy(
|
||||
position = result.initialPosition,
|
||||
mediaRecords = result.records,
|
||||
loadState = MediaPreviewV2State.LoadState.READY,
|
||||
)
|
||||
if (oldState.leftIsRecent) {
|
||||
oldState.copy(
|
||||
position = result.initialPosition,
|
||||
mediaRecords = result.records,
|
||||
loadState = MediaPreviewV2State.LoadState.READY,
|
||||
)
|
||||
} else {
|
||||
oldState.copy(
|
||||
position = result.records.size - result.initialPosition - 1,
|
||||
mediaRecords = result.records.reversed(),
|
||||
loadState = MediaPreviewV2State.LoadState.READY,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +55,12 @@ class MediaPreviewV2ViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
fun setLeftIsRecent(value: Boolean) {
|
||||
store.update { oldState ->
|
||||
oldState.copy(leftIsRecent = value)
|
||||
}
|
||||
}
|
||||
|
||||
fun setCurrentPage(position: Int) {
|
||||
store.update { oldState ->
|
||||
oldState.copy(position = position, loadState = MediaPreviewV2State.LoadState.LOADED)
|
||||
|
|
Loading…
Add table
Reference in a new issue