diff --git a/CHANGELOG.md b/CHANGELOG.md index e10f38121af..d6c14a25ef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ ownCloud admins and users. ## Summary * Change - Replace auto-uploads with automatic uploads: [#4252](https://github.com/owncloud/android/issues/4252) +* Enhancement - Add status message when (un)setting av. offline from preview: [#4382](https://github.com/owncloud/android/issues/4382) ## Details @@ -45,6 +46,15 @@ ownCloud admins and users. https://github.com/owncloud/android/issues/4252 https://github.com/owncloud/android/pull/4492 +* Enhancement - Add status message when (un)setting av. offline from preview: [#4382](https://github.com/owncloud/android/issues/4382) + + A message has been added in all previews when the (un)setting av. offline + buttons are clicked. The options menu has been updated in all previews depending + on the file status. + + https://github.com/owncloud/android/issues/4382 + https://github.com/owncloud/android/pull/4482 + # Changelog for ownCloud Android Client [4.4.0] (2024-09-30) The following sections list the changes in ownCloud Android Client 4.4.0 relevant to diff --git a/changelog/unreleased/4482 b/changelog/unreleased/4482 new file mode 100644 index 00000000000..5ca06e49a17 --- /dev/null +++ b/changelog/unreleased/4482 @@ -0,0 +1,7 @@ +Enhancement: Add status message when (un)setting av. offline from preview + +A message has been added in all previews when the (un)setting av. offline buttons are clicked. +The options menu has been updated in all previews depending on the file status. + +https://github.com/owncloud/android/issues/4382 +https://github.com/owncloud/android/pull/4482 diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewAudioViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewAudioViewModel.kt index 968ecc438e1..4e799d1fb64 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewAudioViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewAudioViewModel.kt @@ -2,8 +2,9 @@ * ownCloud Android client application * * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -25,9 +26,11 @@ import androidx.lifecycle.viewModelScope import com.owncloud.android.R import com.owncloud.android.domain.files.model.FileMenuOption import com.owncloud.android.domain.files.model.OCFile +import com.owncloud.android.domain.files.usecases.GetFileByIdAsStreamUseCase import com.owncloud.android.providers.ContextProvider import com.owncloud.android.providers.CoroutinesDispatcherProvider import com.owncloud.android.usecases.files.FilterFileMenuOptionsUseCase +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update @@ -35,13 +38,19 @@ import kotlinx.coroutines.launch class PreviewAudioViewModel( private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase, + getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase, private val contextProvider: ContextProvider, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, + ocFile: OCFile, ) : ViewModel() { private val _menuOptions: MutableStateFlow> = MutableStateFlow(emptyList()) val menuOptions: StateFlow> = _menuOptions + private val currentFile: Flow = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!)) + + fun getCurrentFile(): Flow = currentFile + fun filterMenuOptions(file: OCFile, accountName: String) { val shareViaLinkAllowed = contextProvider.getBoolean(R.bool.share_via_link_feature) val shareWithUsersAllowed = contextProvider.getBoolean(R.bool.share_with_users_feature) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewTextViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewTextViewModel.kt index bd8f6a8f85f..0b635fffac4 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewTextViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewTextViewModel.kt @@ -3,8 +3,9 @@ * * @author Juan Carlos Garrote Gascón * @author Parneet Singh + * @author Jorge Aguado Recio * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -26,9 +27,11 @@ import androidx.lifecycle.viewModelScope import com.owncloud.android.R import com.owncloud.android.domain.files.model.FileMenuOption import com.owncloud.android.domain.files.model.OCFile +import com.owncloud.android.domain.files.usecases.GetFileByIdAsStreamUseCase import com.owncloud.android.providers.ContextProvider import com.owncloud.android.providers.CoroutinesDispatcherProvider import com.owncloud.android.usecases.files.FilterFileMenuOptionsUseCase +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update @@ -36,13 +39,19 @@ import kotlinx.coroutines.launch class PreviewTextViewModel( private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase, + getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase, private val contextProvider: ContextProvider, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, + ocFile: OCFile, ) : ViewModel() { private val _menuOptions: MutableStateFlow> = MutableStateFlow(emptyList()) val menuOptions: StateFlow> = _menuOptions + private val currentFile: Flow = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!)) + + fun getCurrentFile(): Flow = currentFile + fun filterMenuOptions(file: OCFile, accountName: String) { val shareViaLinkAllowed = contextProvider.getBoolean(R.bool.share_via_link_feature) val shareWithUsersAllowed = contextProvider.getBoolean(R.bool.share_with_users_feature) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewVideoViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewVideoViewModel.kt index d332dc02724..eac7082f6ef 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewVideoViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/previews/PreviewVideoViewModel.kt @@ -2,8 +2,9 @@ * ownCloud Android client application * * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -25,9 +26,11 @@ import androidx.lifecycle.viewModelScope import com.owncloud.android.R import com.owncloud.android.domain.files.model.FileMenuOption import com.owncloud.android.domain.files.model.OCFile +import com.owncloud.android.domain.files.usecases.GetFileByIdAsStreamUseCase import com.owncloud.android.providers.ContextProvider import com.owncloud.android.providers.CoroutinesDispatcherProvider import com.owncloud.android.usecases.files.FilterFileMenuOptionsUseCase +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update @@ -35,13 +38,19 @@ import kotlinx.coroutines.launch class PreviewVideoViewModel( private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase, + getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase, private val contextProvider: ContextProvider, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, + ocFile: OCFile, ) : ViewModel() { private val _menuOptions: MutableStateFlow> = MutableStateFlow(emptyList()) val menuOptions: StateFlow> = _menuOptions + private val currentFile: Flow = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!)) + + fun getCurrentFile(): Flow = currentFile + fun filterMenuOptions(file: OCFile, accountName: String) { val shareViaLinkAllowed = contextProvider.getBoolean(R.bool.share_via_link_feature) val shareWithUsersAllowed = contextProvider.getBoolean(R.bool.share_with_users_feature) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/releasenotes/ReleaseNotesViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/releasenotes/ReleaseNotesViewModel.kt index a650293934d..df8f4367904 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/releasenotes/ReleaseNotesViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/releasenotes/ReleaseNotesViewModel.kt @@ -45,6 +45,11 @@ class ReleaseNotesViewModel( companion object { val releaseNotesList = listOf( + ReleaseNote( + title = R.string.release_notes_4_5_0_title_feedback_in_previews, + subtitle = R.string.release_notes_4_5_0_subtitle_feedback_in_previews, + type = ReleaseNoteType.ENHANCEMENT + ), ReleaseNote( title = R.string.release_notes_bugfixes_title, subtitle = R.string.release_notes_bugfixes_subtitle, diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewAudioFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewAudioFragment.kt index f26847c9872..2087cfffb49 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewAudioFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewAudioFragment.kt @@ -8,6 +8,7 @@ * @author Shashvat Kedia * @author Juan Carlos Garrote Gascón * @author Aitor Ballesteros Pavón + * @author Jorge Aguado Recio * * Copyright (C) 2024 ownCloud GmbH. * @@ -42,6 +43,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.ImageView +import com.google.android.material.snackbar.Snackbar import com.owncloud.android.R import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.extensions.collectLatestLifecycleFlow @@ -59,6 +61,7 @@ import com.owncloud.android.ui.fragment.FileFragment import com.owncloud.android.utils.PreferenceUtils import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf import timber.log.Timber /** @@ -85,7 +88,10 @@ class PreviewAudioFragment : FileFragment() { private var mediaServiceConnection: MediaServiceConnection? = null private var autoplay = true - private val previewAudioViewModel by viewModel() + private val previewAudioViewModel by viewModel { + parametersOf(requireArguments().getParcelable(EXTRA_FILE)) + } + private val fileOperationsViewModel: FileOperationsViewModel by inject() /** @@ -115,6 +121,16 @@ class PreviewAudioFragment : FileFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + collectLatestLifecycleFlow(previewAudioViewModel.getCurrentFile()) { currentFile -> + if (currentFile != null) { + file = currentFile + requireActivity().invalidateOptionsMenu() + } else { + requireActivity().onBackPressed() + } + + } + imagePreview = view.findViewById(R.id.image_preview) mediaController = view.findViewById(R.id.media_controller) } @@ -285,11 +301,13 @@ class PreviewAudioFragment : FileFragment() { R.id.action_set_available_offline -> { fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(listOf(file))) + Snackbar.make(requireView(), R.string.confirmation_set_available_offline, Snackbar.LENGTH_LONG).show() true } R.id.action_unset_available_offline -> { fileOperationsViewModel.performOperation(FileOperation.UnsetFilesAsAvailableOffline(listOf(file))) + Snackbar.make(requireView(), R.string.confirmation_unset_available_offline, Snackbar.LENGTH_LONG).show() true } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt index aaef496e7d2..124faf3c5b7 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt @@ -65,6 +65,7 @@ import com.owncloud.android.usecases.transfers.DOWNLOAD_FINISH_MESSAGE import com.owncloud.android.utils.PreferenceUtils import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf import timber.log.Timber /** @@ -74,7 +75,9 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnPageChangeListener { - private val previewImageViewModel: PreviewImageViewModel by viewModel() + private val previewImageViewModel by viewModel { + parametersOf(file) + } private val fileOperationsViewModel: FileOperationsViewModel by viewModel() private lateinit var viewPager: ViewPager diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt index 3872168a7ac..1e1e2bdd7b8 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt @@ -8,6 +8,7 @@ * @author Shashvat Kedia * @author Juan Carlos Garrote Gascón * @author Aitor Ballesteros Pavón + * @author Jorge Aguado Recio * * Copyright (C) 2024 ownCloud GmbH. * @@ -46,6 +47,7 @@ import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.github.chrisbanes.photoview.PhotoView +import com.google.android.material.snackbar.Snackbar import com.owncloud.android.R import com.owncloud.android.databinding.PreviewImageFragmentBinding import com.owncloud.android.domain.files.model.MIME_SVG @@ -61,6 +63,7 @@ import com.owncloud.android.ui.fragment.FileFragment import com.owncloud.android.utils.PreferenceUtils import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf import timber.log.Timber import java.io.File @@ -87,7 +90,9 @@ class PreviewImageFragment : FileFragment() { private var _binding: PreviewImageFragmentBinding? = null private val binding get() = _binding!! - private val previewImageViewModel by viewModel() + private val previewImageViewModel by viewModel() { + parametersOf(requireArguments().getParcelable(ARG_FILE)) + } private val fileOperationsViewModel: FileOperationsViewModel by inject() /** @@ -143,6 +148,15 @@ class PreviewImageFragment : FileFragment() { } } + collectLatestLifecycleFlow(previewImageViewModel.getCurrentFile()) { currentFile -> + if (currentFile != null) { + file = currentFile + requireActivity().invalidateOptionsMenu() + } else { + requireActivity().onBackPressed() + } + } + account = requireArguments().getParcelable(PreviewAudioFragment.EXTRA_ACCOUNT) checkNotNull(account) { "Instanced with a NULL ownCloud Account" } checkNotNull(file) { "Instanced with a NULL OCFile" } @@ -234,11 +248,13 @@ class PreviewImageFragment : FileFragment() { R.id.action_set_available_offline -> { fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(listOf(file))) + Snackbar.make(requireActivity().window.decorView, R.string.confirmation_set_available_offline, Snackbar.LENGTH_LONG).show() true } R.id.action_unset_available_offline -> { fileOperationsViewModel.performOperation(FileOperation.UnsetFilesAsAvailableOffline(listOf(file))) + Snackbar.make(requireActivity().window.decorView, R.string.confirmation_unset_available_offline, Snackbar.LENGTH_LONG).show() true } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageViewModel.kt index 8105a2b6dc9..af243d62b82 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageViewModel.kt @@ -3,8 +3,9 @@ * * @author Abel García de Prada * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -30,11 +31,13 @@ import androidx.work.WorkInfo import com.owncloud.android.R import com.owncloud.android.domain.files.model.FileMenuOption import com.owncloud.android.domain.files.model.OCFile +import com.owncloud.android.domain.files.usecases.GetFileByIdAsStreamUseCase import com.owncloud.android.domain.files.usecases.GetFileByIdUseCase import com.owncloud.android.providers.ContextProvider import com.owncloud.android.providers.CoroutinesDispatcherProvider import com.owncloud.android.usecases.files.FilterFileMenuOptionsUseCase import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForFinishedDownloadsFromAccountUseCase +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update @@ -44,8 +47,10 @@ class PreviewImageViewModel( private val getFileByIdUseCase: GetFileByIdUseCase, private val getLiveDataForFinishedDownloadsFromAccountUseCase: GetLiveDataForFinishedDownloadsFromAccountUseCase, private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase, + getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase, private val contextProvider: ContextProvider, - private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider + private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, + ocFile: OCFile, ) : ViewModel() { private val _downloads = MediatorLiveData>>() @@ -54,6 +59,10 @@ class PreviewImageViewModel( private val _menuOptions: MutableStateFlow> = MutableStateFlow(emptyList()) val menuOptions: StateFlow> = _menuOptions + private val currentFile: Flow = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!)) + + fun getCurrentFile(): Flow = currentFile + fun startListeningToDownloadsFromAccount(account: Account) { _downloads.addSource( getLiveDataForFinishedDownloadsFromAccountUseCase(GetLiveDataForFinishedDownloadsFromAccountUseCase.Params(account)) diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.kt index f6b912b3e7c..18421282bc6 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.kt @@ -37,6 +37,7 @@ import android.view.ViewGroup import android.widget.RelativeLayout import android.widget.TextView import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import com.owncloud.android.R @@ -55,6 +56,7 @@ import com.owncloud.android.ui.fragment.FileFragment import com.owncloud.android.utils.PreferenceUtils import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.component.getScopeName +import org.koin.core.parameter.parametersOf import timber.log.Timber import java.io.BufferedWriter import java.io.FileInputStream @@ -66,7 +68,9 @@ class PreviewTextFragment : FileFragment() { private var account: Account? = null private lateinit var textLoadTask: TextLoadAsyncTask - private val previewTextViewModel by viewModel() + private val previewTextViewModel by viewModel { + parametersOf(requireArguments().getParcelable(EXTRA_FILE)) + } private val fileOperationsViewModel by viewModel() private lateinit var binding: PreviewTextFragmentBinding @@ -111,6 +115,16 @@ class PreviewTextFragment : FileFragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + collectLatestLifecycleFlow(previewTextViewModel.getCurrentFile()) { currentFile -> + if (currentFile != null) { + file = currentFile + requireActivity().invalidateOptionsMenu() + } else { + requireActivity().onBackPressed() + } + + } + loadAndShowTextPreview() } @@ -157,6 +171,7 @@ class PreviewTextFragment : FileFragment() { val fileToSetAsAvailableOffline = ArrayList() fileToSetAsAvailableOffline.add(file) fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(fileToSetAsAvailableOffline)) + Snackbar.make(requireView(), R.string.confirmation_set_available_offline, Snackbar.LENGTH_LONG).show() true } @@ -164,6 +179,7 @@ class PreviewTextFragment : FileFragment() { val fileToUnsetAsAvailableOffline = ArrayList() fileToUnsetAsAvailableOffline.add(file) fileOperationsViewModel.performOperation(FileOperation.UnsetFilesAsAvailableOffline(fileToUnsetAsAvailableOffline)) + Snackbar.make(requireView(), R.string.confirmation_unset_available_offline, Snackbar.LENGTH_LONG).show() true } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewVideoActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewVideoActivity.kt index 03e2212dcc8..88777672205 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewVideoActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewVideoActivity.kt @@ -8,6 +8,7 @@ * @author Shashvat Kedia * @author Juan Carlos Garrote Gascón * @author Aitor Ballesteros Pavón + * @author Jorge Aguado Recio * * Copyright (C) 2024 ownCloud GmbH. * @@ -56,6 +57,7 @@ import androidx.media3.exoplayer.source.MediaSource import androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection import androidx.media3.exoplayer.trackselection.DefaultTrackSelector import androidx.media3.ui.PlayerView +import com.google.android.material.snackbar.Snackbar import com.owncloud.android.R import com.owncloud.android.databinding.VideoPreviewBinding import com.owncloud.android.domain.files.model.OCFile @@ -80,6 +82,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf import timber.log.Timber @OptIn(UnstableApi::class) @@ -92,7 +95,7 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay private var playWhenReady = true private var playbackPosition: Long = 0 private var windowInsetsController: WindowInsetsControllerCompat? = null - private val previewVideoViewModel: PreviewVideoViewModel by viewModel() + private val previewVideoViewModel: PreviewVideoViewModel by viewModel { parametersOf(intent.getParcelableExtra(EXTRA_FILE)) } private val fileOperationsViewModel: FileOperationsViewModel by viewModel() private val transfersViewModel: TransfersViewModel by viewModel() @@ -127,6 +130,16 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay playbackPosition = savedInstanceState.getLong(EXTRA_PLAY_POSITION, 0) } + collectLatestLifecycleFlow(previewVideoViewModel.getCurrentFile()) { currentFile -> + if (currentFile != null) { + file = currentFile + this.invalidateOptionsMenu() + } else { + this.onBackPressed() + } + + } + checkNotNull(file) { "Instanced with a NULL OCFile" } checkNotNull(account) { "Instanced with a NULL ownCloud Account" } check(file.isVideo) { "Not a video file" } @@ -384,6 +397,7 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay val fileToSetAsAvailableOffline = ArrayList() fileToSetAsAvailableOffline.add(file) fileOperationsViewModel.performOperation(SetFilesAsAvailableOffline(fileToSetAsAvailableOffline)) + Snackbar.make(binding.root, R.string.confirmation_set_available_offline, Snackbar.LENGTH_LONG).show() true } @@ -391,6 +405,7 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay val fileToUnsetAsAvailableOffline = ArrayList() fileToUnsetAsAvailableOffline.add(file) fileOperationsViewModel.performOperation(UnsetFilesAsAvailableOffline(fileToUnsetAsAvailableOffline)) + Snackbar.make(binding.root, R.string.confirmation_unset_available_offline, Snackbar.LENGTH_LONG).show() true } diff --git a/owncloudApp/src/main/res/values/strings.xml b/owncloudApp/src/main/res/values/strings.xml index d10451ecf82..08dd4fcc844 100644 --- a/owncloudApp/src/main/res/values/strings.xml +++ b/owncloudApp/src/main/res/values/strings.xml @@ -369,6 +369,8 @@ Set as available offline Unset as available offline + The file was set as available offline correctly + The file was unset as available offline correctly Rename Remove Do you really want to remove %1$s? @@ -727,6 +729,8 @@ Release note icon Minor bugfixes Some bugs were fixed to improve experience in the app + Feedback when (un)setting av. offline in all previews + Added feedback when (un)setting av. offline in all previews and updated options menu depending on file status