From 1e8b71e43b0163c71dc4f9b2d1293cdc2514284f Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Tue, 12 Sep 2017 21:28:56 +0200 Subject: [PATCH] Some performance improvements --- .../dissem/apps/abit/MessageDetailFragment.kt | 7 +- .../dissem/apps/abit/MessageListFragment.kt | 74 ++++++++++++++++--- .../abit/adapter/SwipeableMessageAdapter.kt | 29 ++++++++ .../apps/abit/listener/MessageListener.kt | 8 +- .../repository/AndroidMessageRepository.kt | 11 +-- .../ch/dissem/apps/abit/service/Singleton.kt | 3 + build.gradle | 2 +- 7 files changed, 107 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt b/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt index 51a1bdd..fb881c5 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt @@ -166,18 +166,17 @@ class MessageDetailFragment : Fragment() { return true } R.id.delete -> { + Singleton.labeler.delete(item) if (isInTrash(item)) { messageRepo.remove(item) } else { - item.labels.clear() - item.addLabels(messageRepo.getLabels(Label.Type.TRASH)) messageRepo.save(item) } activity.onBackPressed() return true } R.id.mark_unread -> { - item.addLabels(messageRepo.getLabels(Label.Type.UNREAD)) + Singleton.labeler.markAsUnread(item) messageRepo.save(item) if (activity is MainActivity) { (activity as MainActivity).updateUnread() @@ -188,7 +187,7 @@ class MessageDetailFragment : Fragment() { if (item.isUnread() && activity is MainActivity) { (activity as MainActivity).updateUnread() } - item.labels.clear() + Singleton.labeler.archive(item) messageRepo.save(item) return true } diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt index 9974878..ccf6fc1 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt @@ -17,11 +17,14 @@ package ch.dissem.apps.abit import android.content.Intent + + import android.os.Bundle import android.support.v4.app.Fragment import android.support.v4.content.ContextCompat import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView +import android.support.v7.widget.RecyclerView.OnScrollListener import android.view.* import android.widget.Toast import ch.dissem.apps.abit.ComposeMessageActivity.Companion.EXTRA_BROADCAST @@ -29,6 +32,7 @@ import ch.dissem.apps.abit.ComposeMessageActivity.Companion.EXTRA_IDENTITY import ch.dissem.apps.abit.adapter.SwipeableMessageAdapter import ch.dissem.apps.abit.listener.ListSelectionListener import ch.dissem.apps.abit.repository.AndroidMessageRepository +import ch.dissem.apps.abit.repository.AndroidMessageRepository.Companion.LABEL_ARCHIVE import ch.dissem.apps.abit.service.Singleton import ch.dissem.apps.abit.util.FabUtils import ch.dissem.bitmessage.entity.Plaintext @@ -41,9 +45,12 @@ import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu import kotlinx.android.synthetic.main.fragment_message_list.* import org.jetbrains.anko.doAsync +import org.jetbrains.anko.support.v4.onUiThread import org.jetbrains.anko.uiThread import java.util.* +private const val PAGE_SIZE = 15 + /** * A list fragment representing a list of Messages. This fragment * also supports tablet devices by allowing list items to be given an @@ -56,12 +63,33 @@ import java.util.* */ class MessageListFragment : Fragment(), ListHolder