|
|
|
@ -5,20 +5,26 @@ import android.content.ClipboardManager
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.view.Menu
|
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import kotlinx.android.synthetic.main.activity_settings.*
|
|
|
|
|
import network.loki.messenger.R
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext
|
|
|
|
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
|
|
|
|
import org.thoughtcrime.securesms.loki.redesign.utilities.push
|
|
|
|
|
import org.thoughtcrime.securesms.loki.toPx
|
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp
|
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
|
|
|
|
|
|
|
|
|
class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|
|
|
|
private lateinit var glide: GlideRequests
|
|
|
|
|
private var isEditingDisplayName = false
|
|
|
|
|
set(value) { field = value; handleIsEditingDisplayNameChanged() }
|
|
|
|
|
private var displayNameToBeUploaded: String? = null
|
|
|
|
|
|
|
|
|
|
private val hexEncodedPublicKey: String
|
|
|
|
|
get() {
|
|
|
|
@ -32,8 +38,11 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|
|
|
|
super.onCreate(savedInstanceState, isReady)
|
|
|
|
|
// Set content view
|
|
|
|
|
setContentView(R.layout.activity_settings)
|
|
|
|
|
// Set title
|
|
|
|
|
supportActionBar!!.title = "Settings"
|
|
|
|
|
// Set custom toolbar
|
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
cancelButton.setOnClickListener { cancelEditingDisplayName() }
|
|
|
|
|
saveButton.setOnClickListener { saveDisplayName() }
|
|
|
|
|
showQRCodeButton.setOnClickListener { showQRCode() }
|
|
|
|
|
// Set up Glide
|
|
|
|
|
glide = GlideApp.with(this)
|
|
|
|
|
// Set up profile picture view
|
|
|
|
@ -41,6 +50,8 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|
|
|
|
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
|
|
|
|
|
profilePictureView.isLarge = true
|
|
|
|
|
profilePictureView.update()
|
|
|
|
|
// Set up display name container
|
|
|
|
|
displayNameContainer.setOnClickListener { showEditDisplayNameUI() }
|
|
|
|
|
// Set up display name text view
|
|
|
|
|
displayNameTextView.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
|
|
|
|
|
// Set up public key text view
|
|
|
|
@ -50,21 +61,53 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|
|
|
|
// Set up share button
|
|
|
|
|
shareButton.setOnClickListener { sharePublicKey() }
|
|
|
|
|
}
|
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
|
|
|
|
menuInflater.inflate(R.menu.menu_settings, menu)
|
|
|
|
|
return true
|
|
|
|
|
// region Updating
|
|
|
|
|
private fun handleIsEditingDisplayNameChanged() {
|
|
|
|
|
cancelButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
|
|
|
|
showQRCodeButton.visibility = if (isEditingDisplayName) View.GONE else View.VISIBLE
|
|
|
|
|
saveButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
|
|
|
|
displayNameTextView.visibility = if (isEditingDisplayName) View.INVISIBLE else View.VISIBLE
|
|
|
|
|
displayNameEditText.visibility = if (isEditingDisplayName) View.VISIBLE else View.INVISIBLE
|
|
|
|
|
val titleTextViewLayoutParams = titleTextView.layoutParams as LinearLayout.LayoutParams
|
|
|
|
|
titleTextViewLayoutParams.leftMargin = if (isEditingDisplayName) toPx(16, resources) else 0
|
|
|
|
|
titleTextView.layoutParams = titleTextViewLayoutParams
|
|
|
|
|
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
|
|
if (isEditingDisplayName) {
|
|
|
|
|
displayNameEditText.requestFocus()
|
|
|
|
|
inputMethodManager.showSoftInput(displayNameEditText, 0)
|
|
|
|
|
} else {
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(displayNameEditText.windowToken, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun updateProfile(isUpdatingDisplayName: Boolean, isUpdatingProfilePicture: Boolean) {
|
|
|
|
|
val displayName = displayNameToBeUploaded ?: TextSecurePreferences.getProfileName(this)
|
|
|
|
|
TextSecurePreferences.setProfileName(this, displayName)
|
|
|
|
|
val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI
|
|
|
|
|
if (publicChatAPI != null) {
|
|
|
|
|
val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers()
|
|
|
|
|
for (server in servers) {
|
|
|
|
|
publicChatAPI.setDisplayName(displayName, server)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
displayNameTextView.text = displayName
|
|
|
|
|
displayNameToBeUploaded = null
|
|
|
|
|
}
|
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
// region Interaction
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
|
val id = item.itemId
|
|
|
|
|
when (id) {
|
|
|
|
|
R.id.showQRCodeItem -> showQRCode()
|
|
|
|
|
else -> { /* Do nothing */ }
|
|
|
|
|
}
|
|
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
|
|
private fun cancelEditingDisplayName() {
|
|
|
|
|
isEditingDisplayName = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun saveDisplayName() {
|
|
|
|
|
val displayName = displayNameEditText.text.trim().toString()
|
|
|
|
|
// TODO: Validation
|
|
|
|
|
isEditingDisplayName = false
|
|
|
|
|
displayNameToBeUploaded = displayName
|
|
|
|
|
updateProfile(true, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showQRCode() {
|
|
|
|
@ -72,6 +115,10 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|
|
|
|
push(intent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showEditDisplayNameUI() {
|
|
|
|
|
isEditingDisplayName = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun copyPublicKey() {
|
|
|
|
|
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
|
|
|
val clip = ClipData.newPlainText("Session ID", hexEncodedPublicKey)
|
|
|
|
|