Skip to content

Commit

Permalink
refactor: some CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joragua committed Oct 8, 2024
1 parent 762c4ce commit 3aecffe
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
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 Down Expand Up @@ -37,10 +38,10 @@ import kotlinx.coroutines.launch

class PreviewAudioViewModel(
private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
private val contextProvider: ContextProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
ocFile: OCFile
ocFile: OCFile,
) : ViewModel() {

private val _menuOptions: MutableStateFlow<List<FileMenuOption>> = MutableStateFlow(emptyList())
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 Down Expand Up @@ -38,10 +39,10 @@ import kotlinx.coroutines.launch

class PreviewTextViewModel(
private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
private val contextProvider: ContextProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
ocFile: OCFile
ocFile: OCFile,
) : ViewModel() {

private val _menuOptions: MutableStateFlow<List<FileMenuOption>> = MutableStateFlow(emptyList())
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 Down Expand Up @@ -37,10 +38,10 @@ import kotlinx.coroutines.launch

class PreviewVideoViewModel(
private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
private val contextProvider: ContextProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
ocFile: OCFile
ocFile: OCFile,
) : ViewModel() {

private val _menuOptions: MutableStateFlow<List<FileMenuOption>> = MutableStateFlow(emptyList())
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 @@ -87,7 +88,7 @@ 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))
}

Expand Down Expand Up @@ -300,13 +301,13 @@ class PreviewAudioFragment : FileFragment() {

R.id.action_set_available_offline -> {
fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(listOf(file)))
Snackbar.make(requireView(), R.string.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG).show()
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.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG).show()
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 @@ -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 @@ -247,13 +248,13 @@ class PreviewImageFragment : FileFragment() {

R.id.action_set_available_offline -> {
fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(listOf(file)))
showSnackbarMessage()
showSnackbarMessage(setAvailableOffline = true)
true
}

R.id.action_unset_available_offline -> {
fileOperationsViewModel.performOperation(FileOperation.UnsetFilesAsAvailableOffline(listOf(file)))
showSnackbarMessage()
showSnackbarMessage(setAvailableOffline = false)
true
}

Expand Down Expand Up @@ -347,8 +348,13 @@ class PreviewImageFragment : FileFragment() {
return if (isSVGFile(file)) Color.WHITE else Color.BLACK
}

private fun showSnackbarMessage() {
val snackbar = Snackbar.make(requireView(), R.string.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG)
private fun showSnackbarMessage(setAvailableOffline: Boolean) {
val snackbarString = if (setAvailableOffline){
R.string.confirmation_set_available_offline
} else {
R.string.confirmation_unset_available_offline
}
val snackbar = Snackbar.make(requireView(), snackbarString, Snackbar.LENGTH_LONG)
val params = snackbar.view.layoutParams as ViewGroup.MarginLayoutParams
params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, 100)
snackbar.view.layoutParams = params
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 Down Expand Up @@ -46,13 +47,12 @@ class PreviewImageViewModel(
private val getFileByIdUseCase: GetFileByIdUseCase,
private val getLiveDataForFinishedDownloadsFromAccountUseCase: GetLiveDataForFinishedDownloadsFromAccountUseCase,
private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
private val contextProvider: ContextProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
getFileByIdAsStreamUseCase: GetFileByIdAsStreamUseCase,
ocFile: OCFile,
) : ViewModel() {


private val _downloads = MediatorLiveData<List<Pair<OCFile, WorkInfo>>>()
val downloads: LiveData<List<Pair<OCFile, WorkInfo>>> = _downloads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ class PreviewTextFragment : FileFragment() {
val fileToSetAsAvailableOffline = ArrayList<OCFile>()
fileToSetAsAvailableOffline.add(file)
fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(fileToSetAsAvailableOffline))
Snackbar.make(requireView(), R.string.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG).show()
Snackbar.make(requireView(), R.string.confirmation_set_available_offline, Snackbar.LENGTH_LONG).show()
true
}

R.id.action_unset_available_offline -> {
val fileToUnsetAsAvailableOffline = ArrayList<OCFile>()
fileToUnsetAsAvailableOffline.add(file)
fileOperationsViewModel.performOperation(FileOperation.UnsetFilesAsAvailableOffline(fileToUnsetAsAvailableOffline))
Snackbar.make(requireView(), R.string.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG).show()
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 @@ -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 @@ -37,7 +38,6 @@ import android.view.MenuItem
import android.view.View
import android.view.Window
import androidx.annotation.OptIn
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.core.view.MenuProvider
import androidx.core.view.WindowCompat
Expand All @@ -62,7 +62,6 @@ import com.owncloud.android.R
import com.owncloud.android.databinding.VideoPreviewBinding
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.domain.utils.Event
import com.owncloud.android.extensions.collectLatestLifecycleFlow
import com.owncloud.android.extensions.filterMenuOptions
import com.owncloud.android.extensions.sendDownloadedFilesByShareSheet
import com.owncloud.android.extensions.showErrorInSnackbar
Expand All @@ -86,7 +85,6 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import timber.log.Timber

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@OptIn(UnstableApi::class)
class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlayerTaskListener, FileFragment.ContainerActivity, MenuProvider {
private var account: Account? = null
Expand All @@ -97,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() { parametersOf(intent.getParcelableExtra(EXTRA_FILE, OCFile::class.java)) }
private val previewVideoViewModel: PreviewVideoViewModel by viewModel { parametersOf(intent.getParcelableExtra(EXTRA_FILE)) }
private val fileOperationsViewModel: FileOperationsViewModel by viewModel()
private val transfersViewModel: TransfersViewModel by viewModel()

Expand Down Expand Up @@ -333,8 +331,6 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay
}

override fun onPrepareMenu(menu: Menu) {


val safeFile = file
val accountName = account!!.name
previewVideoViewModel.filterMenuOptions(safeFile, accountName)
Expand Down Expand Up @@ -401,15 +397,15 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay
val fileToSetAsAvailableOffline = ArrayList<OCFile>()
fileToSetAsAvailableOffline.add(file)
fileOperationsViewModel.performOperation(SetFilesAsAvailableOffline(fileToSetAsAvailableOffline))
Snackbar.make(binding.root, R.string.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG).show()
Snackbar.make(binding.root, R.string.confirmation_set_available_offline, Snackbar.LENGTH_LONG).show()
true
}

R.id.action_unset_available_offline -> {
val fileToUnsetAsAvailableOffline = ArrayList<OCFile>()
fileToUnsetAsAvailableOffline.add(file)
fileOperationsViewModel.performOperation(UnsetFilesAsAvailableOffline(fileToUnsetAsAvailableOffline))
Snackbar.make(binding.root, R.string.sync_file_nothing_to_do_msg, Snackbar.LENGTH_LONG).show()
Snackbar.make(binding.root, R.string.confirmation_unset_available_offline, Snackbar.LENGTH_LONG).show()
true
}

Expand Down
2 changes: 2 additions & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@

<string name="set_available_offline">Set as available offline</string>
<string name="unset_available_offline">Unset as available offline</string>
<string name="confirmation_set_available_offline">The file was set as available offline correctly</string>
<string name="confirmation_unset_available_offline">The file was unset as available offline correctly</string>
<string name="common_rename">Rename</string>
<string name="common_remove">Remove</string>
<string name="confirmation_remove_file_alert">Do you really want to remove %1$s?</string>
Expand Down

0 comments on commit 3aecffe

Please sign in to comment.