Showing confirmation dialog when about to create a new contact without SIP URI nor phone number (won't be displayed)
This commit is contained in:
parent
08575dd4d1
commit
256a3ed77a
3 changed files with 75 additions and 4 deletions
|
@ -20,6 +20,7 @@
|
|||
package org.linphone.activities.main.contact.fragments
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
|
@ -38,9 +39,11 @@ import org.linphone.activities.main.MainActivity
|
|||
import org.linphone.activities.main.contact.data.ContactEditorData
|
||||
import org.linphone.activities.main.contact.data.NumberOrAddressEditorData
|
||||
import org.linphone.activities.main.contact.viewmodels.*
|
||||
import org.linphone.activities.main.viewmodels.DialogViewModel
|
||||
import org.linphone.activities.navigateToContact
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ContactEditorFragmentBinding
|
||||
import org.linphone.utils.DialogUtils
|
||||
import org.linphone.utils.FileUtils
|
||||
import org.linphone.utils.PermissionHelper
|
||||
|
||||
|
@ -71,10 +74,38 @@ class ContactEditorFragment : GenericFragment<ContactEditorFragmentBinding>(), S
|
|||
data.syncAccountName = null
|
||||
data.syncAccountType = null
|
||||
|
||||
if (data.friend == null && corePreferences.showNewContactAccountDialog) {
|
||||
Log.i("[Contact Editor] New contact, ask user where to store it")
|
||||
SyncAccountPickerFragment(this).show(childFragmentManager, "SyncAccountPicker")
|
||||
if (data.friend == null) {
|
||||
var atLeastASipAddressOrPhoneNumber = false
|
||||
for (addr in data.addresses.value.orEmpty()) {
|
||||
if (addr.newValue.value.orEmpty().isNotEmpty()) {
|
||||
atLeastASipAddressOrPhoneNumber = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!atLeastASipAddressOrPhoneNumber) {
|
||||
for (number in data.numbers.value.orEmpty()) {
|
||||
if (number.newValue.value.orEmpty().isNotEmpty()) {
|
||||
atLeastASipAddressOrPhoneNumber = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!atLeastASipAddressOrPhoneNumber) {
|
||||
// Contact will be created without phone and SIP address
|
||||
// Let's warn the user it won't be visible in Linphone app
|
||||
Log.w(
|
||||
"[Contact Editor] New contact without SIP address nor phone number, showing warning dialog"
|
||||
)
|
||||
showInvisibleContactWarningDialog()
|
||||
} else if (corePreferences.showNewContactAccountDialog) {
|
||||
Log.i("[Contact Editor] New contact, ask user where to store it")
|
||||
SyncAccountPickerFragment(this).show(childFragmentManager, "SyncAccountPicker")
|
||||
} else {
|
||||
Log.i("[Contact Editor] Saving new contact")
|
||||
saveContact()
|
||||
}
|
||||
} else {
|
||||
Log.i("[Contact Editor] Saving contact changes")
|
||||
saveContact()
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +129,7 @@ class ContactEditorFragment : GenericFragment<ContactEditorFragmentBinding>(), S
|
|||
}
|
||||
|
||||
override fun onSyncAccountClicked(name: String?, type: String?) {
|
||||
Log.i("[Contact Editor] Using account $name / $type")
|
||||
Log.i("[Contact Editor] Saving new contact using account $name / $type")
|
||||
data.syncAccountName = name
|
||||
data.syncAccountType = type
|
||||
saveContact()
|
||||
|
@ -146,6 +177,9 @@ class ContactEditorFragment : GenericFragment<ContactEditorFragmentBinding>(), S
|
|||
Log.i("[Contact Editor] Displaying contact $savedContact")
|
||||
navigateToContact(id)
|
||||
} else {
|
||||
Log.w(
|
||||
"[Contact Editor] Can't display $savedContact because it doesn't have a refKey, going back"
|
||||
)
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
|
@ -183,4 +217,35 @@ class ContactEditorFragment : GenericFragment<ContactEditorFragmentBinding>(), S
|
|||
|
||||
startActivityForResult(chooserIntent, 0)
|
||||
}
|
||||
|
||||
private fun showInvisibleContactWarningDialog() {
|
||||
val dialogViewModel =
|
||||
DialogViewModel(getString(R.string.contacts_new_contact_wont_be_visible_warning_dialog))
|
||||
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
|
||||
|
||||
dialogViewModel.showCancelButton(
|
||||
{
|
||||
Log.i("[Contact Editor] Aborting new contact saving")
|
||||
dialog.dismiss()
|
||||
},
|
||||
getString(R.string.no)
|
||||
)
|
||||
|
||||
dialogViewModel.showOkButton(
|
||||
{
|
||||
dialog.dismiss()
|
||||
|
||||
if (corePreferences.showNewContactAccountDialog) {
|
||||
Log.i("[Contact Editor] New contact, ask user where to store it")
|
||||
SyncAccountPickerFragment(this).show(childFragmentManager, "SyncAccountPicker")
|
||||
} else {
|
||||
Log.i("[Contact Editor] Saving new contact")
|
||||
saveContact()
|
||||
}
|
||||
},
|
||||
getString(R.string.yes)
|
||||
)
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -791,4 +791,7 @@
|
|||
<string name="android_14_full_screen_intent_permission_not_granted">Permission requise pour afficher les appels entrant non accordée</string>
|
||||
<string name="android_14_go_to_full_screen_intent_permission_setting">Afficher</string>
|
||||
<string name="assistant_error_invalid_international_prefix">Préfixe international inconnu</string>
|
||||
<string name="contacts_new_contact_wont_be_visible_warning_dialog">Vous êtes sur le point de créer un nouveau contact sans adresse SIP ni numéro de téléphone, il ne sera donc pas visible dans &appName;.\n\nVoulez-vous le créer quand même ?</string>
|
||||
<string name="yes">Oui</string>
|
||||
<string name="no">Non</string>
|
||||
</resources>
|
|
@ -49,6 +49,8 @@
|
|||
<item quantity="other">%d days</item>
|
||||
</plurals>
|
||||
<string name="share_uploaded_logs_link">Share logs link using…</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string name="error_unexpected">Unexpected error…</string>
|
||||
|
@ -114,6 +116,7 @@
|
|||
<string name="contact_local_sync_account">Store locally</string>
|
||||
<string name="contact_cant_be_deleted">This contact can\'t be deleted</string>
|
||||
<string name="contacts_ldap_query_more_results_available">More results are available, refine your search</string>
|
||||
<string name="contacts_new_contact_wont_be_visible_warning_dialog">You are about to create a new contact without a SIP URI nor a phone number, thus it won\'t be visible in &appName;.\n\nDo you want to create it anyway?</string>
|
||||
|
||||
<!-- Dialer -->
|
||||
<string name="dialer_address_bar_hint">Enter a number or an address</string>
|
||||
|
|
Loading…
Reference in a new issue