updating Commons to 5.0.21 with adapter changes

This commit is contained in:
tibbi 2018-10-15 14:19:32 +02:00
parent 9059e2499a
commit bdac3fba05
33 changed files with 213 additions and 238 deletions

View File

@ -8,7 +8,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.simplemobiletools.contacts" applicationId "com.simplemobiletools.contacts"
minSdkVersion 16 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 32 versionCode 32
versionName "4.5.0" versionName "4.5.0"
@ -41,10 +41,10 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:4.8.0' implementation 'com.simplemobiletools:commons:5.0.21'
implementation 'joda-time:joda-time:2.9.9' implementation 'joda-time:joda-time:2.9.9'
implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.4' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.4'
} }

View File

@ -194,7 +194,7 @@
android:parentActivityName=".activities.MainActivity"/> android:parentActivityName=".activities.MainActivity"/>
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"
android:exported="false" android:exported="false"
android:grantUriPermissions="true"> android:grantUriPermissions="true">

View File

@ -1,17 +1,13 @@
package com.simplemobiletools.contacts.activities package com.simplemobiletools.contacts.activities
import android.annotation.TargetApi
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import android.view.KeyEvent import android.view.KeyEvent
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.adapters.ContactsAdapter import com.simplemobiletools.contacts.adapters.ContactsAdapter
import com.simplemobiletools.contacts.dialogs.CallConfirmationDialog import com.simplemobiletools.contacts.dialogs.CallConfirmationDialog
@ -120,13 +116,8 @@ class DialpadActivity : SimpleActivity() {
else -> KeyEvent.KEYCODE_POUND else -> KeyEvent.KEYCODE_POUND
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private fun disableKeyboardPopping() { private fun disableKeyboardPopping() {
if (isLollipopPlus()) {
dialpad_input.showSoftInputOnFocus = false dialpad_input.showSoftInputOnFocus = false
} else {
dialpad_input.inputType = InputType.TYPE_NULL
}
} }
private fun gotContacts(newContacts: ArrayList<Contact>) { private fun gotContacts(newContacts: ArrayList<Contact>) {

View File

@ -9,11 +9,11 @@ import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.support.v4.view.MenuItemCompat
import android.support.v4.view.ViewPager
import android.support.v7.widget.SearchView
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
@ -401,7 +401,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
fun showFilterDialog() { fun showFilterDialog() {
FilterContactSourcesDialog(this) { FilterContactSourcesDialog(this) {
contacts_fragment?.forceListRedraw = true contacts_fragment?.forceListRedraw = true
refreshContacts(CONTACTS_TAB_MASK) refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
} }
} }
@ -484,7 +484,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
} }
private fun launchAbout() { private fun launchAbout() {
val licenses = LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_STETHO val licenses = LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_STETHO
val faqItems = arrayListOf( val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title, R.string.faq_1_text), FAQItem(R.string.faq_1_title, R.string.faq_1_text),
@ -495,9 +495,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
} }
override fun refreshContacts(refreshTabsMask: Int) { override fun refreshContacts(refreshTabsMask: Int) {
if (isActivityDestroyed() || isGettingContacts) { if (isDestroyed || isGettingContacts) {
return return
} }
isGettingContacts = true isGettingContacts = true
if (viewpager.adapter == null) { if (viewpager.adapter == null) {
@ -507,7 +508,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
ContactsHelper(this).getContacts { ContactsHelper(this).getContacts {
isGettingContacts = false isGettingContacts = false
if (isActivityDestroyed()) { if (isDestroyed) {
return@getContacts return@getContacts
} }

View File

@ -7,7 +7,6 @@ import android.provider.ContactsContract
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.simplemobiletools.commons.extensions.baseConfig import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
@ -80,7 +79,7 @@ class SelectContactActivity : SimpleActivity() {
private fun initContacts() { private fun initContacts() {
ContactsHelper(this).getContacts { ContactsHelper(this).getContacts {
if (isActivityDestroyed()) { if (isDestroyed) {
return@getContacts return@getContacts
} }

View File

@ -12,7 +12,10 @@ import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.highlightTextPart
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
@ -72,14 +75,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
} }
} }
override fun prepareItemSelection(viewHolder: ViewHolder) {}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.contact_frame?.isSelected = select
}
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
@ -100,6 +97,10 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
override fun getIsItemSelectable(position: Int) = true override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = contactItems.getOrNull(position)?.id
override fun getItemKeyPosition(key: Int) = contactItems.indexOfFirst { it.id == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout = if (showPhoneNumbers) R.layout.item_contact_with_number else R.layout.item_contact_without_number val layout = if (showPhoneNumbers) R.layout.item_contact_with_number else R.layout.item_contact_without_number
return createViewHolder(layout, parent) return createViewHolder(layout, parent)
@ -108,14 +109,16 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val contact = contactItems[position] val contact = contactItems[position]
val allowLongClick = location != LOCATION_INSERT_OR_EDIT val allowLongClick = location != LOCATION_INSERT_OR_EDIT
val view = holder.bindView(contact, true, allowLongClick) { itemView, layoutPosition -> holder.bindView(contact, true, allowLongClick) { itemView, layoutPosition ->
setupView(itemView, contact) setupView(itemView, contact)
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = contactItems.size override fun getItemCount() = contactItems.size
private fun getItemWithKey(key: Int): Contact? = contactItems.firstOrNull { it.id == key }
fun initDrawables() { fun initDrawables() {
contactDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_person, textColor) contactDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_person, textColor)
} }
@ -134,7 +137,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
} }
private fun editContact() { private fun editContact() {
activity.editContact(contactItems[selectedPositions.first()]) val contact = getItemWithKey(selectedKeys.first()) ?: return
activity.editContact(contact)
} }
private fun askConfirmDelete() { private fun askConfirmDelete() {
@ -144,17 +148,12 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
} }
private fun deleteContacts() { private fun deleteContacts() {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
val contactsToRemove = ArrayList<Contact>() val contactsToRemove = getSelectedItems()
selectedPositions.sortedDescending().forEach { val positions = getSelectedItemPositions(contactsToRemove)
val contact = contactItems.getOrNull(it)
if (contact != null) {
contactsToRemove.add(contact)
}
}
contactItems.removeAll(contactsToRemove) contactItems.removeAll(contactsToRemove)
ContactsHelper(activity).deleteContacts(contactsToRemove) ContactsHelper(activity).deleteContacts(contactsToRemove)
@ -162,16 +161,15 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
refreshListener?.refreshContacts(ALL_TABS_MASK) refreshListener?.refreshContacts(ALL_TABS_MASK)
finishActMode() finishActMode()
} else { } else {
removeSelectedItems() removeSelectedItems(positions)
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK) refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
} }
} }
// used for removing contacts from groups or favorites, not deleting actual contacts
private fun removeContacts() { private fun removeContacts() {
val contactsToRemove = ArrayList<Contact>() val contactsToRemove = getSelectedItems()
selectedPositions.sortedDescending().forEach { val positions = getSelectedItemPositions(contactsToRemove)
contactsToRemove.add(contactItems[it])
}
contactItems.removeAll(contactsToRemove) contactItems.removeAll(contactsToRemove)
if (location == LOCATION_FAVORITES_TAB) { if (location == LOCATION_FAVORITES_TAB) {
@ -180,22 +178,22 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
refreshListener?.refreshContacts(FAVORITES_TAB_MASK) refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
finishActMode() finishActMode()
} else { } else {
removeSelectedItems() removeSelectedItems(positions)
} }
} else if (location == LOCATION_GROUP_CONTACTS) { } else if (location == LOCATION_GROUP_CONTACTS) {
removeListener?.removeFromGroup(contactsToRemove) removeListener?.removeFromGroup(contactsToRemove)
removeSelectedItems() removeSelectedItems(positions)
} }
} }
private fun addToFavorites() { private fun addToFavorites() {
ContactsHelper(activity).addFavorites(getSelectedContacts()) ContactsHelper(activity).addFavorites(getSelectedItems())
refreshListener?.refreshContacts(FAVORITES_TAB_MASK) refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
finishActMode() finishActMode()
} }
private fun addToGroup() { private fun addToGroup() {
val selectedContacts = getSelectedContacts() val selectedContacts = getSelectedItems()
val NEW_GROUP_ID = -1 val NEW_GROUP_ID = -1
val items = ArrayList<RadioItem>() val items = ArrayList<RadioItem>()
ContactsHelper(activity).getStoredGroups().forEach { ContactsHelper(activity).getStoredGroups().forEach {
@ -223,40 +221,42 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
} }
private fun shareContacts() { private fun shareContacts() {
val contactsIDs = ArrayList<Int>() activity.shareContacts(getSelectedItems())
selectedPositions.forEach {
contactsIDs.add(contactItems[it].id)
}
val filtered = contactItems.filter { contactsIDs.contains(it.id) } as ArrayList<Contact>
activity.shareContacts(filtered)
} }
private fun sendSMSToContacts() { private fun sendSMSToContacts() {
activity.sendSMSToContacts(getSelectedContacts()) activity.sendSMSToContacts(getSelectedItems())
} }
private fun sendEmailToContacts() { private fun sendEmailToContacts() {
activity.sendEmailToContacts(getSelectedContacts()) activity.sendEmailToContacts(getSelectedItems())
} }
private fun getSelectedContacts(): ArrayList<Contact> { private fun getSelectedItems() = contactItems.filter { selectedKeys.contains(it.id) } as ArrayList<Contact>
val contacts = ArrayList<Contact>()
selectedPositions.forEach { private fun getSelectedItemPositions(contacts: ArrayList<Contact>): ArrayList<Int> {
contacts.add(contactItems[it]) val positions = ArrayList<Int>()
contacts.forEach {
val position = getItemKeyPosition(it.id)
if (position != -1) {
positions.add(position)
} }
return contacts }
positions.sortDescending()
return positions
} }
override fun onViewRecycled(holder: ViewHolder) { override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder) super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) { if (!activity.isDestroyed) {
Glide.with(activity).clear(holder.itemView?.contact_tmb!!) Glide.with(activity).clear(holder.itemView.contact_tmb)
} }
} }
private fun setupView(view: View, contact: Contact) { private fun setupView(view: View, contact: Contact) {
view.apply { view.apply {
contact_frame?.isSelected = selectedKeys.contains(contact.id)
val fullName = contact.getFullName() val fullName = contact.getFullName()
contact_name.text = if (textToHighlight.isEmpty()) fullName else fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor) contact_name.text = if (textToHighlight.isEmpty()) fullName else fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
contact_name.setTextColor(textColor) contact_name.setTextColor(textColor)

View File

@ -1,11 +1,9 @@
package com.simplemobiletools.contacts.adapters package com.simplemobiletools.contacts.adapters
import android.support.v7.widget.RecyclerView
import android.util.SparseArray
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.interfaces.MyAdapterListener
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config
@ -16,13 +14,12 @@ import java.util.*
class FilterContactSourcesAdapter(val activity: SimpleActivity, private val contactSources: List<ContactSource>, private val displayContactSources: ArrayList<String>) : class FilterContactSourcesAdapter(val activity: SimpleActivity, private val contactSources: List<ContactSource>, private val displayContactSources: ArrayList<String>) :
RecyclerView.Adapter<FilterContactSourcesAdapter.ViewHolder>() { RecyclerView.Adapter<FilterContactSourcesAdapter.ViewHolder>() {
private val itemViews = SparseArray<View>() private val selectedKeys = HashSet<Int>()
private val selectedPositions = HashSet<Int>()
init { init {
contactSources.forEachIndexed { index, contactSource -> contactSources.forEachIndexed { index, contactSource ->
if (displayContactSources.contains(contactSource.name)) { if (displayContactSources.contains(contactSource.name)) {
selectedPositions.add(index) selectedKeys.add(contactSource.hashCode())
} }
if (contactSource.name == activity.config.localAccountName && contactSource.type == activity.config.localAccountType) { if (contactSource.name == activity.config.localAccountName && contactSource.type == activity.config.localAccountType) {
@ -30,61 +27,50 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, private val cont
} }
if (contactSource.type == SMT_PRIVATE && displayContactSources.contains(SMT_PRIVATE)) { if (contactSource.type == SMT_PRIVATE && displayContactSources.contains(SMT_PRIVATE)) {
selectedPositions.add(index) selectedKeys.add(contactSource.hashCode())
} }
} }
} }
private fun toggleItemSelection(select: Boolean, pos: Int) { private fun toggleItemSelection(select: Boolean, contactSource: ContactSource, position: Int) {
if (select) { if (select) {
if (itemViews[pos] != null) { selectedKeys.add(contactSource.hashCode())
selectedPositions.add(pos)
}
} else { } else {
selectedPositions.remove(pos) selectedKeys.remove(contactSource.hashCode())
} }
itemViews[pos]?.filter_contact_source_checkbox?.isChecked = select notifyItemChanged(position)
} }
private val adapterListener = object : MyAdapterListener { fun getSelectedContactSources() = contactSources.filter { selectedKeys.contains(it.hashCode()) }
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position)
}
override fun getSelectedPositions() = selectedPositions
override fun itemLongClicked(position: Int) {}
}
fun getSelectedItemsSet() = selectedPositions
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = activity.layoutInflater.inflate(R.layout.item_filter_contact_source, parent, false) val view = activity.layoutInflater.inflate(R.layout.item_filter_contact_source, parent, false)
return ViewHolder(view, adapterListener, activity) return ViewHolder(view)
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val contactSource = contactSources[position] val contactSource = contactSources[position]
itemViews.put(position, holder.bindView(contactSource.name)) holder.bindView(contactSource)
toggleItemSelection(selectedPositions.contains(position), position)
} }
override fun getItemCount() = contactSources.size override fun getItemCount() = contactSources.size
class ViewHolder(view: View, private val adapterListener: MyAdapterListener, val activity: SimpleActivity) : RecyclerView.ViewHolder(view) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(contactSource: String): View { fun bindView(contactSource: ContactSource): View {
val isSelected = selectedKeys.contains(contactSource.hashCode())
itemView.apply { itemView.apply {
filter_contact_source_checkbox.isChecked = isSelected
filter_contact_source_checkbox.setColors(activity.config.textColor, activity.getAdjustedPrimaryColor(), activity.config.backgroundColor) filter_contact_source_checkbox.setColors(activity.config.textColor, activity.getAdjustedPrimaryColor(), activity.config.backgroundColor)
filter_contact_source_checkbox.text = contactSource filter_contact_source_checkbox.text = contactSource.name
filter_contact_source_holder.setOnClickListener { viewClicked(!filter_contact_source_checkbox.isChecked) } filter_contact_source_holder.setOnClickListener { viewClicked(!isSelected, contactSource) }
} }
return itemView return itemView
} }
private fun viewClicked(select: Boolean) { private fun viewClicked(select: Boolean, contactSource: ContactSource) {
adapterListener.toggleItemSelectionAdapter(select, adapterPosition) toggleItemSelection(select, contactSource, adapterPosition)
} }
} }
} }

View File

@ -41,14 +41,8 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
} }
} }
override fun prepareItemSelection(viewHolder: ViewHolder) {}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.group_frame?.isSelected = select
}
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
@ -63,18 +57,24 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
override fun getIsItemSelectable(position: Int) = true override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = groups.getOrNull(position)?.id?.toInt()
override fun getItemKeyPosition(key: Int) = groups.indexOfFirst { it.id.toInt() == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_group, parent) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_group, parent)
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val group = groups[position] val group = groups[position]
val view = holder.bindView(group, true, true) { itemView, layoutPosition -> holder.bindView(group, true, true) { itemView, layoutPosition ->
setupView(itemView, group) setupView(itemView, group)
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = groups.size override fun getItemCount() = groups.size
private fun getItemWithKey(key: Int): Group? = groups.firstOrNull { it.id.toInt() == key }
fun updateItems(newItems: ArrayList<Group>) { fun updateItems(newItems: ArrayList<Group>) {
groups = newItems groups = newItems
notifyDataSetChanged() notifyDataSetChanged()
@ -83,7 +83,8 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
} }
private fun renameGroup() { private fun renameGroup() {
RenameGroupDialog(activity, groups[selectedPositions.first()]) { val group = getItemWithKey(selectedKeys.first()) ?: return
RenameGroupDialog(activity, group) {
finishActMode() finishActMode()
refreshListener?.refreshContacts(GROUPS_TAB_MASK) refreshListener?.refreshContacts(GROUPS_TAB_MASK)
} }
@ -96,18 +97,17 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
} }
private fun deleteGroups() { private fun deleteGroups() {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
val groupsToRemove = ArrayList<Group>() val groupsToRemove = groups.filter { selectedKeys.contains(it.id.toInt()) } as ArrayList<Group>
selectedPositions.sortedDescending().forEach { val positions = getSelectedItemPositions(groupsToRemove)
val group = groups[it] groupsToRemove.forEach {
groupsToRemove.add(group) if (it.isPrivateSecretGroup()) {
if (group.isPrivateSecretGroup()) { activity.dbHelper.deleteGroup(it.id)
activity.dbHelper.deleteGroup(group.id)
} else { } else {
ContactsHelper(activity).deleteGroup(group.id) ContactsHelper(activity).deleteGroup(it.id)
} }
} }
groups.removeAll(groupsToRemove) groups.removeAll(groupsToRemove)
@ -116,12 +116,26 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
refreshListener?.refreshContacts(GROUPS_TAB_MASK) refreshListener?.refreshContacts(GROUPS_TAB_MASK)
finishActMode() finishActMode()
} else { } else {
removeSelectedItems() removeSelectedItems(positions)
} }
} }
private fun getSelectedItemPositions(groups: ArrayList<Group>): ArrayList<Int> {
val positions = ArrayList<Int>()
groups.forEach {
val position = getItemKeyPosition(it.id.toInt())
if (position != -1) {
positions.add(position)
}
}
positions.sortDescending()
return positions
}
private fun setupView(view: View, group: Group) { private fun setupView(view: View, group: Group) {
view.apply { view.apply {
group_frame?.isSelected = isKeySelected(group.id.toInt())
group_name.apply { group_name.apply {
setTextColor(textColor) setTextColor(textColor)
text = String.format(activity.getString(R.string.groups_placeholder), group.title, group.contactsCount.toString()) text = String.format(activity.getString(R.string.groups_placeholder), group.title, group.contactsCount.toString())

View File

@ -30,14 +30,8 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
override fun prepareActionMode(menu: Menu) {} override fun prepareActionMode(menu: Menu) {}
override fun prepareItemSelection(viewHolder: ViewHolder) {}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.recent_call_frame?.isSelected = select
}
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
@ -51,14 +45,18 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
override fun getIsItemSelectable(position: Int) = true override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = recentCalls.getOrNull(position)?.id
override fun getItemKeyPosition(key: Int) = recentCalls.indexOfFirst { it.id == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_recent_call, parent) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_recent_call, parent)
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val recentCall = recentCalls[position] val recentCall = recentCalls[position]
val view = holder.bindView(recentCall, true, true) { itemView, layoutPosition -> holder.bindView(recentCall, true, true) { itemView, layoutPosition ->
setupView(itemView, recentCall) setupView(itemView, recentCall)
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = recentCalls.size override fun getItemCount() = recentCalls.size
@ -77,15 +75,12 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
} }
private fun deleteRecentCalls() { private fun deleteRecentCalls() {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
val callsToRemove = ArrayList<RecentCall>() val callsToRemove = getSelectedItems()
selectedPositions.sortedDescending().forEach { val positions = getSelectedItemPositions(callsToRemove)
val call = recentCalls[it]
callsToRemove.add(call)
}
ContactsHelper(activity).removeRecentCalls(callsToRemove.map { it.id } as ArrayList<Int>) ContactsHelper(activity).removeRecentCalls(callsToRemove.map { it.id } as ArrayList<Int>)
recentCalls.removeAll(callsToRemove) recentCalls.removeAll(callsToRemove)
@ -93,12 +88,28 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
refreshListener?.refreshContacts(RECENTS_TAB_MASK) refreshListener?.refreshContacts(RECENTS_TAB_MASK)
finishActMode() finishActMode()
} else { } else {
removeSelectedItems() removeSelectedItems(positions)
} }
} }
private fun getSelectedItems() = recentCalls.filter { selectedKeys.contains(it.id) } as ArrayList<RecentCall>
private fun getSelectedItemPositions(callsToRemove: ArrayList<RecentCall>): ArrayList<Int> {
val positions = ArrayList<Int>()
callsToRemove.forEach {
val position = getItemKeyPosition(it.id)
if (position != -1) {
positions.add(position)
}
}
positions.sortDescending()
return positions
}
private fun setupView(view: View, recentCall: RecentCall) { private fun setupView(view: View, recentCall: RecentCall) {
view.apply { view.apply {
recent_call_frame?.isSelected = selectedKeys.contains(recentCall.id)
recent_call_name.apply { recent_call_name.apply {
text = recentCall.name ?: recentCall.number text = recentCall.name ?: recentCall.number
setTextColor(textColor) setTextColor(textColor)

View File

@ -1,10 +1,10 @@
package com.simplemobiletools.contacts.adapters package com.simplemobiletools.contacts.adapters
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.util.SparseArray import android.util.SparseArray
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
@ -13,8 +13,6 @@ import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.interfaces.MyAdapterListener
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config
@ -56,16 +54,6 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
itemViews[pos]?.contact_checkbox?.isChecked = select itemViews[pos]?.contact_checkbox?.isChecked = select
} }
private val adapterListener = object : MyAdapterListener {
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position)
}
override fun getSelectedPositions() = selectedPositions
override fun itemLongClicked(position: Int) {}
}
fun getSelectedItemsSet(): HashSet<Contact> { fun getSelectedItemsSet(): HashSet<Contact> {
val selectedItemsSet = HashSet<Contact>(selectedPositions.size) val selectedItemsSet = HashSet<Contact>(selectedPositions.size)
selectedPositions.forEach { selectedItemsSet.add(contacts[it]) } selectedPositions.forEach { selectedItemsSet.add(contacts[it]) }
@ -74,7 +62,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = activity.layoutInflater.inflate(itemLayout, parent, false) val view = activity.layoutInflater.inflate(itemLayout, parent, false)
return ViewHolder(view, adapterListener, activity, allowPickMultiple, itemClick) return ViewHolder(view)
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -85,12 +73,11 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
override fun getItemCount() = contacts.size override fun getItemCount() = contacts.size
class ViewHolder(view: View, private val adapterListener: MyAdapterListener, val activity: SimpleActivity, private val showCheckbox: Boolean, inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private val itemClick: ((Contact) -> Unit)?) : RecyclerView.ViewHolder(view) {
fun bindView(contact: Contact, contactDrawable: Drawable, config: Config, showContactThumbnails: Boolean, fun bindView(contact: Contact, contactDrawable: Drawable, config: Config, showContactThumbnails: Boolean,
smallPadding: Int, bigPadding: Int): View { smallPadding: Int, bigPadding: Int): View {
itemView.apply { itemView.apply {
contact_checkbox.beVisibleIf(showCheckbox) contact_checkbox.beVisibleIf(allowPickMultiple)
contact_checkbox.setColors(config.textColor, context.getAdjustedPrimaryColor(), config.backgroundColor) contact_checkbox.setColors(config.textColor, context.getAdjustedPrimaryColor(), config.backgroundColor)
val textColor = config.textColor val textColor = config.textColor
@ -119,7 +106,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
.error(contactDrawable) .error(contactDrawable)
.centerCrop() .centerCrop()
if (activity.isActivityDestroyed()) { if (activity.isDestroyed) {
Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb) Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb)
} }
} else { } else {
@ -132,14 +119,14 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Con
} }
private fun viewClicked(select: Boolean) { private fun viewClicked(select: Boolean) {
adapterListener.toggleItemSelectionAdapter(select, adapterPosition) toggleItemSelection(select, adapterPosition)
} }
} }
override fun onViewRecycled(holder: ViewHolder) { override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder) super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) { if (!activity.isDestroyed) {
Glide.with(activity).clear(holder.itemView?.contact_tmb!!) Glide.with(activity).clear(holder.itemView.contact_tmb)
} }
} }
} }

View File

@ -1,8 +1,8 @@
package com.simplemobiletools.contacts.adapters package com.simplemobiletools.contacts.adapters
import android.support.v4.view.PagerAdapter
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.MainActivity import com.simplemobiletools.contacts.activities.MainActivity
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import android.view.animation.AnimationUtils import android.view.animation.AnimationUtils
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.applyColorFilter

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import android.view.View import android.view.View
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.showKeyboard

View File

@ -1,7 +1,7 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.activities.SimpleActivity
@ -23,7 +23,7 @@ class ExportContactsDialog(val activity: SimpleActivity, val path: String, priva
export_contacts_filename.setText("contacts_${activity.getCurrentFormattedDateTime()}") export_contacts_filename.setText("contacts_${activity.getCurrentFormattedDateTime()}")
ContactsHelper(activity).getContactSources { ContactsHelper(activity).getContactSources {
it.mapTo(contactSources, { it.copy() }) it.mapTo(contactSources) { it.copy() }
activity.runOnUiThread { activity.runOnUiThread {
export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it, activity.getVisibleContactSources()) export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it, activity.getVisibleContactSources())
} }
@ -50,12 +50,12 @@ class ExportContactsDialog(val activity: SimpleActivity, val path: String, priva
return@setOnClickListener return@setOnClickListener
} }
val selectedIndexes = (view.export_contacts_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet() val selectedSources = (view.export_contacts_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val selectedContactSources = HashSet<String>() val selectedContactSourceNames = HashSet<String>()
selectedIndexes.forEach { selectedSources.forEach {
selectedContactSources.add(if (contactSources[it].type == SMT_PRIVATE) SMT_PRIVATE else contactSources[it].name) selectedContactSourceNames.add(if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name)
} }
callback(file, selectedContactSources) callback(file, selectedContactSourceNames)
dismiss() dismiss()
} }
else -> activity.toast(R.string.invalid_name) else -> activity.toast(R.string.invalid_name)

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.activities.SimpleActivity
@ -24,13 +24,13 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
return@getContactSources return@getContactSources
} }
it.mapTo(contactSources, { it.copy() }) it.mapTo(contactSources) { it.copy() }
val selectedSources = activity.getVisibleContactSources() val selectedSources = activity.getVisibleContactSources()
activity.runOnUiThread { activity.runOnUiThread {
view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources) view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources)
dialog = AlertDialog.Builder(activity) dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() }) .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmEventTypes() }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
activity.setupDialogStuff(view, this) activity.setupDialogStuff(view, this)
@ -40,21 +40,13 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
} }
private fun confirmEventTypes() { private fun confirmEventTypes() {
val selectedIndexes = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet() val selectedContactSources = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val ignoredIndexes = ArrayList<Int>() val ignoredContactSourceNames = contactSources.filter { !selectedContactSources.contains(it) }.map {
for (i in 0 until contactSources.size) { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name
if (!selectedIndexes.contains(i)) { }.toHashSet()
ignoredIndexes.add(i)
}
}
val ignoredContactSources = HashSet<String>() if (activity.getVisibleContactSources() != ignoredContactSourceNames) {
ignoredIndexes.forEach { activity.config.ignoredContactSources = ignoredContactSourceNames
ignoredContactSources.add(if (contactSources[it].type == SMT_PRIVATE) SMT_PRIVATE else contactSources[it].name)
}
if (activity.getVisibleContactSources() != ignoredContactSources) {
activity.config.ignoredContactSources = ignoredContactSources
callback() callback()
} }
dialog?.dismiss() dialog?.dismiss()

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import android.view.ViewGroup import android.view.ViewGroup
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.MyAppCompatCheckbox import com.simplemobiletools.commons.views.MyAppCompatCheckbox

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.MyAppCompatCheckbox import com.simplemobiletools.commons.views.MyAppCompatCheckbox

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.baseConfig import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
@ -42,7 +42,7 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL
} }
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
activity.setupDialogStuff(view, this) activity.setupDialogStuff(view, this)

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.contacts.dialogs package com.simplemobiletools.contacts.dialogs
import android.support.v7.app.AlertDialog import androidx.appcompat.app.AlertDialog
import android.view.ViewGroup import android.view.ViewGroup
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.MyAppCompatCheckbox import com.simplemobiletools.commons.views.MyAppCompatCheckbox

View File

@ -1,19 +1,16 @@
package com.simplemobiletools.contacts.extensions package com.simplemobiletools.contacts.extensions
import android.annotation.TargetApi
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.database.Cursor import android.database.Cursor
import android.net.Uri import android.net.Uri
import android.os.Build
import android.provider.ContactsContract import android.provider.ContactsContract
import android.support.v4.content.FileProvider import androidx.core.content.FileProvider
import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.hasPermission import com.simplemobiletools.commons.extensions.hasPermission
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.contacts.BuildConfig import com.simplemobiletools.contacts.BuildConfig
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.EditContactActivity import com.simplemobiletools.contacts.activities.EditContactActivity
@ -88,10 +85,9 @@ fun Context.openWebsiteIntent(url: String) {
} }
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun Context.getLookupUriRawId(dataUri: Uri): Int { fun Context.getLookupUriRawId(dataUri: Uri): Int {
val lookupKey = getLookupKeyFromUri(dataUri) val lookupKey = getLookupKeyFromUri(dataUri)
if (lookupKey != null && isLollipopPlus()) { if (lookupKey != null) {
val uri = lookupContactUri(lookupKey, this) val uri = lookupContactUri(lookupKey, this)
if (uri != null) { if (uri != null) {
return getContactUriRawId(uri) return getContactUriRawId(uri)
@ -100,7 +96,6 @@ fun Context.getLookupUriRawId(dataUri: Uri): Int {
return -1 return -1
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun Context.getContactUriRawId(uri: Uri): Int { fun Context.getContactUriRawId(uri: Uri): Int {
val projection = arrayOf(ContactsContract.Contacts.NAME_RAW_CONTACT_ID) val projection = arrayOf(ContactsContract.Contacts.NAME_RAW_CONTACT_ID)
var cursor: Cursor? = null var cursor: Cursor? = null

View File

@ -2,7 +2,7 @@ package com.simplemobiletools.contacts.fragments
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.support.design.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import android.util.AttributeSet import android.util.AttributeSet
import android.view.ViewGroup import android.view.ViewGroup
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter

View File

@ -5,7 +5,6 @@ import android.content.Intent
import android.util.AttributeSet import android.util.AttributeSet
import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.hasPermission import com.simplemobiletools.commons.extensions.hasPermission
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG
import com.simplemobiletools.contacts.activities.EditContactActivity import com.simplemobiletools.contacts.activities.EditContactActivity
@ -33,7 +32,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
} }
fun updateRecentCalls(recentCalls: ArrayList<RecentCall>) { fun updateRecentCalls(recentCalls: ArrayList<RecentCall>) {
if (activity == null || activity!!.isActivityDestroyed()) { if (activity == null || activity!!.isDestroyed) {
return return
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dialpad_holder" android:id="@+id/dialpad_holder"
@ -243,4 +243,4 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/> app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/group_contacts_coordinator" android:id="@+id/group_contacts_coordinator"
@ -67,4 +67,4 @@
android:layout_margin="@dimen/activity_margin" android:layout_margin="@dimen/activity_margin"
android:src="@drawable/ic_plus"/> android:src="@drawable/ic_plus"/>
</android.support.design.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -6,7 +6,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.design.widget.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/main_tabs_holder" android:id="@+id/main_tabs_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
@ -16,7 +16,7 @@
app:tabMinWidth="150dp" app:tabMinWidth="150dp"
app:tabSelectedTextColor="@android:color/white"/> app:tabSelectedTextColor="@android:color/white"/>
<com.booking.rtlviewpager.RtlViewPager <com.simplemobiletools.commons.views.MyViewPager
android:id="@+id/viewpager" android:id="@+id/viewpager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"

View File

@ -12,8 +12,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin" android:paddingTop="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"> android:paddingRight="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_contacts_folder_label" android:id="@+id/export_contacts_folder_label"
@ -26,11 +26,11 @@
android:id="@+id/export_contacts_folder" android:id="@+id/export_contacts_folder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin" android:layout_marginLeft="@dimen/activity_margin"
android:paddingBottom="@dimen/small_margin" android:layout_marginBottom="@dimen/activity_margin"
android:paddingTop="@dimen/small_margin"
android:paddingRight="@dimen/small_margin" android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"/> android:paddingBottom="@dimen/small_margin"/>
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_contacts_filename_label" android:id="@+id/export_contacts_filename_label"
@ -43,18 +43,18 @@
android:id="@+id/export_contacts_filename" android:id="@+id/export_contacts_filename"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin" android:layout_marginLeft="@dimen/activity_margin"
android:paddingRight="@dimen/small_margin" android:layout_marginBottom="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin"
android:paddingRight="@dimen/small_margin"
android:textSize="@dimen/normal_text_size"/> android:textSize="@dimen/normal_text_size"/>
<ImageView <ImageView
android:id="@+id/export_contacts_divider" android:id="@+id/export_contacts_divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1px" android:layout_height="1px"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin" android:layout_marginTop="@dimen/medium_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:background="@color/divider_grey" android:background="@color/divider_grey"
android:importantForAccessibility="no"/> android:importantForAccessibility="no"/>
@ -65,7 +65,7 @@
android:text="@string/include_contact_sources" android:text="@string/include_contact_sources"
android:textSize="@dimen/smaller_text_size"/> android:textSize="@dimen/smaller_text_size"/>
<android.support.v7.widget.RecyclerView <com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/export_contacts_list" android:id="@+id/export_contacts_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView <com.simplemobiletools.commons.views.MyRecyclerView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/filter_contact_sources_list" android:id="@+id/filter_contact_sources_list"

View File

@ -11,7 +11,7 @@
android:focusable="true" android:focusable="true"
android:foreground="@drawable/selector"> android:foreground="@drawable/selector">
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/recent_call_holder" android:id="@+id/recent_call_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/contact_item_with_number_height" android:layout_height="@dimen/contact_item_with_number_height"
@ -59,5 +59,5 @@
tools:layout_editor_absoluteY="0dp" tools:layout_editor_absoluteY="0dp"
tools:text="Yesterday, 17:00"/> tools:text="Yesterday, 17:00"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

View File

@ -5,7 +5,7 @@
android:id="@+id/search" android:id="@+id/search"
android:icon="@drawable/ic_search" android:icon="@drawable/ic_search"
android:title="@string/search" android:title="@string/search"
app:actionViewClass="android.support.v7.widget.SearchView" app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom"/> app:showAsAction="collapseActionView|ifRoom"/>
<item <item
android:id="@+id/sort" android:id="@+id/sort"