Added setting to disable new contact account dialog + prevent saving new empty contact

This commit is contained in:
Sylvain Berfini 2020-08-24 14:18:02 +02:00
parent 260ed4b3cb
commit 253e2dc654
7 changed files with 34 additions and 7 deletions

View file

@ -35,6 +35,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import java.io.File
import kotlinx.coroutines.launch
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.activities.main.MainActivity
import org.linphone.activities.main.contact.viewmodels.*
@ -86,7 +87,10 @@ class ContactEditorFragment : Fragment(), SyncAccountPickerFragment.SyncAccountP
}
binding.setSaveChangesClickListener {
if (viewModel.c == null) {
viewModel.syncAccountName = null
viewModel.syncAccountType = null
if (viewModel.c == null && corePreferences.showNewContactAccountDialog) {
Log.i("[Contact Editor] New contact, ask user where to store it")
SyncAccountPickerFragment(this).show(childFragmentManager, "SyncAccountPicker")
} else {

View file

@ -68,12 +68,10 @@ class ContactEditorViewModel(val c: Contact?) : ViewModel(), ContactViewModelInt
var syncAccountType: String? = null
init {
if (c != null) {
contact.value = c
firstName.value = c.firstName
lastName.value = c.lastName
organization.value = c.organization
}
contact.value = c
firstName.value = c?.firstName ?: ""
lastName.value = c?.lastName ?: ""
organization.value = c?.organization ?: ""
updateNumbersAndAddresses()
}

View file

@ -38,6 +38,13 @@ class ContactsSettingsViewModel : GenericSettingsViewModel() {
}
val friendListSubscribe = MutableLiveData<Boolean>()
val showNewContactAccountDialogListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.showNewContactAccountDialog = newValue
}
}
val showNewContactAccountDialog = MutableLiveData<Boolean>()
val nativePresenceListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
if (newValue) {
@ -73,6 +80,7 @@ class ContactsSettingsViewModel : GenericSettingsViewModel() {
readContactsPermissionGranted.value = PermissionHelper.get().hasReadContactsPermission()
friendListSubscribe.value = core.isFriendListSubscriptionEnabled
showNewContactAccountDialog.value = prefs.showNewContactAccountDialog
nativePresence.value = prefs.storePresenceInNativeContact
showOrganization.value = prefs.displayOrganization
launcherShortcuts.value = prefs.contactsShortcuts

View file

@ -125,6 +125,12 @@ class CorePreferences constructor(private val context: Context) {
config.setBool("app", "store_presence_in_native_contact", value)
}
var showNewContactAccountDialog: Boolean
get() = config.getBool("app", "show_new_contact_account_dialog", true)
set(value) {
config.setBool("app", "show_new_contact_account_dialog", value)
}
var displayOrganization: Boolean
get() = config.getBool("app", "display_contact_organization", contactOrganizationVisible)
set(value) {

View file

@ -48,6 +48,7 @@
<ImageView
android:id="@+id/ok"
android:enabled="@{!viewModel.firstName.empty || !viewModel.lastName.empty}"
android:contentDescription="@string/content_description_confirm_contact_edit"
android:onClick="@{saveChangesClickListener}"
android:layout_width="0dp"

View file

@ -72,6 +72,14 @@
linphone:checked="@={viewModel.friendListSubscribe}"
linphone:enabled="@{viewModel.readContactsPermissionGranted}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/contacts_settings_show_new_contact_account_dialog_title}"
linphone:subtitle="@{@string/contacts_settings_show_new_contact_account_dialog_summary}"
linphone:listener="@{viewModel.showNewContactAccountDialogListener}"
linphone:checked="@={viewModel.showNewContactAccountDialog}"
linphone:enabled="@{viewModel.readContactsPermissionGranted}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/contacts_settings_native_presence_title}"

View file

@ -439,6 +439,8 @@
<string name="contacts_settings_show_organization_summary"></string>
<string name="contacts_settings_launcher_shortcuts_title">Create shortcuts to contacts in launcher</string>
<string name="contacts_settings_launcher_shortcuts_summary">Will replace chat room shortcuts if any</string>
<string name="contacts_settings_show_new_contact_account_dialog_title">Always ask in which account save newly created contact</string>
<string name="contacts_settings_show_new_contact_account_dialog_summary">If disabled contact will be stored locally</string>
<!-- Advanced settings -->
<string name="advanced_settings_debug_mode_title">Debug logs</string>