mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Merge pull request #12209 from nextcloud/feature/files-action-in-search-mode
Add Files Action to Search
This commit is contained in:
commit
397ac21eda
5 changed files with 103 additions and 41 deletions
|
@ -254,6 +254,7 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
|
||||
@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);
|
||||
|
@ -611,6 +612,28 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
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);
|
||||
|
@ -626,7 +649,6 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected void resetTitleBarAndScrolling() {
|
||||
updateActionBarTitleAndHomeButton(null);
|
||||
resetScrolling(true);
|
||||
|
@ -782,6 +804,7 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean retval = true;
|
||||
|
||||
int itemId = item.getItemId();
|
||||
|
||||
if (itemId == android.R.id.home) {
|
||||
|
@ -940,6 +963,11 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
}
|
||||
}
|
||||
|
||||
private Boolean isRootDirectory() {
|
||||
OCFile currentDir = getCurrentDir();
|
||||
return (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID);
|
||||
}
|
||||
|
||||
/*
|
||||
* BackPressed priority/hierarchy:
|
||||
* 1. close search view if opened
|
||||
|
@ -959,8 +987,7 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
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();
|
||||
|
@ -974,18 +1001,6 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
@ -995,9 +1010,6 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
setDrawerAllFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* It resets the Search Action (call when search is open)
|
||||
*/
|
||||
private void resetSearchAction() {
|
||||
Fragment leftFragment = getLeftFragment();
|
||||
if (isSearchOpen() && searchView != null) {
|
||||
|
@ -1005,8 +1017,7 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
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;
|
||||
|
@ -1022,6 +1033,18 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -2444,18 +2467,7 @@ public class FileDisplayActivity extends FileActivity implements FileFragment.Co
|
|||
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();
|
||||
|
|
|
@ -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
|
||||
|
@ -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) }
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -92,6 +93,7 @@ class UnifiedSearchListAdapter(
|
|||
clientFactory,
|
||||
storageManager,
|
||||
listInterface,
|
||||
filesAction,
|
||||
context,
|
||||
viewThemeUtils
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
@ -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!!
|
||||
|
@ -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]
|
||||
|
@ -200,7 +208,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
|
|||
startActivity(browserIntent)
|
||||
}
|
||||
vm.file.observe(this) {
|
||||
showFile(it)
|
||||
showFile(it, showMoreActions)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -222,6 +245,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
|
|||
adapter = UnifiedSearchListAdapter(
|
||||
storageManager,
|
||||
this,
|
||||
this,
|
||||
currentAccountProvider.user,
|
||||
clientFactory,
|
||||
requireContext(),
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -277,4 +295,9 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface
|
|||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun showFilesAction(searchResultEntry: SearchResultEntry) {
|
||||
showMoreActions = true
|
||||
vm.openResult(searchResultEntry)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue