Selaa lähdekoodia

Convert trashbin activity to kt

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 vuosi sitten
vanhempi
commit
e879bca55f

+ 224 - 225
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt

@@ -21,314 +21,313 @@
  * 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;
+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
  */
-public class TrashbinActivity extends DrawerActivity implements
-    TrashbinActivityInterface,
-    SortingOrderDialogFragment.OnSortingOrderListener,
-    TrashbinContract.View,
+class TrashbinActivity : DrawerActivity(), TrashbinActivityInterface, OnSortingOrderListener, TrashbinContract.View,
     Injectable {
+    
+    @JvmField
+    @Inject
+    var preferences: AppPreferences? = null
 
-    public static final int EMPTY_LIST_COUNT = 1;
-    @Inject AppPreferences preferences;
-    @Inject CurrentAccountProvider accountProvider;
-    @Inject ClientFactory clientFactory;
-    @Inject ViewThemeUtils viewThemeUtils;
+    @JvmField
+    @Inject
+    var accountProvider: CurrentAccountProvider? = null
 
-    private TrashbinListAdapter trashbinListAdapter;
+    @JvmField
+    @Inject
+    var clientFactory: ClientFactory? = null
+
+    @JvmField
+    @Inject
+    var viewThemeUtils: ViewThemeUtils? = null
+
+    private var trashbinListAdapter: TrashbinListAdapter? = null
 
     @VisibleForTesting
-    TrashbinPresenter trashbinPresenter;
+    var trashbinPresenter: TrashbinPresenter? = null
+   
+    private var active = false
+    private lateinit var binding: TrashbinActivityBinding
+    
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
 
-    private boolean active;
-    private TrashbinActivityBinding binding;
+        val currentUser = user.orElse(accountProvider!!.user)
+        val targetAccount = intent.getStringExtra(Intent.EXTRA_USER)
 
-    @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());
+            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;
+                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);
+        val trashRepository = RemoteTrashbinRepository(user.orElse(accountProvider!!.user), clientFactory)
+        trashbinPresenter = TrashbinPresenter(trashRepository, this)
+        binding = TrashbinActivityBinding.inflate(layoutInflater)
 
-        binding = TrashbinActivityBinding.inflate(getLayoutInflater());
-        setContentView(binding.getRoot());
+        setContentView(binding.root)
+        setupToolbar()
 
-        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);
+        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
-    protected void onStart() {
-        super.onStart();
-        active = true;
-        setupContent();
+    override fun onStart() {
+        super.onStart()
+
+        active = true
+        setupContent()
     }
 
-    @Override
-    protected void onResume() {
-        super.onResume();
+    override fun onResume() {
+        super.onResume()
 
-        setDrawerMenuItemChecked(R.id.nav_trashbin);
+        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(
+    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,
-            getStorageManager(),
+            storageManager,
             preferences,
             this,
-            getUser().orElse(accountProvider.getUser()),
+            user.orElse(accountProvider!!.user),
             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);
+        )
+
+        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
+                )
+            )
+        }
 
-        viewThemeUtils.material.colorMaterialTextButton(findViewById(R.id.sort_button));
+        loadFolder()
 
-        findViewById(R.id.sort_button).setOnClickListener(l ->
-                                                              openSortingOrderDialogFragment(getSupportFragmentManager(),
-                                                                                             preferences.getSortOrderByType(
-                                                                                                 FileSortOrder.Type.trashBinView,
-                                                                                                 FileSortOrder.sort_new_to_old))
-                                                         );
+        handleOnBackPressed()
+    }
 
-        loadFolder();
+    private fun handleOnBackPressed() {
+        onBackPressedDispatcher.addCallback(
+            this,
+            object : OnBackPressedCallback(true) {
+                override fun handleOnBackPressed() {
+                    trashbinPresenter?.navigateUp()
+                }
+            }
+        )
     }
 
-    protected void loadFolder() {
-        if (trashbinListAdapter.getItemCount() > EMPTY_LIST_COUNT) {
-            binding.swipeContainingList.setRefreshing(true);
-        } else {
-            showInitialLoading();
+    private fun loadFolder() {
+        trashbinListAdapter?.let {
+            if (it.itemCount > EMPTY_LIST_COUNT) {
+                binding.swipeContainingList.isRefreshing = true
+            } else {
+                showInitialLoading()
+            }
+
+            trashbinPresenter?.loadFolder()
         }
-        trashbinPresenter.loadFolder();
     }
 
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        boolean retval = true;
-        int itemId = item.getItemId();
+    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()) {
-                onBackPressed();
+            if (isDrawerOpen) {
+                closeDrawer()
+            } else if (trashbinPresenter?.isRoot == true) {
+                trashbinPresenter?.navigateUp()
             } else {
-                openDrawer();
+                openDrawer()
             }
         } else if (itemId == R.id.action_empty_trashbin) {
-            trashbinPresenter.emptyTrashbin();
+            trashbinPresenter?.emptyTrashbin()
         } else {
-            retval = super.onOptionsItemSelected(item);
+            retval = super.onOptionsItemSelected(item)
         }
-
-        return retval;
+        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 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
-    public void onRestoreIconClicked(TrashbinFile file, View view) {
-        trashbinPresenter.restoreTrashbinFile(file);
+    override fun onItemClicked(file: TrashbinFile) {
+        if (file.isFolder) {
+            trashbinPresenter?.enterFolder(file.remotePath)
+            mDrawerToggle.isDrawerIndicatorEnabled = false
+        }
     }
 
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        getMenuInflater().inflate(R.menu.activity_trashbin, menu);
-
-        return true;
+    override fun onRestoreIconClicked(file: TrashbinFile, view: View) {
+        trashbinPresenter?.restoreTrashbinFile(file)
     }
 
-    @Override
-    protected void onPause() {
-        super.onPause();
-        active = false;
-
-        trashbinListAdapter.cancelAllPendingTasks();
+    override fun onCreateOptionsMenu(menu: Menu): Boolean {
+        menuInflater.inflate(R.menu.activity_trashbin, menu)
+        return true
     }
 
-    @Override
-    public void onBackPressed() {
-        trashbinPresenter.navigateUp();
+    override fun onPause() {
+        super.onPause()
+        active = false
+        trashbinListAdapter?.cancelAllPendingTasks()
     }
 
-    public void close() {
-        super.onBackPressed();
+    override fun close() {
+        trashbinPresenter?.navigateUp()
     }
 
-    public void setDrawerIndicatorEnabled(boolean bool) {
-        mDrawerToggle.setDrawerIndicatorEnabled(bool);
+    override fun setDrawerIndicatorEnabled(bool: Boolean) {
+        mDrawerToggle.isDrawerIndicatorEnabled = bool
     }
 
-
-    @Override
-    public void onSortingOrderChosen(FileSortOrder sortOrder) {
-        TextView sortButton = findViewById(R.id.sort_button);
-        sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder));
-        trashbinListAdapter.setSortOrder(sortOrder);
+    override fun onSortingOrderChosen(sortOrder: FileSortOrder?) {
+        val sortButton = findViewById<TextView>(R.id.sort_button)
+        sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder))
+        trashbinListAdapter?.setSortOrder(sortOrder)
     }
 
-    @Override
-    public void showTrashbinFolder(List<TrashbinFile> trashbinFiles) {
+    override fun showTrashbinFolder(trashbinFiles: List<TrashbinFile?>?) {
         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);
+            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
-    public void removeFile(TrashbinFile file) {
+    override fun removeFile(file: TrashbinFile?) {
         if (active) {
-            trashbinListAdapter.removeFile(file);
+            trashbinListAdapter?.removeFile(file)
         }
     }
 
-    @Override
-    public void removeAllFiles() {
-        trashbinListAdapter.removeAllFiles();
+    override fun removeAllFiles() {
+        trashbinListAdapter?.removeAllFiles()
     }
 
-    @Override
-    public void showSnackbarError(int message, TrashbinFile file) {
+    override fun showSnackbarError(message: Int, file: TrashbinFile?) {
         if (active) {
-            binding.swipeContainingList.setRefreshing(false);
-            Snackbar.make(binding.list,
-                          String.format(getString(message), file.getFileName()), Snackbar.LENGTH_LONG)
-                .show();
+            binding.swipeContainingList.isRefreshing = false
+            Snackbar.make(binding.list, String.format(getString(message), file?.fileName), Snackbar.LENGTH_LONG)
+                .show()
         }
     }
 
     @VisibleForTesting
-    public void showInitialLoading() {
-        binding.emptyList.emptyListView.setVisibility(View.GONE);
-        binding.list.setVisibility(View.GONE);
-        binding.loadingContent.setVisibility(View.VISIBLE);
+    fun showInitialLoading() {
+        binding.emptyList.emptyListView.visibility = View.GONE
+        binding.list.visibility = View.GONE
+        binding.loadingContent.visibility = 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);
+    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
-    public void showError(int message) {
+    override fun showError(message: Int) {
         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);
+            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.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()
     }
 }

+ 59 - 67
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinPresenter.kt

@@ -18,99 +18,91 @@
  * 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.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;
+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
  */
-public class TrashbinPresenter implements TrashbinContract.Presenter {
+class TrashbinPresenter(
+    private val trashbinRepository: TrashbinRepository,
+    private val trashbinView: TrashbinContract.View
+) : Presenter {
 
-    private TrashbinContract.View trashbinView;
-    private TrashbinRepository trashbinRepository;
-    private String currentPath = ROOT_PATH;
+    private var currentPath: String? = OCFile.ROOT_PATH
 
-    public TrashbinPresenter(TrashbinRepository trashbinRepository, TrashbinContract.View trashbinView) {
-        this.trashbinRepository = trashbinRepository;
-        this.trashbinView = trashbinView;
+    override fun enterFolder(folder: String?) {
+        currentPath = folder
+        loadFolder()
     }
 
-    @Override
-    public void enterFolder(String folder) {
-        currentPath = folder;
-        loadFolder();
-    }
+    override val isRoot: Boolean
+        get() = OCFile.ROOT_PATH != currentPath
 
-    @Override
-    public boolean isRoot() {
-        return !ROOT_PATH.equals(currentPath);
-    }
-
-    @Override
-    public void navigateUp() {
-        if (ROOT_PATH.equals(currentPath)) {
-            trashbinView.close();
+    override fun navigateUp() {
+        if (OCFile.ROOT_PATH == currentPath) {
+            trashbinView.close()
         } else {
-            currentPath = new File(currentPath).getParent();
-
-            loadFolder();
+            currentPath?.let {
+                currentPath = File(it).parent
+                loadFolder()
+            }
         }
 
-        trashbinView.setDrawerIndicatorEnabled(ROOT_PATH.equals(currentPath));
+        trashbinView.setDrawerIndicatorEnabled(OCFile.ROOT_PATH == currentPath)
     }
 
-    @Override
-    public void loadFolder() {
-        trashbinRepository.getFolder(currentPath, new TrashbinRepository.LoadFolderCallback() {
-            @Override
-            public void onSuccess(List<TrashbinFile> files) {
-                trashbinView.showTrashbinFolder(files);
+    override fun loadFolder() {
+        trashbinRepository.getFolder(currentPath, object : LoadFolderCallback {
+            override fun onSuccess(files: List<TrashbinFile?>?) {
+                trashbinView.showTrashbinFolder(files)
             }
 
-            @Override
-            public void onError(int error) {
-                trashbinView.showError(error);
+            override fun onError(error: Int) {
+                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 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
-    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 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
-    public void emptyTrashbin() {
-        trashbinRepository.emptyTrashbin(success -> {
-            if (success) {
-                trashbinView.removeAllFiles();
-            } else {
-                trashbinView.showError(R.string.trashbin_not_emptied);
+    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.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?)
 }