فهرست منبع

Merge pull request #12133 from nextcloud/refactor/convert-TrashbinActivity-to-kt

Convert TrashbinActivity to Kotlin
Andy Scherzinger 1 سال پیش
والد
کامیت
aaf0fb27dc

+ 1 - 1
app/src/androidTest/java/com/owncloud/android/ui/trashbin/TrashbinLocalRepository.kt

@@ -26,7 +26,7 @@ import com.owncloud.android.R
 import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
 import com.owncloud.android.ui.trashbin.TrashbinRepository.LoadFolderCallback
 
-class TrashbinLocalRepository(val testCase: TrashbinActivityIT.TestCase) : TrashbinRepository {
+class TrashbinLocalRepository(private val testCase: TrashbinActivityIT.TestCase) : TrashbinRepository {
     override fun emptyTrashbin(callback: TrashbinRepository.OperationCallback?) {
         TODO("Not yet implemented")
     }

+ 0 - 227
app/src/main/java/com/owncloud/android/ui/trashbin/RemoteTrashbinRepository.java

@@ -1,227 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * @author TSI-mc
- * @author Chris Narkiewicz
- *
- * Copyright (C) 2018 Tobias Kaminsky
- * Copyright (C) 2018 Nextcloud GmbH.
- * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
- * Copyright (C) 2023 TSI-mc
- *
- * 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 <https://www.gnu.org/licenses/>.
- */
-package com.owncloud.android.ui.trashbin;
-
-import android.os.AsyncTask;
-
-import com.nextcloud.client.account.User;
-import com.nextcloud.client.network.ClientFactory;
-import com.nextcloud.common.NextcloudClient;
-import com.owncloud.android.R;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.trashbin.EmptyTrashbinRemoteOperation;
-import com.owncloud.android.lib.resources.trashbin.ReadTrashbinFolderRemoteOperation;
-import com.owncloud.android.lib.resources.trashbin.RemoveTrashbinFileRemoteOperation;
-import com.owncloud.android.lib.resources.trashbin.RestoreTrashbinFileRemoteOperation;
-import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
-
-import java.util.List;
-
-import androidx.annotation.NonNull;
-
-public class RemoteTrashbinRepository implements TrashbinRepository {
-
-    private final User user;
-    private final ClientFactory clientFactory;
-
-    RemoteTrashbinRepository(User user, ClientFactory clientFactory) {
-        this.user = user;
-        this.clientFactory = clientFactory;
-    }
-
-    public void removeTrashbinFile(TrashbinFile file, OperationCallback callback) {
-        new RemoveTrashbinFileTask(user, clientFactory, file, callback).execute();
-    }
-
-    private static class RemoveTrashbinFileTask extends AsyncTask<Void, Void, Boolean> {
-
-        private User user;
-        private ClientFactory clientFactory;
-        private TrashbinFile file;
-        private OperationCallback callback;
-
-        private RemoveTrashbinFileTask(User user,
-                                       ClientFactory clientFactory,
-                                       TrashbinFile file,
-                                       OperationCallback callback) {
-            this.user = user;
-            this.clientFactory = clientFactory;
-            this.file = file;
-            this.callback = callback;
-        }
-
-        @Override
-        protected Boolean doInBackground(Void... voids) {
-            try {
-                OwnCloudClient client = clientFactory.create(user);
-                RemoteOperationResult result = new RemoveTrashbinFileRemoteOperation(file.getFullRemotePath())
-                    .execute(client);
-                return result.isSuccess();
-            } catch (ClientFactory.CreationException e) {
-                Log_OC.e(this, "Cannot create client", e);
-                return Boolean.FALSE;
-            }
-        }
-
-        @Override
-        protected void onPostExecute(Boolean success) {
-            super.onPostExecute(success);
-
-            callback.onResult(success);
-        }
-    }
-
-    public void emptyTrashbin(OperationCallback callback) {
-        new EmptyTrashbinTask(user, clientFactory, callback).execute();
-    }
-
-    private static class EmptyTrashbinTask extends AsyncTask<Void, Void, Boolean> {
-
-        private User user;
-        private ClientFactory clientFactory;
-        private OperationCallback callback;
-
-        private EmptyTrashbinTask(User user, ClientFactory clientFactory, OperationCallback callback) {
-            this.user = user;
-            this.clientFactory = clientFactory;
-            this.callback = callback;
-        }
-
-        @Override
-        protected Boolean doInBackground(Void... voids) {
-            try {
-                NextcloudClient client = clientFactory.createNextcloudClient(user);
-                EmptyTrashbinRemoteOperation emptyTrashbinFileOperation = new EmptyTrashbinRemoteOperation();
-                RemoteOperationResult<Boolean> result = emptyTrashbinFileOperation.execute(client);
-                return result.isSuccess();
-            } catch (ClientFactory.CreationException e) {
-                Log_OC.e(this, "Cannot create client", e);
-                return Boolean.FALSE;
-            }
-        }
-
-        @Override
-        protected void onPostExecute(Boolean success) {
-            super.onPostExecute(success);
-
-            callback.onResult(success);
-        }
-    }
-
-    @Override
-    public void restoreFile(TrashbinFile file, OperationCallback callback) {
-        new RestoreTrashbinFileTask(file, user, clientFactory, callback).execute();
-    }
-
-    private static class RestoreTrashbinFileTask extends AsyncTask<Void, Void, Boolean> {
-
-        private TrashbinFile file;
-        private User user;
-        private ClientFactory clientFactory;
-        private TrashbinRepository.OperationCallback callback;
-
-        private RestoreTrashbinFileTask(TrashbinFile file, User user, ClientFactory clientFactory,
-                                        TrashbinRepository.OperationCallback callback) {
-            this.file = file;
-            this.user = user;
-            this.clientFactory = clientFactory;
-            this.callback = callback;
-        }
-
-        @Override
-        protected Boolean doInBackground(Void... voids) {
-            try {
-                OwnCloudClient client = clientFactory.create(user);
-                RemoteOperationResult result = new RestoreTrashbinFileRemoteOperation(file.getFullRemotePath(),
-                                                                                      file.getFileName()).execute(client);
-
-                return result.isSuccess();
-            } catch (ClientFactory.CreationException e) {
-                Log_OC.e(this, "Cannot create client", e);
-                return Boolean.FALSE;
-            }
-        }
-
-        @Override
-        protected void onPostExecute(Boolean success) {
-            super.onPostExecute(success);
-
-            callback.onResult(success);
-        }
-    }
-
-    @Override
-    public void getFolder(String remotePath, @NonNull LoadFolderCallback callback) {
-        new ReadRemoteTrashbinFolderTask(remotePath, user, clientFactory, callback).execute();
-    }
-
-    private static class ReadRemoteTrashbinFolderTask extends AsyncTask<Void, Void, Boolean> {
-
-        private String remotePath;
-        private User user;
-        private ClientFactory clientFactory;
-        private List<TrashbinFile> trashbinFiles;
-        private LoadFolderCallback callback;
-
-        private ReadRemoteTrashbinFolderTask(String remotePath, User user, ClientFactory clientFactory,
-                                             LoadFolderCallback callback) {
-            this.remotePath = remotePath;
-            this.user = user;
-            this.clientFactory = clientFactory;
-            this.callback = callback;
-        }
-
-        @Override
-        protected Boolean doInBackground(Void... voids) {
-            try {
-                OwnCloudClient client = clientFactory.create(user);
-                RemoteOperationResult<List<TrashbinFile>> result =
-                    new ReadTrashbinFolderRemoteOperation(remotePath).execute(client);
-                if (result.isSuccess()) {
-                    trashbinFiles = result.getResultData();
-                    return Boolean.TRUE;
-                } else {
-                    return Boolean.FALSE;
-                }
-            } catch (ClientFactory.CreationException e) {
-                return Boolean.FALSE;
-            }
-        }
-
-        @Override
-        protected void onPostExecute(Boolean success) {
-            super.onPostExecute(success);
-
-            if (success) {
-                callback.onSuccess(trashbinFiles);
-            } else {
-                callback.onError(R.string.trashbin_loading_failed);
-            }
-        }
-    }
-}

+ 182 - 0
app/src/main/java/com/owncloud/android/ui/trashbin/RemoteTrashbinRepository.kt

@@ -0,0 +1,182 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * @author TSI-mc
+ * @author Chris Narkiewicz
+ *
+ * Copyright (C) 2018 Tobias Kaminsky
+ * Copyright (C) 2018 Nextcloud GmbH.
+ * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
+ * Copyright (C) 2023 TSI-mc
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+@file:Suppress("DEPRECATION")
+
+package com.owncloud.android.ui.trashbin
+
+import android.os.AsyncTask
+import com.nextcloud.client.account.User
+import com.nextcloud.client.network.ClientFactory
+import com.nextcloud.client.network.ClientFactory.CreationException
+import com.owncloud.android.R
+import com.owncloud.android.lib.common.utils.Log_OC
+import com.owncloud.android.lib.resources.trashbin.EmptyTrashbinRemoteOperation
+import com.owncloud.android.lib.resources.trashbin.ReadTrashbinFolderRemoteOperation
+import com.owncloud.android.lib.resources.trashbin.RemoveTrashbinFileRemoteOperation
+import com.owncloud.android.lib.resources.trashbin.RestoreTrashbinFileRemoteOperation
+import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
+import com.owncloud.android.ui.trashbin.TrashbinRepository.LoadFolderCallback
+import com.owncloud.android.ui.trashbin.TrashbinRepository.OperationCallback
+
+class RemoteTrashbinRepository internal constructor(private val user: User, private val clientFactory: ClientFactory) :
+    TrashbinRepository {
+
+    override fun removeTrashbinFile(file: TrashbinFile?, callback: OperationCallback?) {
+        RemoveTrashbinFileTask(user, clientFactory, file, callback).execute()
+    }
+
+    private class RemoveTrashbinFileTask(
+        private val user: User,
+        private val clientFactory: ClientFactory,
+        private val file: TrashbinFile?,
+        private val callback: OperationCallback?
+    ) : AsyncTask<Void?, Void?, Boolean>() {
+
+        @Deprecated("Deprecated in Java")
+        override fun doInBackground(vararg voids: Void?): Boolean {
+            return try {
+                val client = clientFactory.create(user)
+                val result = RemoveTrashbinFileRemoteOperation(file!!.fullRemotePath)
+                    .execute(client)
+                result.isSuccess
+            } catch (e: CreationException) {
+                Log_OC.e(this, "Cannot create client", e)
+                false
+            }
+        }
+
+        @Deprecated("Deprecated in Java")
+        override fun onPostExecute(success: Boolean) {
+            super.onPostExecute(success)
+            callback?.onResult(success)
+        }
+    }
+
+    override fun emptyTrashbin(callback: OperationCallback?) {
+        EmptyTrashbinTask(user, clientFactory, callback).execute()
+    }
+
+    private class EmptyTrashbinTask(
+        private val user: User,
+        private val clientFactory: ClientFactory,
+        private val callback: OperationCallback?
+    ) : AsyncTask<Void?, Void?, Boolean>() {
+
+        @Deprecated("Deprecated in Java")
+        override fun doInBackground(vararg voids: Void?): Boolean {
+            return try {
+                val client = clientFactory.createNextcloudClient(user)
+                val emptyTrashbinFileOperation = EmptyTrashbinRemoteOperation()
+                val result = emptyTrashbinFileOperation.execute(client)
+                result.isSuccess
+            } catch (e: CreationException) {
+                Log_OC.e(this, "Cannot create client", e)
+                false
+            }
+        }
+
+        @Deprecated("Deprecated in Java")
+        override fun onPostExecute(success: Boolean) {
+            super.onPostExecute(success)
+            callback?.onResult(success)
+        }
+    }
+
+    override fun restoreFile(file: TrashbinFile?, callback: OperationCallback?) {
+        RestoreTrashbinFileTask(file, user, clientFactory, callback).execute()
+    }
+
+    private class RestoreTrashbinFileTask(
+        private val file: TrashbinFile?,
+        private val user: User,
+        private val clientFactory: ClientFactory,
+        private val callback: OperationCallback?
+    ) : AsyncTask<Void?, Void?, Boolean>() {
+
+        @Deprecated("Deprecated in Java")
+        override fun doInBackground(vararg voids: Void?): Boolean {
+            return try {
+                val client = clientFactory.create(user)
+                val result = RestoreTrashbinFileRemoteOperation(
+                    file!!.fullRemotePath,
+                    file.fileName
+                ).execute(client)
+                result.isSuccess
+            } catch (e: CreationException) {
+                Log_OC.e(this, "Cannot create client", e)
+                false
+            }
+        }
+
+        @Deprecated("Deprecated in Java")
+        override fun onPostExecute(success: Boolean) {
+            super.onPostExecute(success)
+            callback?.onResult(success)
+        }
+    }
+
+    override fun getFolder(remotePath: String?, callback: LoadFolderCallback?) {
+        callback?.let {
+            ReadRemoteTrashbinFolderTask(remotePath, user, clientFactory, it).execute()
+        }
+    }
+
+    private class ReadRemoteTrashbinFolderTask(
+        private val remotePath: String?,
+        private val user: User,
+        private val clientFactory: ClientFactory,
+        private val callback: LoadFolderCallback
+    ) : AsyncTask<Void?, Void?, Boolean>() {
+        private var trashbinFiles: List<TrashbinFile?>? = null
+
+        @Deprecated("Deprecated in Java")
+        override fun doInBackground(vararg voids: Void?): Boolean {
+            return try {
+                val client = clientFactory.create(user)
+                val result = ReadTrashbinFolderRemoteOperation(remotePath).execute(client)
+                if (result.isSuccess) {
+                    trashbinFiles = result.resultData
+                    true
+                } else {
+                    false
+                }
+            } catch (e: CreationException) {
+                false
+            }
+        }
+
+        @Deprecated("Deprecated in Java")
+        override fun onPostExecute(success: Boolean) {
+            super.onPostExecute(success)
+
+            if (success) {
+                callback.onSuccess(trashbinFiles)
+            } else {
+                callback.onError(R.string.trashbin_loading_failed)
+            }
+        }
+    }
+}

+ 0 - 334
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java

@@ -1,334 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * @author Chris Narkiewicz
- *
- * Copyright (C) 2018 Tobias Kaminsky
- * Copyright (C) 2018 Nextcloud GmbH.
- * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.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 <https://www.gnu.org/licenses/>.
- */
-package com.owncloud.android.ui.trashbin;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.PopupMenu;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.google.android.material.snackbar.Snackbar;
-import com.nextcloud.client.account.CurrentAccountProvider;
-import com.nextcloud.client.account.User;
-import com.nextcloud.client.di.Injectable;
-import com.nextcloud.client.network.ClientFactory;
-import com.nextcloud.client.preferences.AppPreferences;
-import com.nextcloud.java.util.Optional;
-import com.owncloud.android.R;
-import com.owncloud.android.databinding.TrashbinActivityBinding;
-import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
-import com.owncloud.android.ui.EmptyRecyclerView;
-import com.owncloud.android.ui.activity.DrawerActivity;
-import com.owncloud.android.ui.adapter.TrashbinListAdapter;
-import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
-import com.owncloud.android.ui.interfaces.TrashbinActivityInterface;
-import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.FileSortOrder;
-import com.owncloud.android.utils.theme.ViewThemeUtils;
-
-import java.util.List;
-
-import javax.inject.Inject;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.core.content.res.ResourcesCompat;
-import androidx.recyclerview.widget.LinearLayoutManager;
-
-import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment;
-
-/**
- * Presenting trashbin data, received from presenter
- */
-public class TrashbinActivity extends DrawerActivity implements
-    TrashbinActivityInterface,
-    SortingOrderDialogFragment.OnSortingOrderListener,
-    TrashbinContract.View,
-    Injectable {
-
-    public static final int EMPTY_LIST_COUNT = 1;
-    @Inject AppPreferences preferences;
-    @Inject CurrentAccountProvider accountProvider;
-    @Inject ClientFactory clientFactory;
-    @Inject ViewThemeUtils viewThemeUtils;
-
-    private TrashbinListAdapter trashbinListAdapter;
-
-    @VisibleForTesting
-    TrashbinPresenter trashbinPresenter;
-
-    private boolean active;
-    private TrashbinActivityBinding binding;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        final User currentUser = getUser().orElse(accountProvider.getUser());
-        final String targetAccount = getIntent().getStringExtra(Intent.EXTRA_USER);
-        if (targetAccount != null && !currentUser.nameEquals(targetAccount)) {
-            final Optional<User> targetUser = getUserAccountManager().getUser(targetAccount);
-            if (targetUser.isPresent()) {
-                setUser(targetUser.get());
-            } else {
-                Toast.makeText(this, R.string.associated_account_not_found, Toast.LENGTH_LONG).show();
-                finish();
-                return;
-            }
-        }
-
-        final RemoteTrashbinRepository trashRepository =
-            new RemoteTrashbinRepository(getUser().orElse(accountProvider.getUser()), clientFactory);
-        trashbinPresenter = new TrashbinPresenter(trashRepository, this);
-
-        binding = TrashbinActivityBinding.inflate(getLayoutInflater());
-        setContentView(binding.getRoot());
-
-        setupToolbar();
-        findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE);
-        findViewById(R.id.switch_grid_view_button).setVisibility(View.GONE);
-        updateActionBarTitleAndHomeButtonByString(getString(R.string.trashbin_activity_title));
-        setupDrawer(R.id.nav_trashbin);
-    }
-
-    @Override
-    protected void onStart() {
-        super.onStart();
-        active = true;
-        setupContent();
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-
-        setDrawerMenuItemChecked(R.id.nav_trashbin);
-    }
-
-    private void setupContent() {
-        EmptyRecyclerView recyclerView = binding.list;
-        recyclerView.setEmptyView(binding.emptyList.emptyListView);
-        binding.emptyList.emptyListView.setVisibility(View.GONE);
-        binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_delete);
-        binding.emptyList.emptyListIcon.setVisibility(View.VISIBLE);
-        binding.emptyList.emptyListViewHeadline.setText(getString(R.string.trashbin_empty_headline));
-        binding.emptyList.emptyListViewText.setText(getString(R.string.trashbin_empty_message));
-        binding.emptyList.emptyListViewText.setVisibility(View.VISIBLE);
-
-        trashbinListAdapter = new TrashbinListAdapter(
-            this,
-            getStorageManager(),
-            preferences,
-            this,
-            getUser().orElse(accountProvider.getUser()),
-            viewThemeUtils
-        );
-        recyclerView.setAdapter(trashbinListAdapter);
-        recyclerView.setHasFixedSize(true);
-        recyclerView.setHasFooter(true);
-        recyclerView.setLayoutManager(new LinearLayoutManager(this));
-
-        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList);
-        binding.swipeContainingList.setOnRefreshListener(this::loadFolder);
-
-        viewThemeUtils.material.colorMaterialTextButton(findViewById(R.id.sort_button));
-
-        findViewById(R.id.sort_button).setOnClickListener(l ->
-                                                              openSortingOrderDialogFragment(getSupportFragmentManager(),
-                                                                                             preferences.getSortOrderByType(
-                                                                                                 FileSortOrder.Type.trashBinView,
-                                                                                                 FileSortOrder.sort_new_to_old))
-                                                         );
-
-        loadFolder();
-    }
-
-    protected void loadFolder() {
-        if (trashbinListAdapter.getItemCount() > EMPTY_LIST_COUNT) {
-            binding.swipeContainingList.setRefreshing(true);
-        } else {
-            showInitialLoading();
-        }
-        trashbinPresenter.loadFolder();
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        boolean retval = true;
-        int itemId = item.getItemId();
-        if (itemId == android.R.id.home) {
-            if (isDrawerOpen()) {
-                closeDrawer();
-            } else if (trashbinPresenter.isRoot()) {
-                onBackPressed();
-            } else {
-                openDrawer();
-            }
-        } else if (itemId == R.id.action_empty_trashbin) {
-            trashbinPresenter.emptyTrashbin();
-        } else {
-            retval = super.onOptionsItemSelected(item);
-        }
-
-        return retval;
-    }
-
-    @Override
-    public void onOverflowIconClicked(TrashbinFile file, View view) {
-        PopupMenu popup = new PopupMenu(this, view);
-        popup.inflate(R.menu.item_trashbin);
-
-        popup.setOnMenuItemClickListener(item -> {
-            trashbinPresenter.removeTrashbinFile(file);
-
-            return true;
-        });
-        popup.show();
-    }
-
-    @Override
-    public void onItemClicked(TrashbinFile file) {
-        if (file.isFolder()) {
-            trashbinPresenter.enterFolder(file.getRemotePath());
-
-            mDrawerToggle.setDrawerIndicatorEnabled(false);
-        }
-    }
-
-    @Override
-    public void onRestoreIconClicked(TrashbinFile file, View view) {
-        trashbinPresenter.restoreTrashbinFile(file);
-    }
-
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        getMenuInflater().inflate(R.menu.activity_trashbin, menu);
-
-        return true;
-    }
-
-    @Override
-    protected void onPause() {
-        super.onPause();
-        active = false;
-
-        trashbinListAdapter.cancelAllPendingTasks();
-    }
-
-    @Override
-    public void onBackPressed() {
-        trashbinPresenter.navigateUp();
-    }
-
-    public void close() {
-        super.onBackPressed();
-    }
-
-    public void setDrawerIndicatorEnabled(boolean bool) {
-        mDrawerToggle.setDrawerIndicatorEnabled(bool);
-    }
-
-
-    @Override
-    public void onSortingOrderChosen(FileSortOrder sortOrder) {
-        TextView sortButton = findViewById(R.id.sort_button);
-        sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder));
-        trashbinListAdapter.setSortOrder(sortOrder);
-    }
-
-    @Override
-    public void showTrashbinFolder(List<TrashbinFile> trashbinFiles) {
-        if (active) {
-            trashbinListAdapter.setTrashbinFiles(trashbinFiles, true);
-            binding.swipeContainingList.setRefreshing(false);
-            binding.loadingContent.setVisibility(View.GONE);
-            binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_delete);
-            binding.emptyList.emptyListViewHeadline.setText(getString(R.string.trashbin_empty_headline));
-            binding.emptyList.emptyListViewText.setText(getString(R.string.trashbin_empty_message));
-            binding.list.setVisibility(View.VISIBLE);
-        }
-    }
-
-    @Override
-    public void removeFile(TrashbinFile file) {
-        if (active) {
-            trashbinListAdapter.removeFile(file);
-        }
-    }
-
-    @Override
-    public void removeAllFiles() {
-        trashbinListAdapter.removeAllFiles();
-    }
-
-    @Override
-    public void showSnackbarError(int message, TrashbinFile file) {
-        if (active) {
-            binding.swipeContainingList.setRefreshing(false);
-            Snackbar.make(binding.list,
-                          String.format(getString(message), file.getFileName()), Snackbar.LENGTH_LONG)
-                .show();
-        }
-    }
-
-    @VisibleForTesting
-    public void showInitialLoading() {
-        binding.emptyList.emptyListView.setVisibility(View.GONE);
-        binding.list.setVisibility(View.GONE);
-        binding.loadingContent.setVisibility(View.VISIBLE);
-    }
-
-    @VisibleForTesting
-    public void showUser() {
-        binding.loadingContent.setVisibility(View.GONE);
-        binding.list.setVisibility(View.VISIBLE);
-        binding.swipeContainingList.setRefreshing(false);
-
-        binding.emptyList.emptyListViewText.setText(getUser().get().getAccountName());
-        binding.emptyList.emptyListViewText.setVisibility(View.VISIBLE);
-        binding.emptyList.emptyListView.setVisibility(View.VISIBLE);
-    }
-
-    @Override
-    public void showError(int message) {
-        if (active) {
-            trashbinListAdapter.removeAllFiles();
-            
-            binding.loadingContent.setVisibility(View.GONE);
-            binding.list.setVisibility(View.VISIBLE);
-            binding.swipeContainingList.setRefreshing(false);
-
-            binding.emptyList.emptyListViewHeadline.setText(R.string.common_error);
-            binding.emptyList.emptyListIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
-                                                                                         R.drawable.ic_list_empty_error,
-                                                                                         null));
-            binding.emptyList.emptyListViewText.setText(message);
-            binding.emptyList.emptyListViewText.setVisibility(View.VISIBLE);
-            binding.emptyList.emptyListIcon.setVisibility(View.VISIBLE);
-            binding.emptyList.emptyListView.setVisibility(View.VISIBLE);
-        }
-    }
-}

+ 340 - 0
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt

@@ -0,0 +1,340 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * @author Chris Narkiewicz
+ *
+ * Copyright (C) 2018 Tobias Kaminsky
+ * Copyright (C) 2018 Nextcloud GmbH.
+ * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.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 <https://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android.ui.trashbin
+
+import android.content.Intent
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import android.view.View
+import android.widget.PopupMenu
+import android.widget.TextView
+import android.widget.Toast
+import androidx.activity.OnBackPressedCallback
+import androidx.annotation.VisibleForTesting
+import androidx.core.content.res.ResourcesCompat
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.google.android.material.snackbar.Snackbar
+import com.nextcloud.client.account.CurrentAccountProvider
+import com.nextcloud.client.di.Injectable
+import com.nextcloud.client.network.ClientFactory
+import com.nextcloud.client.preferences.AppPreferences
+import com.owncloud.android.R
+import com.owncloud.android.databinding.TrashbinActivityBinding
+import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
+import com.owncloud.android.ui.activity.DrawerActivity
+import com.owncloud.android.ui.adapter.TrashbinListAdapter
+import com.owncloud.android.ui.dialog.SortingOrderDialogFragment.OnSortingOrderListener
+import com.owncloud.android.ui.interfaces.TrashbinActivityInterface
+import com.owncloud.android.utils.DisplayUtils
+import com.owncloud.android.utils.FileSortOrder
+import com.owncloud.android.utils.theme.ViewThemeUtils
+import javax.inject.Inject
+
+/**
+ * Presenting trashbin data, received from presenter
+ */
+class TrashbinActivity :
+    DrawerActivity(),
+    TrashbinActivityInterface,
+    OnSortingOrderListener,
+    TrashbinContract.View,
+    Injectable {
+
+    @JvmField
+    @Inject
+    var preferences: AppPreferences? = null
+
+    @JvmField
+    @Inject
+    var accountProvider: CurrentAccountProvider? = null
+
+    @JvmField
+    @Inject
+    var clientFactory: ClientFactory? = null
+
+    @JvmField
+    @Inject
+    var viewThemeUtils: ViewThemeUtils? = null
+
+    private var trashbinListAdapter: TrashbinListAdapter? = null
+
+    @VisibleForTesting
+    var trashbinPresenter: TrashbinPresenter? = null
+
+    private var active = false
+    private lateinit var binding: TrashbinActivityBinding
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        val currentUser = user.orElse(accountProvider!!.user)
+        val targetAccount = intent.getStringExtra(Intent.EXTRA_USER)
+
+        if (targetAccount != null && !currentUser.nameEquals(targetAccount)) {
+            val targetUser = userAccountManager.getUser(targetAccount)
+            if (targetUser.isPresent) {
+                setUser(targetUser.get())
+            } else {
+                Toast.makeText(this, R.string.associated_account_not_found, Toast.LENGTH_LONG).show()
+                finish()
+                return
+            }
+        }
+
+        clientFactory?.let {
+            val trashRepository = RemoteTrashbinRepository(user.orElse(accountProvider!!.user), it)
+            trashbinPresenter = TrashbinPresenter(trashRepository, this)
+        }
+
+        binding = TrashbinActivityBinding.inflate(layoutInflater)
+
+        setContentView(binding.root)
+        setupToolbar()
+
+        findViewById<View>(R.id.sort_list_button_group).visibility = View.VISIBLE
+        findViewById<View>(R.id.switch_grid_view_button).visibility =
+            View.GONE
+
+        updateActionBarTitleAndHomeButtonByString(getString(R.string.trashbin_activity_title))
+        setupDrawer(R.id.nav_trashbin)
+    }
+
+    override fun onStart() {
+        super.onStart()
+
+        active = true
+        setupContent()
+    }
+
+    override fun onResume() {
+        super.onResume()
+
+        setDrawerMenuItemChecked(R.id.nav_trashbin)
+    }
+
+    private fun setupContent() {
+        val recyclerView = binding.list
+        recyclerView.setEmptyView(binding.emptyList.emptyListView)
+
+        binding.emptyList.emptyListView.visibility = View.GONE
+        binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_delete)
+        binding.emptyList.emptyListIcon.visibility = View.VISIBLE
+        binding.emptyList.emptyListViewHeadline.text = getString(R.string.trashbin_empty_headline)
+        binding.emptyList.emptyListViewText.text = getString(R.string.trashbin_empty_message)
+        binding.emptyList.emptyListViewText.visibility = View.VISIBLE
+
+        trashbinListAdapter = TrashbinListAdapter(
+            this,
+            storageManager,
+            preferences,
+            this,
+            user.orElse(accountProvider!!.user),
+            viewThemeUtils
+        )
+
+        recyclerView.adapter = trashbinListAdapter
+        recyclerView.setHasFixedSize(true)
+        recyclerView.setHasFooter(true)
+        recyclerView.layoutManager = LinearLayoutManager(this)
+
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList)
+        binding.swipeContainingList.setOnRefreshListener { loadFolder() }
+        viewThemeUtils.material.colorMaterialTextButton(findViewById(R.id.sort_button))
+
+        findViewById<View>(R.id.sort_button).setOnClickListener {
+            DisplayUtils.openSortingOrderDialogFragment(
+                supportFragmentManager,
+                preferences?.getSortOrderByType(
+                    FileSortOrder.Type.trashBinView,
+                    FileSortOrder.sort_new_to_old
+                )
+            )
+        }
+
+        loadFolder()
+
+        handleOnBackPressed()
+    }
+
+    private fun handleOnBackPressed() {
+        onBackPressedDispatcher.addCallback(
+            this,
+            object : OnBackPressedCallback(true) {
+                override fun handleOnBackPressed() {
+                    trashbinPresenter?.navigateUp()
+                }
+            }
+        )
+    }
+
+    fun loadFolder() {
+        trashbinListAdapter?.let {
+            if (it.itemCount > EMPTY_LIST_COUNT) {
+                binding.swipeContainingList.isRefreshing = true
+            } else {
+                showInitialLoading()
+            }
+
+            trashbinPresenter?.loadFolder()
+        }
+    }
+
+    override fun onOptionsItemSelected(item: MenuItem): Boolean {
+        var retval = true
+        val itemId = item.itemId
+        if (itemId == android.R.id.home) {
+            if (isDrawerOpen) {
+                closeDrawer()
+            } else if (trashbinPresenter?.isRoot == true) {
+                trashbinPresenter?.navigateUp()
+            } else {
+                openDrawer()
+            }
+        } else if (itemId == R.id.action_empty_trashbin) {
+            trashbinPresenter?.emptyTrashbin()
+        } else {
+            retval = super.onOptionsItemSelected(item)
+        }
+        return retval
+    }
+
+    override fun onOverflowIconClicked(file: TrashbinFile, view: View) {
+        val popup = PopupMenu(this, view)
+        popup.inflate(R.menu.item_trashbin)
+        popup.setOnMenuItemClickListener {
+            trashbinPresenter?.removeTrashbinFile(file)
+            true
+        }
+        popup.show()
+    }
+
+    override fun onItemClicked(file: TrashbinFile) {
+        if (file.isFolder) {
+            trashbinPresenter?.enterFolder(file.remotePath)
+            mDrawerToggle.isDrawerIndicatorEnabled = false
+        }
+    }
+
+    override fun onRestoreIconClicked(file: TrashbinFile, view: View) {
+        trashbinPresenter?.restoreTrashbinFile(file)
+    }
+
+    override fun onCreateOptionsMenu(menu: Menu): Boolean {
+        menuInflater.inflate(R.menu.activity_trashbin, menu)
+        return true
+    }
+
+    override fun onPause() {
+        super.onPause()
+        active = false
+        trashbinListAdapter?.cancelAllPendingTasks()
+    }
+
+    override fun close() {
+        trashbinPresenter?.navigateUp()
+    }
+
+    override fun setDrawerIndicatorEnabled(bool: Boolean) {
+        mDrawerToggle.isDrawerIndicatorEnabled = bool
+    }
+
+    override fun onSortingOrderChosen(sortOrder: FileSortOrder?) {
+        val sortButton = findViewById<TextView>(R.id.sort_button)
+        sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder))
+        trashbinListAdapter?.setSortOrder(sortOrder)
+    }
+
+    override fun showTrashbinFolder(trashbinFiles: List<TrashbinFile?>?) {
+        if (active) {
+            trashbinListAdapter?.setTrashbinFiles(trashbinFiles, true)
+            binding.swipeContainingList.isRefreshing = false
+            binding.loadingContent.visibility = View.GONE
+            binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_delete)
+            binding.emptyList.emptyListViewHeadline.text = getString(R.string.trashbin_empty_headline)
+            binding.emptyList.emptyListViewText.text = getString(R.string.trashbin_empty_message)
+            binding.list.visibility = View.VISIBLE
+        }
+    }
+
+    override fun removeFile(file: TrashbinFile?) {
+        if (active) {
+            trashbinListAdapter?.removeFile(file)
+        }
+    }
+
+    override fun removeAllFiles() {
+        trashbinListAdapter?.removeAllFiles()
+    }
+
+    override fun showSnackbarError(message: Int, file: TrashbinFile?) {
+        if (active) {
+            binding.swipeContainingList.isRefreshing = false
+            Snackbar.make(binding.list, String.format(getString(message), file?.fileName), Snackbar.LENGTH_LONG)
+                .show()
+        }
+    }
+
+    @VisibleForTesting
+    fun showInitialLoading() {
+        binding.emptyList.emptyListView.visibility = View.GONE
+        binding.list.visibility = View.GONE
+        binding.loadingContent.visibility = View.VISIBLE
+    }
+
+    @VisibleForTesting
+    fun showUser() {
+        binding.loadingContent.visibility = View.GONE
+        binding.list.visibility = View.VISIBLE
+        binding.swipeContainingList.isRefreshing = false
+        binding.emptyList.emptyListViewText.text = user.get().accountName
+        binding.emptyList.emptyListViewText.visibility = View.VISIBLE
+        binding.emptyList.emptyListView.visibility = View.VISIBLE
+    }
+
+    override fun showError(message: Int) {
+        if (active) {
+            trashbinListAdapter?.removeAllFiles()
+            binding.loadingContent.visibility = View.GONE
+            binding.list.visibility = View.VISIBLE
+            binding.swipeContainingList.isRefreshing = false
+            binding.emptyList.emptyListViewHeadline.setText(R.string.common_error)
+            binding.emptyList.emptyListIcon.setImageDrawable(
+                ResourcesCompat.getDrawable(
+                    resources,
+                    R.drawable.ic_list_empty_error,
+                    null
+                )
+            )
+            binding.emptyList.emptyListViewText.setText(message)
+            binding.emptyList.emptyListViewText.visibility = View.VISIBLE
+            binding.emptyList.emptyListIcon.visibility = View.VISIBLE
+            binding.emptyList.emptyListView.visibility = View.VISIBLE
+        }
+    }
+
+    companion object {
+        const val EMPTY_LIST_COUNT = 1
+    }
+}

+ 17 - 33
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinContract.java → app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinContract.kt

@@ -18,47 +18,31 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  */
-package com.owncloud.android.ui.trashbin;
+package com.owncloud.android.ui.trashbin
 
-import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
-
-import java.util.List;
+import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
 
 /**
  * Contract between view (TrashbinActivity) and presenter (TrashbinPresenter)
  */
-public interface TrashbinContract {
-
+interface TrashbinContract {
     interface View {
-        void showTrashbinFolder(List<TrashbinFile> trashbinFiles);
-
-        void showSnackbarError(int message, TrashbinFile file);
-
-        void showError(int message);
-
-        void removeFile(TrashbinFile file);
-
-        void removeAllFiles();
-
-        void close();
-
-        void setDrawerIndicatorEnabled(boolean bool);
+        fun showTrashbinFolder(trashbinFiles: List<TrashbinFile?>?)
+        fun showSnackbarError(message: Int, file: TrashbinFile?)
+        fun showError(message: Int)
+        fun removeFile(file: TrashbinFile?)
+        fun removeAllFiles()
+        fun close()
+        fun setDrawerIndicatorEnabled(bool: Boolean)
     }
 
     interface Presenter {
-
-        boolean isRoot();
-
-        void loadFolder();
-
-        void navigateUp();
-
-        void enterFolder(String folder);
-
-        void restoreTrashbinFile(TrashbinFile file);
-
-        void removeTrashbinFile(TrashbinFile file);
-
-        void emptyTrashbin();
+        val isRoot: Boolean
+        fun loadFolder()
+        fun navigateUp()
+        fun enterFolder(folder: String?)
+        fun restoreTrashbinFile(file: TrashbinFile?)
+        fun removeTrashbinFile(file: TrashbinFile?)
+        fun emptyTrashbin()
     }
 }

+ 0 - 116
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinPresenter.java

@@ -1,116 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * Copyright (C) 2018 Tobias Kaminsky
- * Copyright (C) 2018 Nextcloud GmbH.
- *
- * 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 <https://www.gnu.org/licenses/>.
- */
-package com.owncloud.android.ui.trashbin;
-
-import com.owncloud.android.R;
-import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
-
-import java.io.File;
-import java.util.List;
-
-import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
-
-/**
- * Coordinates between model and view: querying model, updating view, react to UI input
- */
-public class TrashbinPresenter implements TrashbinContract.Presenter {
-
-    private TrashbinContract.View trashbinView;
-    private TrashbinRepository trashbinRepository;
-    private String currentPath = ROOT_PATH;
-
-    public TrashbinPresenter(TrashbinRepository trashbinRepository, TrashbinContract.View trashbinView) {
-        this.trashbinRepository = trashbinRepository;
-        this.trashbinView = trashbinView;
-    }
-
-    @Override
-    public void enterFolder(String folder) {
-        currentPath = folder;
-        loadFolder();
-    }
-
-    @Override
-    public boolean isRoot() {
-        return !ROOT_PATH.equals(currentPath);
-    }
-
-    @Override
-    public void navigateUp() {
-        if (ROOT_PATH.equals(currentPath)) {
-            trashbinView.close();
-        } else {
-            currentPath = new File(currentPath).getParent();
-
-            loadFolder();
-        }
-
-        trashbinView.setDrawerIndicatorEnabled(ROOT_PATH.equals(currentPath));
-    }
-
-    @Override
-    public void loadFolder() {
-        trashbinRepository.getFolder(currentPath, new TrashbinRepository.LoadFolderCallback() {
-            @Override
-            public void onSuccess(List<TrashbinFile> files) {
-                trashbinView.showTrashbinFolder(files);
-            }
-
-            @Override
-            public void onError(int error) {
-                trashbinView.showError(error);
-            }
-        });
-    }
-
-    @Override
-    public void restoreTrashbinFile(TrashbinFile file) {
-        trashbinRepository.restoreFile(file, success -> {
-            if (success) {
-                trashbinView.removeFile(file);
-            } else {
-                trashbinView.showSnackbarError(R.string.trashbin_file_not_restored, file);
-            }
-        });
-    }
-
-    @Override
-    public void removeTrashbinFile(TrashbinFile file) {
-        trashbinRepository.removeTrashbinFile(file, success -> {
-            if (success) {
-                trashbinView.removeFile(file);
-            } else {
-                trashbinView.showSnackbarError(R.string.trashbin_file_not_deleted, file);
-            }
-        });
-    }
-
-    @Override
-    public void emptyTrashbin() {
-        trashbinRepository.emptyTrashbin(success -> {
-            if (success) {
-                trashbinView.removeAllFiles();
-            } else {
-                trashbinView.showError(R.string.trashbin_not_emptied);
-            }
-        });
-    }
-}

+ 117 - 0
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinPresenter.kt

@@ -0,0 +1,117 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2018 Tobias Kaminsky
+ * Copyright (C) 2018 Nextcloud GmbH.
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android.ui.trashbin
+
+import com.owncloud.android.R
+import com.owncloud.android.datamodel.OCFile
+import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
+import com.owncloud.android.ui.trashbin.TrashbinContract.Presenter
+import com.owncloud.android.ui.trashbin.TrashbinRepository.LoadFolderCallback
+import java.io.File
+
+/**
+ * Coordinates between model and view: querying model, updating view, react to UI input
+ */
+class TrashbinPresenter(
+    private val trashbinRepository: TrashbinRepository,
+    private val trashbinView: TrashbinContract.View
+) : Presenter {
+
+    private var currentPath: String? = OCFile.ROOT_PATH
+
+    override fun enterFolder(folder: String?) {
+        currentPath = folder
+        loadFolder()
+    }
+
+    override val isRoot: Boolean
+        get() = OCFile.ROOT_PATH != currentPath
+
+    override fun navigateUp() {
+        if (OCFile.ROOT_PATH == currentPath) {
+            trashbinView.close()
+        } else {
+            currentPath?.let {
+                currentPath = File(it).parent
+                loadFolder()
+            }
+        }
+
+        trashbinView.setDrawerIndicatorEnabled(OCFile.ROOT_PATH == currentPath)
+    }
+
+    override fun loadFolder() {
+        trashbinRepository.getFolder(
+            currentPath,
+            object : LoadFolderCallback {
+                override fun onSuccess(files: List<TrashbinFile?>?) {
+                    trashbinView.showTrashbinFolder(files)
+                }
+
+                override fun onError(error: Int) {
+                    trashbinView.showError(error)
+                }
+            }
+        )
+    }
+
+    override fun restoreTrashbinFile(file: TrashbinFile?) {
+        trashbinRepository.restoreFile(
+            file,
+            object : TrashbinRepository.OperationCallback {
+                override fun onResult(success: Boolean) {
+                    if (success) {
+                        trashbinView.removeFile(file)
+                    } else {
+                        trashbinView.showSnackbarError(R.string.trashbin_file_not_restored, file)
+                    }
+                }
+            }
+        )
+    }
+
+    override fun removeTrashbinFile(file: TrashbinFile?) {
+        trashbinRepository.removeTrashbinFile(
+            file,
+            object : TrashbinRepository.OperationCallback {
+                override fun onResult(success: Boolean) {
+                    if (success) {
+                        trashbinView.removeFile(file)
+                    } else {
+                        trashbinView.showSnackbarError(R.string.trashbin_file_not_deleted, file)
+                    }
+                }
+            }
+        )
+    }
+
+    override fun emptyTrashbin() {
+        trashbinRepository.emptyTrashbin(object : TrashbinRepository.OperationCallback {
+            override fun onResult(success: Boolean) {
+                if (success) {
+                    trashbinView.removeAllFiles()
+                } else {
+                    trashbinView.showError(R.string.trashbin_not_emptied)
+                }
+            }
+        })
+    }
+}

+ 10 - 16
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinRepository.java → app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinRepository.kt

@@ -18,31 +18,25 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  */
-package com.owncloud.android.ui.trashbin;
+package com.owncloud.android.ui.trashbin
 
-import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
-
-import java.util.List;
+import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
 
 /**
  * Contract between presenter and model
  */
-public interface TrashbinRepository {
+interface TrashbinRepository {
     interface LoadFolderCallback {
-        void onSuccess(List<TrashbinFile> files);
-
-        void onError(int error);
+        fun onSuccess(files: List<TrashbinFile?>?)
+        fun onError(error: Int)
     }
 
     interface OperationCallback {
-        void onResult(boolean success);
+        fun onResult(success: Boolean)
     }
 
-    void getFolder(String remotePath, LoadFolderCallback callback);
-
-    void restoreFile(TrashbinFile file, OperationCallback callback);
-
-    void emptyTrashbin(OperationCallback callback);
-
-    void removeTrashbinFile(TrashbinFile file, OperationCallback callback);
+    fun getFolder(remotePath: String?, callback: LoadFolderCallback?)
+    fun restoreFile(file: TrashbinFile?, callback: OperationCallback?)
+    fun emptyTrashbin(callback: OperationCallback?)
+    fun removeTrashbinFile(file: TrashbinFile?, callback: OperationCallback?)
 }