Apply alert dialog style to identity name preference

This commit is contained in:
Matéo Duparc 2021-05-31 12:37:25 +02:00
parent fee2cfaf3d
commit 558248b87e
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
4 changed files with 30 additions and 9 deletions

View File

@ -22,6 +22,7 @@ import com.bumptech.glide.request.transition.Transition
import sushi.hardcore.aira.background_service.AIRAService
import sushi.hardcore.aira.databinding.ActivitySettingsBinding
import sushi.hardcore.aira.databinding.ChangeAvatarDialogBinding
import sushi.hardcore.aira.databinding.DialogEditTextBinding
import sushi.hardcore.aira.utils.AvatarPicker
import sushi.hardcore.aira.utils.StringUtils
@ -46,9 +47,7 @@ class SettingsActivity: AppCompatActivity() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
findPreference<Preference>("identityAvatar")?.let { identityAvatarPreference = it }
val identityNamePreference = findPreference<EditTextPreference>("identityName")
val paddingPreference = findPreference<SwitchPreferenceCompat>("psecPadding")
identityNamePreference?.isPersistent = false
paddingPreference?.isPersistent = false
AIRADatabase.getIdentityAvatar(Constants.getDatabaseFolder(activity))?.let { avatar ->
displayAvatar(avatar)
@ -58,7 +57,6 @@ class SettingsActivity: AppCompatActivity() {
override fun onServiceConnected(name: ComponentName?, service: IBinder) {
val binder = service as AIRAService.AIRABinder
airaService = binder.getService()
identityNamePreference?.text = airaService.identityName
paddingPreference?.isChecked = airaService.usePadding
}
override fun onServiceDisconnected(name: ComponentName?) {}
@ -84,10 +82,17 @@ class SettingsActivity: AppCompatActivity() {
dialogBuilder.setView(dialogBinding.root).show()
false
}
identityNamePreference?.setOnPreferenceChangeListener { _, newValue ->
if (airaService.changeName(newValue as String)) {
identityNamePreference.text = newValue
}
findPreference<Preference>("identityName")?.setOnPreferenceClickListener {
val dialogBinding = DialogEditTextBinding.inflate(layoutInflater)
dialogBinding.editText.setText(airaService.identityName)
AlertDialog.Builder(activity, R.style.CustomAlertDialog)
.setTitle(it.title)
.setView(dialogBinding.root)
.setPositiveButton(R.string.ok) { _, _ ->
airaService.changeName(dialogBinding.editText.text.toString())
}
.setNegativeButton(R.string.cancel, null)
.show()
false
}
findPreference<Preference>("deleteIdentity")?.setOnPreferenceClickListener {

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:autofillHints="name"
android:hint="@string/name"
android:inputType="textPersonName"/>
</RelativeLayout>

View File

@ -104,4 +104,5 @@
<string name="show_your_ips">Show your IPs</string>
<string name="clickable_indicator">Clickable indicator</string>
<string name="avatar">Avatar</string>
</resources>
<string name="name">Name</string>
</resources>

View File

@ -9,7 +9,7 @@
android:summary="The avatar of your identity. Shown to all active sessions."
android:icon="@drawable/ic_face"/>
<EditTextPreference
<Preference
android:key="identityName"
android:title="@string/identity_name"
android:summary="@string/summary_name"