From 2a1aa736cc3508b32b2e51400da2fced7c4c6a1e Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 18 Jan 2018 22:16:55 +0100 Subject: [PATCH] Fixed newly introduced bugs --- .../java/ch/dissem/apps/abit/MainActivity.kt | 3 +- .../abit/repository/AndroidLabelRepository.kt | 2 +- .../ch/dissem/apps/abit/service/Singleton.kt | 56 ++++++++++--------- 3 files changed, 32 insertions(+), 29 deletions(-) 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 2e288dd..2f1d3aa 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt @@ -220,6 +220,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { val drawerItems = ArrayList>() drawerItems.add(PrimaryDrawerItem() + .withIdentifier(LABEL_ARCHIVE.id as Long) .withName(R.string.archive) .withTag(LABEL_ARCHIVE) .withIcon(CommunityMaterial.Icon.cmd_archive) @@ -343,7 +344,7 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { } Singleton.getMessageListener(this).resetNotification() currentLabel.addObserver(this) { label -> - if (label != null) { + if (label != null && label.id is Long) { drawer.setSelection(label.id as Long) } } diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt index f00880c..f9b000d 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidLabelRepository.kt @@ -85,7 +85,7 @@ class AndroidLabelRepository(private val sql: SqlHelper, private val context: Co internal fun findLabels(msgId: Any) = find("id IN (SELECT label_id FROM Message_Label WHERE message_id=$msgId)") companion object { - val LABEL_ARCHIVE = Label("archive", null, 0) + val LABEL_ARCHIVE = Label("archive", null, 0).apply { id = Long.MAX_VALUE } private const val TABLE_NAME = "Label" private const val COLUMN_ID = "id" diff --git a/app/src/main/java/ch/dissem/apps/abit/service/Singleton.kt b/app/src/main/java/ch/dissem/apps/abit/service/Singleton.kt index 3530534..1ecfd10 100644 --- a/app/src/main/java/ch/dissem/apps/abit/service/Singleton.kt +++ b/app/src/main/java/ch/dissem/apps/abit/service/Singleton.kt @@ -50,36 +50,38 @@ object Singleton { private var swipeableMessageAdapter: WeakReference? = null val labeler = DefaultLabeler().apply { listener = { message, added, removed -> - swipeableMessageAdapter?.get()?.let { swipeableMessageAdapter -> - currentLabel.value?.let { label -> - when { - label.type == Label.Type.TRASH - && added.all { it.type == Label.Type.TRASH } - && removed.any { it.type == Label.Type.TRASH } -> { - // work-around for messages that are deleted from trash - swipeableMessageAdapter.remove(message) - } - label.type == Label.Type.UNREAD - && added.all { it.type == Label.Type.TRASH } -> { - // work-around for messages that are deleted from unread, which already have the unread label removed - swipeableMessageAdapter.remove(message) - } - added.contains(label) -> { - // in most cases, top should be the correct position, but time will show if - // the message should be properly sorted in - swipeableMessageAdapter.addFirst(message) - } - removed.contains(label) -> { - swipeableMessageAdapter.remove(message) - } - removed.any { it.type == Label.Type.UNREAD } || added.any { it.type == Label.Type.UNREAD } -> { - swipeableMessageAdapter.update(message) + MainActivity.apply { + runOnUiThread { + swipeableMessageAdapter?.get()?.let { swipeableMessageAdapter -> + currentLabel.value?.let { label -> + when { + label.type == Label.Type.TRASH + && added.all { it.type == Label.Type.TRASH } + && removed.any { it.type == Label.Type.TRASH } -> { + // work-around for messages that are deleted from trash + swipeableMessageAdapter.remove(message) + } + label.type == Label.Type.UNREAD + && added.all { it.type == Label.Type.TRASH } -> { + // work-around for messages that are deleted from unread, which already have the unread label removed + swipeableMessageAdapter.remove(message) + } + added.contains(label) -> { + // in most cases, top should be the correct position, but time will show if + // the message should be properly sorted in + swipeableMessageAdapter.addFirst(message) + } + removed.contains(label) -> { + swipeableMessageAdapter.remove(message) + } + removed.any { it.type == Label.Type.UNREAD } || added.any { it.type == Label.Type.UNREAD } -> { + swipeableMessageAdapter.update(message) + } + } } } } - } - if (removed.any { it.type == Label.Type.UNREAD } || added.any { it.type == Label.Type.UNREAD }) { - MainActivity.apply { + if (removed.any { it.type == Label.Type.UNREAD } || added.any { it.type == Label.Type.UNREAD }) { updateUnread() } }