From 696cd6c0a660cab29635a360b29eade15d394542 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 1 Sep 2017 07:29:44 +0200 Subject: [PATCH] Removed most '!!' --- .../apps/abit/AbstractItemListFragment.kt | 4 +- .../dissem/apps/abit/AddressListFragment.kt | 11 ++--- .../apps/abit/ComposeMessageActivity.kt | 27 ++++++------ .../ch/dissem/apps/abit/DetailActivity.kt | 4 +- .../dissem/apps/abit/MessageDetailFragment.kt | 4 +- .../dissem/apps/abit/MessageListFragment.kt | 2 +- .../ch/dissem/apps/abit/StatusActivity.kt | 6 ++- .../apps/abit/adapter/ContactAdapter.kt | 41 +++++++++---------- .../DeterministicIdentityDialogFragment.kt | 13 +++--- .../abit/notification/NetworkNotification.kt | 28 ++++++------- .../notification/NewMessageNotification.kt | 5 ++- .../repository/AndroidMessageRepository.kt | 7 ++-- .../dissem/apps/abit/repository/SqlHelper.kt | 2 +- .../abit/service/BitmessageIntentService.kt | 24 ++++++----- .../apps/abit/service/ServicePowEngine.kt | 5 +-- .../ch/dissem/apps/abit/service/Singleton.kt | 11 ++--- .../apps/abit/synchronization/SyncAdapter.kt | 2 +- .../ch/dissem/apps/abit/util/Drawables.kt | 5 ++- .../java/ch/dissem/apps/abit/util/PowStats.kt | 2 +- 19 files changed, 103 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.kt b/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.kt index 85ffc16..3907e7d 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.kt @@ -94,9 +94,9 @@ abstract class AbstractItemListFragment : ListFragment(), ListHolder { override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) - if (activatedPosition != ListView.INVALID_POSITION) { + if (outState != null && activatedPosition != ListView.INVALID_POSITION) { // Serialize and persist the activated item position. - outState!!.putInt(STATE_ACTIVATED_POSITION, activatedPosition) + outState.putInt(STATE_ACTIVATED_POSITION, activatedPosition) } } diff --git a/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.kt b/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.kt index c34cbee..abd52fc 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.kt @@ -68,11 +68,12 @@ class AddressListFragment : AbstractItemListFragment() v = convertView.tag as ViewHolder result = convertView } - val item = getItem(position)!! - v.avatar.setImageDrawable(Identicon(item)) - v.name.text = item.toString() - v.streamNumber.text = v.ctx.getString(R.string.stream_number, item.stream) - v.subscribed.visibility = if (item.isSubscribed) View.VISIBLE else View.INVISIBLE + getItem(position)?.let { item -> + v.avatar.setImageDrawable(Identicon(item)) + v.name.text = item.toString() + v.streamNumber.text = v.ctx.getString(R.string.stream_number, item.stream) + v.subscribed.visibility = if (item.isSubscribed) View.VISIBLE else View.INVISIBLE + } return result } } diff --git a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.kt b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.kt index 49e0bcd..39310d2 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageActivity.kt @@ -37,14 +37,17 @@ class ComposeMessageActivity : AppCompatActivity() { setContentView(R.layout.toolbar_layout) setSupportActionBar(toolbar) - supportActionBar!!.setHomeAsUpIndicator(R.drawable.ic_action_close) - supportActionBar!!.setDisplayHomeAsUpEnabled(true) - supportActionBar!!.setHomeButtonEnabled(false) + supportActionBar?.apply { + setHomeAsUpIndicator(R.drawable.ic_action_close) + setDisplayHomeAsUpEnabled(true) + setHomeButtonEnabled(false) + } // Display the fragment as the main content. val fragment = ComposeMessageFragment() fragment.arguments = intent.extras - supportFragmentManager.beginTransaction() + supportFragmentManager + .beginTransaction() .replace(R.id.content, fragment) .commit() } @@ -69,7 +72,7 @@ class ComposeMessageActivity : AppCompatActivity() { private fun getReplyIntent(ctx: Context, item: Plaintext): Intent { val replyIntent = Intent(ctx, ComposeMessageActivity::class.java) val receivingIdentity = item.to - if (receivingIdentity!!.isChan) { + if (receivingIdentity?.isChan ?: false) { // reply to chan, not to the sender of the message replyIntent.putExtra(EXTRA_RECIPIENT, receivingIdentity) // I hate when people send as chan, so it won't be the default behaviour. @@ -84,14 +87,14 @@ class ComposeMessageActivity : AppCompatActivity() { replyIntent.putExtra(EXTRA_ENCODING, EXTENDED) } replyIntent.putExtra(EXTRA_PARENT, item) - val prefix: String - if (item.subject!!.length >= 3 && item.subject!!.substring(0, 3) - .equals("RE:", ignoreCase = true)) { - prefix = "" - } else { - prefix = "RE: " + item.subject?.let { subject -> + val prefix: String = if (subject.length >= 3 && subject.substring(0, 3).equals("RE:", ignoreCase = true)) { + "" + } else { + "RE: " + } + replyIntent.putExtra(EXTRA_SUBJECT, prefix + subject) } - replyIntent.putExtra(EXTRA_SUBJECT, prefix + item.subject!!) replyIntent.putExtra(EXTRA_CONTENT, "\n\n------------------------------------------------------\n" + item.text!!) return replyIntent diff --git a/app/src/main/java/ch/dissem/apps/abit/DetailActivity.kt b/app/src/main/java/ch/dissem/apps/abit/DetailActivity.kt index b6ae31b..2890b01 100644 --- a/app/src/main/java/ch/dissem/apps/abit/DetailActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/DetailActivity.kt @@ -19,7 +19,9 @@ abstract class DetailActivity : AppCompatActivity() { setSupportActionBar(toolbar) // Show the Up button in the action bar. - supportActionBar!!.setDisplayHomeAsUpEnabled(true) + supportActionBar?.apply { + setDisplayHomeAsUpEnabled(true) + } MaterializeBuilder() .withActivity(this) 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 bcfa9cf..51a1bdd 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageDetailFragment.kt @@ -145,8 +145,8 @@ class MessageDetailFragment : Fragment() { recyclerView.layoutManager = LinearLayoutManager(activity) } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater?) { - inflater!!.inflate(R.menu.message, menu) + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.message, menu) Drawables.addIcon(activity, menu, R.id.reply, GoogleMaterial.Icon.gmd_reply) Drawables.addIcon(activity, menu, R.id.delete, GoogleMaterial.Icon.gmd_delete) 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 7cde336..9974878 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