diff --git a/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.kt b/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.kt index 991919f..cb36e01 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.kt @@ -58,12 +58,11 @@ class AddressDetailFragment : Fragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.address, menu) - val activity = activity - Drawables.addIcon(activity, menu, R.id.write_message, GoogleMaterial.Icon.gmd_mail) - Drawables.addIcon(activity, menu, R.id.share, GoogleMaterial.Icon.gmd_share) - Drawables.addIcon(activity, menu, R.id.delete, GoogleMaterial.Icon.gmd_delete) - Drawables.addIcon(activity, menu, R.id.export, - CommunityMaterial.Icon.cmd_export).isVisible = item != null && item!!.privateKey != null + val ctx = activity + Drawables.addIcon(ctx, menu, R.id.write_message, GoogleMaterial.Icon.gmd_mail) + Drawables.addIcon(ctx, menu, R.id.share, GoogleMaterial.Icon.gmd_share) + Drawables.addIcon(ctx, menu, R.id.delete, GoogleMaterial.Icon.gmd_delete) + Drawables.addIcon(ctx, menu, R.id.export, CommunityMaterial.Icon.cmd_export).isVisible = item?.privateKey != null super.onCreateOptionsMenu(menu, inflater) } @@ -187,9 +186,8 @@ class AddressDetailFragment : Fragment() { override fun onPause() { item?.let { item -> Singleton.getAddressRepository(context).save(item) - val mainActivity = MainActivity.getInstance() - if (mainActivity != null && item.privateKey != null) { - mainActivity.updateIdentityEntry(item) + if (item.privateKey != null) { + MainActivity.getInstance()?.updateIdentityEntry(item) } } super.onPause() diff --git a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt index b839bed..4174ace 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt @@ -56,7 +56,7 @@ class ComposeMessageFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (arguments != null) { + arguments?.let { arguments -> var id = arguments.getSerializable(EXTRA_IDENTITY) as? BitmessageAddress if (context != null && (id == null || id.privateKey == null)) { id = Singleton.getIdentity(context) @@ -81,9 +81,9 @@ class ComposeMessageFragment : Fragment() { if (arguments.containsKey(EXTRA_PARENT)) { parent = arguments.getSerializable(EXTRA_PARENT) as Plaintext } - } else { + } ?: { throw IllegalStateException("No identity set for ComposeMessageFragment") - } + }.invoke() setHasOptionsMenu(true) } @@ -109,20 +109,18 @@ class ComposeMessageFragment : Fragment() { // leave current selection } } - if (recipient != null) { - recipient_input.setText(recipient.toString()) - } + recipient?.let { recipient_input.setText(it.toString()) } } subject_input.setText(subject) body_input.setText(content) - if (recipient == null) { - recipient_input.requestFocus() - } else if (subject.isEmpty()) { - subject_input.requestFocus() - } else { - body_input.requestFocus() - body_input.setSelection(0) + when { + recipient == null -> recipient_input.requestFocus() + subject.isEmpty() -> subject_input.requestFocus() + else -> { + body_input.requestFocus() + body_input.setSelection(0) + } } } diff --git a/app/src/main/java/ch/dissem/apps/abit/CreateAddressActivity.kt b/app/src/main/java/ch/dissem/apps/abit/CreateAddressActivity.kt index 9d9dac4..34f500a 100644 --- a/app/src/main/java/ch/dissem/apps/abit/CreateAddressActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/CreateAddressActivity.kt @@ -90,7 +90,7 @@ class CreateAddressActivity : AppCompatActivity() { if (subscribe.isChecked) { bmc.addSubscribtion(bmAddress) } - if (pubkeyBytes != null) { + pubkeyBytes?.let { pubkeyBytes -> try { val pubkeyStream = ByteArrayInputStream(pubkeyBytes) val stream = bmAddress.stream 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 1f5b7b7..f8586cb 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageDetailActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageDetailActivity.kt @@ -33,7 +33,7 @@ class MessageDetailActivity : DetailActivity() { // http://developer.android.com/guide/components/fragments.html // if (savedInstanceState == null) { - label = intent.getSerializableExtra(MainActivity.EXTRA_SHOW_LABEL) as Label + label = intent.getSerializableExtra(MainActivity.EXTRA_SHOW_LABEL) as Label? // Create the detail fragment and add it to the activity // using a fragment transaction. val arguments = Bundle() 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 f2aa566..7cde336 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt @@ -90,7 +90,7 @@ class MessageListFragment : Fragment(), ListHolder