diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d8b8d4c37d..a98134a55e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -119,7 +119,7 @@ + android:label="@string/activity_settings_title"/> diff --git a/res/drawable/ic_qr_code.xml b/res/drawable/ic_qr_code.xml index 00ab0f639f..a14566b955 100644 --- a/res/drawable/ic_qr_code.xml +++ b/res/drawable/ic_qr_code.xml @@ -2,14 +2,15 @@ android:width="25dp" android:height="25dp" android:viewportWidth="25" - android:viewportHeight="25"> + android:viewportHeight="25" + android:tint="?attr/colorControlNormal"> + android:fillColor="@android:color/white"/> @@ -18,7 +19,7 @@ + android:fillColor="@android:color/white"/> @@ -27,7 +28,7 @@ + android:fillColor="@android:color/white"/> @@ -36,7 +37,7 @@ + android:fillColor="@android:color/white"/> @@ -45,7 +46,7 @@ + android:fillColor="@android:color/white"/> @@ -54,7 +55,7 @@ + android:fillColor="@android:color/white"/> @@ -63,7 +64,7 @@ + android:fillColor="@android:color/white"/> @@ -72,7 +73,7 @@ + android:fillColor="@android:color/white"/> @@ -81,7 +82,7 @@ + android:fillColor="@android:color/white"/> @@ -90,7 +91,7 @@ + android:fillColor="@android:color/white"/> @@ -99,7 +100,7 @@ + android:fillColor="@android:color/white"/> @@ -108,7 +109,7 @@ + android:fillColor="@android:color/white"/> @@ -117,7 +118,7 @@ + android:fillColor="@android:color/white"/> @@ -126,7 +127,7 @@ + android:fillColor="@android:color/white"/> @@ -135,7 +136,7 @@ + android:fillColor="@android:color/white"/> @@ -144,7 +145,7 @@ + android:fillColor="@android:color/white"/> @@ -153,7 +154,7 @@ + android:fillColor="@android:color/white"/> @@ -162,7 +163,7 @@ + android:fillColor="@android:color/white"/> @@ -171,7 +172,7 @@ + android:fillColor="@android:color/white"/> @@ -180,7 +181,7 @@ + android:fillColor="@android:color/white"/> @@ -189,7 +190,7 @@ + android:fillColor="@android:color/white"/> @@ -198,7 +199,7 @@ + android:fillColor="@android:color/white"/> @@ -207,7 +208,7 @@ + android:fillColor="@android:color/white"/> @@ -216,7 +217,7 @@ + android:fillColor="@android:color/white"/> @@ -225,7 +226,7 @@ + android:fillColor="@android:color/white"/> @@ -234,7 +235,7 @@ + android:fillColor="@android:color/white"/> diff --git a/res/drawable/icon_qr_code.xml b/res/drawable/icon_qr_code.xml index f1a095221e..d694c7297f 100644 --- a/res/drawable/icon_qr_code.xml +++ b/res/drawable/icon_qr_code.xml @@ -1,9 +1,15 @@ - + - + diff --git a/res/layout/activity_settings.xml b/res/layout/activity_settings.xml index 0d31b47809..aa62a3bbd5 100644 --- a/res/layout/activity_settings.xml +++ b/res/layout/activity_settings.xml @@ -20,59 +20,6 @@ android:orientation="vertical" android:gravity="center_horizontal"> - - - - - - - - - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/activities/SettingsActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/SettingsActivity.kt index 72ec815eca..caf99cba77 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/SettingsActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/SettingsActivity.kt @@ -11,9 +11,11 @@ import android.os.AsyncTask import android.os.Bundle import android.os.Handler import android.os.Looper +import android.view.ActionMode +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 androidx.appcompat.app.AppCompatDelegate import kotlinx.android.synthetic.main.activity_settings.* @@ -34,7 +36,6 @@ import org.thoughtcrime.securesms.loki.dialogs.SeedDialog import org.thoughtcrime.securesms.loki.utilities.fadeIn import org.thoughtcrime.securesms.loki.utilities.fadeOut import org.thoughtcrime.securesms.loki.utilities.push -import org.thoughtcrime.securesms.loki.utilities.toPx import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.profiles.AvatarHelper @@ -51,9 +52,11 @@ import java.security.SecureRandom import java.util.* class SettingsActivity : PassphraseRequiredActionBarActivity() { + + private var displayNameEditActionMode: ActionMode? = null + set(value) { field = value; handleDisplayNameEditActionModeChanged() } + private lateinit var glide: GlideRequests - private var isEditingDisplayName = false - set(value) { field = value; handleIsEditingDisplayNameChanged() } private var displayNameToBeUploaded: String? = null private var profilePictureToBeUploaded: ByteArray? = null private var tempFile: File? = null @@ -68,23 +71,16 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { // region Lifecycle override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) { super.onCreate(savedInstanceState, isReady) -// setTheme(if (isDarkTheme()) -// R.style.Session_DarkTheme_NoActionBar -// else -// R.style.Session_LightTheme_NoActionBar) setContentView(R.layout.activity_settings) - setSupportActionBar(toolbar) - cancelButton.setOnClickListener { cancelEditingDisplayName() } - saveButton.setOnClickListener { saveDisplayName() } - showQRCodeButton.setOnClickListener { showQRCode() } + glide = GlideApp.with(this) profilePictureView.glide = glide profilePictureView.publicKey = hexEncodedPublicKey profilePictureView.isLarge = true profilePictureView.update() profilePictureView.setOnClickListener { showEditProfilePictureUI() } - ctnGroupNameSection.setOnClickListener { showEditDisplayNameUI() } + ctnGroupNameSection.setOnClickListener { startActionMode(DisplayNameEditActionModeCallback()) } btnGroupNameDisplay.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey) publicKeyTextView.text = hexEncodedPublicKey copyButton.setOnClickListener { copyPublicKey() } @@ -110,18 +106,22 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { } } - private fun isDarkTheme(): Boolean { - val themeFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - return themeFlag == Configuration.UI_MODE_NIGHT_YES; + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.settings_general, menu) + return true } - //TODO Remove it. - private fun setDarkTheme(darkTheme: Boolean) { -// AppCompatDelegate.setDefaultNightMode(if (darkTheme) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO ) - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.action_qr_code -> { + showQRCode() + return true + } + else -> super.onOptionsItemSelected(item) + } } - public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { AvatarSelection.REQUEST_CODE_AVATAR -> { @@ -151,17 +151,16 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { // endregion // 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 + private fun handleDisplayNameEditActionModeChanged() { + val isEditingDisplayName = this.displayNameEditActionMode !== null + btnGroupNameDisplay.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.setText(btnGroupNameDisplay.text) + displayNameEditText.selectAll() displayNameEditText.requestFocus() inputMethodManager.showSoftInput(displayNameEditText, 0) } else { @@ -216,21 +215,24 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { // endregion // region Interaction - private fun cancelEditingDisplayName() { - isEditingDisplayName = false - } - private fun saveDisplayName() { + /** + * @return true if the update was successful. + */ + private fun saveDisplayName(): Boolean { val displayName = displayNameEditText.text.toString().trim() if (displayName.isEmpty()) { - return Toast.makeText(this, R.string.activity_settings_display_name_missing_error, Toast.LENGTH_SHORT).show() + Toast.makeText(this, R.string.activity_settings_display_name_missing_error, Toast.LENGTH_SHORT).show() + return false } if (displayName.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) { - return Toast.makeText(this, R.string.activity_settings_display_name_too_long_error, Toast.LENGTH_SHORT).show() + Toast.makeText(this, R.string.activity_settings_display_name_too_long_error, Toast.LENGTH_SHORT).show() + return false } - isEditingDisplayName = false +// isEditingDisplayName = false displayNameToBeUploaded = displayName updateProfile(false) + return true } private fun showQRCode() { @@ -242,10 +244,6 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { tempFile = AvatarSelection.startAvatarSelection(this, false, true) } - private fun showEditDisplayNameUI() { - isEditingDisplayName = true - } - private fun copyPublicKey() { val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clip = ClipData.newPlainText("Session ID", hexEncodedPublicKey) @@ -289,4 +287,46 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { ClearAllDataDialog().show(supportFragmentManager, "Clear All Data Dialog") } // endregion + + //TODO Remove it. + private fun isDarkTheme(): Boolean { + val themeFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return themeFlag == Configuration.UI_MODE_NIGHT_YES; + } + + //TODO Remove it. + private fun setDarkTheme(darkTheme: Boolean) { +// AppCompatDelegate.setDefaultNightMode(if (darkTheme) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO ) + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + } + + private inner class DisplayNameEditActionModeCallback: ActionMode.Callback { + + override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { + mode.title = getString(R.string.activity_settings_display_name_edit_text_hint) + mode.menuInflater.inflate(R.menu.menu_apply, menu) + this@SettingsActivity.displayNameEditActionMode = mode + return true + } + + override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { + return false + } + + override fun onDestroyActionMode(mode: ActionMode) { + this@SettingsActivity.displayNameEditActionMode = null + } + + override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + when (item.itemId) { + R.id.applyButton -> { + if (this@SettingsActivity.saveDisplayName()) { + mode.finish() + } + return true + } + } + return false; + } + } } \ No newline at end of file