Skip to content

Commit

Permalink
Merge pull request #4482 from owncloud/feature/add_feedback_in_previe…
Browse files Browse the repository at this point in the history
…w_menu

[FEATURE REQUEST] Add status message when (un)setting av. offline from preview
  • Loading branch information
joragua authored Oct 10, 2024
2 parents 5350049 + bdd665f commit 51c910a
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions changelog/unreleased/4482
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,23 +26,31 @@ 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
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<List<FileMenuOption>> = MutableStateFlow(emptyList())
val menuOptions: StateFlow<List<FileMenuOption>> = _menuOptions

private val currentFile: Flow<OCFile?> = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!))

fun getCurrentFile(): Flow<OCFile?> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,23 +27,31 @@ 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
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<List<FileMenuOption>> = MutableStateFlow(emptyList())
val menuOptions: StateFlow<List<FileMenuOption>> = _menuOptions

private val currentFile: Flow<OCFile?> = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!))

fun getCurrentFile(): Flow<OCFile?> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,23 +26,31 @@ 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
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<List<FileMenuOption>> = MutableStateFlow(emptyList())
val menuOptions: StateFlow<List<FileMenuOption>> = _menuOptions

private val currentFile: Flow<OCFile?> = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!))

fun getCurrentFile(): Flow<OCFile?> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -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

/**
Expand All @@ -85,7 +88,10 @@ class PreviewAudioFragment : FileFragment() {
private var mediaServiceConnection: MediaServiceConnection? = null
private var autoplay = true

private val previewAudioViewModel by viewModel<PreviewAudioViewModel>()
private val previewAudioViewModel by viewModel<PreviewAudioViewModel> {
parametersOf(requireArguments().getParcelable(EXTRA_FILE))
}

private val fileOperationsViewModel: FileOperationsViewModel by inject()

/**
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -74,7 +75,9 @@ class PreviewImageActivity : FileActivity(),
FileFragment.ContainerActivity,
OnPageChangeListener {

private val previewImageViewModel: PreviewImageViewModel by viewModel()
private val previewImageViewModel by viewModel <PreviewImageViewModel> {
parametersOf(file)
}
private val fileOperationsViewModel: FileOperationsViewModel by viewModel()

private lateinit var viewPager: ViewPager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -87,7 +90,9 @@ class PreviewImageFragment : FileFragment() {
private var _binding: PreviewImageFragmentBinding? = null
private val binding get() = _binding!!

private val previewImageViewModel by viewModel<PreviewImageViewModel>()
private val previewImageViewModel by viewModel<PreviewImageViewModel>() {
parametersOf(requireArguments().getParcelable(ARG_FILE))
}
private val fileOperationsViewModel: FileOperationsViewModel by inject()

/**
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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<List<Pair<OCFile, WorkInfo>>>()
Expand All @@ -54,6 +59,10 @@ class PreviewImageViewModel(
private val _menuOptions: MutableStateFlow<List<FileMenuOption>> = MutableStateFlow(emptyList())
val menuOptions: StateFlow<List<FileMenuOption>> = _menuOptions

private val currentFile: Flow<OCFile?> = getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!))

fun getCurrentFile(): Flow<OCFile?> = currentFile

fun startListeningToDownloadsFromAccount(account: Account) {
_downloads.addSource(
getLiveDataForFinishedDownloadsFromAccountUseCase(GetLiveDataForFinishedDownloadsFromAccountUseCase.Params(account))
Expand Down
Loading

0 comments on commit 51c910a

Please sign in to comment.