fix #115, add an option to show grouped calls

This commit is contained in:
tibbi 2020-12-31 21:28:16 +01:00
parent f55bbfd96d
commit 82e39ac8ad
5 changed files with 69 additions and 10 deletions

View File

@ -17,6 +17,7 @@ import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.activities.SimpleActivity import com.simplemobiletools.dialer.activities.SimpleActivity
import com.simplemobiletools.dialer.dialogs.ShowGroupedCallsDialog
import com.simplemobiletools.dialer.extensions.areMultipleSIMsAvailable import com.simplemobiletools.dialer.extensions.areMultipleSIMsAvailable
import com.simplemobiletools.dialer.extensions.callContactWithSim import com.simplemobiletools.dialer.extensions.callContactWithSim
import com.simplemobiletools.dialer.extensions.config import com.simplemobiletools.dialer.extensions.config
@ -26,7 +27,7 @@ import com.simplemobiletools.dialer.models.RecentCall
import kotlinx.android.synthetic.main.item_recent_call.view.* import kotlinx.android.synthetic.main.item_recent_call.view.*
import java.util.* import java.util.*
class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, val refreshItemsListener: RefreshItemsListener, class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, val refreshItemsListener: RefreshItemsListener?,
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
private lateinit var outgoingCallIcon: Drawable private lateinit var outgoingCallIcon: Drawable
@ -97,7 +98,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val recentCall = recentCalls[position] val recentCall = recentCalls[position]
holder.bindView(recentCall, true, true) { itemView, layoutPosition -> holder.bindView(recentCall, refreshItemsListener != null, refreshItemsListener != null) { itemView, layoutPosition ->
setupView(itemView, recentCall) setupView(itemView, recentCall)
} }
bindViewHolder(holder) bindViewHolder(holder)
@ -182,7 +183,10 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
} }
private fun showGroupedCalls() { private fun showGroupedCalls() {
val recentCall = getSelectedItems().firstOrNull() ?: return
val callIds = recentCall.neighbourIDs.map { it }.toMutableList() as ArrayList<Int>
callIds.add(recentCall.id)
ShowGroupedCallsDialog(activity, callIds)
} }
private fun copyNumber() { private fun copyNumber() {
@ -216,7 +220,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
recentCalls.removeAll(callsToRemove) recentCalls.removeAll(callsToRemove)
activity.runOnUiThread { activity.runOnUiThread {
if (recentCalls.isEmpty()) { if (recentCalls.isEmpty()) {
refreshItemsListener.refreshItems() refreshItemsListener?.refreshItems()
finishActMode() finishActMode()
} else { } else {
removeSelectedItems(positions) removeSelectedItems(positions)

View File

@ -0,0 +1,37 @@
package com.simplemobiletools.dialer.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.activities.SimpleActivity
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
import com.simplemobiletools.dialer.helpers.RecentsHelper
import com.simplemobiletools.dialer.models.RecentCall
import kotlinx.android.synthetic.main.dialog_show_grouped_calls.view.*
import java.util.*
class ShowGroupedCallsDialog(val activity: BaseSimpleActivity, callIds: ArrayList<Int>) {
private var dialog: AlertDialog? = null
private var view = activity.layoutInflater.inflate(R.layout.dialog_show_grouped_calls, null)
init {
view.apply {
RecentsHelper(activity).getRecentCalls(false) { allRecents ->
val recents = allRecents.filter { callIds.contains(it.id) }.toMutableList() as ArrayList<RecentCall>
activity.runOnUiThread {
RecentCallsAdapter(activity as SimpleActivity, recents, select_grouped_calls_list, null) {
}.apply {
select_grouped_calls_list.adapter = this
}
}
}
}
dialog = AlertDialog.Builder(activity)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
}

View File

@ -46,7 +46,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun refreshItems() { override fun refreshItems() {
val privateCursor = context?.getMyContactsCursor()?.loadInBackground() val privateCursor = context?.getMyContactsCursor()?.loadInBackground()
RecentsHelper(context).getRecentCalls { recents -> val groupSubsequentCalls = context?.config?.groupSubsequentCalls ?: false
RecentsHelper(context).getRecentCalls(groupSubsequentCalls) { recents ->
SimpleContactsHelper(context).getAvailableContacts(false) { contacts -> SimpleContactsHelper(context).getAvailableContacts(false) { contacts ->
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor) val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
@ -105,7 +106,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
recents_placeholder.text = context.getString(R.string.no_previous_calls) recents_placeholder.text = context.getString(R.string.no_previous_calls)
recents_placeholder_2.beGone() recents_placeholder_2.beGone()
RecentsHelper(context).getRecentCalls { recents -> val groupSubsequentCalls = context?.config?.groupSubsequentCalls ?: false
RecentsHelper(context).getRecentCalls(groupSubsequentCalls) { recents ->
activity?.runOnUiThread { activity?.runOnUiThread {
gotRecents(recents) gotRecents(recents)
} }

View File

@ -14,7 +14,7 @@ class RecentsHelper(private val context: Context) {
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9 private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
fun getRecentCalls(callback: (ArrayList<RecentCall>) -> Unit) { fun getRecentCalls(groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
val privateCursor = context.getMyContactsCursor()?.loadInBackground() val privateCursor = context.getMyContactsCursor()?.loadInBackground()
ensureBackgroundThread { ensureBackgroundThread {
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) { if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
@ -28,16 +28,15 @@ class RecentsHelper(private val context: Context) {
contacts.addAll(privateContacts) contacts.addAll(privateContacts)
} }
getRecents(contacts, callback) getRecents(contacts, groupSubsequentCalls, callback)
} }
} }
} }
private fun getRecents(contacts: ArrayList<SimpleContact>, callback: (ArrayList<RecentCall>) -> Unit) { private fun getRecents(contacts: ArrayList<SimpleContact>, groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
var recentCalls = ArrayList<RecentCall>() var recentCalls = ArrayList<RecentCall>()
var previousRecentCallFrom = "" var previousRecentCallFrom = ""
val contactsNumbersMap = HashMap<String, String>() val contactsNumbersMap = HashMap<String, String>()
val groupSubsequentCalls = context.config.groupSubsequentCalls
val uri = Calls.CONTENT_URI val uri = Calls.CONTENT_URI
val projection = arrayOf( val projection = arrayOf(
Calls._ID, Calls._ID,

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/select_grouped_calls_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/select_grouped_calls_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:padding="@dimen/activity_margin"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
</RelativeLayout>