session-android/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt

62 lines
2.7 KiB
Kotlin
Raw Normal View History

2019-07-18 05:59:41 +00:00
package org.thoughtcrime.securesms.loki
import android.content.Intent
import android.os.Bundle
2019-07-22 04:05:51 +00:00
import android.view.MenuItem
2019-07-18 05:59:41 +00:00
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_new_conversation.*
2019-07-24 02:30:23 +00:00
import network.loki.messenger.R;
2019-07-18 05:59:41 +00:00
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.ConversationActivity
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.DynamicTheme
import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation
class NewConversationActivity : PassphraseRequiredActionBarActivity() {
private val dynamicTheme = DynamicTheme()
override fun onPreCreate() {
dynamicTheme.onCreate(this)
}
override fun onCreate(bundle: Bundle?, isReady: Boolean) {
setContentView(R.layout.activity_new_conversation)
supportActionBar!!.setTitle(R.string.activity_new_conversation_title)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
nextButton.setOnClickListener { startNewConversationIfPossible() }
}
public override fun onResume() {
super.onResume()
dynamicTheme.onResume(this)
}
2019-07-22 04:05:51 +00:00
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}
2019-07-18 05:59:41 +00:00
private fun startNewConversationIfPossible() {
val hexEncodedPublicKey = publicKeyEditText.text.toString().trim()
if (PublicKeyValidation.isValid(hexEncodedPublicKey)) {
val contact = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), true)
val intent = Intent(this, ConversationActivity::class.java)
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, contact.address)
intent.putExtra(ConversationActivity.TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.TEXT_EXTRA))
intent.setDataAndType(getIntent().data, getIntent().type)
val existingThread = DatabaseFactory.getThreadDatabase(this).getThreadIdIfExistsFor(contact)
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, existingThread)
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT)
startActivity(intent)
finish()
} else {
Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show()
}
}
}