diff --git a/app/build.gradle b/app/build.gradle index 4cd26e58..01081229 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { applicationId "com.simplemobiletools.contacts" - minSdkVersion 16 + minSdkVersion 21 targetSdkVersion 28 versionCode 32 versionName "4.5.0" @@ -41,10 +41,10 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:4.8.0' + implementation 'com.simplemobiletools:commons:5.0.21' implementation 'joda-time:joda-time:2.9.9' 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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 998d518a..91a6c619 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -194,7 +194,7 @@ android:parentActivityName=".activities.MainActivity"/> diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/DialpadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/DialpadActivity.kt index 11a45b07..1d45949a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/DialpadActivity.kt @@ -1,17 +1,13 @@ package com.simplemobiletools.contacts.activities -import android.annotation.TargetApi import android.content.Intent import android.graphics.Color -import android.os.Build import android.os.Bundle -import android.text.InputType import android.view.KeyEvent import android.view.Menu import android.view.MenuItem import android.view.View import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.isLollipopPlus import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.adapters.ContactsAdapter import com.simplemobiletools.contacts.dialogs.CallConfirmationDialog @@ -120,13 +116,8 @@ class DialpadActivity : SimpleActivity() { else -> KeyEvent.KEYCODE_POUND } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) private fun disableKeyboardPopping() { - if (isLollipopPlus()) { - dialpad_input.showSoftInputOnFocus = false - } else { - dialpad_input.inputType = InputType.TYPE_NULL - } + dialpad_input.showSoftInputOnFocus = false } private fun gotContacts(newContacts: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt index 0cb2281b..01ce8b3b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt @@ -9,11 +9,11 @@ import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle 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.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.extensions.* import com.simplemobiletools.commons.helpers.* @@ -401,7 +401,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { fun showFilterDialog() { FilterContactSourcesDialog(this) { 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() { - 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( FAQItem(R.string.faq_1_title, R.string.faq_1_text), @@ -495,9 +495,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { } override fun refreshContacts(refreshTabsMask: Int) { - if (isActivityDestroyed() || isGettingContacts) { + if (isDestroyed || isGettingContacts) { return } + isGettingContacts = true if (viewpager.adapter == null) { @@ -507,7 +508,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { ContactsHelper(this).getContacts { isGettingContacts = false - if (isActivityDestroyed()) { + if (isDestroyed) { return@getContacts } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/SelectContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/SelectContactActivity.kt index 0d592bd1..cb9b0734 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/SelectContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/SelectContactActivity.kt @@ -7,7 +7,6 @@ import android.provider.ContactsContract import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.extensions.baseConfig -import com.simplemobiletools.commons.extensions.isActivityDestroyed import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS @@ -80,7 +79,7 @@ class SelectContactActivity : SimpleActivity() { private fun initContacts() { ContactsHelper(this).getContacts { - if (isActivityDestroyed()) { + if (isDestroyed) { return@getContacts } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt index 4372437e..e1755838 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt @@ -12,7 +12,10 @@ import com.bumptech.glide.signature.ObjectKey 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.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.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView @@ -72,14 +75,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList + holder.bindView(contact, true, allowLongClick) { itemView, layoutPosition -> setupView(itemView, contact) } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = contactItems.size + private fun getItemWithKey(key: Int): Contact? = contactItems.firstOrNull { it.id == key } + fun initDrawables() { contactDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_person, textColor) } @@ -134,7 +137,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList() - selectedPositions.sortedDescending().forEach { - val contact = contactItems.getOrNull(it) - if (contact != null) { - contactsToRemove.add(contact) - } - } + val contactsToRemove = getSelectedItems() + val positions = getSelectedItemPositions(contactsToRemove) contactItems.removeAll(contactsToRemove) ContactsHelper(activity).deleteContacts(contactsToRemove) @@ -162,16 +161,15 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList() - selectedPositions.sortedDescending().forEach { - contactsToRemove.add(contactItems[it]) - } + val contactsToRemove = getSelectedItems() + val positions = getSelectedItemPositions(contactsToRemove) contactItems.removeAll(contactsToRemove) if (location == LOCATION_FAVORITES_TAB) { @@ -180,22 +178,22 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList() ContactsHelper(activity).getStoredGroups().forEach { @@ -223,40 +221,42 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList() - selectedPositions.forEach { - contactsIDs.add(contactItems[it].id) - } - - val filtered = contactItems.filter { contactsIDs.contains(it.id) } as ArrayList - activity.shareContacts(filtered) + activity.shareContacts(getSelectedItems()) } private fun sendSMSToContacts() { - activity.sendSMSToContacts(getSelectedContacts()) + activity.sendSMSToContacts(getSelectedItems()) } private fun sendEmailToContacts() { - activity.sendEmailToContacts(getSelectedContacts()) + activity.sendEmailToContacts(getSelectedItems()) } - private fun getSelectedContacts(): ArrayList { - val contacts = ArrayList() - selectedPositions.forEach { - contacts.add(contactItems[it]) + private fun getSelectedItems() = contactItems.filter { selectedKeys.contains(it.id) } as ArrayList + + private fun getSelectedItemPositions(contacts: ArrayList): ArrayList { + val positions = ArrayList() + contacts.forEach { + val position = getItemKeyPosition(it.id) + if (position != -1) { + positions.add(position) + } } - return contacts + + positions.sortDescending() + return positions } override fun onViewRecycled(holder: ViewHolder) { super.onViewRecycled(holder) - if (!activity.isActivityDestroyed()) { - Glide.with(activity).clear(holder.itemView?.contact_tmb!!) + if (!activity.isDestroyed) { + Glide.with(activity).clear(holder.itemView.contact_tmb) } } private fun setupView(view: View, contact: Contact) { view.apply { + contact_frame?.isSelected = selectedKeys.contains(contact.id) val fullName = contact.getFullName() contact_name.text = if (textToHighlight.isEmpty()) fullName else fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor) contact_name.setTextColor(textColor) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/FilterContactSourcesAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/FilterContactSourcesAdapter.kt index a316d0be..adcb2379 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/FilterContactSourcesAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/FilterContactSourcesAdapter.kt @@ -1,11 +1,9 @@ package com.simplemobiletools.contacts.adapters -import android.support.v7.widget.RecyclerView -import android.util.SparseArray import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor -import com.simplemobiletools.commons.interfaces.MyAdapterListener import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.extensions.config @@ -16,13 +14,12 @@ import java.util.* class FilterContactSourcesAdapter(val activity: SimpleActivity, private val contactSources: List, private val displayContactSources: ArrayList) : RecyclerView.Adapter() { - private val itemViews = SparseArray() - private val selectedPositions = HashSet() + private val selectedKeys = HashSet() init { contactSources.forEachIndexed { index, contactSource -> if (displayContactSources.contains(contactSource.name)) { - selectedPositions.add(index) + selectedKeys.add(contactSource.hashCode()) } 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)) { - 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 (itemViews[pos] != null) { - selectedPositions.add(pos) - } + selectedKeys.add(contactSource.hashCode()) } else { - selectedPositions.remove(pos) + selectedKeys.remove(contactSource.hashCode()) } - itemViews[pos]?.filter_contact_source_checkbox?.isChecked = select + notifyItemChanged(position) } - 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() = selectedPositions + fun getSelectedContactSources() = contactSources.filter { selectedKeys.contains(it.hashCode()) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 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) { val contactSource = contactSources[position] - itemViews.put(position, holder.bindView(contactSource.name)) - toggleItemSelection(selectedPositions.contains(position), position) + holder.bindView(contactSource) } override fun getItemCount() = contactSources.size - class ViewHolder(view: View, private val adapterListener: MyAdapterListener, val activity: SimpleActivity) : RecyclerView.ViewHolder(view) { - fun bindView(contactSource: String): View { + inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + fun bindView(contactSource: ContactSource): View { + val isSelected = selectedKeys.contains(contactSource.hashCode()) 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.text = contactSource - filter_contact_source_holder.setOnClickListener { viewClicked(!filter_contact_source_checkbox.isChecked) } + filter_contact_source_checkbox.text = contactSource.name + filter_contact_source_holder.setOnClickListener { viewClicked(!isSelected, contactSource) } } return itemView } - private fun viewClicked(select: Boolean) { - adapterListener.toggleItemSelectionAdapter(select, adapterPosition) + private fun viewClicked(select: Boolean, contactSource: ContactSource) { + toggleItemSelection(select, contactSource, adapterPosition) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/GroupsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/GroupsAdapter.kt index ca98b7cd..62ab929e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/GroupsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/GroupsAdapter.kt @@ -41,14 +41,8 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val } } - override fun prepareItemSelection(viewHolder: ViewHolder) {} - - override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) { - viewHolder?.itemView?.group_frame?.isSelected = select - } - override fun actionItemPressed(id: Int) { - if (selectedPositions.isEmpty()) { + if (selectedKeys.isEmpty()) { return } @@ -63,18 +57,24 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val 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 onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { val group = groups[position] - val view = holder.bindView(group, true, true) { itemView, layoutPosition -> + holder.bindView(group, true, true) { itemView, layoutPosition -> setupView(itemView, group) } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = groups.size + private fun getItemWithKey(key: Int): Group? = groups.firstOrNull { it.id.toInt() == key } + fun updateItems(newItems: ArrayList) { groups = newItems notifyDataSetChanged() @@ -83,7 +83,8 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val } private fun renameGroup() { - RenameGroupDialog(activity, groups[selectedPositions.first()]) { + val group = getItemWithKey(selectedKeys.first()) ?: return + RenameGroupDialog(activity, group) { finishActMode() refreshListener?.refreshContacts(GROUPS_TAB_MASK) } @@ -96,18 +97,17 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val } private fun deleteGroups() { - if (selectedPositions.isEmpty()) { + if (selectedKeys.isEmpty()) { return } - val groupsToRemove = ArrayList() - selectedPositions.sortedDescending().forEach { - val group = groups[it] - groupsToRemove.add(group) - if (group.isPrivateSecretGroup()) { - activity.dbHelper.deleteGroup(group.id) + val groupsToRemove = groups.filter { selectedKeys.contains(it.id.toInt()) } as ArrayList + val positions = getSelectedItemPositions(groupsToRemove) + groupsToRemove.forEach { + if (it.isPrivateSecretGroup()) { + activity.dbHelper.deleteGroup(it.id) } else { - ContactsHelper(activity).deleteGroup(group.id) + ContactsHelper(activity).deleteGroup(it.id) } } groups.removeAll(groupsToRemove) @@ -116,12 +116,26 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val refreshListener?.refreshContacts(GROUPS_TAB_MASK) finishActMode() } else { - removeSelectedItems() + removeSelectedItems(positions) } } + private fun getSelectedItemPositions(groups: ArrayList): ArrayList { + val positions = ArrayList() + 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) { view.apply { + group_frame?.isSelected = isKeySelected(group.id.toInt()) group_name.apply { setTextColor(textColor) text = String.format(activity.getString(R.string.groups_placeholder), group.title, group.contactsCount.toString()) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/RecentCallsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/RecentCallsAdapter.kt index e54d8d2b..938ec1ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/RecentCallsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/RecentCallsAdapter.kt @@ -30,14 +30,8 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList + holder.bindView(recentCall, true, true) { itemView, layoutPosition -> setupView(itemView, recentCall) } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = recentCalls.size @@ -77,15 +75,12 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList() - selectedPositions.sortedDescending().forEach { - val call = recentCalls[it] - callsToRemove.add(call) - } + val callsToRemove = getSelectedItems() + val positions = getSelectedItemPositions(callsToRemove) ContactsHelper(activity).removeRecentCalls(callsToRemove.map { it.id } as ArrayList) recentCalls.removeAll(callsToRemove) @@ -93,12 +88,28 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList + + private fun getSelectedItemPositions(callsToRemove: ArrayList): ArrayList { + val positions = ArrayList() + callsToRemove.forEach { + val position = getItemKeyPosition(it.id) + if (position != -1) { + positions.add(position) + } + } + + positions.sortDescending() + return positions + } + private fun setupView(view: View, recentCall: RecentCall) { view.apply { + recent_call_frame?.isSelected = selectedKeys.contains(recentCall.id) recent_call_name.apply { text = recentCall.name ?: recentCall.number setTextColor(textColor) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/SelectContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/SelectContactsAdapter.kt index df9d5fe8..f7448dc6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/SelectContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/SelectContactsAdapter.kt @@ -1,10 +1,10 @@ package com.simplemobiletools.contacts.adapters import android.graphics.drawable.Drawable -import android.support.v7.widget.RecyclerView import android.util.SparseArray import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy 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.getAdjustedPrimaryColor 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.activities.SimpleActivity import com.simplemobiletools.contacts.extensions.config @@ -56,16 +54,6 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List { val selectedItemsSet = HashSet(selectedPositions.size) selectedPositions.forEach { selectedItemsSet.add(contacts[it]) } @@ -74,7 +62,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List Unit)?) : RecyclerView.ViewHolder(view) { + inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { fun bindView(contact: Contact, contactDrawable: Drawable, config: Config, showContactThumbnails: Boolean, smallPadding: Int, bigPadding: Int): View { itemView.apply { - contact_checkbox.beVisibleIf(showCheckbox) + contact_checkbox.beVisibleIf(allowPickMultiple) contact_checkbox.setColors(config.textColor, context.getAdjustedPrimaryColor(), config.backgroundColor) val textColor = config.textColor @@ -119,7 +106,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List activity.toast(R.string.empty_name) - filename.isAValidFilename() -> { - val file = File(path, "$filename.vcf") - if (file.exists()) { - activity.toast(R.string.name_taken) + activity.setupDialogStuff(view, this, R.string.export_contacts) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + if (view.export_contacts_list.adapter == null) { return@setOnClickListener } - val selectedIndexes = (view.export_contacts_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet() - val selectedContactSources = HashSet() - selectedIndexes.forEach { - selectedContactSources.add(if (contactSources[it].type == SMT_PRIVATE) SMT_PRIVATE else contactSources[it].name) + val filename = view.export_contacts_filename.value + when { + filename.isEmpty() -> activity.toast(R.string.empty_name) + filename.isAValidFilename() -> { + val file = File(path, "$filename.vcf") + if (file.exists()) { + activity.toast(R.string.name_taken) + return@setOnClickListener + } + + val selectedSources = (view.export_contacts_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources() + val selectedContactSourceNames = HashSet() + selectedSources.forEach { + selectedContactSourceNames.add(if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name) + } + callback(file, selectedContactSourceNames) + dismiss() + } + else -> activity.toast(R.string.invalid_name) } - callback(file, selectedContactSources) - dismiss() } - else -> activity.toast(R.string.invalid_name) } } - } - } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/FilterContactSourcesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/FilterContactSourcesDialog.kt index 5be53220..e3a91b82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/FilterContactSourcesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/FilterContactSourcesDialog.kt @@ -1,6 +1,6 @@ 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.contacts.R import com.simplemobiletools.contacts.activities.SimpleActivity @@ -24,13 +24,13 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb return@getContactSources } - it.mapTo(contactSources, { it.copy() }) + it.mapTo(contactSources) { it.copy() } val selectedSources = activity.getVisibleContactSources() activity.runOnUiThread { view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources) dialog = AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() }) + .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmEventTypes() } .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this) @@ -40,21 +40,13 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb } private fun confirmEventTypes() { - val selectedIndexes = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet() - val ignoredIndexes = ArrayList() - for (i in 0 until contactSources.size) { - if (!selectedIndexes.contains(i)) { - ignoredIndexes.add(i) - } - } + val selectedContactSources = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources() + val ignoredContactSourceNames = contactSources.filter { !selectedContactSources.contains(it) }.map { + if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name + }.toHashSet() - val ignoredContactSources = HashSet() - ignoredIndexes.forEach { - ignoredContactSources.add(if (contactSources[it].type == SMT_PRIVATE) SMT_PRIVATE else contactSources[it].name) - } - - if (activity.getVisibleContactSources() != ignoredContactSources) { - activity.config.ignoredContactSources = ignoredContactSources + if (activity.getVisibleContactSources() != ignoredContactSourceNames) { + activity.config.ignoredContactSources = ignoredContactSourceNames callback() } dialog?.dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ImportContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ImportContactsDialog.kt index 8f2ed22f..8e85e744 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ImportContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ImportContactsDialog.kt @@ -1,6 +1,6 @@ package com.simplemobiletools.contacts.dialogs -import android.support.v7.app.AlertDialog +import androidx.appcompat.app.AlertDialog import android.view.ViewGroup import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleFieldsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleFieldsDialog.kt index 9b9afcf6..23bdd35c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleFieldsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleFieldsDialog.kt @@ -1,6 +1,6 @@ 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.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyAppCompatCheckbox diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleTabsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleTabsDialog.kt index 241c62cf..381e8dca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleTabsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ManageVisibleTabsDialog.kt @@ -1,6 +1,6 @@ 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.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyAppCompatCheckbox diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/RenameGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/RenameGroupDialog.kt index de1f654c..ca35f293 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/RenameGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/RenameGroupDialog.kt @@ -1,6 +1,6 @@ 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.extensions.* import com.simplemobiletools.contacts.R diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectContactsDialog.kt index 76660338..2b719c2a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectContactsDialog.kt @@ -1,6 +1,6 @@ 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.setupDialogStuff import com.simplemobiletools.contacts.R @@ -42,7 +42,7 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL } AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectGroupsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectGroupsDialog.kt index f69a34a0..6682d083 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectGroupsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/SelectGroupsDialog.kt @@ -1,6 +1,6 @@ package com.simplemobiletools.contacts.dialogs -import android.support.v7.app.AlertDialog +import androidx.appcompat.app.AlertDialog import android.view.ViewGroup import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyAppCompatCheckbox diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt index dfcafded..45b65c72 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt @@ -1,19 +1,16 @@ package com.simplemobiletools.contacts.extensions -import android.annotation.TargetApi import android.content.Context import android.content.Intent import android.database.Cursor import android.net.Uri -import android.os.Build 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.hasPermission import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS -import com.simplemobiletools.commons.helpers.isLollipopPlus import com.simplemobiletools.contacts.BuildConfig import com.simplemobiletools.contacts.R 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 { val lookupKey = getLookupKeyFromUri(dataUri) - if (lookupKey != null && isLollipopPlus()) { + if (lookupKey != null) { val uri = lookupContactUri(lookupKey, this) if (uri != null) { return getContactUriRawId(uri) @@ -100,7 +96,6 @@ fun Context.getLookupUriRawId(dataUri: Uri): Int { return -1 } -@TargetApi(Build.VERSION_CODES.LOLLIPOP) fun Context.getContactUriRawId(uri: Uri): Int { val projection = arrayOf(ContactsContract.Contacts.NAME_RAW_CONTACT_ID) var cursor: Cursor? = null diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt index 208c7715..1be5b977 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt @@ -2,7 +2,7 @@ package com.simplemobiletools.contacts.fragments import android.content.Context import android.content.Intent -import android.support.design.widget.CoordinatorLayout +import androidx.coordinatorlayout.widget.CoordinatorLayout import android.util.AttributeSet import android.view.ViewGroup import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/RecentsFragment.kt index d4b30ab9..54e09773 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/RecentsFragment.kt @@ -5,7 +5,6 @@ import android.content.Intent import android.util.AttributeSet import com.simplemobiletools.commons.extensions.beVisibleIf 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_WRITE_CALL_LOG import com.simplemobiletools.contacts.activities.EditContactActivity @@ -33,7 +32,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } fun updateRecentCalls(recentCalls: ArrayList) { - if (activity == null || activity!!.isActivityDestroyed()) { + if (activity == null || activity!!.isDestroyed) { return } diff --git a/app/src/main/res/layout/activity_dialpad.xml b/app/src/main/res/layout/activity_dialpad.xml index 6378918f..7435e5c2 100644 --- a/app/src/main/res/layout/activity_dialpad.xml +++ b/app/src/main/res/layout/activity_dialpad.xml @@ -1,5 +1,5 @@ - - + diff --git a/app/src/main/res/layout/activity_group_contacts.xml b/app/src/main/res/layout/activity_group_contacts.xml index 197db89c..adf3c68b 100644 --- a/app/src/main/res/layout/activity_group_contacts.xml +++ b/app/src/main/res/layout/activity_group_contacts.xml @@ -1,5 +1,5 @@ - - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f3b5d8e9..319333c6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + android:paddingTop="@dimen/activity_margin" + android:paddingRight="@dimen/activity_margin"> + android:paddingBottom="@dimen/small_margin"/> @@ -65,7 +65,7 @@ android:text="@string/include_contact_sources" android:textSize="@dimen/smaller_text_size"/> - - - - + diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 30f2f275..6e87be0f 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -5,7 +5,7 @@ android:id="@+id/search" android:icon="@drawable/ic_search" android:title="@string/search" - app:actionViewClass="android.support.v7.widget.SearchView" + app:actionViewClass="androidx.appcompat.widget.SearchView" app:showAsAction="collapseActionView|ifRoom"/>