From f27f43899840cc0a51ab9de55a1bdfb90f5d652e Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 22 Sep 2017 20:29:23 +0200 Subject: [PATCH] Minor fixes and improvements --- .../java/ch/dissem/apps/abit/MainActivity.kt | 14 ++--- .../dissem/apps/abit/MessageDetailFragment.kt | 15 ++---- .../dissem/apps/abit/MessageListFragment.kt | 53 ++++++++++--------- .../dissem/apps/abit/listener/WifiReceiver.kt | 28 +--------- .../java/ch/dissem/apps/abit/util/FabUtils.kt | 2 +- .../ch/dissem/apps/abit/util/Preferences.kt | 4 +- .../layout/dialog_select_message_encoding.xml | 5 +- .../main/res/layout/select_identity_row.xml | 1 - app/src/main/res/menu/compose.xml | 2 +- app/src/main/res/values-de/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 1 + 11 files changed, 51 insertions(+), 77 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 677ca79..7734e09 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt @@ -29,7 +29,6 @@ import ch.dissem.apps.abit.drawer.ProfileImageListener import ch.dissem.apps.abit.drawer.ProfileSelectionListener import ch.dissem.apps.abit.listener.ListSelectionListener import ch.dissem.apps.abit.repository.AndroidMessageRepository.Companion.LABEL_ARCHIVE -import ch.dissem.apps.abit.service.BitmessageService.Companion.isRunning import ch.dissem.apps.abit.service.Singleton import ch.dissem.apps.abit.synchronization.SyncAdapter import ch.dissem.apps.abit.util.Labels @@ -99,8 +98,8 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { private lateinit var drawer: Drawer private lateinit var nodeSwitch: SwitchDrawerItem - val floatingActionButton: FabSpeedDial - get() = fab + val floatingActionButton: FabSpeedDial? + get() = findViewById(R.id.fab) as FabSpeedDial? override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -359,11 +358,12 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { } override fun onRestoreInstanceState(savedInstanceState: Bundle) { - selectedLabel = savedInstanceState.getSerializable("selectedLabel") as Label + selectedLabel = savedInstanceState.getSerializable("selectedLabel") as Label? - val selectedItem = drawer.getDrawerItem(selectedLabel) - if (selectedItem != null) { - drawer.setSelection(selectedItem) + selectedLabel?.let { selectedLabel -> + drawer.getDrawerItem(selectedLabel)?.let { selectedItem -> + drawer.setSelection(selectedItem) + } } super.onRestoreInstanceState(savedInstanceState) } 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 c6cb099..2f62832 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt @@ -111,14 +111,7 @@ class MessageDetailFragment : Fragment() { text.linksClickable = true text.setTextIsSelectable(true) - var removed = false - val labels = item.labels.iterator() - while (labels.hasNext()) { - if (labels.next().type == Label.Type.UNREAD) { - labels.remove() - removed = true - } - } + val removed = item.labels.removeAll { it.type==Label.Type.UNREAD } val messageRepo = Singleton.getMessageRepository(context) if (removed) { if (activity is MainActivity) { @@ -173,15 +166,14 @@ class MessageDetailFragment : Fragment() { Singleton.labeler.delete(item) messageRepo.save(item) } + (activity as? MainActivity)?.updateUnread() activity.onBackPressed() return true } R.id.mark_unread -> { Singleton.labeler.markAsUnread(item) messageRepo.save(item) - if (activity is MainActivity) { - (activity as MainActivity).updateUnread() - } + (activity as? MainActivity)?.updateUnread() return true } R.id.archive -> { @@ -190,6 +182,7 @@ class MessageDetailFragment : Fragment() { } Singleton.labeler.archive(item) messageRepo.save(item) + (activity as? MainActivity)?.updateUnread() return true } else -> return false 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 a395751..3e68de5 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt @@ -16,9 +16,8 @@ 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 @@ -32,7 +31,6 @@ 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 @@ -186,18 +184,17 @@ class MessageListFragment : Fragment(), ListHolder