From df61a4df87cc2b842621f4602ba73c8898c726d5 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 8 Jun 2022 23:24:20 +0200 Subject: [PATCH] replace share files remote item chooser with new implementation and remove any legacy implementation Signed-off-by: Andy Scherzinger --- .../adapters/items/BrowserFileItem.java | 210 ----------- .../controllers/BrowserController.kt | 344 ------------------ .../BrowserForSharingController.java | 80 ---- .../interfaces/ListingInterface.java | 27 -- .../filebrowser/operations/DavListing.java | 81 ----- .../operations/ListingAbstractClass.java | 48 --- .../talk/controllers/ChatController.kt | 48 ++- .../talk/controllers/ProfileController.kt | 7 +- .../talk/interfaces/SelectionInterface.kt | 30 -- .../activities/RemoteFileBrowserActivity.kt | 10 +- .../talk/ui/dialog/AttachmentDialog.kt | 3 +- .../ui/dialog/SortingOrderDialogFragment.java | 12 - .../nextcloud/talk/utils/DisplayUtils.java | 32 +- .../com/nextcloud/talk/utils/FileSortOrder.kt | 3 - .../talk/utils/FileSortOrderByDate.kt | 3 - .../talk/utils/FileSortOrderByName.kt | 8 +- .../talk/utils/FileSortOrderBySize.kt | 3 - .../talk/utils/LegacyFileSortOrder.java | 108 ------ .../talk/utils/LegacyFileSortOrderByDate.java | 53 --- .../talk/utils/LegacyFileSortOrderByName.java | 64 ---- .../talk/utils/LegacyFileSortOrderBySize.java | 62 ---- .../daveKoeller/AlphanumComparator.java | 9 +- .../main/res/layout/controller_browser.xml | 100 ----- .../res/layout/rv_item_browser_file_old.xml | 105 ------ app/src/main/res/menu/file_browser_path.xml | 28 -- 25 files changed, 58 insertions(+), 1420 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForSharingController.java delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/interfaces/ListingInterface.java delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/DavListing.java delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/ListingAbstractClass.java delete mode 100644 app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrder.java delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByDate.java delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByName.java delete mode 100644 app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderBySize.java delete mode 100644 app/src/main/res/layout/controller_browser.xml delete mode 100644 app/src/main/res/layout/rv_item_browser_file_old.xml delete mode 100644 app/src/main/res/menu/file_browser_path.xml diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java deleted file mode 100644 index 09926a663..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/adapters/items/BrowserFileItem.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2022 Andy Scherzinger - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.adapters.items; - -import android.content.Context; -import android.text.format.Formatter; -import android.view.View; -import android.widget.CheckBox; -import android.widget.Toast; - -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.drawee.interfaces.DraweeController; -import com.nextcloud.talk.R; -import com.nextcloud.talk.application.NextcloudTalkApplication; -import com.nextcloud.talk.components.filebrowser.models.BrowserFile; -import com.nextcloud.talk.databinding.RvItemBrowserFileBinding; -import com.nextcloud.talk.databinding.RvItemBrowserFileOldBinding; -import com.nextcloud.talk.interfaces.SelectionInterface; -import com.nextcloud.talk.models.database.UserEntity; -import com.nextcloud.talk.utils.ApiUtils; -import com.nextcloud.talk.utils.DateUtils; -import com.nextcloud.talk.utils.DisplayUtils; -import com.nextcloud.talk.utils.DrawableUtils; - -import java.util.List; - -import javax.inject.Inject; - -import androidx.appcompat.content.res.AppCompatResources; -import autodagger.AutoInjector; -import eu.davidea.flexibleadapter.FlexibleAdapter; -import eu.davidea.flexibleadapter.items.AbstractFlexibleItem; -import eu.davidea.flexibleadapter.items.IFilterable; -import eu.davidea.flexibleadapter.items.IFlexible; -import eu.davidea.viewholders.FlexibleViewHolder; - -@AutoInjector(NextcloudTalkApplication.class) -public class BrowserFileItem extends AbstractFlexibleItem implements IFilterable { - @Inject - Context context; - private final BrowserFile browserFile; - private final UserEntity activeUser; - private final SelectionInterface selectionInterface; - private boolean selected; - - public BrowserFileItem(BrowserFile browserFile, UserEntity activeUser, SelectionInterface selectionInterface) { - this.browserFile = browserFile; - this.activeUser = activeUser; - this.selectionInterface = selectionInterface; - NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); - } - - @Override - public boolean equals(Object o) { - if (o instanceof BrowserFileItem) { - BrowserFileItem inItem = (BrowserFileItem) o; - return browserFile.getPath().equals(inItem.getModel().getPath()); - } - - return false; - } - - public BrowserFile getModel() { - return browserFile; - } - - @Override - public int getLayoutRes() { - return R.layout.rv_item_browser_file; - } - - @Override - public BrowserFileItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) { - return new BrowserFileItemViewHolder(view, adapter); - } - - private boolean isSelected() { - return selected; - } - - private void setSelected(boolean selected) { - this.selected = selected; - } - - @Override - public void bindViewHolder(FlexibleAdapter adapter, - BrowserFileItemViewHolder holder, - int position, - List payloads) { - holder.binding.fileIcon.setController(null); - if (!browserFile.isAllowedToReShare() || browserFile.isEncrypted()) { - holder.itemView.setEnabled(false); - holder.itemView.setAlpha(0.38f); - } else { - holder.itemView.setEnabled(true); - holder.itemView.setAlpha(1.0f); - } - - if (browserFile.isEncrypted()) { - holder.binding.fileEncryptedImageView.setVisibility(View.VISIBLE); - - } else { - holder.binding.fileEncryptedImageView.setVisibility(View.GONE); - } - - if (browserFile.isFavorite()) { - holder.binding.fileFavoriteImageView.setVisibility(View.VISIBLE); - } else { - holder.binding.fileFavoriteImageView.setVisibility(View.GONE); - } - - if (selectionInterface.shouldOnlySelectOneImageFile()) { - if (browserFile.isFile() && browserFile.getMimeType().startsWith("image/")) { - holder.binding.selectFileCheckbox.setVisibility(View.VISIBLE); - } else { - holder.binding.selectFileCheckbox.setVisibility(View.GONE); - } - } else { - holder.binding.selectFileCheckbox.setVisibility(View.VISIBLE); - } - - if (context != null) { - holder - .binding - .fileIcon - .getHierarchy() - .setPlaceholderImage( - AppCompatResources.getDrawable( - context, DrawableUtils.INSTANCE.getDrawableResourceIdForMimeType(browserFile.getMimeType()))); - } - - if (browserFile.getHasPreview()) { - String path = ApiUtils.getUrlForFilePreviewWithRemotePath(activeUser.getBaseUrl(), - browserFile.getPath(), - context.getResources().getDimensionPixelSize(R.dimen.small_item_height)); - - if (path.length() > 0) { - DraweeController draweeController = Fresco.newDraweeControllerBuilder() - .setAutoPlayAnimations(true) - .setImageRequest(DisplayUtils.getImageRequestForUrl(path, null)) - .build(); - holder.binding.fileIcon.setController(draweeController); - } - } - - holder.binding.filenameTextView.setText(browserFile.getDisplayName()); - holder.binding.fileModifiedInfo.setText(String.format(context.getString(R.string.nc_last_modified), - Formatter.formatShortFileSize(context, browserFile.getSize()), - DateUtils.INSTANCE.getLocalDateTimeStringFromTimestamp(browserFile.getModifiedTimestamp()))); - setSelected(selectionInterface.isPathSelected(browserFile.getPath())); - holder.binding.selectFileCheckbox.setChecked(isSelected()); - - if (!browserFile.isEncrypted()) { - holder.binding.selectFileCheckbox.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!browserFile.isAllowedToReShare()) { - ((CheckBox) v).setChecked(false); - Toast.makeText( - context, - context.getResources().getString(R.string.nc_file_browser_reshare_forbidden), - Toast.LENGTH_LONG) - .show(); - } else if (((CheckBox) v).isChecked() != isSelected()) { - setSelected(((CheckBox) v).isChecked()); - selectionInterface.toggleBrowserItemSelection(browserFile.getPath()); - } - } - }); - } - - holder.binding.filenameTextView.setSelected(true); - holder.binding.fileModifiedInfo.setSelected(true); - } - - @Override - public boolean filter(String constraint) { - return false; - } - - static class BrowserFileItemViewHolder extends FlexibleViewHolder { - - RvItemBrowserFileOldBinding binding; - - BrowserFileItemViewHolder(View view, FlexibleAdapter adapter) { - super(view, adapter); - binding = RvItemBrowserFileOldBinding.bind(view); - } - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.kt deleted file mode 100644 index d7fcc0ba1..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.kt +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.nextcloud.talk.components.filebrowser.controllers - -import android.annotation.SuppressLint -import android.os.Bundle -import android.os.Parcelable -import android.util.Log -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem -import android.view.View -import androidx.fragment.app.DialogFragment -import androidx.recyclerview.widget.RecyclerView -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout -import autodagger.AutoInjector -import com.nextcloud.talk.R -import com.nextcloud.talk.activities.MainActivity -import com.nextcloud.talk.application.NextcloudTalkApplication -import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication -import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem -import com.nextcloud.talk.components.filebrowser.interfaces.ListingInterface -import com.nextcloud.talk.components.filebrowser.models.BrowserFile -import com.nextcloud.talk.components.filebrowser.models.DavResponse -import com.nextcloud.talk.components.filebrowser.operations.DavListing -import com.nextcloud.talk.components.filebrowser.operations.ListingAbstractClass -import com.nextcloud.talk.controllers.base.NewBaseController -import com.nextcloud.talk.controllers.util.viewBinding -import com.nextcloud.talk.databinding.ControllerBrowserBinding -import com.nextcloud.talk.interfaces.SelectionInterface -import com.nextcloud.talk.models.database.UserEntity -import com.nextcloud.talk.ui.dialog.SortingOrderDialogFragment -import com.nextcloud.talk.utils.DisplayUtils -import com.nextcloud.talk.utils.LegacyFileSortOrder -import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BROWSER_TYPE -import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY -import com.nextcloud.talk.utils.database.user.UserUtils -import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager -import kotlinx.android.parcel.Parcelize -import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener -import okhttp3.OkHttpClient -import org.parceler.Parcels -import java.io.File -import java.util.ArrayList -import java.util.Collections -import java.util.TreeSet -import javax.inject.Inject - -@AutoInjector(NextcloudTalkApplication::class) -abstract class BrowserController(args: Bundle) : - NewBaseController( - R.layout.controller_browser, - args - ), - ListingInterface, - FlexibleAdapter.OnItemClickListener, - SwipeRefreshLayout.OnRefreshListener, - SelectionInterface { - - private val binding: ControllerBrowserBinding by viewBinding(ControllerBrowserBinding::bind) - - @JvmField - protected val selectedPaths: MutableSet - - @JvmField - @Inject - var userUtils: UserUtils? = null - - @JvmField - @Inject - var okHttpClient: OkHttpClient? = null - - @JvmField - protected var activeUser: UserEntity - - private var filesSelectionDoneMenuItem: MenuItem? = null - private var layoutManager: RecyclerView.LayoutManager? = null - private var adapter: FlexibleAdapter? = null - private var recyclerViewItems: List = ArrayList() - private var listingAbstractClass: ListingAbstractClass? = null - private val browserType: BrowserType - private var currentPath: String - - private var sortingChangeListener: OnPreferenceValueChangedListener? = null - - override fun onViewBound(view: View) { - super.onViewBound(view) - if (adapter == null) { - adapter = FlexibleAdapter(recyclerViewItems, context, false) - } - - appPreferences!!.registerSortingChangeListener( - SortingChangeListener(this).also { - sortingChangeListener = it - } - ) - - changeEnabledStatusForBarItems(true) - prepareViews() - } - - abstract fun onFileSelectionDone() - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.menu_share_files, menu) - filesSelectionDoneMenuItem = menu.findItem(R.id.files_selection_done) - filesSelectionDoneMenuItem?.isVisible = selectedPaths.size > 0 - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.files_selection_done) { - onFileSelectionDone() - return true - } - return super.onOptionsItemSelected(item) - } - - override fun onAttach(view: View) { - super.onAttach(view) - - binding.pathNavigation.menu.findItem(R.id.action_back)?.setOnMenuItemClickListener { goBack() } - binding.sortButton.setOnClickListener { changeSorting() } - - binding.sortButton.setText( - DisplayUtils.getSortOrderStringId(LegacyFileSortOrder.getFileSortOrder(appPreferences?.sorting)) - ) - - refreshCurrentPath() - } - - override fun onRefresh() { - refreshCurrentPath() - } - - fun changeSorting() { - val newFragment: DialogFragment = SortingOrderDialogFragment - .newInstance(LegacyFileSortOrder.getFileSortOrder(appPreferences?.sorting)) - newFragment.show( - (activity as MainActivity?)!!.supportFragmentManager, - SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT - ) - } - - public override fun onDestroy() { - super.onDestroy() - listingAbstractClass!!.tearDown() - } - - override val title: String - get() = - currentPath - - fun goBack(): Boolean { - fetchPath(File(currentPath).parent) - return true - } - - fun refreshCurrentPath(): Boolean { - fetchPath(currentPath) - return true - } - - @SuppressLint("RestrictedApi") - private fun changeEnabledStatusForBarItems(shouldBeEnabled: Boolean) { - binding.pathNavigation.menu.findItem(R.id.action_back)?.isEnabled = shouldBeEnabled && currentPath != "/" - } - - private fun fetchPath(path: String) { - listingAbstractClass!!.cancelAllJobs() - changeEnabledStatusForBarItems(false) - listingAbstractClass!!.getFiles( - path, - activeUser, - if (BrowserType.DAV_BROWSER == browserType) okHttpClient else null - ) - } - - override fun listingResult(davResponse: DavResponse) { - recyclerViewItems = ArrayList() - if (davResponse.getData() != null) { - val objectList = davResponse.getData() as List - currentPath = objectList[0].path!! - if (activity != null) { - activity!!.runOnUiThread { setTitle() } - } - for (i in 1 until objectList.size) { - (recyclerViewItems as ArrayList).add(BrowserFileItem(objectList[i], activeUser, this)) - } - } - - LegacyFileSortOrder.getFileSortOrder(appPreferences?.sorting).sortCloudFiles(recyclerViewItems) - - if (activity != null) { - activity!!.runOnUiThread { - adapter!!.clear() - adapter!!.addItems(0, recyclerViewItems) - adapter!!.notifyDataSetChanged() - changeEnabledStatusForBarItems(true) - } - } - - binding.swipeRefreshList.isRefreshing = false - } - - private fun shouldPathBeSelectedDueToParent(currentPath: String): Boolean { - if (selectedPaths.size > 0) { - var file = File(currentPath) - if (file.parent != "/") { - while (file.parent != null) { - var parent = file.parent!! - if (File(file.parent!!).parent != null) { - parent += "/" - } - if (selectedPaths.contains(parent)) { - return true - } - file = File(file.parent!!) - } - } - } - return false - } - - private fun checkAndRemoveAnySelectedParents(currentPath: String) { - var file = File(currentPath) - selectedPaths.remove(currentPath) - while (file.parent != null) { - selectedPaths.remove(file.parent!! + "/") - file = File(file.parent!!) - } - if (activity != null) { - activity!!.runOnUiThread { - adapter!!.notifyDataSetChanged() - } - } - } - - override fun onItemClick(view: View, position: Int): Boolean { - val browserFile = (adapter!!.getItem(position) as BrowserFileItem).model - if ("inode/directory" == browserFile.mimeType) { - fetchPath(browserFile.path!!) - return true - } - return false - } - - private fun prepareViews() { - if (activity != null) { - layoutManager = SmoothScrollLinearLayoutManager(activity) - binding.recyclerView.layoutManager = layoutManager - binding.recyclerView.setHasFixedSize(true) - binding.recyclerView.adapter = adapter - adapter!!.addListener(this) - - binding.swipeRefreshList.setOnRefreshListener(this) - binding.swipeRefreshList.setColorSchemeResources(R.color.colorPrimary) - binding.swipeRefreshList.setProgressBackgroundColorSchemeResource(R.color.refresh_spinner_background) - } - } - - @SuppressLint("RestrictedApi") - override fun toggleBrowserItemSelection(path: String) { - if (selectedPaths.contains(path) || shouldPathBeSelectedDueToParent(path)) { - checkAndRemoveAnySelectedParents(path) - } else { - // TOOD: if it's a folder, remove all the children we added manually - selectedPaths.add(path) - } - filesSelectionDoneMenuItem?.isVisible = selectedPaths.size > 0 - } - - override fun isPathSelected(path: String): Boolean { - return selectedPaths.contains(path) || shouldPathBeSelectedDueToParent(path) - } - - abstract override fun shouldOnlySelectOneImageFile(): Boolean - - @Parcelize - enum class BrowserType : Parcelable { - FILE_BROWSER, DAV_BROWSER - } - - init { - setHasOptionsMenu(true) - sharedApplication!!.componentApplication.inject(this) - browserType = Parcels.unwrap(args.getParcelable(KEY_BROWSER_TYPE)) - activeUser = Parcels.unwrap(args.getParcelable(KEY_USER_ENTITY)) - currentPath = "/" - if (BrowserType.DAV_BROWSER == browserType) { - listingAbstractClass = DavListing(this) - } // else { - // listingAbstractClass = new LocalListing(this); - // } - selectedPaths = Collections.synchronizedSet(TreeSet()) - } - - @Suppress("Detekt.TooGenericExceptionCaught") - private class SortingChangeListener(private val browserController: BrowserController) : - OnPreferenceValueChangedListener { - override fun onChanged(newValue: String) { - try { - val sortOrder = LegacyFileSortOrder.getFileSortOrder(newValue) - - browserController.binding.sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder)) - browserController.recyclerViewItems = sortOrder.sortCloudFiles(browserController.recyclerViewItems) - - if (browserController.activity != null) { - browserController.activity!!.runOnUiThread { - browserController.adapter!!.updateDataSet(browserController.recyclerViewItems) - browserController.changeEnabledStatusForBarItems(true) - } - } - } catch (npe: NullPointerException) { - // view binding can be null - // since this is called asynchronously and UI might have been destroyed in the meantime - Log.i(BrowserController.TAG, "UI destroyed - view binding already gone") - } - } - } - - companion object { - private const val TAG = "BrowserController" - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForSharingController.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForSharingController.java deleted file mode 100644 index f0b0e640a..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForSharingController.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Tobias Kaminsky - * Copyright (C) 2021 Tobias Kaminsky - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.controllers; - -import android.os.Bundle; - -import com.nextcloud.talk.jobs.ShareOperationWorker; -import com.nextcloud.talk.utils.bundle.BundleKeys; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import androidx.work.Data; -import androidx.work.OneTimeWorkRequest; -import androidx.work.WorkManager; - -public class BrowserForSharingController extends BrowserController { - private final String roomToken; - - public BrowserForSharingController(Bundle args) { - super(args); - - roomToken = args.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()); - } - - @Override - public void onFileSelectionDone() { - synchronized (selectedPaths) { - Iterator iterator = selectedPaths.iterator(); - - List paths = new ArrayList<>(); - Data data; - OneTimeWorkRequest shareWorker; - - while (iterator.hasNext()) { - String path = iterator.next(); - paths.add(path); - iterator.remove(); - if (paths.size() == 10 || !iterator.hasNext()) { - data = new Data.Builder() - .putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), activeUser.getId()) - .putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomToken) - .putStringArray(BundleKeys.INSTANCE.getKEY_FILE_PATHS(), paths.toArray(new String[0])) - .build(); - shareWorker = new OneTimeWorkRequest.Builder(ShareOperationWorker.class) - .setInputData(data) - .build(); - WorkManager.getInstance().enqueue(shareWorker); - paths = new ArrayList<>(); - } - } - } - - getRouter().popCurrentController(); - } - - @Override - public boolean shouldOnlySelectOneImageFile() { - return false; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/interfaces/ListingInterface.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/interfaces/ListingInterface.java deleted file mode 100644 index c953d8a59..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/interfaces/ListingInterface.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.interfaces; - -import com.nextcloud.talk.components.filebrowser.models.DavResponse; - -public interface ListingInterface { - void listingResult(DavResponse davResponse); -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/DavListing.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/DavListing.java deleted file mode 100644 index dc69a1422..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/DavListing.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2022 Andy Scherzinger - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.operations; - -import android.util.Log; - -import com.nextcloud.talk.components.filebrowser.interfaces.ListingInterface; -import com.nextcloud.talk.components.filebrowser.models.DavResponse; -import com.nextcloud.talk.components.filebrowser.webdav.ReadFilesystemOperation; -import com.nextcloud.talk.models.database.UserEntity; - -import java.util.concurrent.Callable; - -import androidx.annotation.Nullable; -import io.reactivex.Single; -import io.reactivex.SingleObserver; -import io.reactivex.annotations.NonNull; -import io.reactivex.disposables.Disposable; -import io.reactivex.schedulers.Schedulers; -import okhttp3.OkHttpClient; - -public class DavListing extends ListingAbstractClass { - private static final String TAG = DavListing.class.getSimpleName(); - - private DavResponse davResponse = new DavResponse(); - - public DavListing(ListingInterface listingInterface) { - super(listingInterface); - } - - @Override - public void getFiles(String path, UserEntity currentUser, @Nullable OkHttpClient okHttpClient) { - Single.fromCallable(new Callable() { - @Override - public ReadFilesystemOperation call() { - return new ReadFilesystemOperation(okHttpClient, currentUser, path, 1); - } - }).subscribeOn(Schedulers.io()) - .subscribe(new SingleObserver() { - @Override - public void onSubscribe(@NonNull Disposable d) { - - } - - @Override - public void onSuccess(@NonNull ReadFilesystemOperation readFilesystemOperation) { - davResponse = readFilesystemOperation.readRemotePath(); - try { - listingInterface.listingResult(davResponse); - } catch (NullPointerException npe) { - Log.i(TAG, "Error loading remote folder - due to view already been terminated", npe); - } - } - - @Override - public void onError(@NonNull Throwable e) { - listingInterface.listingResult(davResponse); - } - }); - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/ListingAbstractClass.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/ListingAbstractClass.java deleted file mode 100644 index b01bc31cc..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/operations/ListingAbstractClass.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.operations; - -import android.os.Handler; -import androidx.annotation.Nullable; -import com.nextcloud.talk.components.filebrowser.interfaces.ListingInterface; -import com.nextcloud.talk.models.database.UserEntity; -import okhttp3.OkHttpClient; - -public abstract class ListingAbstractClass { - Handler handler; - ListingInterface listingInterface; - - ListingAbstractClass(ListingInterface listingInterface) { - handler = new Handler(); - this.listingInterface = listingInterface; - } - - public abstract void getFiles(String path, UserEntity currentUser, @Nullable OkHttpClient okHttpClient); - - public void cancelAllJobs() { - handler.removeCallbacksAndMessages(null); - } - - public void tearDown() { - cancelAllJobs(); - handler = null; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 15fbbe98f..18631506a 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -91,7 +91,6 @@ import autodagger.AutoInjector import coil.load import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler -import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler import com.facebook.common.executors.UiThreadImmediateExecutorService import com.facebook.common.references.CloseableReference import com.facebook.datasource.DataSource @@ -121,14 +120,13 @@ import com.nextcloud.talk.adapters.messages.VoiceMessageInterface import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.callbacks.MentionAutocompleteCallback -import com.nextcloud.talk.components.filebrowser.controllers.BrowserController -import com.nextcloud.talk.components.filebrowser.controllers.BrowserForSharingController import com.nextcloud.talk.controllers.base.NewBaseController import com.nextcloud.talk.controllers.util.viewBinding import com.nextcloud.talk.databinding.ControllerChatBinding import com.nextcloud.talk.events.UserMentionClickEvent import com.nextcloud.talk.events.WebSocketCommunicationEvent import com.nextcloud.talk.jobs.DownloadFileToCacheWorker +import com.nextcloud.talk.jobs.ShareOperationWorker import com.nextcloud.talk.jobs.UploadAndShareFilesWorker import com.nextcloud.talk.messagesearch.MessageSearchActivity import com.nextcloud.talk.models.database.CapabilitiesUtil @@ -143,6 +141,7 @@ import com.nextcloud.talk.models.json.conversations.RoomsOverall import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.mention.Mention import com.nextcloud.talk.presenters.MentionAutocompletePresenter +import com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity import com.nextcloud.talk.shareditems.activities.SharedItemsActivity import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet import com.nextcloud.talk.ui.dialog.AttachmentDialog @@ -164,6 +163,8 @@ import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME +import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FILE_PATHS +import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY @@ -1352,6 +1353,33 @@ class ChatController(args: Bundle) : } when (requestCode) { + REQUEST_CODE_SELECT_REMOTE_FILES -> { + val pathList = intent?.getStringArrayListExtra(RemoteFileBrowserActivity.EXTRA_SELECTED_PATHS) + if (pathList?.size!! >= 1) { + var paths: MutableList = ArrayList() + var data: Data + var shareWorker: OneTimeWorkRequest + val iterator = pathList.iterator() + + while (iterator.hasNext()) { + val path = iterator.next() + paths.add(path) + iterator.remove() + if (paths.size == 10 || !iterator.hasNext()) { + data = Data.Builder() + .putLong(KEY_INTERNAL_USER_ID, conversationUser!!.id) + .putString(KEY_ROOM_TOKEN, roomToken) + .putStringArray(KEY_FILE_PATHS, paths.toTypedArray()) + .build() + shareWorker = OneTimeWorkRequest.Builder(ShareOperationWorker::class.java) + .setInputData(data) + .build() + WorkManager.getInstance().enqueue(shareWorker) + paths = java.util.ArrayList() + } + } + } + } REQUEST_CODE_CHOOSE_FILE -> { try { checkNotNull(intent) @@ -1606,16 +1634,9 @@ class ChatController(args: Bundle) : requestReadContacts() } - fun showBrowserScreen(browserType: BrowserController.BrowserType) { - val bundle = Bundle() - bundle.putParcelable(BundleKeys.KEY_BROWSER_TYPE, Parcels.wrap(browserType)) - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser)) - bundle.putString(KEY_ROOM_TOKEN, roomToken) - router.pushController( - RouterTransaction.with(BrowserForSharingController(bundle)) - .pushChangeHandler(VerticalChangeHandler()) - .popChangeHandler(VerticalChangeHandler()) - ) + fun showBrowserScreen() { + val sharingFileBrowserIntent = Intent(activity, RemoteFileBrowserActivity::class.java) + startActivityForResult(sharingFileBrowserIntent, REQUEST_CODE_SELECT_REMOTE_FILES) } fun showShareLocationScreen() { @@ -3142,6 +3163,7 @@ class ChatController(args: Bundle) : private const val REQUEST_READ_CONTACT_PERMISSION = 234 private const val REQUEST_CAMERA_PERMISSION = 223 private const val REQUEST_CODE_PICK_CAMERA: Int = 333 + private const val REQUEST_CODE_SELECT_REMOTE_FILES = 888 private const val OBJECT_MESSAGE: String = "{object}" private const val MINIMUM_VOICE_RECORD_DURATION: Int = 1000 private const val VOICE_RECORD_CANCEL_SLIDER_X: Int = -50 diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt index beb6fb073..3616efee1 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt @@ -487,7 +487,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) { val avatarIntent = Intent(activity, RemoteFileBrowserActivity::class.java) avatarIntent.putExtras(bundle) - startActivityForResult(avatarIntent, RemoteFileBrowserActivity.REQUEST_CODE_SELECT_AVATAR) + startActivityForResult(avatarIntent, REQUEST_CODE_SELECT_REMOTE_FILES) } fun handleAvatar(remotePath: String?) { @@ -547,11 +547,13 @@ class ProfileController : NewBaseController(R.layout.controller_profile) { if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_CODE_IMAGE_PICKER) { uploadAvatar(getFile(intent)) - } else { + } else if (requestCode == REQUEST_CODE_SELECT_REMOTE_FILES) { val pathList = intent?.getStringArrayListExtra(RemoteFileBrowserActivity.EXTRA_SELECTED_PATHS) if (pathList?.size!! >= 1) { handleAvatar(pathList[0]) } + } else { + Log.w(TAG, "Unknown intent request code") } } else if (resultCode == ImagePicker.RESULT_ERROR) { Toast.makeText(activity, getError(intent), Toast.LENGTH_SHORT).show() @@ -806,6 +808,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) { companion object { private const val TAG: String = "ProfileController" + private const val REQUEST_CODE_SELECT_REMOTE_FILES = 22 private const val DEFAULT_CACHE_SIZE: Int = 20 private const val DEFAULT_RETRIES: Long = 3 private const val MAX_SIZE: Int = 1024 diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt b/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt deleted file mode 100644 index d5b20d191..000000000 --- a/app/src/main/java/com/nextcloud/talk/interfaces/SelectionInterface.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.interfaces - -@Deprecated("To be replaced with com.nextcloud.talk.remotefilebrowser.SelectionInterface") -interface SelectionInterface { - fun toggleBrowserItemSelection(path: String) - - fun isPathSelected(path: String): Boolean - - fun shouldOnlySelectOneImageFile(): Boolean -} diff --git a/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt b/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt index 755380a6f..53a6372e9 100644 --- a/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt @@ -236,15 +236,13 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe viewModel.loadItems() } + override fun isPathSelected(path: String): Boolean { + return viewModel.isPathSelected(path) + } + companion object { private val TAG = RemoteFileBrowserActivity::class.simpleName const val SPAN_COUNT: Int = 4 const val EXTRA_SELECTED_PATHS = "EXTRA_SELECTED_PATH" - const val REQUEST_CODE_SELECT_AVATAR = 22 - } - - override fun isPathSelected(path: String): Boolean { - // TODO figure out a better way to do this. Narrower interface? - return viewModel.isPathSelected(path) } } diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/AttachmentDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/AttachmentDialog.kt index 77c5acbfb..c88db9ca6 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/AttachmentDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/AttachmentDialog.kt @@ -29,7 +29,6 @@ import android.view.ViewGroup import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.nextcloud.talk.R -import com.nextcloud.talk.components.filebrowser.controllers.BrowserController import com.nextcloud.talk.controllers.ChatController import com.nextcloud.talk.databinding.DialogAttachmentBinding import com.nextcloud.talk.models.database.CapabilitiesUtil @@ -76,7 +75,7 @@ class AttachmentDialog(val activity: Activity, var chatController: ChatControlle } dialogAttachmentBinding.menuAttachFileFromCloud.setOnClickListener { - chatController.showBrowserScreen(BrowserController.BrowserType.DAV_BROWSER) + chatController.showBrowserScreen() dismiss() } diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/SortingOrderDialogFragment.java b/app/src/main/java/com/nextcloud/talk/ui/dialog/SortingOrderDialogFragment.java index a8c901b90..f2d5c8d66 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/SortingOrderDialogFragment.java +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/SortingOrderDialogFragment.java @@ -37,7 +37,6 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.databinding.SortingOrderFragmentBinding; import com.nextcloud.talk.utils.FileSortOrder; -import com.nextcloud.talk.utils.LegacyFileSortOrder; import com.nextcloud.talk.utils.preferences.AppPreferences; import org.jetbrains.annotations.NotNull; @@ -70,17 +69,6 @@ public class SortingOrderDialogFragment extends DialogFragment implements View.O private View[] taggedViews; private String currentSortOrderName; - @Deprecated - public static SortingOrderDialogFragment newInstance(LegacyFileSortOrder sortOrder) { - SortingOrderDialogFragment dialogFragment = new SortingOrderDialogFragment(); - - Bundle args = new Bundle(); - args.putString(KEY_SORT_ORDER, sortOrder.name); - dialogFragment.setArguments(args); - - return dialogFragment; - } - public static SortingOrderDialogFragment newInstance(@NotNull FileSortOrder sortOrder) { SortingOrderDialogFragment dialogFragment = new SortingOrderDialogFragment(); diff --git a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java index c5baf6ffd..526b09c04 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java @@ -110,12 +110,12 @@ import androidx.core.graphics.ColorUtils; import androidx.core.graphics.drawable.DrawableCompat; import androidx.emoji.text.EmojiCompat; -import static com.nextcloud.talk.utils.LegacyFileSortOrder.sort_a_to_z_id; -import static com.nextcloud.talk.utils.LegacyFileSortOrder.sort_big_to_small_id; -import static com.nextcloud.talk.utils.LegacyFileSortOrder.sort_new_to_old_id; -import static com.nextcloud.talk.utils.LegacyFileSortOrder.sort_old_to_new_id; -import static com.nextcloud.talk.utils.LegacyFileSortOrder.sort_small_to_big_id; -import static com.nextcloud.talk.utils.LegacyFileSortOrder.sort_z_to_a_id; +import static com.nextcloud.talk.utils.FileSortOrder.sort_a_to_z_id; +import static com.nextcloud.talk.utils.FileSortOrder.sort_big_to_small_id; +import static com.nextcloud.talk.utils.FileSortOrder.sort_new_to_old_id; +import static com.nextcloud.talk.utils.FileSortOrder.sort_old_to_new_id; +import static com.nextcloud.talk.utils.FileSortOrder.sort_small_to_big_id; +import static com.nextcloud.talk.utils.FileSortOrder.sort_z_to_a_id; public class DisplayUtils { @@ -617,26 +617,6 @@ public class DisplayUtils { targetView.setController(newController); } - @Deprecated - public static @StringRes - int getSortOrderStringId(LegacyFileSortOrder sortOrder) { - switch (sortOrder.name) { - case sort_z_to_a_id: - return R.string.menu_item_sort_by_name_z_a; - case sort_new_to_old_id: - return R.string.menu_item_sort_by_date_newest_first; - case sort_old_to_new_id: - return R.string.menu_item_sort_by_date_oldest_first; - case sort_big_to_small_id: - return R.string.menu_item_sort_by_size_biggest_first; - case sort_small_to_big_id: - return R.string.menu_item_sort_by_size_smallest_first; - case sort_a_to_z_id: - default: - return R.string.menu_item_sort_by_name_a_z; - } - } - public static @StringRes int getSortOrderStringId(FileSortOrder sortOrder) { switch (sortOrder.getName()) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrder.kt b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrder.kt index 9519874a7..53511b7a6 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrder.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrder.kt @@ -25,9 +25,6 @@ import android.text.TextUtils import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem import java.util.Collections -/** - * Sort order - */ open class FileSortOrder(var name: String, var isAscending: Boolean) { companion object { const val sort_a_to_z_id = "sort_a_to_z" diff --git a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByDate.kt b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByDate.kt index c6d66d6ed..f7bcc5e05 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByDate.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByDate.kt @@ -24,9 +24,6 @@ package com.nextcloud.talk.utils import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem import java.util.Collections -/** - * Created by srkunze on 28.08.17. - */ class FileSortOrderByDate internal constructor(name: String, ascending: Boolean) : FileSortOrder(name, ascending) { /** * Sorts list by Date. diff --git a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByName.kt b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByName.kt index 8062b8a8d..4c5535938 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByName.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByName.kt @@ -25,9 +25,6 @@ import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem import third_parties.daveKoeller.AlphanumComparator import java.util.Collections -/** - * Created by srkunze on 28.08.17. - */ class FileSortOrderByName internal constructor(name: String, ascending: Boolean) : FileSortOrder(name, ascending) { /** * Sorts list by Name. @@ -46,13 +43,14 @@ class FileSortOrderByName internal constructor(name: String, ascending: Boolean) override fun compare(left: RemoteFileBrowserItem, right: RemoteFileBrowserItem): Int { return if (!left.isFile && !right.isFile) { - return multiplier * AlphanumComparator().compare(left, right) + return multiplier * AlphanumComparator() + .compareRemoteFileBrowserItem(left, right) } else if (!left.isFile) { -1 } else if (!right.isFile) { 1 } else { - multiplier * AlphanumComparator().compare(left, right) + multiplier * AlphanumComparator().compareRemoteFileBrowserItem(left, right) } } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderBySize.kt b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderBySize.kt index d0390251d..9beab94a4 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderBySize.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/FileSortOrderBySize.kt @@ -24,9 +24,6 @@ package com.nextcloud.talk.utils import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem import java.util.Collections -/** - * Sorts files by sizes - */ class FileSortOrderBySize internal constructor(name: String, ascending: Boolean) : FileSortOrder(name, ascending) { /** * Sorts list by Size. diff --git a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrder.java b/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrder.java deleted file mode 100644 index ada429d78..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrder.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Sven R. Kunze - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017 Sven R. Kunze - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.utils; - -import android.text.TextUtils; - -import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import androidx.annotation.Nullable; - -/** - * Sort order - */ -@Deprecated -public class LegacyFileSortOrder { - public static final String sort_a_to_z_id = "sort_a_to_z"; - public static final String sort_z_to_a_id = "sort_z_to_a"; - public static final String sort_old_to_new_id = "sort_old_to_new"; - public static final String sort_new_to_old_id = "sort_new_to_old"; - public static final String sort_small_to_big_id = "sort_small_to_big"; - public static final String sort_big_to_small_id = "sort_big_to_small"; - - public static final LegacyFileSortOrder sort_a_to_z = new LegacyFileSortOrderByName(sort_a_to_z_id, true); - public static final LegacyFileSortOrder sort_z_to_a = new LegacyFileSortOrderByName(sort_z_to_a_id, false); - public static final LegacyFileSortOrder sort_old_to_new = new LegacyFileSortOrderByDate(sort_old_to_new_id, true); - public static final LegacyFileSortOrder sort_new_to_old = new LegacyFileSortOrderByDate(sort_new_to_old_id, false); - public static final LegacyFileSortOrder sort_small_to_big = new LegacyFileSortOrderBySize(sort_small_to_big_id, true); - public static final LegacyFileSortOrder sort_big_to_small = new LegacyFileSortOrderBySize(sort_big_to_small_id, false); - - public static final Map sortOrders; - - static { - HashMap temp = new HashMap<>(); - temp.put(sort_a_to_z.name, sort_a_to_z); - temp.put(sort_z_to_a.name, sort_z_to_a); - temp.put(sort_old_to_new.name, sort_old_to_new); - temp.put(sort_new_to_old.name, sort_new_to_old); - temp.put(sort_small_to_big.name, sort_small_to_big); - temp.put(sort_big_to_small.name, sort_big_to_small); - - sortOrders = Collections.unmodifiableMap(temp); - } - - public String name; - public boolean isAscending; - - public LegacyFileSortOrder(String name, boolean ascending) { - this.name = name; - isAscending = ascending; - } - - public static LegacyFileSortOrder getFileSortOrder(@Nullable String key) { - if (TextUtils.isEmpty(key) || !sortOrders.containsKey(key)) { - return sort_a_to_z; - } else { - return sortOrders.get(key); - } - } - - public List sortCloudFiles(List files) { - return sortCloudFilesByFavourite(files); - } - - /** - * Sorts list by Favourites. - * - * @param files files to sort - */ - public static List sortCloudFilesByFavourite(List files) { - Collections.sort(files, (o1, o2) -> { - if (o1.getModel().isFavorite() && o2.getModel().isFavorite()) { - return 0; - } else if (o1.getModel().isFavorite()) { - return -1; - } else if (o2.getModel().isFavorite()) { - return 1; - } - return 0; - }); - - return files; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByDate.java b/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByDate.java deleted file mode 100644 index 774d27d59..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByDate.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Sven R. Kunze - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017 Sven R. Kunze - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.utils; - -import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem; - -import java.util.Collections; -import java.util.List; - -/** - * Created by srkunze on 28.08.17. - */ -@Deprecated -public class LegacyFileSortOrderByDate extends LegacyFileSortOrder { - - LegacyFileSortOrderByDate(String name, boolean ascending) { - super(name, ascending); - } - - /** - * Sorts list by Date. - * - * @param files list of files to sort - */ - public List sortCloudFiles(List files) { - final int multiplier = isAscending ? 1 : -1; - - Collections.sort(files, (o1, o2) -> - multiplier * Long.compare(o1.getModel().getModifiedTimestamp(), o2.getModel().getModifiedTimestamp())); - - return super.sortCloudFiles(files); - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByName.java b/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByName.java deleted file mode 100644 index d3b7befe7..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderByName.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Sven R. Kunze - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017 Sven R. Kunze - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.utils; - -import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem; - -import java.util.Collections; -import java.util.List; - -import third_parties.daveKoeller.AlphanumComparator; - -/** - * Created by srkunze on 28.08.17. - */ -@Deprecated -public class LegacyFileSortOrderByName extends LegacyFileSortOrder { - - LegacyFileSortOrderByName(String name, boolean ascending) { - super(name, ascending); - } - - /** - * Sorts list by Name. - * - * @param files files to sort - */ - @SuppressWarnings("Bx") - public List sortCloudFiles(List files) { - final int multiplier = isAscending ? 1 : -1; - - Collections.sort(files, (o1, o2) -> { - if (!o1.getModel().isFile() && !o2.getModel().isFile()) { - return multiplier * new AlphanumComparator().compare(o1, o2); - } else if (!o1.getModel().isFile()) { - return -1; - } else if (!o2.getModel().isFile()) { - return 1; - } - return multiplier * new AlphanumComparator().compare(o1, o2); - }); - - return super.sortCloudFiles(files); - } -} diff --git a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderBySize.java b/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderBySize.java deleted file mode 100644 index 80829c751..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/LegacyFileSortOrderBySize.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Sven R. Kunze - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017 Sven R. Kunze - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.utils; - -import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem; - -import java.util.Collections; -import java.util.List; - -/** - * Sorts files by sizes - */ -@Deprecated -public class LegacyFileSortOrderBySize extends LegacyFileSortOrder { - - LegacyFileSortOrderBySize(String name, boolean ascending) { - super(name, ascending); - } - - /** - * Sorts list by Size. - * - * @param files list of files to sort - */ - public List sortCloudFiles(List files) { - final int multiplier = isAscending ? 1 : -1; - - Collections.sort(files, (o1, o2) -> { - if (!o1.getModel().isFile() && !o2.getModel().isFile()) { - return multiplier * Long.compare(o1.getModel().getSize(), o2.getModel().getSize()); - } else if (!o1.getModel().isFile()) { - return -1; - } else if (!o2.getModel().isFile()) { - return 1; - } else { - return multiplier * Long.compare(o1.getModel().getSize(), o2.getModel().getSize()); - } - }); - - return super.sortCloudFiles(files); - } -} diff --git a/app/src/main/java/third_parties/daveKoeller/AlphanumComparator.java b/app/src/main/java/third_parties/daveKoeller/AlphanumComparator.java index af25c47b2..9f7025136 100644 --- a/app/src/main/java/third_parties/daveKoeller/AlphanumComparator.java +++ b/app/src/main/java/third_parties/daveKoeller/AlphanumComparator.java @@ -24,9 +24,8 @@ package third_parties.daveKoeller; -import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem; +import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem; -import java.io.File; import java.io.Serializable; import java.math.BigInteger; import java.text.Collator; @@ -87,9 +86,9 @@ public class AlphanumComparator implements Comparator, Serializable { return chunk.toString(); } - public int compare(BrowserFileItem f1, BrowserFileItem f2) { - String s1 = f1.getModel().getPath(); - String s2 = f2.getModel().getPath(); + public int compareRemoteFileBrowserItem(RemoteFileBrowserItem f1, RemoteFileBrowserItem f2) { + String s1 = f1.getPath(); + String s2 = f2.getPath(); return compare(s1, s2); } diff --git a/app/src/main/res/layout/controller_browser.xml b/app/src/main/res/layout/controller_browser.xml deleted file mode 100644 index 0fc96eb12..000000000 --- a/app/src/main/res/layout/controller_browser.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/rv_item_browser_file_old.xml b/app/src/main/res/layout/rv_item_browser_file_old.xml deleted file mode 100644 index dfc50383f..000000000 --- a/app/src/main/res/layout/rv_item_browser_file_old.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/file_browser_path.xml b/app/src/main/res/menu/file_browser_path.xml deleted file mode 100644 index 67c6dfd52..000000000 --- a/app/src/main/res/menu/file_browser_path.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - \ No newline at end of file