🚀 Improve performance

This commit is contained in:
Christian Basler 2018-05-25 20:48:42 +02:00
parent 9cc07f73ae
commit 90bb538692
3 changed files with 15 additions and 9 deletions

View File

@ -26,6 +26,7 @@ import ch.dissem.apps.abit.util.Drawables
import ch.dissem.bitmessage.entity.Conversation import ch.dissem.bitmessage.entity.Conversation
import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.mikepenz.google_material_typeface_library.GoogleMaterial
import kotlinx.android.synthetic.main.fragment_conversation_detail.* import kotlinx.android.synthetic.main.fragment_conversation_detail.*
import java.util.*
/** /**
* A fragment representing a single Message detail screen. * A fragment representing a single Message detail screen.
@ -38,17 +39,18 @@ class ConversationDetailFragment : Fragment() {
/** /**
* The content this fragment is presenting. * The content this fragment is presenting.
*/ */
private var itemId: UUID? = null
private var item: Conversation? = null private var item: Conversation? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments -> arguments?.let { arguments ->
if (arguments.containsKey(ARG_ITEM)) { if (arguments.containsKey(ARG_ITEM_ID)) {
// Load the dummy content specified by the fragment // Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader // arguments. In a real-world scenario, use a Loader
// to load content from a content provider. // to load content from a content provider.
item = arguments.getSerializable(ARG_ITEM) as Conversation itemId = arguments.getSerializable(ARG_ITEM_ID) as UUID
} }
} }
setHasOptionsMenu(true) setHasOptionsMenu(true)
@ -66,6 +68,8 @@ class ConversationDetailFragment : Fragment() {
val ctx = activity ?: throw IllegalStateException("Fragment is not attached to an activity") 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. // Show the dummy content as text in a TextView.
item?.let { item -> item?.let { item ->
subject.text = item.subject subject.text = item.subject
@ -104,7 +108,6 @@ class ConversationDetailFragment : Fragment() {
item.messages.forEach { item.messages.forEach {
Singleton.labeler.archive(it) Singleton.labeler.archive(it)
messageRepo.save(it) messageRepo.save(it)
} }
MainActivity.apply { updateUnread() } MainActivity.apply { updateUnread() }
return true return true
@ -120,6 +123,6 @@ class ConversationDetailFragment : Fragment() {
* The fragment argument representing the item ID that this fragment * The fragment argument representing the item ID that this fragment
* represents. * represents.
*/ */
const val ARG_ITEM = "item" const val ARG_ITEM_ID = "item_id"
} }
} }

View File

@ -471,7 +471,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener<Serializable> {
is Conversation -> { is Conversation -> {
ConversationDetailFragment().apply { ConversationDetailFragment().apply {
arguments = Bundle().apply { arguments = Bundle().apply {
putSerializable(ConversationDetailFragment.ARG_ITEM, item) putSerializable(ConversationDetailFragment.ARG_ITEM_ID, item.id)
} }
} }
} }
@ -508,7 +508,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener<Serializable> {
val detailIntent = when (item) { val detailIntent = when (item) {
is Conversation -> { is Conversation -> {
Intent(this, MessageDetailActivity::class.java).apply { Intent(this, MessageDetailActivity::class.java).apply {
putExtra(ConversationDetailFragment.ARG_ITEM, item) putExtra(ConversationDetailFragment.ARG_ITEM_ID, item.id)
} }
} }
is Plaintext -> { is Plaintext -> {

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.support.v4.app.NavUtils import android.support.v4.app.NavUtils
import android.view.MenuItem import android.view.MenuItem
import ch.dissem.bitmessage.entity.Conversation import ch.dissem.bitmessage.entity.Conversation
import ch.dissem.bitmessage.entity.Plaintext
/** /**
@ -36,10 +37,12 @@ class MessageDetailActivity : DetailActivity() {
val arguments = Bundle() val arguments = Bundle()
val item = intent.getSerializableExtra(MessageDetailFragment.ARG_ITEM) val item = intent.getSerializableExtra(MessageDetailFragment.ARG_ITEM)
arguments.putSerializable(MessageDetailFragment.ARG_ITEM, item) arguments.putSerializable(MessageDetailFragment.ARG_ITEM, item)
val fragment = if (item is Conversation) { val itemId = intent.getSerializableExtra(ConversationDetailFragment.ARG_ITEM_ID)
ConversationDetailFragment() arguments.putSerializable(ConversationDetailFragment.ARG_ITEM_ID, itemId)
} else { val fragment = if (item is Plaintext) {
MessageDetailFragment() MessageDetailFragment()
} else {
ConversationDetailFragment()
} }
fragment.arguments = arguments fragment.arguments = arguments
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()