mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Improve settings dialogs
This commit is contained in:
parent
7f66c84e5c
commit
04e88a8494
13 changed files with 260 additions and 194 deletions
|
|
@ -1,11 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/spacing_medium">
|
||||
<EditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_height="match_parent">
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text" />
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,37 +1,55 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/spacing_medium">
|
||||
<TextView
|
||||
android:id="@+id/emailTitleTextView"
|
||||
android:layout_height="match_parent">
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/email"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/passwordTitleTextView"
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:hint="@string/email">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/emailTitleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/password"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:hint="@string/password"
|
||||
android:layout_marginTop="@dimen/content_section_spacing">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/confirmpassword"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/passwordRepeatEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"/>
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:hint="@string/confirmpassword"
|
||||
android:layout_marginTop="@dimen/content_section_spacing">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/passwordRepeatEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,36 +1,55 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/spacing_medium">
|
||||
<TextView
|
||||
android:layout_height="match_parent">
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/old_password"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/editText"
|
||||
android:hint="@string/old_password"
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"/>
|
||||
<TextView
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:hint="@string/new_password"
|
||||
android:layout_marginTop="@dimen/content_section_spacing">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_password"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_password_repeat"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/passwordRepeatEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword" />
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:hint="@string/new_password_repeat"
|
||||
android:layout_marginTop="@dimen/content_section_spacing">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/passwordRepeatEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,20 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/spacing_medium">
|
||||
<EditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/passwordTitleTextView"
|
||||
android:layout_height="match_parent">
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/password"
|
||||
android:layout_marginTop="@dimen/content_section_spacing"/>
|
||||
<EditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/password"
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:layout_marginTop="@dimen/content_section_spacing">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/passwordEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="@dimen/spacing_large"
|
||||
android:paddingEnd="@dimen/spacing_large" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -44,9 +44,9 @@
|
|||
android:textColor="?textColorSecondary"
|
||||
style="@style/Body2"
|
||||
tools:text="This is the message"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"
|
||||
android:layout_marginStart="@dimen/alert_side_padding"
|
||||
android:layout_marginEnd="@dimen/alert_side_padding"
|
||||
android:paddingBottom="@dimen/spacing_medium"
|
||||
android:paddingStart="@dimen/alert_side_padding"
|
||||
android:paddingEnd="@dimen/alert_side_padding"
|
||||
/>
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -3,5 +3,4 @@
|
|||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
style="@style/HabiticaButton.Primary">
|
||||
|
||||
</Button>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Button xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
style="@style/HabiticaButton.Red">
|
||||
</Button>
|
||||
|
|
@ -655,8 +655,8 @@
|
|||
<string name="delete_account">Delete Account</string>
|
||||
<string name="delete_account_description">Are you sure? This will delete your account forever, and it can never be restored! You will need to register a new account to use Habitica again. Banked or spent Gems will not be refunded. If you\'re absolutely certain, type your password into the text box below.</string>
|
||||
<string name="delete_oauth_account_description">Are you sure? This will delete your account forever, and it can never be restored! You will need to register a new account to use Habitica again. Banked or spent Gems will not be refunded. If you\'re absolutely certain, type DELETE into the text box below.</string>
|
||||
<string name="reset_account_confirmation">reset my account</string>
|
||||
<string name="delete_account_confirmation">delete my account</string>
|
||||
<string name="reset_account_confirmation">Reset my Account</string>
|
||||
<string name="delete_account_confirmation">Delete my Account</string>
|
||||
<string name="danger_zone">Danger Zone</string>
|
||||
<string name="nevermind">Nevermind</string>
|
||||
<string name="resetting_account">Resetting Account</string>
|
||||
|
|
@ -933,4 +933,5 @@
|
|||
<string name="special_achievements">Special Achievements</string>
|
||||
<string name="switch_to_list_view">Switch to list view</string>
|
||||
<string name="switch_to_grid_view">Switch to grid view</string>
|
||||
<string name="confirm_deletion">Confirm deletion</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
|
||||
fun HabiticaAlertDialog.addOkButton(isPrimary: Boolean = true, listener: ((HabiticaAlertDialog, Int) -> Unit)? = null) {
|
||||
this.addButton(R.string.ok, isPrimary, listener)
|
||||
this.addButton(R.string.ok, isPrimary, false, listener)
|
||||
}
|
||||
|
||||
fun HabiticaAlertDialog.addCloseButton(isPrimary: Boolean = false, listener: ((DialogInterface, Int) -> Unit)? = null) {
|
||||
this.addButton(R.string.close, isPrimary, listener)
|
||||
this.addButton(R.string.close, isPrimary, false, listener)
|
||||
}
|
||||
|
||||
fun HabiticaAlertDialog.addCancelButton(isPrimary: Boolean = false, listener: ((DialogInterface, Int) -> Unit)? = null) {
|
||||
this.addButton(R.string.cancel, isPrimary, listener)
|
||||
this.addButton(R.string.cancel, isPrimary, false, listener)
|
||||
}
|
||||
|
|
@ -368,7 +368,7 @@ public class IntentIntegrator {
|
|||
HabiticaAlertDialog downloadDialog = new HabiticaAlertDialog(activity);
|
||||
downloadDialog.setTitle(title);
|
||||
downloadDialog.setMessage(message);
|
||||
downloadDialog.addButton(buttonYes, true, (dialogInterface, i) -> {
|
||||
downloadDialog.addButton(buttonYes, true, false, (dialogInterface, i) -> {
|
||||
String packageName = targetApplications.get(0);
|
||||
Uri uri = Uri.parse("market://details?id=" + packageName);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
|
|
@ -380,7 +380,7 @@ public class IntentIntegrator {
|
|||
}
|
||||
return null;
|
||||
});
|
||||
downloadDialog.addButton(buttonNo, false, null);
|
||||
downloadDialog.addButton(buttonNo, false, false, null);
|
||||
downloadDialog.show();
|
||||
return downloadDialog;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
val alert = HabiticaAlertDialog(this)
|
||||
alert.setTitle(event.title)
|
||||
alert.setMessage(event.message)
|
||||
alert.addButton(android.R.string.ok, true, null)
|
||||
alert.addButton(android.R.string.ok, true, false, null)
|
||||
alert.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,21 @@ import android.app.ProgressDialog
|
|||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.preference.Preference
|
||||
import android.text.InputType
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import androidx.preference.Preference
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.data.ApiClient
|
||||
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.extensions.*
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionDetailsView
|
||||
import io.reactivex.functions.Consumer
|
||||
import javax.inject.Inject
|
||||
|
|
@ -101,18 +98,17 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
val passwordEditText = view?.findViewById<EditText>(R.id.passwordEditText)
|
||||
val passwordRepeatEditText = view?.findViewById<EditText>(R.id.passwordRepeatEditText)
|
||||
context.notNull { context ->
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setTitle(R.string.change_password)
|
||||
.setPositiveButton(R.string.change) { thisDialog, _ ->
|
||||
thisDialog.dismiss()
|
||||
userRepository.updatePassword(oldPasswordEditText?.text.toString(), passwordEditText?.text.toString(), passwordRepeatEditText?.text.toString())
|
||||
.subscribe(Consumer {
|
||||
Toast.makeText(activity, R.string.password_changed, Toast.LENGTH_SHORT).show()
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
.setNegativeButton(R.string.action_cancel) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
dialog.setView(view)
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.change_password)
|
||||
dialog.addButton(R.string.change, true) { _, _ ->
|
||||
userRepository.updatePassword(oldPasswordEditText?.text.toString(), passwordEditText?.text.toString(), passwordRepeatEditText?.text.toString())
|
||||
.subscribe(Consumer {
|
||||
Toast.makeText(activity, R.string.password_changed, Toast.LENGTH_SHORT).show()
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.setAdditionalContentView(view)
|
||||
dialog.setAdditionalContentSidePadding(12)
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -122,20 +118,20 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
val view = inflater?.inflate(R.layout.dialog_edittext_confirm_pw, null)
|
||||
val emailEditText = view?.findViewById<EditText>(R.id.editText)
|
||||
emailEditText?.setText(user?.authentication?.localAuthentication?.email)
|
||||
view?.findViewById<TextInputLayout>(R.id.input_layout)?.hint = context?.getString(R.string.email)
|
||||
val passwordEditText = view?.findViewById<EditText>(R.id.passwordEditText)
|
||||
context.notNull { context ->
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setTitle(R.string.change_email)
|
||||
.setPositiveButton(R.string.change) { thisDialog, _ ->
|
||||
thisDialog.dismiss()
|
||||
userRepository.updateEmail(emailEditText?.text.toString(), passwordEditText?.text.toString())
|
||||
.subscribe(Consumer {
|
||||
configurePreference(findPreference("email"), emailEditText?.text.toString(), true)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
.setNegativeButton(R.string.action_cancel) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
dialog.setView(view)
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.change_email)
|
||||
dialog.addButton(R.string.change, true) { _, _ ->
|
||||
userRepository.updateEmail(emailEditText?.text.toString(), passwordEditText?.text.toString())
|
||||
.subscribe(Consumer {
|
||||
configurePreference(findPreference("email"), emailEditText?.text.toString(), true)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.setAdditionalContentView(view)
|
||||
dialog.setAdditionalContentSidePadding(12.dpToPx(context))
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -145,47 +141,44 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
val view = inflater?.inflate(R.layout.dialog_edittext, null)
|
||||
val loginNameEditText = view?.findViewById<EditText>(R.id.editText)
|
||||
loginNameEditText?.setText(user?.authentication?.localAuthentication?.username)
|
||||
view?.findViewById<TextInputLayout>(R.id.input_layout)?.hint = context?.getString(R.string.username)
|
||||
context.notNull { context ->
|
||||
val builder = AlertDialog.Builder(context).setTitle(R.string.change_username)
|
||||
val dialog = builder.setPositiveButton(R.string.save) { thisDialog, _ ->
|
||||
thisDialog.dismiss()
|
||||
userRepository.updateLoginName(loginNameEditText?.text.toString())
|
||||
.subscribe(Consumer {
|
||||
configurePreference(findPreference("login_name"), loginNameEditText?.text.toString(), true)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
.setNegativeButton(R.string.action_cancel) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
dialog.setView(view)
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.change_username)
|
||||
dialog.addButton(R.string.save, true) { _, _ ->
|
||||
userRepository.updateLoginName(loginNameEditText?.text.toString())
|
||||
.subscribe(Consumer {
|
||||
configurePreference(findPreference("login_name"), loginNameEditText?.text.toString(), true)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.setAdditionalContentView(view)
|
||||
dialog.setAdditionalContentSidePadding(12.dpToPx(context))
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showAccountDeleteConfirmation() {
|
||||
val input = EditText(context)
|
||||
val view = context?.layoutInflater?.inflate(R.layout.dialog_edittext, null)
|
||||
var deleteMessage = getString(R.string.delete_account_description)
|
||||
val editText = view?.findViewById<EditText>(R.id.editText)
|
||||
if (user?.authentication?.localAuthentication != null) {
|
||||
input.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
editText?.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
} else {
|
||||
deleteMessage = getString(R.string.delete_oauth_account_description)
|
||||
input.inputType = InputType.TYPE_CLASS_TEXT
|
||||
editText?.inputType = InputType.TYPE_CLASS_TEXT
|
||||
}
|
||||
val lp = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT)
|
||||
input.layoutParams = lp
|
||||
view?.findViewById<TextInputLayout>(R.id.input_layout)?.hint = context?.getString(R.string.confirm_deletion)
|
||||
context.notNull { context ->
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_account)
|
||||
.setMessage(deleteMessage)
|
||||
.setPositiveButton(R.string.delete_account_confirmation) { thisDialog, _ ->
|
||||
thisDialog.dismiss()
|
||||
deleteAccount(input.text.toString())
|
||||
}
|
||||
.setNegativeButton(R.string.nevermind) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
dialog.setOnShowListener { dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(context, R.color.red_10)) }
|
||||
dialog.setView(input)
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.delete_account)
|
||||
dialog.setMessage(deleteMessage)
|
||||
dialog.addButton(R.string.delete_account_confirmation, true, true) { _, _ ->
|
||||
deleteAccount(editText?.text?.toString() ?: "")
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.setAdditionalContentView(view)
|
||||
dialog.setAdditionalContentSidePadding(12.dpToPx(context))
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -197,22 +190,22 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
val passwordEditText = view?.findViewById<EditText>(R.id.passwordEditText)
|
||||
val passwordRepeatEditText = view?.findViewById<EditText>(R.id.passwordRepeatEditText)
|
||||
context.notNull { context ->
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setTitle(R.string.add_local_authentication)
|
||||
.setPositiveButton(R.string.save) { thisDialog, _ ->
|
||||
if (passwordEditText?.text == passwordRepeatEditText?.text) {
|
||||
return@setPositiveButton
|
||||
}
|
||||
thisDialog.dismiss()
|
||||
apiClient.registerUser(user?.username ?: "", emailEditText?.text.toString(), passwordEditText?.text.toString(), passwordRepeatEditText?.text.toString())
|
||||
.flatMap { userRepository.retrieveUser(false) }
|
||||
.subscribe(Consumer {
|
||||
configurePreference(findPreference("email"), emailEditText?.text.toString(), true)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
.setNegativeButton(R.string.action_cancel) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
dialog.setView(view)
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.add_local_authentication)
|
||||
dialog.addButton(R.string.save, true) { thisDialog, _ ->
|
||||
if (passwordEditText?.text == passwordRepeatEditText?.text) {
|
||||
return@addButton
|
||||
}
|
||||
thisDialog.dismiss()
|
||||
apiClient.registerUser(user?.username ?: "", emailEditText?.text.toString(), passwordEditText?.text.toString(), passwordRepeatEditText?.text.toString())
|
||||
.flatMap { userRepository.retrieveUser(false) }
|
||||
.subscribe(Consumer {
|
||||
configurePreference(findPreference("email"), emailEditText?.text.toString(), true)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.setAdditionalContentView(view)
|
||||
dialog.setAdditionalContentSidePadding(12.dpToPx(context))
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -220,43 +213,39 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
private fun deleteAccount(password: String) {
|
||||
@Suppress("DEPRECATION")
|
||||
val dialog = ProgressDialog.show(context, context?.getString(R.string.deleting_account), null, true)
|
||||
userRepository.deleteAccount(password).subscribe({ _ ->
|
||||
compositeSubscription.add(userRepository.deleteAccount(password).subscribe({ _ ->
|
||||
context.notNull { HabiticaBaseApplication.logout(it) }
|
||||
activity?.finish()
|
||||
}) { throwable ->
|
||||
dialog.dismiss()
|
||||
RxErrorHandler.reportError(throwable)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showAccountResetConfirmation() {
|
||||
context.notNull { context ->
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setTitle(R.string.reset_account)
|
||||
.setMessage(R.string.reset_account_description)
|
||||
.setPositiveButton(R.string.reset_account_confirmation) { thisDialog, _ ->
|
||||
thisDialog.dismiss()
|
||||
resetAccount()
|
||||
}
|
||||
.setNegativeButton(R.string.nevermind) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
dialog.setOnShowListener { dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(context, R.color.red_10)) }
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.reset_account)
|
||||
dialog.setMessage(R.string.reset_account_description)
|
||||
dialog.addButton(R.string.reset_account_confirmation, true, true) { _, _ ->
|
||||
resetAccount()
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.setAdditionalContentSidePadding(12.dpToPx(context))
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showConfirmUsernameDialog() {
|
||||
context.notNull { context ->
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setTitle(R.string.confirm_username_title)
|
||||
.setMessage(R.string.confirm_username_description)
|
||||
.setPositiveButton(R.string.confirm) { thisDialog, _ ->
|
||||
thisDialog.dismiss()
|
||||
userRepository.updateLoginName(user?.authentication?.localAuthentication?.username ?: "")
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
.setNegativeButton(R.string.cancel) { thisDialog, _ -> thisDialog.dismiss() }
|
||||
.create()
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.confirm_username_title)
|
||||
dialog.setMessage(R.string.confirm_username_description)
|
||||
dialog.addButton(R.string.confirm, true) { _, _ ->
|
||||
userRepository.updateLoginName(user?.authentication?.localAuthentication?.username ?: "")
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
dialog.addCancelButton()
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -264,10 +253,10 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
private fun resetAccount() {
|
||||
@Suppress("DEPRECATION")
|
||||
val dialog = ProgressDialog.show(context, context?.getString(R.string.resetting_account), null, true)
|
||||
userRepository.resetAccount().subscribe({ dialog.dismiss() }) { throwable ->
|
||||
compositeSubscription.add(userRepository.resetAccount().subscribe({ dialog.dismiss() }) { throwable ->
|
||||
dialog.dismiss()
|
||||
RxErrorHandler.reportError(throwable)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showSubscriptionStatusDialog() {
|
||||
|
|
@ -276,10 +265,10 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() {
|
|||
user?.purchased?.plan?.notNull {
|
||||
view.setPlan(it)
|
||||
}
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setView(view)
|
||||
.setTitle(R.string.subscription_status)
|
||||
.setPositiveButton(R.string.close) { dialogInterface, _ -> dialogInterface.dismiss() }.create()
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setAdditionalContentView(view)
|
||||
dialog.setTitle(R.string.subscription_status)
|
||||
dialog.addCloseButton()
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.widget.FrameLayout
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.children
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.dpToPx
|
||||
|
|
@ -120,7 +121,7 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
|
||||
fun setAdditionalContentSidePadding(padding: Int) {
|
||||
contentView.setPadding(padding, 0, padding, contentView.paddingBottom)
|
||||
contentView.requestLayout()
|
||||
messageTextView.setPadding(padding, messageTextView.paddingTop, padding, messageTextView.paddingBottom)
|
||||
}
|
||||
|
||||
private fun updateButtonLayout() {
|
||||
|
|
@ -144,15 +145,23 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
|
||||
fun getContentView(): View? = additionalContentView
|
||||
|
||||
fun addButton(stringRes: Int, isPrimary: Boolean, function: ((HabiticaAlertDialog, Int) -> Unit)? = null): Button {
|
||||
return addButton(context.getString(stringRes), isPrimary, function)
|
||||
fun addButton(stringRes: Int, isPrimary: Boolean, isDestructive: Boolean = false, function: ((HabiticaAlertDialog, Int) -> Unit)? = null): Button {
|
||||
return addButton(context.getString(stringRes), isPrimary, isDestructive, function)
|
||||
}
|
||||
|
||||
fun addButton(string: String, isPrimary: Boolean, function: ((HabiticaAlertDialog, Int) -> Unit)? = null): Button {
|
||||
fun addButton(string: String, isPrimary: Boolean, isDestructive: Boolean = false, function: ((HabiticaAlertDialog, Int) -> Unit)? = null): Button {
|
||||
val button: Button = if (isPrimary) {
|
||||
buttonsWrapper.inflate(R.layout.dialog_habitica_primary_button) as Button
|
||||
if (isDestructive) {
|
||||
buttonsWrapper.inflate(R.layout.dialog_habitica_primary_destructive_button) as Button
|
||||
} else {
|
||||
buttonsWrapper.inflate(R.layout.dialog_habitica_primary_button) as Button
|
||||
}
|
||||
} else {
|
||||
buttonsWrapper.inflate(R.layout.dialog_habitica_secondary_button) as Button
|
||||
val button = buttonsWrapper.inflate(R.layout.dialog_habitica_secondary_button) as Button
|
||||
if (isDestructive) {
|
||||
button.setTextColor(ContextCompat.getColor(context, R.color.red_100))
|
||||
}
|
||||
button
|
||||
}
|
||||
button.text = string
|
||||
button.minWidth = 147.dpToPx(context)
|
||||
|
|
|
|||
Loading…
Reference in a new issue