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

Add Files Action to Search #12209

Merged
merged 30 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b7045ab
Add files action to search
alperozturk96 Nov 28, 2023
32e026f
Reuse same functions, cleanup code
alperozturk96 Nov 28, 2023
d3f4f33
Reuse content description for more button
alperozturk96 Nov 29, 2023
2464ec5
Clear search view
alperozturk96 Nov 29, 2023
67a544d
Optimize imports
alperozturk96 Nov 29, 2023
6141502
Merge master
alperozturk96 Nov 29, 2023
1364f01
Add move task back option
alperozturk96 Nov 30, 2023
940b700
Merge master
alperozturk96 Nov 30, 2023
89d704a
Add files action to search
alperozturk96 Nov 28, 2023
ff21a62
Reuse same functions, cleanup code
alperozturk96 Nov 28, 2023
37ae2dc
Reuse content description for more button
alperozturk96 Nov 29, 2023
db8946d
Clear search view
alperozturk96 Nov 29, 2023
03d778f
Optimize imports
alperozturk96 Nov 29, 2023
5404a07
Add move task back option
alperozturk96 Nov 30, 2023
7052829
Fix needlessly boxes a boolean constant
alperozturk96 Nov 30, 2023
bc6990c
Fix needlessly boxes a boolean constant
alperozturk96 Nov 30, 2023
3ee19ac
Merge master (cant rebase due to multiple git conflicts)
alperozturk96 Dec 7, 2023
eeb91ab
Add files action to search
alperozturk96 Nov 28, 2023
7c03634
Reuse same functions, cleanup code
alperozturk96 Nov 28, 2023
af7d898
Reuse content description for more button
alperozturk96 Nov 29, 2023
5b4db1b
Clear search view
alperozturk96 Nov 29, 2023
180b27c
Optimize imports
alperozturk96 Nov 29, 2023
60401b1
Add move task back option
alperozturk96 Nov 30, 2023
16a6a9b
Fix needlessly boxes a boolean constant
alperozturk96 Nov 30, 2023
e018a65
Rebase master
alperozturk96 Dec 7, 2023
d0de68b
Merge remote-tracking branch 'origin/feature/files-action-in-search-m…
alperozturk96 Dec 7, 2023
17657f3
Rebase master
alperozturk96 Dec 7, 2023
60ec295
Merge master
alperozturk96 Dec 8, 2023
ca4b421
Solve git conflicts
alperozturk96 Dec 11, 2023
157fee3
Solve git conflicts
alperozturk96 Dec 13, 2023
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 @@ -254,6 +254,7 @@ public static Intent openFileIntent(Context context, User user, OCFile file) {

@Override
protected void onCreate(Bundle savedInstanceState) {

Log_OC.v(TAG, "onCreate() start");
// Set the default theme to replace the launch screen theme.
setTheme(R.style.Theme_ownCloud_Toolbar_Drawer);
Expand Down Expand Up @@ -611,6 +612,28 @@ private void setLeftFragment(Fragment fragment, boolean showSortListGroup) {
transaction.commit();
}

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();
browseUp(listOfFiles);
listOfFiles.onOverflowIconClicked(file, null);
}

public @androidx.annotation.Nullable Fragment getLeftFragment() {
return getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES);
Expand All @@ -626,7 +649,6 @@ private void setLeftFragment(Fragment fragment, boolean showSortListGroup) {
return null;
}


protected void resetTitleBarAndScrolling() {
updateActionBarTitleAndHomeButton(null);
resetScrolling(true);
Expand Down Expand Up @@ -782,6 +804,7 @@ public void onGlobalLayout() {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean retval = true;

int itemId = item.getItemId();

if (itemId == android.R.id.home) {
Expand Down Expand Up @@ -940,6 +963,11 @@ private boolean isSearchOpen() {
}
}

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 @@ -959,8 +987,7 @@ public void onBackPressed() {
resetSearchAction();
} else if (isDrawerOpen) {
super.onBackPressed();
} else if (leftFragment instanceof OCFileListFragment) {
OCFileListFragment listOfFiles = (OCFileListFragment) leftFragment;
} else if (leftFragment instanceof OCFileListFragment listOfFiles) {

// all closed
OCFile currentDir = getCurrentDir();
Expand All @@ -974,18 +1001,6 @@ public void onBackPressed() {
}
}

/**
* Use this method when want to pop the fragment on back press. It resets Scrolling (See
* {@link #resetScrolling(boolean) with true} and pop the visibility for sortListGroup (See
* {@link #setSortListGroup(boolean, boolean)}. At last call to super.onBackPressed()
*/
private void popBack() {
// pop back fragment
resetScrolling(true);
popSortListGroupVisibility();
super.onBackPressed();
}

private void browseUp(OCFileListFragment listOfFiles) {
listOfFiles.onBrowseUp();
setFile(listOfFiles.getCurrentFile());
Expand All @@ -995,18 +1010,14 @@ private void browseUp(OCFileListFragment listOfFiles) {
setDrawerAllFiles();
}

/**
* It resets the Search Action (call when search is open)
*/
private void resetSearchAction() {
Fragment leftFragment = getLeftFragment();
if (isSearchOpen() && searchView != null) {
searchView.setQuery("", true);
searchView.onActionViewCollapsed();
searchView.clearFocus();

if (isRoot(getCurrentDir()) && leftFragment instanceof OCFileListFragment) {
OCFileListFragment listOfFiles = (OCFileListFragment) leftFragment;
if (isRoot(getCurrentDir()) && leftFragment instanceof OCFileListFragment listOfFiles) {

// Remove the list to the original state
ArrayList<String> listOfHiddenFiles = listOfFiles.getAdapter().listOfHiddenFiles;
Expand All @@ -1022,6 +1033,18 @@ private void resetSearchAction() {
}
}

/**
* Use this method when want to pop the fragment on back press. It resets Scrolling (See
* {@link #resetScrolling(boolean) with true} and pop the visibility for sortListGroup (See
* {@link #setSortListGroup(boolean, boolean)}. At last call to super.onBackPressed()
*/
private void popBack() {
// pop back fragment
resetScrolling(true);
popSortListGroupVisibility();
super.onBackPressed();
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
// responsibility of restore is preferred in onCreate() before than in
Expand Down Expand Up @@ -2444,18 +2467,7 @@ public void setMainFabVisible(final boolean visible) {
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();
}
OCFileListFragment listOfFiles = getOCFileListFragmentFromFile();

if (TextUtils.isEmpty(message)) {
OCFile temp = getFile();
Expand Down
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 @@ -50,6 +50,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 @@ -92,6 +93,7 @@ class UnifiedSearchListAdapter(
clientFactory,
storageManager,
listInterface,
filesAction,
context,
viewThemeUtils
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -63,7 +64,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 Down Expand Up @@ -106,6 +112,8 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface

private var listOfHiddenFiles = ArrayList<String>()

private var showMoreActions = false

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

Expand All @@ -210,6 +218,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("")
}
}
}
}

private fun setupFileDisplayActivity() {
(activity as? FileDisplayActivity)?.run {
setMainFabVisible(false)
Expand All @@ -222,6 +245,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
adapter = UnifiedSearchListAdapter(
storageManager,
this,
this,
currentAccountProvider.user,
clientFactory,
requireContext(),
Expand All @@ -233,14 +257,8 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
binding.listRoot.adapter = adapter
}

private fun showFile(file: OCFile) {
(activity as? FileDisplayActivity)?.let {
it.file = file
it.showFile("")
}
}

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

Expand Down Expand Up @@ -277,4 +295,9 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
super.onDestroyView()
_binding = null
}

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