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

test #12250

Closed
wants to merge 8 commits into from
Closed

test #12250

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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) 2023 Alper Ozturk
* Copyright (C) 2023 Nextcloud GmbH
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,43 @@ private void setLeftFragment(Fragment fragment) {
}
}

private OCFileListFragment getOCFileListFragmentFromFile() {
final Fragment leftFragment = getLeftFragment();
OCFileListFragment listOfFiles = null;
if (leftFragment instanceof OCFileListFragment) {
listOfFiles = (OCFileListFragment) leftFragment;
} else {
listOfFiles = new OCFileListFragment();
Bundle args = new Bundle();
args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
listOfFiles.setArguments(args);
setLeftFragment(listOfFiles);
getSupportFragmentManager().executePendingTransactions();
}
return listOfFiles;
}

public void showFileActions(OCFile file) {
dismissLoadingDialog();
OCFileListFragment listOfFiles = getOCFileListFragmentFromFile();
clearSearchViewIfSearchAndDrawerNotOpened(listOfFiles);
listOfFiles.onOverflowIconClicked(file, null);
}

public void showFile(String message) {
dismissLoadingDialog();

OCFileListFragment listOfFiles = getOCFileListFragmentFromFile();

if (TextUtils.isEmpty(message)) {
OCFile temp = getFile();
setFile(getCurrentDir());
listOfFiles.listDirectory(getCurrentDir(), temp, MainApp.isOnlyOnDevice(), false);
updateActionBarTitleAndHomeButton(null);
} else {
DisplayUtils.showSnackMessage(listOfFiles.getView(), message);
}
}

public @androidx.annotation.Nullable
Fragment getLeftFragment() {
Expand All @@ -649,7 +686,6 @@ OCFileListFragment getListOfFilesFragment() {
return null;
}


protected void resetTitleBarAndScrolling() {
updateActionBarTitleAndHomeButton(null);
resetScrolling(true);
Expand Down Expand Up @@ -886,7 +922,7 @@ public void onCheckAvailableSpaceFinish(boolean hasEnoughSpaceAvailable, String.
FileUploader.LOCAL_BEHAVIOUR_DELETE);
}
}
}, new String[] { FileOperationsHelper.createImageFile(getActivity()).getAbsolutePath() }).execute();
}, new String[]{FileOperationsHelper.createImageFile(getActivity()).getAbsolutePath()}).execute();
} else if (requestCode == REQUEST_CODE__MOVE_OR_COPY_FILES && resultCode == RESULT_OK) {
exitSelectionMode();
} else if (requestCode == PermissionUtil.REQUEST_CODE_MANAGE_ALL_FILES) {
Expand Down Expand Up @@ -1004,6 +1040,34 @@ private boolean isSearchOpen() {
}
}

private void clearSearchView(OCFileListFragment listOfFiles) {
searchView.setQuery("", true);
searchView.onActionViewCollapsed();
searchView.clearFocus();

// Remove the list to the original state
listOfFiles.performSearch("", true);

hideSearchView(getCurrentDir());

setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
}

private void clearSearchViewIfSearchAndDrawerNotOpened(OCFileListFragment listOfFiles) {
listOfFiles.onBrowseUp();
setFile(listOfFiles.getCurrentFile());
listOfFiles.setFabVisible(true);
listOfFiles.registerFabListener();
showSortListGroup(true);
resetTitleBarAndScrolling();
setDrawerAllFiles();
}

private Boolean isRootDirectory() {
OCFile currentDir = getCurrentDir();
return (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID);
}

/*
* BackPressed priority/hierarchy:
* 1. close search view if opened
Expand All @@ -1019,37 +1083,19 @@ public void onBackPressed() {

final Fragment leftFragment = getLeftFragment();

if (leftFragment instanceof OCFileListFragment) {
OCFileListFragment listOfFiles = (OCFileListFragment) leftFragment;

if (leftFragment instanceof OCFileListFragment listOfFiles) {
if (isSearchOpen && searchView != null) {
searchView.setQuery("", true);
searchView.onActionViewCollapsed();
searchView.clearFocus();

// Remove the list to the original state
listOfFiles.performSearch("", true);

hideSearchView(getCurrentDir());

setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
clearSearchView(listOfFiles);
} else if (isDrawerOpen) {
// close drawer first
super.onBackPressed();
} else {
// all closed
OCFile currentDir = getCurrentDir();
if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
if (isRootDirectory()) {
finish();
return;
}
listOfFiles.onBrowseUp();
setFile(listOfFiles.getCurrentFile());
listOfFiles.setFabVisible(true);
listOfFiles.registerFabListener();
showSortListGroup(true);
resetTitleBarAndScrolling();
setDrawerAllFiles();

clearSearchViewIfSearchAndDrawerNotOpened(listOfFiles);
}
} else if (leftFragment instanceof PreviewTextStringFragment) {
createMinFragments(null);
Expand Down Expand Up @@ -2258,7 +2304,7 @@ public void startDownloadForPreview(OCFile file, OCFile parentFolder) {
* Opens EditImageActivity with given file loaded. If file is not available locally, it will be synced before
* opening the image editor.
*
* @param file {@link OCFile} (image) to be loaded into image editor
* @param file {@link OCFile} (image) to be loaded into image editor
*/
public void startImageEditor(OCFile file) {
if (file.isDown()) {
Expand All @@ -2267,7 +2313,7 @@ public void startImageEditor(OCFile file) {
startActivity(editImageIntent);
} else {
mWaitingToPreview = file;
requestForDownload(file,EditImageActivity.OPEN_IMAGE_EDITOR, getPackageName(),
requestForDownload(file, EditImageActivity.OPEN_IMAGE_EDITOR, getPackageName(),
this.getClass().getSimpleName());
updateActionBarTitleAndHomeButton(file);
setFile(file);
Expand Down Expand Up @@ -2590,30 +2636,4 @@ public void setMainFabVisible(final boolean visible) {
final int visibility = visible ? View.VISIBLE : View.GONE;
binding.fabMain.setVisibility(visibility);
}

public void showFile(String message) {
dismissLoadingDialog();

final Fragment leftFragment = getLeftFragment();
OCFileListFragment listOfFiles = null;
if (leftFragment instanceof OCFileListFragment) {
listOfFiles = (OCFileListFragment) leftFragment;
} else {
listOfFiles = new OCFileListFragment();
Bundle args = new Bundle();
args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
listOfFiles.setArguments(args);
setLeftFragment(listOfFiles);
getSupportFragmentManager().executePendingTransactions();
}

if (TextUtils.isEmpty(message)) {
OCFile temp = getFile();
setFile(getCurrentDir());
listOfFiles.listDirectory(getCurrentDir(), temp, MainApp.isOnlyOnDevice(), false);
updateActionBarTitleAndHomeButton(null);
} else {
DisplayUtils.showSnackMessage(listOfFiles.getView(), message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ class UnifiedSearchItemViewHolder(
val clientFactory: ClientFactory,
private val storageManager: FileDataStorageManager,
private val listInterface: UnifiedSearchListInterface,
private val filesAction: FilesAction,
val context: Context,
private val viewThemeUtils: ViewThemeUtils
) :
SectionedViewHolder(binding.root) {

interface FilesAction {
fun showFilesAction(searchResultEntry: SearchResultEntry)
}

fun bind(entry: SearchResultEntry) {
binding.title.text = entry.title
binding.subline.text = entry.subline
Expand All @@ -77,6 +82,13 @@ class UnifiedSearchItemViewHolder(
.listener(RoundIfNeededListener(entry))
.into(binding.thumbnail)

if (entry.isFile) {
binding.more.visibility = View.VISIBLE
binding.more.setOnClickListener { filesAction.showFilesAction(entry) }
} else {
binding.more.visibility = View.GONE
}

binding.unifiedSearchItemLayout.setOnClickListener { listInterface.onSearchResultClicked(entry) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils
class UnifiedSearchListAdapter(
private val storageManager: FileDataStorageManager,
private val listInterface: UnifiedSearchListInterface,
private val filesAction: UnifiedSearchItemViewHolder.FilesAction,
private val user: User,
private val clientFactory: ClientFactory,
private val context: Context,
Expand Down Expand Up @@ -91,6 +92,7 @@ class UnifiedSearchListAdapter(
clientFactory,
storageManager,
listInterface,
filesAction,
context,
viewThemeUtils
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.SearchResultEntry
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.adapter.UnifiedSearchItemViewHolder
import com.owncloud.android.ui.adapter.UnifiedSearchListAdapter
import com.owncloud.android.ui.fragment.util.PairMediatorLiveData
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
Expand All @@ -61,7 +62,12 @@ import javax.inject.Inject
* Starts query to all capable unified search providers and displays them Opens result in our app, redirect to other
* apps, if installed, or opens browser
*/
class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface, SearchView.OnQueryTextListener {
class UnifiedSearchFragment :
Fragment(),
Injectable,
UnifiedSearchListInterface,
SearchView.OnQueryTextListener,
UnifiedSearchItemViewHolder.FilesAction {
private lateinit var adapter: UnifiedSearchListAdapter
private var _binding: ListFragmentBinding? = null
private val binding get() = _binding!!
Expand All @@ -86,6 +92,8 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
@Inject
lateinit var viewThemeUtils: ViewThemeUtils

private var showMoreActions = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
vm = ViewModelProvider(this, vmFactory)[UnifiedSearchViewModel::class.java]
Expand Down Expand Up @@ -140,7 +148,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
startActivity(browserIntent)
}
vm.file.observe(this) {
showFile(it)
showFile(it, showMoreActions)
}
}

Expand All @@ -150,6 +158,21 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
}
}

private fun showFile(file: OCFile, showFileActions: Boolean) {
activity.let {
if (activity is FileDisplayActivity) {
val fda = activity as FileDisplayActivity
fda.file = file

if (showFileActions) {
fda.showFileActions(file)
} else {
fda.showFile("")
}
}
}
}

@Suppress("DEPRECATION")
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = ListFragmentBinding.inflate(inflater, container, false)
Expand All @@ -173,6 +196,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
adapter = UnifiedSearchListAdapter(
storageManager,
this,
this,
currentAccountProvider.user,
clientFactory,
requireContext(),
Expand All @@ -189,17 +213,8 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
_binding = null
}

private fun showFile(file: OCFile) {
activity.let {
if (activity is FileDisplayActivity) {
val fda = activity as FileDisplayActivity
fda.file = file
fda.showFile("")
}
}
}

override fun onSearchResultClicked(searchResultEntry: SearchResultEntry) {
showMoreActions = false
vm.openResult(searchResultEntry)
}

Expand Down Expand Up @@ -269,4 +284,9 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
}
return true
}

override fun showFilesAction(searchResultEntry: SearchResultEntry) {
showMoreActions = true
vm.openResult(searchResultEntry)
}
}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/unified_search_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,18 @@
tools:text="in TestFolder" />

</LinearLayout>

<ImageButton
android:id="@+id/more"
android:visibility="gone"
android:background="@color/transparent"
app:srcCompat="@drawable/ic_dots_vertical"
app:tint="@color/standard_grey"
android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="@string/overflow_menu"
tools:visibility="visible" />

</LinearLayout>

Loading