From 7c0363496f9dbf533128246771c3979b2e6a140d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 28 Nov 2023 08:55:37 +0100 Subject: [PATCH] Reuse same functions, cleanup code Signed-off-by: alperozturk --- .../ui/activity/FileDisplayActivity.java | 34 ++++++++----------- .../ui/fragment/UnifiedSearchFragment.kt | 30 +++++++--------- .../main/res/layout/unified_search_item.xml | 5 +-- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 4940909185..a96c58769d 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -71,7 +71,6 @@ import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.utils.IntentUtil; import com.nextcloud.java.util.Optional; -import com.nextcloud.ui.fileactions.FileActionsBottomSheet; import com.nextcloud.utils.view.FastScrollUtils; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -143,11 +142,8 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Set; import javax.inject.Inject; @@ -657,6 +653,21 @@ public class FileDisplayActivity extends FileActivity 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() { return getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES); @@ -2614,19 +2625,4 @@ public class FileDisplayActivity extends FileActivity final int visibility = visible ? View.VISIBLE : View.GONE; binding.fabMain.setVisibility(visibility); } - - 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); - } - } } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt index a7db2101e3..a3382815da 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt @@ -62,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, UnifiedSearchItemViewHolder.FilesAction { +class UnifiedSearchFragment : + Fragment(), + Injectable, + UnifiedSearchListInterface, + SearchView.OnQueryTextListener, + UnifiedSearchItemViewHolder.FilesAction { private lateinit var adapter: UnifiedSearchListAdapter private var _binding: ListFragmentBinding? = null private val binding get() = _binding!! @@ -143,11 +148,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface startActivity(browserIntent) } vm.file.observe(this) { - if (showMoreActions) { - showFileActions(it) - } else { - showFile(it) - } + showFile(it, showMoreActions) } } @@ -157,22 +158,17 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface } } - private fun showFileActions(file: OCFile) { + private fun showFile(file: OCFile, showFileActions: Boolean) { activity.let { if (activity is FileDisplayActivity) { val fda = activity as FileDisplayActivity fda.file = file - fda.showFileActions(file) - } - } - } - private fun showFile(file: OCFile) { - activity.let { - if (activity is FileDisplayActivity) { - val fda = activity as FileDisplayActivity - fda.file = file - fda.showFile("") + if (showFileActions) { + fda.showFileActions(file) + } else { + fda.showFile("") + } } } } diff --git a/app/src/main/res/layout/unified_search_item.xml b/app/src/main/res/layout/unified_search_item.xml index ce226ba581..9366ff95aa 100755 --- a/app/src/main/res/layout/unified_search_item.xml +++ b/app/src/main/res/layout/unified_search_item.xml @@ -115,9 +115,10 @@ app:srcCompat="@drawable/ic_dots_vertical" app:tint="@color/standard_grey" android:layout_gravity="center" - android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_width="50dp" + android:layout_height="50dp" android:contentDescription="open file actions" + tools:visibility="visible" tools:ignore="HardcodedText" />