Skip to content

Commit

Permalink
refactor(PublicShareViewModel): Rename fetchCacheFileForAction() to…
Browse files Browse the repository at this point in the history
… `startAction()`
  • Loading branch information
FabianDevel committed Sep 19, 2024
1 parent 7ed34e9 commit 0e5c8cb
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ interface OnPublicShareItemClickListener : FileInfoActionsView.OnItemClickListen
}
}

override fun openWith() = fetchCacheFileForAction(DownloadAction.OPEN_WITH)
override fun openWith() = startAction(DownloadAction.OPEN_WITH)

override fun shareFile() = fetchCacheFileForAction(DownloadAction.SEND_COPY)
override fun shareFile() = startAction(DownloadAction.SEND_COPY)

override fun saveToKDrive() = fetchCacheFileForAction(DownloadAction.SAVE_TO_DRIVE)
override fun saveToKDrive() = startAction(DownloadAction.SAVE_TO_DRIVE)

override fun downloadFileClicked() {
super.downloadFileClicked()
Expand All @@ -66,17 +66,19 @@ interface OnPublicShareItemClickListener : FileInfoActionsView.OnItemClickListen
super.printClicked()
previewPDFHandler?.printClicked(
context = currentContext,
onDefaultCase = { fetchCacheFileForAction(DownloadAction.PRINT_PDF) },
onDefaultCase = { startAction(DownloadAction.PRINT_PDF) },
onError = { onDownloadError(R.string.errorFileNotFound) },
)
}

private fun fetchCacheFileForAction(action: DownloadAction) {
private fun startAction(action: DownloadAction) {
val cacheFileResult = publicShareViewModel.fetchCacheFileForAction(
file = currentFile,
navigateToDownloadDialog = ::navigateToDownloadDialog,
)

ownerFragment?.viewLifecycleOwner?.let { lifecycleOwner ->
publicShareViewModel.fetchCacheFileForAction(
file = currentFile,
navigateToDownloadDialog = ::navigateToDownloadDialog,
).observe(lifecycleOwner) { cacheFile ->
cacheFileResult.observe(lifecycleOwner) { cacheFile ->
cacheFile?.let { file -> executeDownloadAction(action, file) } ?: onDownloadError(getErrorMessage(action))
}
}
Expand Down

0 comments on commit 0e5c8cb

Please sign in to comment.