Merge pull request #703 from qwertyfinger/qwertyfinger/feature/sort-contacts-by-date-created
Allow sorting contacts by date created
This commit is contained in:
commit
00a81472c5
5 changed files with 79 additions and 57 deletions
|
@ -56,7 +56,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:11c7236fdb'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:203ed6018e'
|
||||
implementation 'joda-time:joda-time:2.10.3'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a'
|
||||
|
|
|
@ -32,7 +32,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
|
|||
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_full_name
|
||||
currSorting and SORT_BY_FULL_NAME != 0 -> sortingRadio.sorting_dialog_radio_full_name
|
||||
else -> sortingRadio.sorting_dialog_radio_date_created
|
||||
}
|
||||
sortBtn.isChecked = true
|
||||
}
|
||||
|
@ -53,7 +54,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback
|
|||
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_FULL_NAME
|
||||
R.id.sorting_dialog_radio_full_name -> SORT_BY_FULL_NAME
|
||||
else -> SORT_BY_DATE_CREATED
|
||||
}
|
||||
|
||||
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
|
||||
|
|
|
@ -844,7 +844,8 @@ class ContactsHelper(val context: Context) {
|
|||
sorting and SORT_BY_FIRST_NAME != 0 -> "${StructuredName.GIVEN_NAME} COLLATE NOCASE"
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> "${StructuredName.MIDDLE_NAME} COLLATE NOCASE"
|
||||
sorting and SORT_BY_SURNAME != 0 -> "${StructuredName.FAMILY_NAME} COLLATE NOCASE"
|
||||
else -> Phone.NUMBER
|
||||
sorting and SORT_BY_FULL_NAME != 0 -> StructuredName.DISPLAY_NAME
|
||||
else -> Data.RAW_CONTACT_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,7 @@ import android.graphics.Bitmap
|
|||
import android.telephony.PhoneNumberUtils
|
||||
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.commons.helpers.*
|
||||
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
||||
|
||||
data class Contact(var id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var nickname: String,
|
||||
|
@ -22,62 +19,28 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
}
|
||||
|
||||
override fun compareTo(other: Contact): Int {
|
||||
var firstString: String
|
||||
var secondString: String
|
||||
|
||||
when {
|
||||
var result = when {
|
||||
sorting and SORT_BY_FIRST_NAME != 0 -> {
|
||||
firstString = firstName.normalizeString()
|
||||
secondString = other.firstName.normalizeString()
|
||||
val firstString = firstName.normalizeString()
|
||||
val secondString = other.firstName.normalizeString()
|
||||
compareUsingStrings(firstString, secondString, other)
|
||||
}
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> {
|
||||
firstString = middleName.normalizeString()
|
||||
secondString = other.middleName.normalizeString()
|
||||
val firstString = middleName.normalizeString()
|
||||
val secondString = other.middleName.normalizeString()
|
||||
compareUsingStrings(firstString, secondString, other)
|
||||
}
|
||||
sorting and SORT_BY_SURNAME != 0 -> {
|
||||
firstString = surname.normalizeString()
|
||||
secondString = other.surname.normalizeString()
|
||||
val firstString = surname.normalizeString()
|
||||
val secondString = other.surname.normalizeString()
|
||||
compareUsingStrings(firstString, secondString, other)
|
||||
}
|
||||
else -> {
|
||||
firstString = getNameToDisplay().normalizeString()
|
||||
secondString = other.getNameToDisplay().normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty()) {
|
||||
val fullCompany = getFullCompany()
|
||||
if (fullCompany.isNotEmpty()) {
|
||||
firstString = fullCompany.normalizeString()
|
||||
} else if (emails.isNotEmpty()) {
|
||||
firstString = emails.first().value
|
||||
}
|
||||
}
|
||||
|
||||
if (secondString.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty()) {
|
||||
val otherFullCompany = other.getFullCompany()
|
||||
if (otherFullCompany.isNotEmpty()) {
|
||||
secondString = otherFullCompany.normalizeString()
|
||||
} else if (other.emails.isNotEmpty()) {
|
||||
secondString = other.emails.first().value
|
||||
}
|
||||
}
|
||||
|
||||
var result = if (firstString.firstOrNull()?.isLetter() == true && secondString.firstOrNull()?.isLetter() == false) {
|
||||
-1
|
||||
} else if (firstString.firstOrNull()?.isLetter() == false && secondString.firstOrNull()?.isLetter() == true) {
|
||||
1
|
||||
} else {
|
||||
if (firstString.isEmpty() && secondString.isNotEmpty()) {
|
||||
1
|
||||
} else if (firstString.isNotEmpty() && secondString.isEmpty()) {
|
||||
-1
|
||||
} else {
|
||||
if (firstString.equals(secondString, ignoreCase = true)) {
|
||||
getNameToDisplay().compareTo(other.getNameToDisplay(), true)
|
||||
} else {
|
||||
firstString.compareTo(secondString, true)
|
||||
}
|
||||
sorting and SORT_BY_FULL_NAME != 0 -> {
|
||||
val firstString = getNameToDisplay().normalizeString()
|
||||
val secondString = other.getNameToDisplay().normalizeString()
|
||||
compareUsingStrings(firstString, secondString, other)
|
||||
}
|
||||
else -> compareUsingIds(other)
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
|
@ -87,6 +50,54 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
return result
|
||||
}
|
||||
|
||||
private fun compareUsingStrings(firstString: String, secondString: String, other: Contact): Int {
|
||||
var firstValue = firstString
|
||||
var secondValue = secondString
|
||||
|
||||
if (firstValue.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty()) {
|
||||
val fullCompany = getFullCompany()
|
||||
if (fullCompany.isNotEmpty()) {
|
||||
firstValue = fullCompany.normalizeString()
|
||||
} else if (emails.isNotEmpty()) {
|
||||
firstValue = emails.first().value
|
||||
}
|
||||
}
|
||||
|
||||
if (secondValue.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty()) {
|
||||
val otherFullCompany = other.getFullCompany()
|
||||
if (otherFullCompany.isNotEmpty()) {
|
||||
secondValue = otherFullCompany.normalizeString()
|
||||
} else if (other.emails.isNotEmpty()) {
|
||||
secondValue = other.emails.first().value
|
||||
}
|
||||
}
|
||||
|
||||
return if (firstValue.firstOrNull()?.isLetter() == true && secondValue.firstOrNull()?.isLetter() == false) {
|
||||
-1
|
||||
} else if (firstValue.firstOrNull()?.isLetter() == false && secondValue.firstOrNull()?.isLetter() == true) {
|
||||
1
|
||||
} else {
|
||||
if (firstValue.isEmpty() && secondValue.isNotEmpty()) {
|
||||
1
|
||||
} else if (firstValue.isNotEmpty() && secondValue.isEmpty()) {
|
||||
-1
|
||||
} else {
|
||||
if (firstValue.equals(secondValue, ignoreCase = true)) {
|
||||
getNameToDisplay().compareTo(other.getNameToDisplay(), true)
|
||||
} else {
|
||||
firstValue.compareTo(secondValue, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun compareUsingIds(other: Contact): Int {
|
||||
val firstId = id
|
||||
val secondId = other.id
|
||||
|
||||
return firstId.compareTo(secondId)
|
||||
}
|
||||
|
||||
fun getBubbleText() = when {
|
||||
sorting and SORT_BY_FIRST_NAME != 0 -> firstName
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> middleName
|
||||
|
|
|
@ -51,6 +51,14 @@
|
|||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:text="@string/full_name" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/sorting_dialog_radio_date_created"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:text="@string/date_created" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<include layout="@layout/divider" />
|
||||
|
|
Loading…
Reference in a new issue