mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
use DialogFragment to retain state
Signed-off-by: Parneet Singh <gurayaparneet@gmail.com>
This commit is contained in:
parent
304f6ad564
commit
6c52e73b9c
@ -34,10 +34,8 @@ import android.annotation.SuppressLint
|
|||||||
import android.app.KeyguardManager
|
import android.app.KeyguardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.DialogInterface.OnShowListener
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.ColorStateList
|
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
@ -46,18 +44,12 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.security.KeyChain
|
import android.security.KeyChain
|
||||||
import android.text.Editable
|
|
||||||
import android.text.InputType
|
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.text.TextWatcher
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.view.ContextThemeWrapper
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
@ -88,9 +80,10 @@ import com.nextcloud.talk.jobs.ContactAddressBookWorker.Companion.deleteAll
|
|||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||||
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
|
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
|
||||||
import com.nextcloud.talk.profile.ProfileActivity
|
import com.nextcloud.talk.profile.ProfileActivity
|
||||||
|
import com.nextcloud.talk.ui.dialog.SetPhoneNumberDialogFragment
|
||||||
import com.nextcloud.talk.users.UserManager
|
import com.nextcloud.talk.users.UserManager
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import com.nextcloud.talk.utils.SpreedFeatures
|
import com.nextcloud.talk.utils.CapabilitiesUtil
|
||||||
import com.nextcloud.talk.utils.ClosedInterfaceImpl
|
import com.nextcloud.talk.utils.ClosedInterfaceImpl
|
||||||
import com.nextcloud.talk.utils.DisplayUtils
|
import com.nextcloud.talk.utils.DisplayUtils
|
||||||
import com.nextcloud.talk.utils.LoggingUtils.sendMailWithAttachment
|
import com.nextcloud.talk.utils.LoggingUtils.sendMailWithAttachment
|
||||||
@ -98,7 +91,7 @@ import com.nextcloud.talk.utils.NotificationUtils
|
|||||||
import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri
|
import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri
|
||||||
import com.nextcloud.talk.utils.NotificationUtils.getMessageRingtoneUri
|
import com.nextcloud.talk.utils.NotificationUtils.getMessageRingtoneUri
|
||||||
import com.nextcloud.talk.utils.SecurityUtils
|
import com.nextcloud.talk.utils.SecurityUtils
|
||||||
import com.nextcloud.talk.utils.CapabilitiesUtil
|
import com.nextcloud.talk.utils.SpreedFeatures
|
||||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||||
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
|
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
|
||||||
import com.nextcloud.talk.utils.power.PowerManagerUtils
|
import com.nextcloud.talk.utils.power.PowerManagerUtils
|
||||||
@ -122,7 +115,7 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@Suppress("LargeClass", "TooManyFunctions")
|
@Suppress("LargeClass", "TooManyFunctions")
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class SettingsActivity : BaseActivity() {
|
class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNumberDialogClickListener {
|
||||||
private lateinit var binding: ActivitySettingsBinding
|
private lateinit var binding: ActivitySettingsBinding
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -1241,61 +1234,15 @@ class SettingsActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun askForPhoneNumber() {
|
private fun askForPhoneNumber() {
|
||||||
val phoneNumberLayoutWrapper = LinearLayout(context)
|
val dialog = SetPhoneNumberDialogFragment.newInstance()
|
||||||
phoneNumberLayoutWrapper.orientation = LinearLayout.VERTICAL
|
dialog.show(supportFragmentManager, SetPhoneNumberDialogFragment.TAG)
|
||||||
phoneNumberLayoutWrapper.setPadding(PHONE_NUMBER_SIDE_PADDING, 0, PHONE_NUMBER_SIDE_PADDING, 0)
|
|
||||||
val phoneNumberInputLayout = TextInputLayout(ContextThemeWrapper(this, R.style.TextInputLayoutTheme))
|
|
||||||
val phoneNumberField = EditText(context)
|
|
||||||
phoneNumberInputLayout.setHelperTextColor(
|
|
||||||
ColorStateList.valueOf(resources!!.getColor(R.color.nc_darkRed, null))
|
|
||||||
)
|
|
||||||
phoneNumberField.inputType = InputType.TYPE_CLASS_PHONE
|
|
||||||
phoneNumberField.setText("+")
|
|
||||||
phoneNumberField.addTextChangedListener(object : TextWatcher {
|
|
||||||
override fun afterTextChanged(s: Editable) {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
|
||||||
phoneNumberInputLayout.helperText = ""
|
|
||||||
}
|
|
||||||
})
|
|
||||||
phoneNumberInputLayout.addView(phoneNumberField)
|
|
||||||
phoneNumberLayoutWrapper.addView(phoneNumberInputLayout)
|
|
||||||
val dialogBuilder = MaterialAlertDialogBuilder(phoneNumberInputLayout.context)
|
|
||||||
.setTitle(R.string.nc_settings_phone_book_integration_phone_number_dialog_title)
|
|
||||||
.setMessage(R.string.nc_settings_phone_book_integration_phone_number_dialog_description)
|
|
||||||
.setView(phoneNumberLayoutWrapper)
|
|
||||||
.setPositiveButton(context.resources.getString(R.string.nc_common_set), null)
|
|
||||||
.setNegativeButton(context.resources.getString(R.string.nc_common_skip), null)
|
|
||||||
|
|
||||||
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(phoneNumberInputLayout.context, dialogBuilder)
|
|
||||||
|
|
||||||
val dialog = dialogBuilder.create()
|
|
||||||
dialog.setOnShowListener(object : OnShowListener {
|
|
||||||
override fun onShow(dialogInterface: DialogInterface) {
|
|
||||||
val button = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
|
||||||
button.setOnClickListener(object : View.OnClickListener {
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
setPhoneNumber(phoneNumberInputLayout, dialog)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
dialog.show()
|
|
||||||
|
|
||||||
viewThemeUtils.platform.colorTextButtons(
|
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
|
|
||||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setPhoneNumber(textInputLayout: TextInputLayout, dialog: AlertDialog) {
|
override fun onSubmitClick(textInputLayout: TextInputLayout, dialog: DialogInterface) {
|
||||||
|
setPhoneNumber(textInputLayout, dialog)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setPhoneNumber(textInputLayout: TextInputLayout, dialog: DialogInterface) {
|
||||||
val phoneNumber = textInputLayout.editText!!.text.toString()
|
val phoneNumber = textInputLayout.editText!!.text.toString()
|
||||||
ncApi.setUserData(
|
ncApi.setUserData(
|
||||||
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
|
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
|
||||||
@ -1315,7 +1262,7 @@ class SettingsActivity : BaseActivity() {
|
|||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
binding.root,
|
binding.root,
|
||||||
context.resources.getString(
|
getString(
|
||||||
R.string.nc_settings_phone_book_integration_phone_number_dialog_success
|
R.string.nc_settings_phone_book_integration_phone_number_dialog_success
|
||||||
),
|
),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
@ -1323,7 +1270,7 @@ class SettingsActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
textInputLayout.helperText = context.resources.getString(
|
textInputLayout.helperText = getString(
|
||||||
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
|
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
|
||||||
)
|
)
|
||||||
Log.d(TAG, "failed to set phoneNumber. statusCode=$statusCode")
|
Log.d(TAG, "failed to set phoneNumber. statusCode=$statusCode")
|
||||||
@ -1332,10 +1279,10 @@ class SettingsActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
override fun onError(e: Throwable) {
|
||||||
textInputLayout.helperText = context.resources.getString(
|
textInputLayout.helperText = getString(
|
||||||
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
|
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
|
||||||
)
|
)
|
||||||
Log.e(TAG, "setPhoneNumber error", e)
|
Log.e(SetPhoneNumberDialogFragment.TAG, "setPhoneNumber error", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onComplete() {
|
override fun onComplete() {
|
||||||
@ -1427,7 +1374,6 @@ class SettingsActivity : BaseActivity() {
|
|||||||
private const val START_DELAY: Long = 5000
|
private const val START_DELAY: Long = 5000
|
||||||
private const val DISABLED_ALPHA: Float = 0.38f
|
private const val DISABLED_ALPHA: Float = 0.38f
|
||||||
private const val ENABLED_ALPHA: Float = 1.0f
|
private const val ENABLED_ALPHA: Float = 1.0f
|
||||||
private const val HTTP_CODE_OK: Int = 200
|
const val HTTP_CODE_OK: Int = 200
|
||||||
private const val PHONE_NUMBER_SIDE_PADDING: Int = 50
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Nextcloud Talk application
|
||||||
|
*
|
||||||
|
* @author Andy Scherzinger
|
||||||
|
* @author Parneet Singh
|
||||||
|
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
|
||||||
|
* Copyright (C) 2024 Parneet Singh <gurayaparneet@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.nextcloud.talk.ui.dialog
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import autodagger.AutoInjector
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
|
import com.nextcloud.talk.R
|
||||||
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||||
|
import com.nextcloud.talk.databinding.DialogSetPhoneNumberBinding
|
||||||
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
|
class SetPhoneNumberDialogFragment : DialogFragment() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var viewThemeUtils: ViewThemeUtils
|
||||||
|
|
||||||
|
private lateinit var clickListener: SetPhoneNumberDialogClickListener
|
||||||
|
|
||||||
|
private lateinit var binding: DialogSetPhoneNumberBinding
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
NextcloudTalkApplication.sharedApplication?.componentApplication?.inject(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
binding = DialogSetPhoneNumberBinding.inflate(requireActivity().layoutInflater)
|
||||||
|
|
||||||
|
val dialogBuilder =
|
||||||
|
MaterialAlertDialogBuilder(requireActivity())
|
||||||
|
.setTitle(R.string.nc_settings_phone_book_integration_phone_number_dialog_title)
|
||||||
|
.setView(binding.root)
|
||||||
|
.setMessage(R.string.nc_settings_phone_book_integration_phone_number_dialog_description)
|
||||||
|
.setPositiveButton(requireContext().resources.getString(R.string.nc_common_set)) { dialog, _ ->
|
||||||
|
clickListener
|
||||||
|
.onSubmitClick(binding.phoneInputLayout, dialog)
|
||||||
|
}
|
||||||
|
.setNegativeButton(requireContext().resources.getString(R.string.nc_common_skip), null)
|
||||||
|
|
||||||
|
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireActivity(), dialogBuilder)
|
||||||
|
|
||||||
|
binding.phoneInputLayout.setHelperTextColor(
|
||||||
|
ColorStateList.valueOf(resources.getColor(R.color.nc_darkRed, null))
|
||||||
|
)
|
||||||
|
|
||||||
|
binding.phoneEditTextField.addTextChangedListener(object : TextWatcher {
|
||||||
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||||
|
binding.phoneInputLayout.helperText = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||||
|
override fun afterTextChanged(s: Editable?) {}
|
||||||
|
})
|
||||||
|
|
||||||
|
return dialogBuilder.create()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
val alertDialog = dialog as AlertDialog?
|
||||||
|
alertDialog?.let {
|
||||||
|
viewThemeUtils.platform.colorTextButtons(it.getButton(AlertDialog.BUTTON_POSITIVE))
|
||||||
|
viewThemeUtils.platform.colorTextButtons(it.getButton(AlertDialog.BUTTON_NEGATIVE))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttach(context: Context) {
|
||||||
|
super.onAttach(context)
|
||||||
|
clickListener = context as SetPhoneNumberDialogClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SetPhoneNumberDialogClickListener {
|
||||||
|
fun onSubmitClick(textInputLayout: TextInputLayout, dialog: DialogInterface)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "SetPhoneNumberDialogFragment"
|
||||||
|
|
||||||
|
fun newInstance(): DialogFragment {
|
||||||
|
return SetPhoneNumberDialogFragment()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
app/src/main/res/layout/dialog_set_phone_number.xml
Normal file
41
app/src/main/res/layout/dialog_set_phone_number.xml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!--
|
||||||
|
~ Nextcloud Talk application
|
||||||
|
~
|
||||||
|
~ @author Parneet Singh
|
||||||
|
~ Copyright (C) 2024 Parneet Singh <gurayaparneet@gmail.com>
|
||||||
|
~
|
||||||
|
~ This program is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by
|
||||||
|
~ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
~ at your option) any later version.
|
||||||
|
~
|
||||||
|
~ This program is distributed in the hope that it will be useful,
|
||||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
~ GNU General Public License for more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License
|
||||||
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/phone_input_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:prefixText="+"
|
||||||
|
android:hint="@string/nc_settings_phone_book_integration_phone_number_dialog_edit_text_hint">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/phone_edit_text_field"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="phone" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
</FrameLayout>
|
@ -571,6 +571,7 @@ How to translate with transifex:
|
|||||||
<string name="nc_settings_phone_book_integration_phone_number_dialog_description">You can set your phone number so other users will be able to find you</string>
|
<string name="nc_settings_phone_book_integration_phone_number_dialog_description">You can set your phone number so other users will be able to find you</string>
|
||||||
<string name="nc_settings_phone_book_integration_phone_number_dialog_invalid">Invalid phone number</string>
|
<string name="nc_settings_phone_book_integration_phone_number_dialog_invalid">Invalid phone number</string>
|
||||||
<string name="nc_settings_phone_book_integration_phone_number_dialog_success">Phone number set successfully</string>
|
<string name="nc_settings_phone_book_integration_phone_number_dialog_success">Phone number set successfully</string>
|
||||||
|
<string name="nc_settings_phone_book_integration_phone_number_dialog_edit_text_hint">Enter Phone Number</string>
|
||||||
<string name="no_phone_book_integration_due_to_permissions">No phone number integration due to missing permissions</string>
|
<string name="no_phone_book_integration_due_to_permissions">No phone number integration due to missing permissions</string>
|
||||||
<string name="nc_phone_book_integration_chat_via">Chat via %s</string>
|
<string name="nc_phone_book_integration_chat_via">Chat via %s</string>
|
||||||
<string name="nc_phone_book_integration_account_not_found">Account not found</string>
|
<string name="nc_phone_book_integration_account_not_found">Account not found</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user