mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
taking some Contact handling related things from Commons
This commit is contained in:
@ -36,6 +36,6 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.27.9'
|
||||
implementation 'com.simplemobiletools:commons:5.27.10'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ContactsHelper
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_GET_ACCOUNTS
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.commons.models.FAQItem
|
||||
@ -140,6 +141,10 @@ class MainActivity : SimpleActivity() {
|
||||
viewpager.adapter = ViewPagerAdapter(this)
|
||||
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||
}
|
||||
|
||||
ContactsHelper(this).getAvailableContacts { contacts ->
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment)
|
||||
|
@ -5,15 +5,15 @@ import android.util.AttributeSet
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.underlineText
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.Config
|
||||
import com.simplemobiletools.dialer.models.Contact
|
||||
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
||||
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
||||
protected var activity: SimpleActivity? = null
|
||||
protected var allContacts = ArrayList<Contact>()
|
||||
protected var allContacts = ArrayList<SimpleContact>()
|
||||
|
||||
private var lastHashCode = 0
|
||||
private lateinit var config: Config
|
||||
|
@ -1,95 +0,0 @@
|
||||
package com.simplemobiletools.dialer.models
|
||||
|
||||
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_DESCENDING
|
||||
|
||||
data class Contact(var id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String,
|
||||
var photoUri: String, var phoneNumbers: ArrayList<PhoneNumber>, var source: String, var starred: Int, var contactId: Int, var thumbnailUri: String,
|
||||
var organization: Organization) : Comparable<Contact> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
var startWithSurname = false
|
||||
}
|
||||
|
||||
override fun compareTo(other: Contact): Int {
|
||||
var firstString: String
|
||||
var secondString: String
|
||||
|
||||
when {
|
||||
sorting and SORT_BY_FIRST_NAME != 0 -> {
|
||||
firstString = firstName.normalizeString()
|
||||
secondString = other.firstName.normalizeString()
|
||||
}
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> {
|
||||
firstString = middleName.normalizeString()
|
||||
secondString = other.middleName.normalizeString()
|
||||
}
|
||||
else -> {
|
||||
firstString = surname.normalizeString()
|
||||
secondString = other.surname.normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty()) {
|
||||
val fullCompany = getFullCompany()
|
||||
if (fullCompany.isNotEmpty()) {
|
||||
firstString = fullCompany.normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
if (secondString.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty()) {
|
||||
val otherFullCompany = other.getFullCompany()
|
||||
if (otherFullCompany.isNotEmpty()) {
|
||||
secondString = otherFullCompany.normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
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.toLowerCase() == secondString.toLowerCase()) {
|
||||
getNameToDisplay().compareTo(other.getNameToDisplay(), true)
|
||||
} else {
|
||||
firstString.compareTo(secondString, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
result *= -1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun getNameToDisplay(): String {
|
||||
var firstPart = if (startWithSurname) surname else firstName
|
||||
if (middleName.isNotEmpty()) {
|
||||
firstPart += " $middleName"
|
||||
}
|
||||
|
||||
val lastPart = if (startWithSurname) firstName else surname
|
||||
val suffixComma = if (suffix.isEmpty()) "" else ", $suffix"
|
||||
val fullName = "$prefix $firstPart $lastPart$suffixComma".trim()
|
||||
return if (fullName.isEmpty() && organization.isNotEmpty()) {
|
||||
getFullCompany()
|
||||
} else {
|
||||
fullName
|
||||
}
|
||||
}
|
||||
|
||||
fun getFullCompany(): String {
|
||||
var fullOrganization = if (organization.company.isEmpty()) "" else "${organization.company}, "
|
||||
fullOrganization += organization.jobPosition
|
||||
return fullOrganization.trim().trimEnd(',')
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user