fix #570, allow sorting by full name

This commit is contained in:
tibbi 2020-06-03 11:18:47 +02:00
parent 1a478dcfee
commit 10ddac1914
3 changed files with 24 additions and 12 deletions

View File

@ -3,10 +3,7 @@ package com.simplemobiletools.contacts.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
@ -18,11 +15,11 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
init {
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
}
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
}
currSorting = config.sorting
setupSortRadio()
@ -34,7 +31,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
val sortBtn = when {
currSorting and SORT_BY_FIRST_NAME != 0 -> sortingRadio.sorting_dialog_radio_first_name
currSorting and SORT_BY_MIDDLE_NAME != 0 -> sortingRadio.sorting_dialog_radio_middle_name
else -> sortingRadio.sorting_dialog_radio_surname
currSorting and SORT_BY_SURNAME != 0 -> sortingRadio.sorting_dialog_radio_surname
else -> sortingRadio.sorting_dialog_radio_full_name
}
sortBtn.isChecked = true
}
@ -54,7 +52,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_first_name -> SORT_BY_FIRST_NAME
R.id.sorting_dialog_radio_middle_name -> SORT_BY_MIDDLE_NAME
else -> SORT_BY_SURNAME
R.id.sorting_dialog_radio_surname -> SORT_BY_SURNAME
else -> SORT_BY_FULL_NAME
}
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {

View File

@ -6,6 +6,7 @@ import com.simplemobiletools.commons.extensions.normalizePhoneNumber
import com.simplemobiletools.commons.extensions.normalizeString
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
@ -32,10 +33,14 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
firstString = middleName.normalizeString()
secondString = other.middleName.normalizeString()
}
else -> {
sorting and SORT_BY_SURNAME != 0 -> {
firstString = surname.normalizeString()
secondString = other.surname.normalizeString()
}
else -> {
firstString = getNameToDisplay().normalizeString()
secondString = other.getNameToDisplay().normalizeString()
}
}
if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty()) {

View File

@ -44,6 +44,14 @@
android:paddingTop="@dimen/medium_margin"
android:text="@string/surname"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/sorting_dialog_radio_full_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium_margin"
android:paddingTop="@dimen/medium_margin"
android:text="@string/full_name"/>
</RadioGroup>
<include