replace share files remote item chooser with new implementation and remove any legacy implementation

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-06-08 23:24:20 +02:00
parent 41694b64bb
commit df61a4df87
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
25 changed files with 58 additions and 1420 deletions

View file

@ -1,210 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<BrowserFileItem.BrowserFileItemViewHolder> implements IFilterable<String> {
@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<IFlexible> adapter) {
return new BrowserFileItemViewHolder(view, adapter);
}
private boolean isSelected() {
return selected;
}
private void setSelected(boolean selected) {
this.selected = selected;
}
@Override
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter,
BrowserFileItemViewHolder holder,
int position,
List<Object> 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);
}
}
}

View file

@ -1,344 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<String>
@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<BrowserFileItem>? = null
private var recyclerViewItems: List<BrowserFileItem> = ArrayList()
private var listingAbstractClass: ListingAbstractClass? = null
private val browserType: BrowserType
private var currentPath: String
private var sortingChangeListener: OnPreferenceValueChangedListener<String>? = 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<BrowserFile>
currentPath = objectList[0].path!!
if (activity != null) {
activity!!.runOnUiThread { setTitle() }
}
for (i in 1 until objectList.size) {
(recyclerViewItems as ArrayList<BrowserFileItem>).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<String> {
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"
}
}

View file

@ -1,80 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Tobias Kaminsky
* Copyright (C) 2021 Tobias Kaminsky <tobias.kaminsky@nextcloud.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<String> iterator = selectedPaths.iterator();
List<String> 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;
}
}

View file

@ -1,27 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.components.filebrowser.interfaces;
import com.nextcloud.talk.components.filebrowser.models.DavResponse;
public interface ListingInterface {
void listingResult(DavResponse davResponse);
}

View file

@ -1,81 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<ReadFilesystemOperation>() {
@Override
public ReadFilesystemOperation call() {
return new ReadFilesystemOperation(okHttpClient, currentUser, path, 1);
}
}).subscribeOn(Schedulers.io())
.subscribe(new SingleObserver<ReadFilesystemOperation>() {
@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);
}
});
}
}

View file

@ -1,48 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -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<String?> = 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<BrowserController.BrowserType>(browserType))
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap<UserEntity>(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

View file

@ -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

View file

@ -1,30 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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
}

View file

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

View file

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

View file

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

View file

@ -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()) {

View file

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

View file

@ -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.

View file

@ -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<Any?>().compare(left, right)
return multiplier * AlphanumComparator<RemoteFileBrowserItem>()
.compareRemoteFileBrowserItem(left, right)
} else if (!left.isFile) {
-1
} else if (!right.isFile) {
1
} else {
multiplier * AlphanumComparator<Any?>().compare(left, right)
multiplier * AlphanumComparator<RemoteFileBrowserItem>().compareRemoteFileBrowserItem(left, right)
}
}
}

View file

@ -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.

View file

@ -1,108 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Sven R. Kunze
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* 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 <http://www.gnu.org/licenses/>.
*/
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<String, LegacyFileSortOrder> sortOrders;
static {
HashMap<String, LegacyFileSortOrder> 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<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> files) {
return sortCloudFilesByFavourite(files);
}
/**
* Sorts list by Favourites.
*
* @param files files to sort
*/
public static List<BrowserFileItem> sortCloudFilesByFavourite(List<BrowserFileItem> 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;
}
}

View file

@ -1,53 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Sven R. Kunze
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* 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 <http://www.gnu.org/licenses/>.
*/
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<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> 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);
}
}

View file

@ -1,64 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Sven R. Kunze
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* 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 <http://www.gnu.org/licenses/>.
*/
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<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> 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);
}
}

View file

@ -1,62 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Sven R. Kunze
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* 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 <http://www.gnu.org/licenses/>.
*/
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<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> 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);
}
}

View file

@ -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<T> implements Comparator<T>, 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);
}

View file

@ -1,100 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ @author Andy Scherzinger
~ Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ 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 <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_default"
android:orientation="vertical">
<!-- sorting/layout bar -->
<RelativeLayout
android:id="@+id/sort_list_button_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/appbar"
android:visibility="visible"
tools:visibility="visible">
<com.google.android.material.button.MaterialButton
android:id="@+id/sort_button"
style="@style/Nextcloud.Material.TextButton"
android:layout_width="wrap_content"
android:layout_height="@dimen/min_size_clickable_area"
android:layout_marginStart="7dp"
android:contentDescription=""
android:text="@string/menu_item_sort_by_date_newest_first"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="@color/fontAppbar"
android:textSize="14sp"
app:icon="@drawable/ic_keyboard_arrow_down"
app:iconGravity="textEnd"
app:iconSize="16dp"
app:iconTint="@color/fontAppbar" />
<com.google.android.material.button.MaterialButton
android:id="@+id/switch_grid_view_button"
style="@style/Widget.AppTheme.Button.IconButton"
android:layout_width="@dimen/min_size_clickable_area"
android:layout_height="@dimen/min_size_clickable_area"
android:layout_marginEnd="1dp"
android:contentDescription=""
android:layout_alignEnd="@+id/sort_button"
android:layout_alignParentEnd="true"
android:visibility="invisible"
app:cornerRadius="24dp"
app:icon="@drawable/ic_search_grey"
app:iconTint="@color/fontAppbar" />
</RelativeLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/path_navigation"
style="@style/BottomNavigationView"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_below="@id/sort_list_button_group"
android:layout_marginTop="-1dp"
android:background="@color/bg_default"
app:itemIconTint="@color/fg_default"
app:itemTextColor="@color/fg_default"
app:menu="@menu/file_browser_path" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/path_navigation"
android:footerDividersEnabled="false">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/rv_item_browser_file_old" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>

View file

@ -1,105 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ 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 <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_margin"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin"
android:background="@color/bg_default">
<CheckBox
android:id="@+id/select_file_checkbox"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:longClickable="false"
android:visibility="visible" />
<ImageView
android:id="@+id/fileFavoriteImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_below="@id/file_icon"
android:layout_alignEnd="@id/file_icon"
android:contentDescription="@string/starred"
android:src="@drawable/ic_star_black_24dp"
app:tint="@color/favorite_icon_tint" />
<ImageView
android:id="@+id/fileEncryptedImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_below="@id/file_icon"
android:layout_alignStart="@+id/file_icon"
android:contentDescription="@string/encrypted"
android:src="@drawable/ic_lock_grey600_24px" />
<TextView
android:id="@+id/file_modified_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/filename_text_view"
android:layout_alignParentBottom="true"
android:layout_toStartOf="@id/select_file_checkbox"
android:layout_toEndOf="@id/file_icon"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"
android:paddingBottom="6dp"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="@color/textColorMaxContrast"
android:textSize="14sp"
tools:text="3 minutes ago" />
<TextView
android:id="@+id/filename_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true"
android:layout_toStartOf="@id/select_file_checkbox"
android:layout_toEndOf="@id/file_icon"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"
android:paddingTop="6dp"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="@color/conversation_item_header"
android:textSize="@dimen/two_line_primary_text_size"
tools:text="filename.md" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/file_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/standard_margin"
app:actualImageScaleType="fitCenter"
app:placeholderImageScaleType="fitCenter" />
</RelativeLayout>

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ 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 <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_back"
android:icon="@drawable/ic_arrow_back_black_24dp"
android:enabled="false"
android:title="@string/nc_file_browser_back"/>
</menu>