Skip to content

Commit

Permalink
feat: updated options menu in image preview
Browse files Browse the repository at this point in the history
  • Loading branch information
joragua committed Oct 3, 2024
1 parent 2123686 commit dd9538c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
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 @@ -62,6 +62,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 @@ -88,7 +89,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 @@ -144,6 +147,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
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,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 @@ -45,15 +47,22 @@ class PreviewImageViewModel(
private val getLiveDataForFinishedDownloadsFromAccountUseCase: GetLiveDataForFinishedDownloadsFromAccountUseCase,
private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase,
private val contextProvider: ContextProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider
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

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

0 comments on commit dd9538c

Please sign in to comment.