mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-04 17:57:41 +01:00
allow sorting contacts by every name separately
This commit is contained in:
parent
243c1a3da5
commit
74c5b19025
@ -32,5 +32,5 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.2.17'
|
||||
implementation 'com.simplemobiletools:commons:3.2.18'
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import com.simplemobiletools.commons.interfaces.MyAdapterListener
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import kotlinx.android.synthetic.main.filter_contact_source_view.view.*
|
||||
import kotlinx.android.synthetic.main.item_filter_contact_source.view.*
|
||||
import java.util.*
|
||||
|
||||
class FilterContactSourcesAdapter(val activity: SimpleActivity, val contactSources: List<String>, val displayContactSources: Set<String>) :
|
||||
@ -53,7 +53,7 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, val contactSourc
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = activity.layoutInflater.inflate(R.layout.filter_contact_source_view, parent, false)
|
||||
val view = activity.layoutInflater.inflate(R.layout.item_filter_contact_source, parent, false)
|
||||
return ViewHolder(view, adapterListener, activity)
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,7 @@ package com.simplemobiletools.contacts.dialogs
|
||||
import android.support.v7.app.AlertDialog
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_NUMBER
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||
@ -31,8 +29,10 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val callback: () ->
|
||||
private fun setupSortRadio() {
|
||||
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||
val sortBtn = when {
|
||||
currSorting and SORT_BY_NUMBER != 0 -> sortingRadio.sorting_dialog_radio_number
|
||||
else -> sortingRadio.sorting_dialog_radio_name
|
||||
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
|
||||
currSorting and SORT_BY_SURNAME != 0 -> sortingRadio.sorting_dialog_radio_surname
|
||||
else -> sortingRadio.sorting_dialog_radio_number
|
||||
}
|
||||
sortBtn.isChecked = true
|
||||
}
|
||||
@ -50,8 +50,10 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val callback: () ->
|
||||
private fun dialogConfirmed() {
|
||||
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||
var sorting = when (sortingRadio.checkedRadioButtonId) {
|
||||
R.id.sorting_dialog_radio_number -> SORT_BY_NUMBER
|
||||
else -> SORT_BY_NAME
|
||||
R.id.sorting_dialog_radio_first_name -> SORT_BY_FIRST_NAME
|
||||
R.id.sorting_dialog_radio_middle_name -> SORT_BY_MIDDLE_NAME
|
||||
R.id.sorting_dialog_radio_surname -> SORT_BY_SURNAME
|
||||
else -> SORT_BY_NUMBER
|
||||
}
|
||||
|
||||
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
|
||||
|
@ -2,7 +2,7 @@ package com.simplemobiletools.contacts.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
@ -10,7 +10,7 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
}
|
||||
|
||||
var sorting: Int
|
||||
get() = prefs.getInt(SORTING, SORT_BY_NAME)
|
||||
get() = prefs.getInt(SORTING, SORT_BY_FIRST_NAME)
|
||||
set(sorting) = prefs.edit().putInt(SORTING, sorting).apply()
|
||||
|
||||
var callContact: Boolean
|
||||
|
@ -5,7 +5,9 @@ import android.provider.ContactsContract
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||
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.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
@ -229,7 +231,9 @@ class ContactsHelper(val activity: SimpleActivity) {
|
||||
private fun getSortString(): String {
|
||||
val sorting = activity.config.sorting
|
||||
var sort = when {
|
||||
sorting and SORT_BY_NAME != 0 -> "${ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME} COLLATE NOCASE"
|
||||
sorting and SORT_BY_FIRST_NAME != 0 -> "${ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME} COLLATE NOCASE"
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> "${ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME} COLLATE NOCASE"
|
||||
sorting and SORT_BY_SURNAME != 0 -> "${ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME} COLLATE NOCASE"
|
||||
else -> ContactsContract.CommonDataKinds.Phone.NUMBER
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.simplemobiletools.contacts.models
|
||||
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_NUMBER
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
|
||||
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, var number: String,
|
||||
var email: String, var source: String) : Comparable<Contact> {
|
||||
@ -11,14 +10,10 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v
|
||||
|
||||
override fun compareTo(other: Contact): Int {
|
||||
var result = when {
|
||||
(sorting and SORT_BY_NUMBER != 0) -> number.toLowerCase().compareTo(other.number.toLowerCase())
|
||||
else -> if (firstName.firstOrNull()?.isLetter() == true && other.firstName.firstOrNull()?.isLetter() == false) {
|
||||
-1
|
||||
} else if (firstName.firstOrNull()?.isLetter() == false && other.firstName.firstOrNull()?.isLetter() == true) {
|
||||
1
|
||||
} else {
|
||||
firstName.toLowerCase().compareTo(other.firstName.toLowerCase())
|
||||
}
|
||||
sorting and SORT_BY_FIRST_NAME != 0 -> compareStrings(firstName, other.firstName)
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> compareStrings(middleName, other.middleName)
|
||||
sorting and SORT_BY_SURNAME != 0 -> compareStrings(surname, other.surname)
|
||||
else -> number.toLowerCase().compareTo(other.number.toLowerCase())
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
@ -40,4 +35,20 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v
|
||||
}
|
||||
return "$name $surname".trim()
|
||||
}
|
||||
|
||||
private fun compareStrings(first: String, second: String): Int {
|
||||
return if (first.firstOrNull()?.isLetter() == true && second.firstOrNull()?.isLetter() == false) {
|
||||
-1
|
||||
} else if (first.firstOrNull()?.isLetter() == false && second.firstOrNull()?.isLetter() == true) {
|
||||
1
|
||||
} else {
|
||||
if (first.isEmpty() && second.isNotEmpty()) {
|
||||
1
|
||||
} else if (first.isNotEmpty() && second.isEmpty()) {
|
||||
-1
|
||||
} else {
|
||||
first.toLowerCase().compareTo(second.toLowerCase())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,28 @@
|
||||
android:layout_marginBottom="@dimen/medium_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/sorting_dialog_radio_name"
|
||||
android:id="@+id/sorting_dialog_radio_first_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/name"/>
|
||||
android:text="@string/first_name"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/sorting_dialog_radio_middle_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/middle_name"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/sorting_dialog_radio_surname"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/surname"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/sorting_dialog_radio_number"
|
||||
|
Loading…
x
Reference in New Issue
Block a user