From 90bb538692b981ac35ad0adca9dbe771f7111e89 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 25 May 2018 20:48:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Improve=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch/dissem/apps/abit/ConversationDetailFragment.kt | 11 +++++++---- app/src/main/java/ch/dissem/apps/abit/MainActivity.kt | 4 ++-- .../java/ch/dissem/apps/abit/MessageDetailActivity.kt | 9 ++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/ConversationDetailFragment.kt b/app/src/main/java/ch/dissem/apps/abit/ConversationDetailFragment.kt index 87f9cba..f611ff1 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ConversationDetailFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/ConversationDetailFragment.kt @@ -26,6 +26,7 @@ import ch.dissem.apps.abit.util.Drawables import ch.dissem.bitmessage.entity.Conversation import com.mikepenz.google_material_typeface_library.GoogleMaterial import kotlinx.android.synthetic.main.fragment_conversation_detail.* +import java.util.* /** * A fragment representing a single Message detail screen. @@ -38,17 +39,18 @@ class ConversationDetailFragment : Fragment() { /** * The content this fragment is presenting. */ + private var itemId: UUID? = null private var item: Conversation? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { arguments -> - if (arguments.containsKey(ARG_ITEM)) { + if (arguments.containsKey(ARG_ITEM_ID)) { // Load the dummy content specified by the fragment // arguments. In a real-world scenario, use a Loader // to load content from a content provider. - item = arguments.getSerializable(ARG_ITEM) as Conversation + itemId = arguments.getSerializable(ARG_ITEM_ID) as UUID } } setHasOptionsMenu(true) @@ -66,6 +68,8 @@ class ConversationDetailFragment : Fragment() { val ctx = activity ?: throw IllegalStateException("Fragment is not attached to an activity") + item = itemId?.let { Singleton.getConversationService(ctx).getConversation(it) } + // Show the dummy content as text in a TextView. item?.let { item -> subject.text = item.subject @@ -104,7 +108,6 @@ class ConversationDetailFragment : Fragment() { item.messages.forEach { Singleton.labeler.archive(it) messageRepo.save(it) - } MainActivity.apply { updateUnread() } return true @@ -120,6 +123,6 @@ class ConversationDetailFragment : Fragment() { * The fragment argument representing the item ID that this fragment * represents. */ - const val ARG_ITEM = "item" + const val ARG_ITEM_ID = "item_id" } } diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt index 2ed025f..e7d5b88 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt @@ -471,7 +471,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { is Conversation -> { ConversationDetailFragment().apply { arguments = Bundle().apply { - putSerializable(ConversationDetailFragment.ARG_ITEM, item) + putSerializable(ConversationDetailFragment.ARG_ITEM_ID, item.id) } } } @@ -508,7 +508,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { val detailIntent = when (item) { is Conversation -> { Intent(this, MessageDetailActivity::class.java).apply { - putExtra(ConversationDetailFragment.ARG_ITEM, item) + putExtra(ConversationDetailFragment.ARG_ITEM_ID, item.id) } } is Plaintext -> { diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageDetailActivity.kt b/app/src/main/java/ch/dissem/apps/abit/MessageDetailActivity.kt index bb29b16..e1c449c 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageDetailActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageDetailActivity.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.support.v4.app.NavUtils import android.view.MenuItem import ch.dissem.bitmessage.entity.Conversation +import ch.dissem.bitmessage.entity.Plaintext /** @@ -36,10 +37,12 @@ class MessageDetailActivity : DetailActivity() { val arguments = Bundle() val item = intent.getSerializableExtra(MessageDetailFragment.ARG_ITEM) arguments.putSerializable(MessageDetailFragment.ARG_ITEM, item) - val fragment = if (item is Conversation) { - ConversationDetailFragment() - } else { + val itemId = intent.getSerializableExtra(ConversationDetailFragment.ARG_ITEM_ID) + arguments.putSerializable(ConversationDetailFragment.ARG_ITEM_ID, itemId) + val fragment = if (item is Plaintext) { MessageDetailFragment() + } else { + ConversationDetailFragment() } fragment.arguments = arguments supportFragmentManager.beginTransaction()