Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: parneet-guraya <[email protected]>
  • Loading branch information
parneet-guraya committed Jan 21, 2024
1 parent ca19ddf commit 4d35efb
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import com.owncloud.android.domain.files.usecases.GetFileByRemotePathUseCase
import com.owncloud.android.domain.files.usecases.GetFileWithSyncInfoByIdUseCase
import com.owncloud.android.domain.files.usecases.GetFolderContentAsStreamUseCase
import com.owncloud.android.domain.files.usecases.GetFolderContentUseCase
import com.owncloud.android.usecases.files.GetIfFileFolderLocalUseCase
import com.owncloud.android.domain.files.usecases.GetFolderImagesUseCase
import com.owncloud.android.domain.files.usecases.GetPersonalRootFolderForAccountUseCase
import com.owncloud.android.domain.files.usecases.GetSearchFolderContentUseCase
Expand Down Expand Up @@ -164,6 +165,7 @@ val useCaseModule = module {
factoryOf(::GetFolderContentAsStreamUseCase)
factoryOf(::GetFolderContentUseCase)
factoryOf(::GetFolderImagesUseCase)
factoryOf(::GetIfFileFolderLocalUseCase)
factoryOf(::GetPersonalRootFolderForAccountUseCase)
factoryOf(::GetSearchFolderContentUseCase)
factoryOf(::GetSharedByLinkForAccountAsStreamUseCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import com.owncloud.android.presentation.files.removefile.RemoveFilesDialogFragm
import com.owncloud.android.presentation.files.removefile.RemoveFilesDialogFragment.Companion.FRAGMENT_TAG_CONFIRMATION
import com.owncloud.android.presentation.files.renamefile.RenameFileDialogFragment
import com.owncloud.android.presentation.files.renamefile.RenameFileDialogFragment.Companion.FRAGMENT_TAG_RENAME_FILE
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.fragment.FileFragment
import com.owncloud.android.ui.preview.PreviewAudioFragment
Expand Down Expand Up @@ -251,8 +252,11 @@ class FileDetailsFragment : FileFragment() {
}

R.id.action_remove_file -> {
val dialog = RemoveFilesDialogFragment.newInstance(safeFile.file)
dialog.show(parentFragmentManager, FRAGMENT_TAG_CONFIRMATION)
val fileActivity = requireActivity() as FileActivity
fileActivity.showRemoveDialog(safeFile.file) { isLocallyAvailable ->
val dialog = RemoveFilesDialogFragment.newInstance(safeFile.file, isLocallyAvailable)
dialog.show(parentFragmentManager, FRAGMENT_TAG_CONFIRMATION)
}
true
}

Expand Down Expand Up @@ -353,7 +357,7 @@ class FileDetailsFragment : FileFragment() {
thumbnailImageView.bringToFront()
thumbnailImageView.isVisible = false

val file = ocFileWithSyncInfo.file
val file = ocFileWithSyncInfo.file
if (ocFileWithSyncInfo.isSynchronizing) {
thumbnailImageView.setImageResource(R.drawable.sync_pin)
thumbnailImageView.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.domain.files.model.OCFile.Companion.ROOT_PATH
import com.owncloud.android.domain.files.model.OCFileSyncInfo
import com.owncloud.android.domain.files.model.OCFileWithSyncInfo
import com.owncloud.android.usecases.files.GetIfFileFolderLocalUseCase
import com.owncloud.android.domain.spaces.model.OCSpace
import com.owncloud.android.domain.transfers.model.OCTransfer
import com.owncloud.android.domain.transfers.model.TransferStatus
Expand Down Expand Up @@ -111,6 +112,7 @@ import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.MimetypeIconUtil
import com.owncloud.android.utils.PreferenceUtils
import okio.Path.Companion.toPath
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
Expand Down Expand Up @@ -473,8 +475,10 @@ class MainFileListFragment : Fragment(),
}

FileMenuOption.REMOVE -> {
val dialogRemove = RemoveFilesDialogFragment.newInstance(file)
dialogRemove.show(requireActivity().supportFragmentManager, ConfirmationDialogFragment.FTAG_CONFIRMATION)
(requireActivity() as FileActivity).showRemoveDialog(file) { isLocallyAvailable ->
val dialogRemove = RemoveFilesDialogFragment.newInstance(file, isLocallyAvailable)
dialogRemove.show(requireActivity().supportFragmentManager, ConfirmationDialogFragment.FTAG_CONFIRMATION)
}
}

FileMenuOption.OPEN_WITH -> {
Expand Down Expand Up @@ -1095,10 +1099,14 @@ class MainFileListFragment : Fragment(),
}

R.id.action_remove_file -> {
val dialog = RemoveFilesDialogFragment.newInstance(checkedFiles)
dialog.show(requireActivity().supportFragmentManager, ConfirmationDialogFragment.FTAG_CONFIRMATION)
fileListAdapter.clearSelection()
updateActionModeAfterTogglingSelected()
val parentActivity = requireActivity() as FileActivity

parentActivity.showRemoveDialog(checkedFiles) { isLocallyAvailable ->
val dialog = RemoveFilesDialogFragment.newInstance(checkedFiles, isLocallyAvailable)
dialog.show(requireActivity().supportFragmentManager, ConfirmationDialogFragment.FTAG_CONFIRMATION)
fileListAdapter.clearSelection()
updateActionModeAfterTogglingSelected()
}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,19 @@ class RemoveFilesDialogFragment : ConfirmationDialogFragment(), ConfirmationDial
* @return Dialog ready to show.
*/
@JvmStatic
fun newInstance(files: ArrayList<OCFile>): RemoveFilesDialogFragment {
fun newInstance(files: ArrayList<OCFile>, isLocal: Boolean): RemoveFilesDialogFragment {
val messageStringId: Int
var containsFolder = false
var containsDown = false
var containsAvailableOffline = false
for (file in files) {
if (file.isFolder) {
containsFolder = true
}
if (file.isAvailableLocally) {
containsDown = true
}
if (file.isAvailableOffline) {
containsAvailableOffline = true
}
}

messageStringId = if (files.size == 1) {
// choose message for a single file
val file = files.first()
Expand All @@ -109,7 +106,7 @@ class RemoveFilesDialogFragment : ConfirmationDialogFragment(), ConfirmationDial
R.string.confirmation_remove_files_alert
}
}
val localRemoveButton = if (!containsAvailableOffline && (containsFolder || containsDown)) {
val localRemoveButton = if (!containsAvailableOffline && isLocal) {
R.string.confirmation_remove_local
} else {
-1
Expand Down Expand Up @@ -139,8 +136,8 @@ class RemoveFilesDialogFragment : ConfirmationDialogFragment(), ConfirmationDial
*/
@JvmStatic
@JvmName("newInstanceForSingleFile")
fun newInstance(file: OCFile): RemoveFilesDialogFragment {
return newInstance(arrayListOf(file))
fun newInstance(file: OCFile, isLocal: Boolean): RemoveFilesDialogFragment {
return newInstance(arrayListOf(file), isLocal)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.navigation.NavigationView
import com.owncloud.android.BuildConfig
import com.owncloud.android.R
import com.owncloud.android.domain.UseCaseResult
import com.owncloud.android.domain.capabilities.model.OCCapability
import com.owncloud.android.domain.files.model.FileListOption
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.usecases.files.GetIfFileFolderLocalUseCase
import com.owncloud.android.domain.utils.Event
import com.owncloud.android.extensions.goToUrl
import com.owncloud.android.extensions.openPrivacyPolicy
Expand All @@ -70,6 +74,10 @@ import com.owncloud.android.presentation.common.UIResult
import com.owncloud.android.presentation.settings.SettingsActivity
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.PreferenceUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
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 @@ -87,6 +95,7 @@ abstract class DrawerActivity : ToolbarActivity() {
account?.name
)
}
private val getIfFileFolderLocalUseCase: GetIfFileFolderLocalUseCase by inject()

private var menuAccountAvatarRadiusDimension = 0f
private var currentAccountAvatarRadiusDimension = 0f
Expand Down Expand Up @@ -205,17 +214,20 @@ abstract class DrawerActivity : ToolbarActivity() {
val settingsIntent = Intent(applicationContext, SettingsActivity::class.java)
startActivity(settingsIntent)
}

R.id.drawer_menu_account_add -> createAccount(false)
R.id.drawer_menu_account_manage -> {
val manageAccountsIntent = Intent(applicationContext, AccountsManagementActivity::class.java)
startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS)
}

R.id.drawer_menu_feedback -> openFeedback()
R.id.drawer_menu_help -> openHelp()
R.id.drawer_menu_privacy_policy -> openPrivacyPolicy()
Menu.NONE -> {
accountClicked(menuItem.title.toString())
}

else -> Timber.i("Unknown drawer menu item clicked: %s", menuItem.title)
}
true
Expand Down Expand Up @@ -274,6 +286,7 @@ abstract class DrawerActivity : ToolbarActivity() {
uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(uploadListIntent)
}

R.id.nav_available_offline_files -> navigateToOption(FileListOption.AV_OFFLINE)
R.id.nav_shared_by_link_files -> navigateToOption(FileListOption.SHARED_BY_LINK)
}
Expand Down Expand Up @@ -462,10 +475,12 @@ abstract class DrawerActivity : ToolbarActivity() {
)

}

userQuota.available == 0L -> { // Quota 0, guest users
getAccountQuotaBar()?.isVisible = false
getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage)
}

else -> { // Limited quota
// Update progress bar rounding up to next int. Example: quota is 0.54 => 1
getAccountQuotaBar()?.run {
Expand All @@ -482,6 +497,7 @@ abstract class DrawerActivity : ToolbarActivity() {
}
}
}

is UIResult.Loading -> getAccountQuotaText()?.text = getString(R.string.drawer_loading_quota)
is UIResult.Error -> getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage)
}
Expand Down Expand Up @@ -672,6 +688,28 @@ abstract class DrawerActivity : ToolbarActivity() {
restart()
}

// TODO: only for temp basis, should be in FileActivity (not possible currently because it is in java)

fun showRemoveDialog(
fileToRemove: OCFile,
showDialog: (isLocallyAvailable: Boolean) -> Unit
) = showRemoveDialog(listOf(fileToRemove), showDialog)

fun showRemoveDialog(
filesToRemove: List<OCFile>,
showDialog: (isLocallyAvailable: Boolean) -> Unit
) {
lifecycleScope.launch {
val useCaseResult = withContext(Dispatchers.IO) {
getIfFileFolderLocalUseCase(GetIfFileFolderLocalUseCase.Params(filesToRemove))
}
when (useCaseResult) {
is UseCaseResult.Error -> {}
is UseCaseResult.Success -> showDialog(useCaseResult.data)
}
}
}

/**
* populates the avatar drawer array with the first three ownCloud [Account]s while the first element is
* always the current account.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import android.widget.ImageView
import android.widget.ProgressBar
import com.owncloud.android.R
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.usecases.files.GetIfFileFolderLocalUseCase
import com.owncloud.android.extensions.collectLatestLifecycleFlow
import com.owncloud.android.extensions.filterMenuOptions
import com.owncloud.android.extensions.sendDownloadedFilesByShareSheet
Expand All @@ -54,6 +55,7 @@ import com.owncloud.android.presentation.files.operations.FileOperation
import com.owncloud.android.presentation.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.files.removefile.RemoveFilesDialogFragment
import com.owncloud.android.presentation.previews.PreviewAudioViewModel
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.controller.TransferProgressController
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment
import com.owncloud.android.ui.fragment.FileFragment
Expand Down Expand Up @@ -260,35 +262,44 @@ class PreviewAudioFragment : FileFragment() {
mContainerActivity.fileOperationsHelper.showShareFile(file)
true
}

R.id.action_open_file_with -> {
openFile()
true
}

R.id.action_remove_file -> {
val dialog = RemoveFilesDialogFragment.newInstance(file)
dialog.show(parentFragmentManager, ConfirmationDialogFragment.FTAG_CONFIRMATION)
(requireActivity() as FileActivity).showRemoveDialog(file) { isLocallyAvailable ->
val dialog = RemoveFilesDialogFragment.newInstance(file, isLocallyAvailable)
dialog.show(parentFragmentManager, ConfirmationDialogFragment.FTAG_CONFIRMATION)
}
true
}
R.id.action_see_details -> {
seeDetails()
true
}

R.id.action_send_file -> {
requireActivity().sendDownloadedFilesByShareSheet(listOf(file))
true
}

R.id.action_sync_file -> {
mContainerActivity.fileOperationsHelper.syncFile(file)
true
}

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

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

else -> super.onOptionsItemSelected(item)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.owncloud.android.extensions.sendDownloadedFilesByShareSheet
import com.owncloud.android.presentation.files.operations.FileOperation
import com.owncloud.android.presentation.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.files.removefile.RemoveFilesDialogFragment
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.controller.TransferProgressController
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment
import com.owncloud.android.ui.fragment.FileFragment
Expand Down Expand Up @@ -213,35 +214,45 @@ class PreviewImageFragment : FileFragment() {
mContainerActivity.fileOperationsHelper.showShareFile(file)
true
}

R.id.action_open_file_with -> {
openFile()
true
}

R.id.action_remove_file -> {
val dialog = RemoveFilesDialogFragment.newInstance(file)
dialog.show(requireFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION)
(requireActivity() as FileActivity).showRemoveDialog(file) { isLocallyAvailable ->
val dialog = RemoveFilesDialogFragment.newInstance(file, isLocallyAvailable)
dialog.show(requireFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION)
}
true
}

R.id.action_see_details -> {
seeDetails()
true
}

R.id.action_send_file -> {
requireActivity().sendDownloadedFilesByShareSheet(listOf(file))
true
}

R.id.action_sync_file -> {
mContainerActivity.fileOperationsHelper.syncFile(file)
true
}

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

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

else -> super.onOptionsItemSelected(item)
}
}
Expand Down
Loading

0 comments on commit 4d35efb

Please sign in to comment.