Reuse same functions, cleanup code

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-11-28 08:55:37 +01:00
parent eeb91ab6da
commit 7c0363496f
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
3 changed files with 31 additions and 38 deletions

View file

@ -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);
}
}
}

View file

@ -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("")
}
}
}
}

View file

@ -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" />
</LinearLayout>