mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-17 03:51:03 +01:00
add a toggle for starting names with surname
This commit is contained in:
parent
74c5b19025
commit
42cc8aaa2f
@ -6,10 +6,7 @@ import android.os.Bundle
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
|
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
|
||||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||||
import com.simplemobiletools.contacts.BuildConfig
|
import com.simplemobiletools.contacts.BuildConfig
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
@ -28,6 +25,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
private var storedTextColor = 0
|
private var storedTextColor = 0
|
||||||
private var storedBackgroundColor = 0
|
private var storedBackgroundColor = 0
|
||||||
private var storedPrimaryColor = 0
|
private var storedPrimaryColor = 0
|
||||||
|
private var storedStartNameWithSurname = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -72,6 +70,14 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
contacts_fastscroller.updatePrimaryColor()
|
contacts_fastscroller.updatePrimaryColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (storedStartNameWithSurname != config.startNameWithSurname) {
|
||||||
|
(contacts_list.adapter as ContactsAdapter).apply {
|
||||||
|
startNameWithSurname = config.startNameWithSurname
|
||||||
|
config.sorting = if (config.startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
|
||||||
|
initContacts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
contacts_fastscroller.updateBubbleColors()
|
contacts_fastscroller.updateBubbleColors()
|
||||||
contacts_fastscroller.allowBubbleDisplay = config.showInfoBubble
|
contacts_fastscroller.allowBubbleDisplay = config.showInfoBubble
|
||||||
updateTextColors(contacts_holder)
|
updateTextColors(contacts_holder)
|
||||||
@ -126,6 +132,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
storedTextColor = textColor
|
storedTextColor = textColor
|
||||||
storedBackgroundColor = backgroundColor
|
storedBackgroundColor = backgroundColor
|
||||||
storedPrimaryColor = primaryColor
|
storedPrimaryColor = primaryColor
|
||||||
|
storedStartNameWithSurname = startNameWithSurname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupUseEnglish()
|
setupUseEnglish()
|
||||||
setupShowInfoBubble()
|
setupShowInfoBubble()
|
||||||
setupCallContactOnClick()
|
setupCallContactOnClick()
|
||||||
|
setupStartNameWithSurname()
|
||||||
updateTextColors(settings_holder)
|
updateTextColors(settings_holder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,4 +57,12 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
config.callContact = settings_call_contact_on_click.isChecked
|
config.callContact = settings_call_contact_on_click.isChecked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupStartNameWithSurname() {
|
||||||
|
settings_start_with_surname.isChecked = config.startNameWithSurname
|
||||||
|
settings_start_with_surname_holder.setOnClickListener {
|
||||||
|
settings_start_with_surname.toggle()
|
||||||
|
config.startNameWithSurname = settings_start_with_surname.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,13 @@ import kotlinx.android.synthetic.main.item_contact.view.*
|
|||||||
class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Contact>, val listener: RefreshRecyclerViewListener?,
|
class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Contact>, val listener: RefreshRecyclerViewListener?,
|
||||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||||
|
|
||||||
|
var config = activity.config
|
||||||
lateinit private var contactDrawable: Drawable
|
lateinit private var contactDrawable: Drawable
|
||||||
|
var startNameWithSurname: Boolean
|
||||||
|
|
||||||
init {
|
init {
|
||||||
initDrawables()
|
initDrawables()
|
||||||
|
startNameWithSurname = config.startNameWithSurname
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getActionMenuId() = R.menu.cab
|
override fun getActionMenuId() = R.menu.cab
|
||||||
@ -100,7 +103,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||||||
|
|
||||||
private fun setupView(view: View, contact: Contact) {
|
private fun setupView(view: View, contact: Contact) {
|
||||||
view.apply {
|
view.apply {
|
||||||
contact_first_name.text = contact.getFullName()
|
contact_first_name.text = contact.getFullName(startNameWithSurname)
|
||||||
contact_first_name.setTextColor(textColor)
|
contact_first_name.setTextColor(textColor)
|
||||||
contact_number.text = contact.number
|
contact_number.text = contact.number
|
||||||
contact_number.setTextColor(textColor)
|
contact_number.setTextColor(textColor)
|
||||||
|
@ -22,4 +22,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
set(displayContactSources) = prefs.edit().remove(DISPLAY_CONTACT_SOURCES).putStringSet(DISPLAY_CONTACT_SOURCES, displayContactSources).apply()
|
set(displayContactSources) = prefs.edit().remove(DISPLAY_CONTACT_SOURCES).putStringSet(DISPLAY_CONTACT_SOURCES, displayContactSources).apply()
|
||||||
|
|
||||||
fun showAllContacts() = displayContactSources.size == 1 && displayContactSources.first() == "-1"
|
fun showAllContacts() = displayContactSources.size == 1 && displayContactSources.first() == "-1"
|
||||||
|
|
||||||
|
var startNameWithSurname: Boolean
|
||||||
|
get() = prefs.getBoolean(START_NAME_WITH_SURNAME, false)
|
||||||
|
set(startNameWithSurname) = prefs.edit().putBoolean(START_NAME_WITH_SURNAME, startNameWithSurname).apply()
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.simplemobiletools.contacts.helpers
|
|||||||
// shared prefs
|
// shared prefs
|
||||||
val CALL_CONTACT_ON_CLICK = "call_contact_on_click"
|
val CALL_CONTACT_ON_CLICK = "call_contact_on_click"
|
||||||
val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
|
val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
|
||||||
|
val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
||||||
|
|
||||||
val SORTING = "sorting"
|
val SORTING = "sorting"
|
||||||
val CONTACT_ID = "contact_id"
|
val CONTACT_ID = "contact_id"
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.simplemobiletools.contacts.models
|
package com.simplemobiletools.contacts.models
|
||||||
|
|
||||||
import com.simplemobiletools.commons.helpers.*
|
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
|
||||||
|
|
||||||
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, var number: String,
|
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> {
|
var email: String, var source: String) : Comparable<Contact> {
|
||||||
@ -13,7 +16,7 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v
|
|||||||
sorting and SORT_BY_FIRST_NAME != 0 -> compareStrings(firstName, other.firstName)
|
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_MIDDLE_NAME != 0 -> compareStrings(middleName, other.middleName)
|
||||||
sorting and SORT_BY_SURNAME != 0 -> compareStrings(surname, other.surname)
|
sorting and SORT_BY_SURNAME != 0 -> compareStrings(surname, other.surname)
|
||||||
else -> number.toLowerCase().compareTo(other.number.toLowerCase())
|
else -> compareStrings(number, other.number)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sorting and SORT_DESCENDING != 0) {
|
if (sorting and SORT_DESCENDING != 0) {
|
||||||
@ -24,16 +27,19 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getBubbleText() = when {
|
fun getBubbleText() = when {
|
||||||
sorting and SORT_BY_NUMBER != 0 -> number
|
sorting and SORT_BY_FIRST_NAME != 0 -> firstName
|
||||||
else -> firstName
|
sorting and SORT_BY_MIDDLE_NAME != 0 -> middleName
|
||||||
|
sorting and SORT_BY_SURNAME != 0 -> surname
|
||||||
|
else -> number
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFullName(): String {
|
fun getFullName(startWithSurname: Boolean): String {
|
||||||
var name = firstName
|
var firstPart = if (startWithSurname) surname else firstName
|
||||||
if (middleName.isNotEmpty()) {
|
if (middleName.isNotEmpty()) {
|
||||||
name += " $middleName"
|
firstPart += " $middleName"
|
||||||
}
|
}
|
||||||
return "$name $surname".trim()
|
val lastPart = if (startWithSurname) firstName else surname
|
||||||
|
return "$firstPart $lastPart".trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compareStrings(first: String, second: String): Int {
|
private fun compareStrings(first: String, second: String): Int {
|
||||||
|
@ -89,5 +89,25 @@
|
|||||||
android:text="@string/call_contact_on_click"/>
|
android:text="@string/call_contact_on_click"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/settings_start_with_surname_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:padding="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||||
|
android:id="@+id/settings_start_with_surname"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@null"
|
||||||
|
android:clickable="false"
|
||||||
|
android:paddingLeft="@dimen/medium_margin"
|
||||||
|
android:paddingStart="@dimen/medium_margin"
|
||||||
|
android:text="@string/start_name_with_surname"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user