Merge branch 'master' into prevent-adding-empty-contact

This commit is contained in:
Agnieszka C
2021-11-18 09:52:30 +01:00
50 changed files with 637 additions and 560 deletions

View File

@ -65,8 +65,10 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
fabClicked()
}
val adjustedPrimaryColor = getAdjustedPrimaryColor()
group_contacts_fastscroller?.updateColors(adjustedPrimaryColor, adjustedPrimaryColor.getContrastColor())
group_contacts_placeholder_2.underlineText()
group_contacts_placeholder_2.setTextColor(getAdjustedPrimaryColor())
group_contacts_placeholder_2.setTextColor(adjustedPrimaryColor)
}
override fun onResume() {
@ -108,7 +110,7 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
groupContacts = it.filter { it.groups.map { it.id }.contains(group.id) } as ArrayList<Contact>
group_contacts_placeholder_2.beVisibleIf(groupContacts.isEmpty())
group_contacts_placeholder.beVisibleIf(groupContacts.isEmpty())
group_contacts_list.beVisibleIf(groupContacts.isNotEmpty())
group_contacts_fastscroller.beVisibleIf(groupContacts.isNotEmpty())
updateContacts(groupContacts)
}
}
@ -133,17 +135,14 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
private fun updateContacts(contacts: ArrayList<Contact>) {
val currAdapter = group_contacts_list.adapter
if (currAdapter == null) {
ContactsAdapter(this, contacts, this, LOCATION_GROUP_CONTACTS, this, group_contacts_list, group_contacts_fastscroller) {
ContactsAdapter(this, contacts, this, LOCATION_GROUP_CONTACTS, this, group_contacts_list) {
contactClicked(it as Contact)
}.apply {
group_contacts_list.adapter = this
}
group_contacts_list.scheduleLayoutAnimation()
group_contacts_fastscroller.setScrollToY(0)
group_contacts_fastscroller.setViews(group_contacts_list) {
val item = (group_contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it)
group_contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
if (areSystemAnimationsEnabled) {
group_contacts_list.scheduleLayoutAnimation()
}
} else {
(currAdapter as ContactsAdapter).updateItems(contacts)
@ -180,9 +179,9 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, defaultRingtoneUri)
}
}
private fun setRingtoneOnSelected(uri: Uri) {
groupContacts.forEach{
groupContacts.forEach {
ContactsHelper(this).updateRingtone(it.contactId.toString(), uri.toString())
}
}

View File

@ -386,6 +386,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
skippedTabs++
} else {
val tab = main_tabs_holder.newTab().setIcon(getTabIcon(index))
tab.contentDescription = getTabContentDescription(index)
main_tabs_holder.addTab(tab, index - skippedTabs, getDefaultTab() == index - skippedTabs)
}
}

View File

@ -12,9 +12,9 @@ import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.SelectContactsAdapter
import com.simplemobiletools.contacts.pro.dialogs.ChangeSortingDialog
@ -26,6 +26,8 @@ import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
import com.simplemobiletools.contacts.pro.helpers.getProperText
import com.simplemobiletools.contacts.pro.models.Contact
import kotlinx.android.synthetic.main.activity_select_contact.*
import java.util.*
import kotlin.collections.ArrayList
class SelectContactActivity : SimpleActivity() {
private var specialMimeType: String? = null
@ -41,7 +43,7 @@ class SelectContactActivity : SimpleActivity() {
return
}
setupPlaceholders()
setupViews()
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
@ -195,16 +197,25 @@ class SelectContactActivity : SimpleActivity() {
runOnUiThread {
updatePlaceholderVisibility(contacts)
SelectContactsAdapter(this, contacts, ArrayList(), false, select_contact_list, select_contact_fastscroller) {
SelectContactsAdapter(this, contacts, ArrayList(), false, select_contact_list) {
confirmSelection(it)
}.apply {
select_contact_list.adapter = this
}
select_contact_list.scheduleLayoutAnimation()
select_contact_fastscroller.setViews(select_contact_list) {
select_contact_fastscroller.updateBubbleText(contacts[it].getBubbleText())
if (areSystemAnimationsEnabled) {
select_contact_list.scheduleLayoutAnimation()
}
letter_fastscroller.setupWithRecyclerView(select_contact_list, { position ->
try {
val name = contacts[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
FastScrollItemIndicator.Text(character.normalizeString().toUpperCase(Locale.getDefault()))
} catch (e: Exception) {
FastScrollItemIndicator.Text("")
}
})
}
}
}
@ -228,25 +239,35 @@ class SelectContactActivity : SimpleActivity() {
}
}
private fun setupPlaceholders() {
private fun setupViews() {
val adjustedPrimaryColor = getAdjustedPrimaryColor()
select_contact_placeholder.setTextColor(config.textColor)
select_contact_placeholder_2.setTextColor(getAdjustedPrimaryColor())
select_contact_placeholder_2.setTextColor(adjustedPrimaryColor)
select_contact_placeholder_2.underlineText()
select_contact_placeholder_2.setOnClickListener {
FilterContactSourcesDialog(this) {
initContacts()
}
}
letter_fastscroller?.textColor = config.textColor.getColorStateList()
letter_fastscroller?.pressedTextColor = adjustedPrimaryColor
letter_fastscroller_thumb?.fontSize = getTextSize()
letter_fastscroller_thumb?.textColor = adjustedPrimaryColor.getContrastColor()
letter_fastscroller_thumb?.thumbColor = adjustedPrimaryColor.getColorStateList()
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
}
private fun updatePlaceholderVisibility(contacts: ArrayList<Contact>) {
select_contact_list.beVisibleIf(contacts.isNotEmpty())
select_contact_placeholder_2.beVisibleIf(contacts.isEmpty())
select_contact_placeholder.beVisibleIf(contacts.isEmpty())
select_contact_placeholder.setText(when (specialMimeType) {
Email.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_emails
Phone.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_phone_numbers
else -> R.string.no_contacts_found
})
select_contact_placeholder.setText(
when (specialMimeType) {
Email.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_emails
Phone.CONTENT_ITEM_TYPE -> R.string.no_contacts_with_phone_numbers
else -> R.string.no_contacts_found
}
)
}
}

View File

@ -3,10 +3,7 @@ package com.simplemobiletools.contacts.pro.activities
import android.os.Bundle
import android.view.Menu
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getFontSizeText
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.contacts.pro.R
@ -44,6 +41,19 @@ class SettingsActivity : SimpleActivity() {
setupDefaultTab()
updateTextColors(settings_holder)
invalidateOptionsMenu()
arrayOf(settings_color_customization_label, settings_general_settings_label, settings_main_screen_label, settings_list_view_label).forEach {
it.setTextColor(getAdjustedPrimaryColor())
}
arrayOf(
settings_color_customization_holder,
settings_general_settings_holder,
settings_main_screen_holder,
settings_list_view_holder
).forEach {
it.background.applyColorFilter(baseConfig.backgroundColor.getContrastColor())
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -64,7 +74,7 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupManageShownTabs() {
settings_manage_tabs_holder.setOnClickListener {
settings_manage_shown_tabs_holder.setOnClickListener {
ManageVisibleTabsDialog(this)
}
}
@ -76,7 +86,8 @@ class SettingsActivity : SimpleActivity() {
RadioItem(TAB_CONTACTS, getString(R.string.contacts_tab)),
RadioItem(TAB_FAVORITES, getString(R.string.favorites_tab)),
RadioItem(TAB_GROUPS, getString(R.string.groups_tab)),
RadioItem(TAB_LAST_USED, getString(R.string.last_used_tab)))
RadioItem(TAB_LAST_USED, getString(R.string.last_used_tab))
)
RadioGroupDialog(this@SettingsActivity, items, config.defaultTab) {
config.defaultTab = it as Int
@ -85,12 +96,14 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun getDefaultTabText() = getString(when (baseConfig.defaultTab) {
TAB_CONTACTS -> R.string.contacts_tab
TAB_FAVORITES -> R.string.favorites_tab
TAB_GROUPS -> R.string.groups_tab
else -> R.string.last_used_tab
})
private fun getDefaultTabText() = getString(
when (baseConfig.defaultTab) {
TAB_CONTACTS -> R.string.contacts_tab
TAB_FAVORITES -> R.string.favorites_tab
TAB_GROUPS -> R.string.groups_tab
else -> R.string.last_used_tab
}
)
private fun setupFontSize() {
settings_font_size.text = getFontSizeText()
@ -99,7 +112,8 @@ class SettingsActivity : SimpleActivity() {
RadioItem(FONT_SIZE_SMALL, getString(R.string.small)),
RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)),
RadioItem(FONT_SIZE_LARGE, getString(R.string.large)),
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large)))
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))
)
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
config.fontSize = it as Int
@ -111,6 +125,11 @@ class SettingsActivity : SimpleActivity() {
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en")
settings_use_english.isChecked = config.useEnglish
if (settings_use_english_holder.isGone()) {
settings_font_size_holder.background = resources.getDrawable(R.drawable.ripple_top_corners, theme)
}
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
@ -143,10 +162,10 @@ class SettingsActivity : SimpleActivity() {
}
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
settings_start_name_with_surname.isChecked = config.startNameWithSurname
settings_start_name_with_surname_holder.setOnClickListener {
settings_start_name_with_surname.toggle()
config.startNameWithSurname = settings_start_name_with_surname.isChecked
}
}
@ -172,7 +191,8 @@ class SettingsActivity : SimpleActivity() {
val items = arrayListOf(
RadioItem(ON_CLICK_CALL_CONTACT, getString(R.string.call_contact)),
RadioItem(ON_CLICK_VIEW_CONTACT, getString(R.string.view_contact)),
RadioItem(ON_CLICK_EDIT_CONTACT, getString(R.string.edit_contact)))
RadioItem(ON_CLICK_EDIT_CONTACT, getString(R.string.edit_contact))
)
RadioGroupDialog(this@SettingsActivity, items, config.onContactClick) {
config.onContactClick = it as Int
@ -181,11 +201,13 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun getOnContactClickText() = getString(when (config.onContactClick) {
ON_CLICK_CALL_CONTACT -> R.string.call_contact
ON_CLICK_VIEW_CONTACT -> R.string.view_contact
else -> R.string.edit_contact
})
private fun getOnContactClickText() = getString(
when (config.onContactClick) {
ON_CLICK_CALL_CONTACT -> R.string.call_contact
ON_CLICK_VIEW_CONTACT -> R.string.view_contact
else -> R.string.edit_contact
}
)
private fun setupShowCallConfirmation() {
settings_show_call_confirmation.isChecked = config.showCallConfirmation

View File

@ -66,10 +66,20 @@ open class SimpleActivity : BaseSimpleActivity() {
protected fun getTabIcon(position: Int): Drawable {
val drawableId = when (position) {
LOCATION_CONTACTS_TAB -> R.drawable.ic_person_vector
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_on_vector
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_vector
else -> R.drawable.ic_people_vector
}
return resources.getColoredDrawableWithColor(drawableId, config.textColor)
}
protected fun getTabContentDescription(position: Int): String {
val stringId = when (position) {
LOCATION_CONTACTS_TAB -> R.string.contacts_tab
LOCATION_FAVORITES_TAB -> R.string.favorites_tab
else -> R.string.groups_tab
}
return resources.getString(stringId)
}
}

View File

@ -757,7 +757,7 @@ class ViewContactActivity : ContactActivity() {
}
}
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_vector else R.drawable.ic_star_off_vector)
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_vector else R.drawable.ic_star_outline_vector)
private fun hideBigContactPhoto() {
contact_photo_big.animate().alpha(0f).withEndAction { contact_photo_big.beGone() }.start()

View File

@ -19,13 +19,13 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
@ -38,10 +38,11 @@ import com.simplemobiletools.contacts.pro.interfaces.RemoveFromGroupListener
import com.simplemobiletools.contacts.pro.models.Contact
import java.util.*
class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Contact>, private val refreshListener: RefreshContactsListener?,
private val location: Int, private val removeListener: RemoveFromGroupListener?, recyclerView: MyRecyclerView,
fastScroller: FastScroller?, highlightText: String = "", itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
class ContactsAdapter(
activity: SimpleActivity, var contactItems: ArrayList<Contact>, private val refreshListener: RefreshContactsListener?,
private val location: Int, private val removeListener: RemoveFromGroupListener?, recyclerView: MyRecyclerView,
highlightText: String = "", itemClick: (Any) -> Unit
) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
private val NEW_GROUP_ID = -1
private var config = activity.config
@ -66,10 +67,13 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
findItem(R.id.cab_remove).isVisible = location == LOCATION_FAVORITES_TAB || location == LOCATION_GROUP_CONTACTS
findItem(R.id.cab_add_to_favorites).isVisible = location == LOCATION_CONTACTS_TAB
findItem(R.id.cab_add_to_group).isVisible = location == LOCATION_CONTACTS_TAB || location == LOCATION_FAVORITES_TAB
findItem(R.id.cab_send_sms_to_contacts).isVisible = location == LOCATION_CONTACTS_TAB || location == LOCATION_FAVORITES_TAB || location == LOCATION_GROUP_CONTACTS
findItem(R.id.cab_send_email_to_contacts).isVisible = location == LOCATION_CONTACTS_TAB || location == LOCATION_FAVORITES_TAB || location == LOCATION_GROUP_CONTACTS
findItem(R.id.cab_send_sms_to_contacts).isVisible =
location == LOCATION_CONTACTS_TAB || location == LOCATION_FAVORITES_TAB || location == LOCATION_GROUP_CONTACTS
findItem(R.id.cab_send_email_to_contacts).isVisible =
location == LOCATION_CONTACTS_TAB || location == LOCATION_FAVORITES_TAB || location == LOCATION_GROUP_CONTACTS
findItem(R.id.cab_delete).isVisible = location == LOCATION_CONTACTS_TAB || location == LOCATION_GROUP_CONTACTS
findItem(R.id.cab_create_shortcut).isVisible = isOreoPlus() && isOneItemSelected() && (location == LOCATION_FAVORITES_TAB || location == LOCATION_CONTACTS_TAB)
findItem(R.id.cab_create_shortcut).isVisible =
isOreoPlus() && isOneItemSelected() && (location == LOCATION_FAVORITES_TAB || location == LOCATION_CONTACTS_TAB)
if (location == LOCATION_GROUP_CONTACTS) {
findItem(R.id.cab_remove).title = activity.getString(R.string.remove_from_group)
@ -133,7 +137,6 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
textToHighlight = highlightText
notifyDataSetChanged()
}
fastScroller?.measureRecyclerView()
}
private fun editContact() {
@ -170,7 +173,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
ensureBackgroundThread {
contactsToRemove.forEach {
val contactToRemove = it
val duplicates = allContacts.filter { it.id != contactToRemove.id && it.getHashToCompare() == contactToRemove.getHashToCompare() }.toMutableList() as ArrayList<Contact>
val duplicates = allContacts.filter { it.id != contactToRemove.id && it.getHashToCompare() == contactToRemove.getHashToCompare() }
.toMutableList() as ArrayList<Contact>
duplicates.add(contactToRemove)
ContactsHelper(activity).deleteContacts(duplicates)
}
@ -392,4 +396,6 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
}
}
}
override fun onChange(position: Int) = contactItems.getOrNull(position)?.getBubbleText() ?: ""
}

View File

@ -4,6 +4,7 @@ import android.util.TypedValue
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
@ -12,7 +13,6 @@ import com.simplemobiletools.commons.extensions.highlightTextPart
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
@ -25,8 +25,10 @@ import com.simplemobiletools.contacts.pro.models.Group
import kotlinx.android.synthetic.main.item_group.view.*
import java.util.*
class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val refreshListener: RefreshContactsListener?, recyclerView: MyRecyclerView,
fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
class GroupsAdapter(
activity: SimpleActivity, var groups: ArrayList<Group>, val refreshListener: RefreshContactsListener?, recyclerView: MyRecyclerView,
itemClick: (Any) -> Unit
) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
private var textToHighlight = ""
var showContactThumbnails = activity.config.showContactThumbnails
@ -172,4 +174,6 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
}
}
}
override fun onChange(position: Int) = groups.getOrNull(position)?.getBubbleText() ?: ""
}

View File

@ -12,7 +12,6 @@ import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
@ -21,9 +20,11 @@ import com.simplemobiletools.contacts.pro.models.Contact
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
import java.util.*
class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayList<Contact>, private val selectedContacts: ArrayList<Contact>, private val allowPickMultiple: Boolean,
recyclerView: MyRecyclerView, val fastScroller: FastScroller, private val itemClick: ((Contact) -> Unit)? = null) :
RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
class SelectContactsAdapter(
val activity: SimpleActivity, var contacts: ArrayList<Contact>, private val selectedContacts: ArrayList<Contact>, private val allowPickMultiple: Boolean,
recyclerView: MyRecyclerView, private val itemClick: ((Contact) -> Unit)? = null
) :
RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
private val itemViews = SparseArray<View>()
private val selectedPositions = HashSet<Int>()
private val config = activity.config
@ -87,7 +88,6 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
textToHighlight = highlightText
notifyDataSetChanged()
}
fastScroller.measureRecyclerView()
}
override fun onViewRecycled(holder: ViewHolder) {
@ -124,7 +124,8 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
}
val numberText = phoneNumberToUse?.value ?: ""
contact_number.text = if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, adjustedPrimaryColor, false, true)
contact_number.text =
if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, adjustedPrimaryColor, false, true)
contact_number.setTextColor(textColor)
contact_number.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
}

View File

@ -36,6 +36,7 @@ class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val
}
group.title = newTitle
group.contactsCount = 0
ensureBackgroundThread {
if (group.isPrivateSecretGroup()) {
activity.groupsDB.insertOrUpdate(group)

View File

@ -1,17 +1,23 @@
package com.simplemobiletools.contacts.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.adapters.SelectContactsAdapter
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
import com.simplemobiletools.contacts.pro.models.Contact
import kotlinx.android.synthetic.main.layout_select_contact.view.*
import java.util.*
import kotlin.collections.ArrayList
class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayList<Contact>, val allowSelectMultiple: Boolean, val showOnlyContactsWithNumber: Boolean,
selectContacts: ArrayList<Contact>? = null, val callback: (addedContacts: ArrayList<Contact>, removedContacts: ArrayList<Contact>) -> Unit) {
class SelectContactsDialog(
val activity: SimpleActivity, initialContacts: ArrayList<Contact>, val allowSelectMultiple: Boolean, val showOnlyContactsWithNumber: Boolean,
selectContacts: ArrayList<Contact>? = null, val callback: (addedContacts: ArrayList<Contact>, removedContacts: ArrayList<Contact>) -> Unit
) {
private var dialog: AlertDialog? = null
private var view = activity.layoutInflater.inflate(R.layout.layout_select_contact, null)
private var initiallySelectedContacts = ArrayList<Contact>()
@ -31,32 +37,33 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL
initiallySelectedContacts = selectContacts
}
activity.runOnUiThread {
// if selecting multiple contacts is disabled, react on first contact click and dismiss the dialog
val contactClickCallback: ((Contact) -> Unit)? = if (allowSelectMultiple) null else { contact ->
callback(arrayListOf(contact), arrayListOf())
dialog!!.dismiss()
}
// if selecting multiple contacts is disabled, react on first contact click and dismiss the dialog
val contactClickCallback: ((Contact) -> Unit)? = if (allowSelectMultiple) null else { contact ->
callback(arrayListOf(contact), arrayListOf())
dialog!!.dismiss()
}
view.apply {
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, allowSelectMultiple,
select_contact_list, select_contact_fastscroller, contactClickCallback)
view.apply {
select_contact_list.adapter = SelectContactsAdapter(
activity, allContacts, initiallySelectedContacts, allowSelectMultiple,
select_contact_list, contactClickCallback
)
if (context.areSystemAnimationsEnabled) {
select_contact_list.scheduleLayoutAnimation()
select_contact_fastscroller.setViews(select_contact_list) {
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
}
}
}
val builder = AlertDialog.Builder(activity)
if (allowSelectMultiple) {
builder.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
}
builder.setNegativeButton(R.string.cancel, null)
setupFastscroller(allContacts)
dialog = builder.create().apply {
activity.setupDialogStuff(view, this)
}
val builder = AlertDialog.Builder(activity)
if (allowSelectMultiple) {
builder.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
}
builder.setNegativeButton(R.string.cancel, null)
dialog = builder.create().apply {
activity.setupDialogStuff(view, this)
}
}
@ -70,4 +77,26 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL
callback(newlySelectedContacts, unselectedContacts)
}
}
private fun setupFastscroller(allContacts: ArrayList<Contact>) {
val adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
view.apply {
letter_fastscroller?.textColor = context.config.textColor.getColorStateList()
letter_fastscroller?.pressedTextColor = adjustedPrimaryColor
letter_fastscroller_thumb?.fontSize = context.getTextSize()
letter_fastscroller_thumb?.textColor = adjustedPrimaryColor.getContrastColor()
letter_fastscroller_thumb?.thumbColor = adjustedPrimaryColor.getColorStateList()
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
}
view.letter_fastscroller.setupWithRecyclerView(view.select_contact_list, { position ->
try {
val name = allContacts[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
FastScrollItemIndicator.Text(character.normalizeString().toUpperCase(Locale.getDefault()))
} catch (e: Exception) {
FastScrollItemIndicator.Text("")
}
})
}
}

View File

@ -1,9 +1,10 @@
package com.simplemobiletools.contacts.pro.extensions
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.LauncherApps
import android.database.Cursor
import android.graphics.*
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Handler
@ -26,6 +27,7 @@ import com.simplemobiletools.contacts.pro.models.Organization
import com.simplemobiletools.contacts.pro.models.SocialAction
import java.io.File
val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.contactsDB: ContactsDao get() = ContactsDatabase.getInstance(applicationContext).ContactsDao()
@ -35,8 +37,10 @@ val Context.groupsDB: GroupsDao get() = ContactsDatabase.getInstance(application
fun Context.getEmptyContact(): Contact {
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
val organization = Organization("", "")
return Contact(0, "", "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "",
null, "", ArrayList(), organization, ArrayList(), ArrayList(), DEFAULT_MIMETYPE, null)
return Contact(
0, "", "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "",
null, "", ArrayList(), organization, ArrayList(), ArrayList(), DEFAULT_MIMETYPE, null
)
}
fun Context.viewContact(contact: Contact) {
@ -355,22 +359,15 @@ fun Context.getSocialActions(id: Int): ArrayList<SocialAction> {
return socialActions
}
fun Context.getPackageDrawable(packageName: String): Drawable? {
var drawable: Drawable? = null
try {
// try getting the properly colored launcher icons
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle())[0]
drawable = activityList.getBadgedIcon(0)
} catch (ignored: Exception) {
}
if (drawable == null) {
try {
drawable = packageManager.getApplicationIcon(packageName)
} catch (ignored: Exception) {
}
}
return drawable
@SuppressLint("UseCompatLoadingForDrawables")
fun Context.getPackageDrawable(packageName: String): Drawable {
return resources.getDrawable(
when (packageName) {
TELEGRAM_PACKAGE -> R.drawable.ic_telegram_vector
SIGNAL_PACKAGE -> R.drawable.ic_signal_vector
WHATSAPP_PACKAGE -> R.drawable.ic_whatsapp_vector
VIBER_PACKAGE -> R.drawable.ic_viber_vector
else -> R.drawable.ic_threema_vector
}, theme
)
}

View File

@ -84,8 +84,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
context.updateTextColors(fragment_wrapper.parent as ViewGroup)
fragment_fastscroller?.updatePrimaryColor()
fragment_fastscroller?.updateBubblePrimaryColor()
fragment_fastscroller?.updateColors(adjustedPrimaryColor, adjustedPrimaryColor.getContrastColor())
fragment_placeholder_2?.setTextColor(adjustedPrimaryColor)
letter_fastscroller?.textColor = textColor.getColorStateList()
@ -165,11 +164,11 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fragment_placeholder_2.beVisibleIf(storedGroups.isEmpty())
fragment_placeholder.beVisibleIf(storedGroups.isEmpty())
fragment_list.beVisibleIf(storedGroups.isNotEmpty())
fragment_fastscroller.beVisibleIf(storedGroups.isNotEmpty())
val currAdapter = fragment_list.adapter
if (currAdapter == null) {
GroupsAdapter(activity as SimpleActivity, storedGroups, activity as RefreshContactsListener, fragment_list, fragment_fastscroller) {
GroupsAdapter(activity as SimpleActivity, storedGroups, activity as RefreshContactsListener, fragment_list) {
Intent(activity, GroupContactsActivity::class.java).apply {
putExtra(GROUP, it as Group)
activity!!.startActivity(this)
@ -178,11 +177,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fragment_list.adapter = this
}
fragment_list.scheduleLayoutAnimation()
fragment_fastscroller.setScrollToY(0)
fragment_fastscroller.setViews(fragment_list) {
val item = (fragment_list.adapter as GroupsAdapter).groups.getOrNull(it)
fragment_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
if (context.areSystemAnimationsEnabled) {
fragment_list.scheduleLayoutAnimation()
}
} else {
(currAdapter as GroupsAdapter).apply {
@ -206,12 +202,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
else -> LOCATION_CONTACTS_TAB
}
ContactsAdapter(activity as SimpleActivity, contacts, activity as RefreshContactsListener, location, null, fragment_list, null) {
ContactsAdapter(activity as SimpleActivity, contacts, activity as RefreshContactsListener, location, null, fragment_list) {
(activity as RefreshContactsListener).contactClicked(it as Contact)
}.apply {
fragment_list.adapter = this
}
fragment_list.scheduleLayoutAnimation()
if (context.areSystemAnimationsEnabled) {
fragment_list.scheduleLayoutAnimation()
}
} else {
(currAdapter as ContactsAdapter).apply {
startNameWithSurname = config.startNameWithSurname
@ -237,14 +236,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
val sorting = context.config.sorting
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
try {
val contact = contacts[position]
var name = when {
contact.isABusinessContact() -> contact.getFullCompany()
context.config.sorting and SORT_BY_SURNAME != 0 && contact.surname.isNotEmpty() -> contact.surname
context.config.sorting and SORT_BY_MIDDLE_NAME != 0 && contact.middleName.isNotEmpty() -> contact.middleName
context.config.sorting and SORT_BY_FIRST_NAME != 0 && contact.firstName.isNotEmpty() -> contact.firstName
sorting and SORT_BY_SURNAME != 0 && contact.surname.isNotEmpty() -> contact.surname
sorting and SORT_BY_MIDDLE_NAME != 0 && contact.middleName.isNotEmpty() -> contact.middleName
sorting and SORT_BY_FIRST_NAME != 0 && contact.firstName.isNotEmpty() -> contact.firstName
context.config.startNameWithSurname -> contact.surname
else -> contact.firstName
}

View File

@ -28,7 +28,12 @@ class ContactsHelper(val context: Context) {
private val BATCH_SIZE = 50
private var displayContactSources = ArrayList<String>()
fun getContacts(getAll: Boolean = false, gettingDuplicates: Boolean = false, ignoredContactSources: HashSet<String> = HashSet(), callback: (ArrayList<Contact>) -> Unit) {
fun getContacts(
getAll: Boolean = false,
gettingDuplicates: Boolean = false,
ignoredContactSources: HashSet<String> = HashSet(),
callback: (ArrayList<Contact>) -> Unit
) {
ensureBackgroundThread {
val contacts = SparseArray<Contact>()
displayContactSources = context.getVisibleContactSources()
@ -187,8 +192,10 @@ class ContactsHelper(val context: Context) {
val organization = Organization("", "")
val websites = ArrayList<String>()
val ims = ArrayList<IM>()
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, numbers, emails, addresses,
events, accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims, mimetype, ringtone)
val contact = Contact(
id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, numbers, emails, addresses,
events, accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims, mimetype, ringtone
)
contacts.put(id, contact)
}
@ -733,8 +740,10 @@ class ContactsHelper(val context: Context) {
val organization = getOrganizations(id)[id] ?: Organization("", "")
val websites = getWebsites(id)[id] ?: ArrayList()
val ims = getIMs(id)[id] ?: ArrayList()
return Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, number, emails, addresses, events,
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims, mimetype, ringtone)
return Contact(
id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, number, emails, addresses, events,
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ims, mimetype, ringtone
)
}
}
@ -1499,7 +1508,8 @@ class ContactsHelper(val context: Context) {
fun getDuplicatesOfContact(contact: Contact, addOriginal: Boolean, callback: (ArrayList<Contact>) -> Unit) {
ensureBackgroundThread {
getContacts(true, true) { contacts ->
val duplicates = contacts.filter { it.id != contact.id && it.getHashToCompare() == contact.getHashToCompare() }.toMutableList() as ArrayList<Contact>
val duplicates =
contacts.filter { it.id != contact.id && it.getHashToCompare() == contact.getHashToCompare() }.toMutableList() as ArrayList<Contact>
if (addOriginal) {
duplicates.add(contact)
}