Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] New field "last usage" #4187

Merged
merged 11 commits into from
Nov 3, 2023
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Summary
* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072)
* Enhancement - "Apply to all" when many name conflicts arise: [#4078](https://github.com/owncloud/android/issues/4078)
* Enhancement - "Share to" in oCIS accounts allows upload to any space: [#4088](https://github.com/owncloud/android/issues/4088)
* Enhancement - New field "last usage" in database: [#4173](https://github.com/owncloud/android/issues/4173)
* Enhancement - Use invoke operator to execute usecases: [#4179](https://github.com/owncloud/android/pull/4179)
* Enhancement - Deep link open app correctly: [#4181](https://github.com/owncloud/android/issues/4181)

Expand Down Expand Up @@ -61,6 +62,14 @@ Details
https://github.com/owncloud/android/issues/4088
https://github.com/owncloud/android/pull/4160

* Enhancement - New field "last usage" in database: [#4173](https://github.com/owncloud/android/issues/4173)

To know the last usage of a file, a new field has been created in the database to handle this
specific information.

https://github.com/owncloud/android/issues/4173
https://github.com/owncloud/android/pull/4187

* Enhancement - Use invoke operator to execute usecases: [#4179](https://github.com/owncloud/android/pull/4179)

Removes all the "execute" verbosity for use cases by using the "invoke" operator instead.
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/4187
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: New field "last usage" in database

To know the last usage of a file, a new field has been created in the database to handle this specific information.

https://github.com/owncloud/android/issues/4173
https://github.com/owncloud/android/pull/4187
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import com.owncloud.android.domain.files.usecases.SaveFileOrFolderUseCase
import com.owncloud.android.domain.files.usecases.SortFilesUseCase
import com.owncloud.android.domain.files.usecases.SortFilesWithSyncInfoUseCase
import com.owncloud.android.domain.files.usecases.UpdateAlreadyDownloadedFilesPathUseCase
import com.owncloud.android.domain.files.usecases.SetLastUsageFileUseCase
import com.owncloud.android.domain.server.usecases.GetServerInfoAsyncUseCase
import com.owncloud.android.domain.sharing.sharees.GetShareesAsyncUseCase
import com.owncloud.android.domain.sharing.shares.usecases.CreatePrivateShareAsyncUseCase
Expand Down Expand Up @@ -178,6 +179,7 @@ val useCaseModule = module {
factoryOf(::SynchronizeFileUseCase)
factoryOf(::SynchronizeFolderUseCase)
factoryOf(::ManageDeepLinkUseCase)
factoryOf(::SetLastUsageFileUseCase)

// Open in web
factoryOf(::CreateFileWithAppProviderUseCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ val viewModelModule = module {
viewModelOf(::AccountsManagementViewModel)
viewModelOf(::BiometricViewModel)
viewModelOf(::DrawerViewModel)
viewModelOf(::FileDetailsViewModel)
viewModelOf(::FileOperationsViewModel)
viewModelOf(::LogListViewModel)
viewModelOf(::OAuthViewModel)
viewModelOf(::PatternViewModel)
Expand All @@ -84,6 +86,7 @@ val viewModelModule = module {
viewModelOf(::SettingsSecurityViewModel)
viewModelOf(::SettingsVideoUploadsViewModel)
viewModelOf(::SettingsViewModel)
viewModelOf(::FileOperationsViewModel)

viewModel { (accountName: String) -> CapabilityViewModel(accountName, get(), get(), get()) }
viewModel { (action: PasscodeAction) -> PassCodeViewModel(get(), get(), action) }
Expand All @@ -95,8 +98,6 @@ val viewModelModule = module {
}
viewModel { (ocFile: OCFile) -> ConflictsResolveViewModel(get(), get(), get(), get(), get(), ocFile) }
viewModel { AuthenticationViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { FileDetailsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModelOf(::FileOperationsViewModel)
viewModel { MigrationViewModel(MainApp.dataFolder, get(), get(), get(), get(), get(), get(), get()) }
viewModel { TransfersViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { ReceiveExternalFilesViewModel(get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class FileDetailsFragment : FileFragment() {
openInWebProviders.forEach { (openInWebProviderName, menuItemId) ->
if (menuItemId == item.itemId) {
fileDetailsViewModel.openInWeb(safeFile.file.remoteId!!, openInWebProviderName)
fileOperationsViewModel.setLastUsageFile(safeFile.file)
return true
}
}
Expand All @@ -244,6 +245,7 @@ class FileDetailsFragment : FileFragment() {
fileDetailsViewModel.updateActionInDetailsView(SYNC_AND_OPEN_WITH)
} else { // Already downloaded -> Open it
requireActivity().openOCFile(safeFile.file)
fileOperationsViewModel.setLastUsageFile(safeFile.file)
}
true
}
Expand Down Expand Up @@ -543,6 +545,7 @@ class FileDetailsFragment : FileFragment() {

else -> fileDisplayActivity.openOCFile(fileWaitingToPreview)
}
fileOperationsViewModel.setLastUsageFile(fileWaitingToPreview)
}

override fun updateViewForSyncInProgress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,20 @@ class FileDetailsViewModel(
val shareWithUsersAllowed = contextProvider.getBoolean(R.bool.share_with_users_feature)
val sendAllowed = contextProvider.getString(R.string.send_files_to_other_apps).equals("on", ignoreCase = true)
viewModelScope.launch(coroutinesDispatcherProvider.io) {
val result = filterFileMenuOptionsUseCase(FilterFileMenuOptionsUseCase.Params(
files = listOf(file),
accountName = getAccount().name,
isAnyFileVideoPreviewing = false,
displaySelectAll = false,
displaySelectInverse = false,
onlyAvailableOfflineFiles = false,
onlySharedByLinkFiles = false,
shareViaLinkAllowed = shareViaLinkAllowed,
shareWithUsersAllowed = shareWithUsersAllowed,
sendAllowed = sendAllowed,
))
val result = filterFileMenuOptionsUseCase(
FilterFileMenuOptionsUseCase.Params(
files = listOf(file),
accountName = getAccount().name,
isAnyFileVideoPreviewing = false,
displaySelectAll = false,
displaySelectInverse = false,
onlyAvailableOfflineFiles = false,
onlySharedByLinkFiles = false,
shareViaLinkAllowed = shareViaLinkAllowed,
shareWithUsersAllowed = shareWithUsersAllowed,
sendAllowed = sendAllowed,
)
)
result.apply {
remove(FileMenuOption.DETAILS)
remove(FileMenuOption.MOVE)
Expand All @@ -201,6 +203,7 @@ class FileDetailsViewModel(
}
}


enum class ActionsInDetailsView {
NONE, SYNC, SYNC_AND_OPEN, SYNC_AND_OPEN_WITH, SYNC_AND_SEND;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ class MainFileListFragment : Fragment(),
itemIcon = ResourcesCompat.getDrawable(resources, R.drawable.ic_open_in_web, null)
setOnClickListener {
mainFileListViewModel.openInWeb(file.remoteId!!, appRegistryProvider.name)
fileOperationsViewModel.setLastUsageFile(file)
}
}
fileOptionsBottomSheetSingleFileLayout!!.addView(appProviderItemView, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.owncloud.android.domain.files.usecases.ManageDeepLinkUseCase
import com.owncloud.android.domain.files.usecases.MoveFileUseCase
import com.owncloud.android.domain.files.usecases.RemoveFileUseCase
import com.owncloud.android.domain.files.usecases.RenameFileUseCase
import com.owncloud.android.domain.files.usecases.SetLastUsageFileUseCase
import com.owncloud.android.domain.utils.Event
import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult
import com.owncloud.android.presentation.common.UIResult
Expand All @@ -66,6 +67,7 @@ class FileOperationsViewModel(
private val setFilesAsAvailableOfflineUseCase: SetFilesAsAvailableOfflineUseCase,
private val unsetFilesAsAvailableOfflineUseCase: UnsetFilesAsAvailableOfflineUseCase,
private val manageDeepLinkUseCase: ManageDeepLinkUseCase,
private val setLastUsageFileUseCase: SetLastUsageFileUseCase,
private val contextProvider: ContextProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
) : ViewModel() {
Expand Down Expand Up @@ -121,6 +123,20 @@ class FileOperationsViewModel(
}
}

fun setLastUsageFile(file: OCFile) {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
setLastUsageFileUseCase(
SetLastUsageFileUseCase.Params(
fileId = file.id!!,
lastUsage = System.currentTimeMillis(),
isAvailableLocally = file.isAvailableLocally,
isFolder = file.isFolder,
)
)
}
}


private fun createFolderOperation(fileOperation: FileOperation.CreateFolder) {
runOperation(
liveData = _createFolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ class FileDisplayActivity : FileActivity(),
override fun openFile(file: OCFile) {
if (file.isAvailableLocally) {
fileOperationsHelper.openFile(file)
fileOperationsViewModel.setLastUsageFile(file)
} else {
startDownloadForOpening(file)
}
Expand Down Expand Up @@ -1731,6 +1732,7 @@ class FileDisplayActivity : FileActivity(),
startSyncThenOpen(file)
}
}
fileOperationsViewModel.setLastUsageFile(file)
}

override fun onShareFileClicked(file: OCFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class DownloadFileWorker(
length = (File(finalLocationForFile).length())
lastSyncDateForData = currentTime
modifiedAtLastSyncForData = downloadRemoteFileOperation.modificationTimestamp
lastUsage = currentTime
}
saveFileOrFolderUseCase(SaveFileOrFolderUseCase.Params(ocFile))
cleanConflictUseCase(
Expand Down
Loading