diff --git a/app/build.gradle b/app/build.gradle index b4135d5d..a7660df6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,6 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.27.24' + implementation 'com.simplemobiletools:commons:5.27.26' implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9f6b4ba9..a3058d37 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ android:installLocation="auto"> + diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt index 7a856a78..27b1c33a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt @@ -194,7 +194,7 @@ class DialpadActivity : SimpleActivity() { } }) - ContactsAdapter(this, filtered, dialpad_list, text) { + ContactsAdapter(this, filtered, dialpad_list, null, text) { startCallIntent((it as SimpleContact).phoneNumber) }.apply { dialpad_list.adapter = this diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt index 7b95abf4..d6e55f9e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt @@ -15,6 +15,7 @@ import com.simplemobiletools.dialer.BuildConfig import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.adapters.ViewPagerAdapter import com.simplemobiletools.dialer.extensions.config +import com.simplemobiletools.dialer.fragments.MyViewPagerFragment import com.simplemobiletools.dialer.helpers.tabsList import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_contacts.* @@ -56,7 +57,7 @@ class MainActivity : SimpleActivity() { } getAllFragments().forEach { - it?.textColorChanged(configTextColor) + it.textColorChanged(configTextColor) } } @@ -65,7 +66,7 @@ class MainActivity : SimpleActivity() { main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor()) main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor()) getAllFragments().forEach { - it?.primaryColorChanged(configPrimaryColor) + it.primaryColorChanged(configPrimaryColor) } } @@ -154,7 +155,7 @@ class MainActivity : SimpleActivity() { override fun onPageSelected(position: Int) { main_tabs_holder.getTabAt(position)?.select() getAllFragments().forEach { - it?.finishActMode() + it.finishActMode() } invalidateOptionsMenu() } @@ -210,11 +211,11 @@ class MainActivity : SimpleActivity() { viewpager.currentItem = config.lastUsedViewPagerPage } - contacts_fragment.refreshContacts() - recents_fragment.refreshRecents() + contacts_fragment.refreshItems() + recents_fragment.refreshItems() } - private fun getAllFragments() = arrayListOf(contacts_fragment, recents_fragment) + private fun getAllFragments() = arrayListOf(contacts_fragment, recents_fragment).toMutableList() as ArrayList private fun launchAbout() { val licenses = LICENSE_GLIDE or LICENSE_INDICATOR_FAST_SCROLL diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt index e5967c37..c293b676 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt @@ -4,33 +4,48 @@ import android.util.TypedValue import android.view.Menu import android.view.View import android.view.ViewGroup +import android.widget.FrameLayout import android.widget.ImageView import android.widget.TextView import com.bumptech.glide.Glide import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter +import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getTextSize import com.simplemobiletools.commons.extensions.highlightTextFromNumbers import com.simplemobiletools.commons.extensions.highlightTextPart +import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.helpers.SimpleContactsHelper import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.activities.SimpleActivity -import java.util.* +import com.simplemobiletools.dialer.interfaces.RefreshItemsListener -class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList, recyclerView: MyRecyclerView, highlightText: String = "", - itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { +class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList, recyclerView: MyRecyclerView, val refreshItemsListener: RefreshItemsListener? = null, + highlightText: String = "", itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { private var textToHighlight = highlightText private var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() private var fontSize = activity.getTextSize() - override fun getActionMenuId() = 0 + init { + setupDragListener(true) + } + + override fun getActionMenuId() = R.menu.cab_delete_only override fun prepareActionMode(menu: Menu) {} - override fun actionItemPressed(id: Int) {} + override fun actionItemPressed(id: Int) { + if (selectedKeys.isEmpty()) { + return + } + + when (id) { + R.id.cab_delete -> askConfirmDelete() + } + } override fun getSelectableItemCount() = contacts.size @@ -48,7 +63,7 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList + holder.bindView(contact, true, true) { itemView, layoutPosition -> setupView(itemView, contact) } bindViewHolder(holder) @@ -68,6 +83,49 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList + + SimpleContactsHelper(activity).deleteContactRawIDs(idsToRemove) { + activity.runOnUiThread { + if (contacts.isEmpty()) { + refreshItemsListener?.refreshItems() + finishActMode() + } else { + removeSelectedItems(positions) + } + } + } + } + + private fun getSelectedItems() = contacts.filter { selectedKeys.contains(it.rawId) } as ArrayList + override fun onViewRecycled(holder: ViewHolder) { super.onViewRecycled(holder) if (!activity.isDestroyed && !activity.isFinishing) { @@ -77,6 +135,7 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList(R.id.item_contact_frame).isSelected = selectedKeys.contains(contact.rawId) findViewById(R.id.item_contact_name).apply { setTextColor(textColor) setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/RecentCallsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/RecentCallsAdapter.kt index a3a42267..40f61e52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/RecentCallsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/RecentCallsAdapter.kt @@ -20,12 +20,12 @@ import com.simplemobiletools.dialer.extensions.areMultipleSIMsAvailable import com.simplemobiletools.dialer.extensions.config import com.simplemobiletools.dialer.helpers.KEY_PHONE import com.simplemobiletools.dialer.helpers.RecentsHelper -import com.simplemobiletools.dialer.interfaces.RefreshRecentsListener +import com.simplemobiletools.dialer.interfaces.RefreshItemsListener import com.simplemobiletools.dialer.models.RecentCall import kotlinx.android.synthetic.main.item_recent_call.view.* import java.util.* -class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList, recyclerView: MyRecyclerView, val refreshRecentsListener: RefreshRecentsListener, +class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList, recyclerView: MyRecyclerView, val refreshItemsListener: RefreshItemsListener, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { private lateinit var incomingCallIcon: Drawable @@ -133,7 +133,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList activity?.runOnUiThread { gotContacts(contacts) @@ -93,7 +94,8 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag val currAdapter = fragment_list.adapter if (currAdapter == null) { - ContactsAdapter(activity as SimpleActivity, contacts, fragment_list) { + ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this) { + mydebug("clicked $it") val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((it as SimpleContact).rawId.toString()) val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) activity!!.launchViewContactIntent(publicUri) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt index 5ed9c601..3e1f2a48 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt @@ -9,11 +9,11 @@ import com.simplemobiletools.dialer.activities.SimpleActivity import com.simplemobiletools.dialer.adapters.RecentCallsAdapter import com.simplemobiletools.dialer.extensions.config import com.simplemobiletools.dialer.helpers.RecentsHelper -import com.simplemobiletools.dialer.interfaces.RefreshRecentsListener +import com.simplemobiletools.dialer.interfaces.RefreshItemsListener import com.simplemobiletools.dialer.models.RecentCall import kotlinx.android.synthetic.main.fragment_recents.view.* -class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshRecentsListener { +class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener { override fun setupFragment() { val placeholderResId = if (context.hasPermission(PERMISSION_READ_CALL_LOG)) { R.string.no_previous_calls @@ -40,7 +40,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage override fun primaryColorChanged(color: Int) {} - override fun refreshRecents() { + override fun refreshItems() { RecentsHelper(context).getRecentCalls { recents -> activity?.runOnUiThread { gotRecents(recents) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt index aec3ee6f..0c447034 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt @@ -6,7 +6,7 @@ import android.provider.CallLog.Calls import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG import com.simplemobiletools.commons.helpers.ensureBackgroundThread -import com.simplemobiletools.commons.overloads.times +import com.simplemobiletools.commons.helpers.getQuestionMarks import com.simplemobiletools.dialer.extensions.getAvailableSIMCardLabels import com.simplemobiletools.dialer.models.RecentCall @@ -79,6 +79,4 @@ class RecentsHelper(private val context: Context) { callback() } } - - private fun getQuestionMarks(size: Int) = ("?," * size).trimEnd(',') } diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/interfaces/RefreshItemsListener.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/interfaces/RefreshItemsListener.kt new file mode 100644 index 00000000..1346cfb0 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/interfaces/RefreshItemsListener.kt @@ -0,0 +1,5 @@ +package com.simplemobiletools.dialer.interfaces + +interface RefreshItemsListener { + fun refreshItems() +} diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/interfaces/RefreshRecentsListener.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/interfaces/RefreshRecentsListener.kt deleted file mode 100644 index 40ad2977..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/interfaces/RefreshRecentsListener.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.simplemobiletools.dialer.interfaces - -interface RefreshRecentsListener { - fun refreshRecents() -}