Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/src/main/java/com/nextcloud/ui/fileactions/FileAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ enum class FileAction(

constructor(id: Int, title: Int) : this(id, title, null)

fun toggledFavorite(): FileAction? = when (this) {
FAVORITE -> UNSET_FAVORITE
UNSET_FAVORITE -> FAVORITE
else -> null
}

companion object {
/**
* All file actions, in the order they should be displayed
Expand Down Expand Up @@ -209,6 +215,20 @@ enum class FileAction(
return result.toList()
}

fun getCurrentFolderActionsToHide(folder: OCFile): List<Int> {
val currentFolderActions = setOf(
R.id.action_send_share_file,
R.id.action_favorite,
R.id.action_unset_favorite,
R.id.action_see_details,
R.id.action_sync_file,
R.id.action_encrypted
)

return getFileListActionsToHide(setOf(folder)) +
entries.map { it.id }.filterNot { it in currentFolderActions }
}

fun getActionsToHide(files: Set<OCFile>): List<Int> {
if (files.isEmpty()) return emptyList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.core.os.bundleOf
import androidx.core.view.isNotEmpty
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.bottomsheet.BottomSheetBehavior
Expand Down Expand Up @@ -320,27 +319,33 @@ class FileActionsBottomSheet :
val itemBinding = FileActionsBottomSheetItemBinding.inflate(layoutInflater, binding.fileActionsList, false)
.apply {
root.setOnClickListener {
action.toggledFavorite()?.let { showAction(it, viewThemeUtils) }
viewModel.onClick(action)
}
text.setText(action.title)
if (action.icon != null) {
val drawable =
viewThemeUtils.platform.tintDrawable(
requireContext(),
AppCompatResources.getDrawable(requireContext(), action.icon)!!
)
icon.setImageDrawable(drawable)
}
showAction(action, viewThemeUtils)
}
return itemBinding.root
}

private fun dispatchActionClick(id: Int?) {
if (id != null) {
setFragmentResult(REQUEST_KEY, bundleOf(RESULT_KEY_ACTION_ID to id))
parentFragmentManager.clearFragmentResultListener(REQUEST_KEY)
if (id == null) {
return
}

// get the manager and dismiss before sending, as the result can replace the fragment hosting this sheet
val fragmentManager = parentFragmentManager
val isFavoriteToggle = id == R.id.action_favorite || id == R.id.action_unset_favorite
if (!isFavoriteToggle) {
dismiss()
}

fragmentManager.setFragmentResult(REQUEST_KEY, bundleOf(RESULT_KEY_ACTION_ID to id))
fragmentManager.clearFragmentResultListener(REQUEST_KEY)

if (isFavoriteToggle) {
val delay = resources.getInteger(android.R.integer.config_mediumAnimTime).toLong()
binding.root.postDelayed({ dismissAllowingStateLoss() }, delay)
}
}

companion object {
Expand Down Expand Up @@ -382,3 +387,15 @@ class FileActionsBottomSheet :
}
}
}

private fun FileActionsBottomSheetItemBinding.showAction(action: FileAction, viewThemeUtils: ViewThemeUtils) {
text.setText(action.title)
if (action.icon != null) {
val context = root.context
val drawable = viewThemeUtils.platform.tintDrawable(
context,
AppCompatResources.getDrawable(context, action.icon)!!
)
icon.setImageDrawable(drawable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class FileDisplayActivity :
private fun initUI() {
setupHomeSearchToolbarWithSortAndListButtons()
mMenuButton.setOnClickListener { v: View? -> openDrawer() }
findViewById<View>(R.id.toolbar).setOnClickListener { openCurrentFolderActions() }
mSwitchAccountButton.setOnClickListener { v: View? -> showManageAccountsDialog() }
mNotificationButton.setOnClickListener {
pushFragment(NavigatorScreen.Notifications)
Expand Down Expand Up @@ -950,9 +951,24 @@ class FileDisplayActivity :
}
}

menu?.findItem(R.id.action_current_folder_actions)?.isVisible = canShowCurrentFolderActions()

return super.onPrepareOptionsMenu(menu)
}

private fun canShowCurrentFolderActions(): Boolean = leftFragment is OCFileListFragment &&
!isDrawerOpen &&
!isSearchOpen() &&
!isRoot(getCurrentDir()) &&
listOfFilesFragment?.isSearchFragment == false &&
!isAlbumItemsFragment

private fun openCurrentFolderActions() {
if (canShowCurrentFolderActions()) {
listOfFilesFragment?.openCurrentFolderActionsMenu()
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.activity_file_display, menu)
Expand Down Expand Up @@ -1355,6 +1371,11 @@ class FileDisplayActivity :
true
}

R.id.action_current_folder_actions -> {
openCurrentFolderActions()
true
}

else -> super.onOptionsItemSelected(item)
}

Expand Down Expand Up @@ -1886,6 +1907,10 @@ class FileDisplayActivity :
Log_OC.d(TAG, "download worker finished")
val folder = getFolderFromFolderDownloadWorker(intent) ?: return
updateFileDownloadIndicator(FileDownloadIndicator.Downloaded, folder)

if (folder.fileId == getCurrentDir()?.fileId) {
updateListOfFilesFragment()
}
}
}
// endregion
Expand Down Expand Up @@ -2038,6 +2063,8 @@ class FileDisplayActivity :

val detailFragment: Fragment = FileDetailFragment.newInstance(file, currentUser, activeTab)
setLeftFragment(detailFragment, false)
// swap now, so no frame shows the list without its sort row
supportFragmentManager.executePendingTransactions()
configureToolbarForPreview(file)
}

Expand Down Expand Up @@ -2073,6 +2100,7 @@ class FileDisplayActivity :
chosenFile = file // if no file is passed, current file decides
}
super.updateActionBarTitleAndHomeButton(chosenFile)
supportInvalidateOptionsMenu()
}

override fun isDrawerIndicatorAvailable(): Boolean = isRoot(getCurrentDir())
Expand Down Expand Up @@ -2291,7 +2319,9 @@ class FileDisplayActivity :
resetScrollingAndUpdateActionBar()
}

if (leftFragment is OCFileListFragment && !operation.onlyLocalCopy) {
if (leftFragment is OCFileListFragment && operation.onlyLocalCopy) {
leftFragment.adapter?.notifyItemChanged(removedFile)
} else if (leftFragment is OCFileListFragment) {
leftFragment.adapter?.removeFile(removedFile)

if (leftFragment.adapter?.isEmpty == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ public void setFavoriteAttributeForItemID(String remotePath, boolean favorite, b
}
}

if (currentDirectory != null && currentDirectory.getRemotePath().equals(remotePath)) {
currentDirectory.setFavorite(favorite);
mStorageManager.saveFile(currentDirectory);
}

final OCFile updatedFile = changedFile;
new Handler(Looper.getMainLooper()).post(() -> {
List<OCFile> sortedFiles = differ.sortForCurrentView(new ArrayList<>(differ.getLatestFiles()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,27 @@ public void openActionsMenu(final int filesCount, final Set<OCFile> checkedFiles
});
}

public void openCurrentFolderActionsMenu() {
final OCFile currentFolder = getCurrentFile();
if (currentFolder == null || currentFolder.isRootDirectory()) {
return;
}

final Set<OCFile> checkedFiles = new HashSet<>();
checkedFiles.add(currentFolder);

throttler.run("overflowClick", () -> {
final var actionsToHide = FileAction.Companion.getCurrentFolderActionsToHide(currentFolder);
final var childFragmentManager = getChildFragmentManager();
final var actionBottomSheet = FileActionsBottomSheet.newInstance(currentFolder, true, actionsToHide)
.setResultListener(childFragmentManager, this, (id) -> onFileActionChosen(id, checkedFiles));

if (FragmentExtensionsKt.isDialogFragmentReady(this)) {
actionBottomSheet.show(childFragmentManager, "actions");
}
});
}

@Override
public void newDocument() {
ChooseRichDocumentsTemplateDialogFragment.newInstance(mFile,
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/activity_file_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="ifRoom" />

<item
android:id="@+id/action_current_folder_actions"
android:contentDescription="@string/overflow_menu"
android:icon="@drawable/ic_dots_vertical"
android:title="@string/overflow_menu"
app:showAsAction="always" />

<item
android:id="@+id/action_select_all"
android:contentDescription="@string/select_all"
Expand Down
Loading