Skip to content

Commit

Permalink
remove blocked numbers from Recents at blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed May 23, 2020
1 parent a33a4d7 commit 931af9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.simplemobiletools.dialer.adapters
import android.content.Intent
import android.graphics.drawable.Drawable
import android.provider.CallLog.Calls
import android.text.TextUtils
import android.util.TypedValue
import android.view.Menu
import android.view.View
Expand All @@ -11,10 +12,7 @@ import com.bumptech.glide.Glide
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.KEY_PHONE
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.activities.SimpleActivity
Expand Down Expand Up @@ -55,7 +53,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
}

when (id) {
R.id.cab_block_number -> blockNumber()
R.id.cab_block_number -> askConfirmBlock()
R.id.cab_add_number -> addNumberToContact()
R.id.cab_remove -> askConfirmRemove()
}
Expand Down Expand Up @@ -98,8 +96,35 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
incomingMissedCallIcon = resources.getColoredDrawableWithColor(R.drawable.ic_incoming_call_vector, redColor)
}

private fun blockNumber() {
private fun askConfirmBlock() {
val numbers = TextUtils.join(", ", getSelectedItems().distinctBy { it.phoneNumber }.map { it.phoneNumber })
val baseString = R.string.block_confirmation
val question = String.format(resources.getString(baseString), numbers)

ConfirmationDialog(activity, question) {
blockNumbers()
}
}

private fun blockNumbers() {
if (selectedKeys.isEmpty()) {
return
}

val callsToBlock = getSelectedItems()
val positions = getSelectedItemPositions()
recentCalls.removeAll(callsToBlock)

ensureBackgroundThread {
callsToBlock.map { it.phoneNumber }.forEach { number ->
activity.addBlockedNumber(number)
}

activity.runOnUiThread {
removeSelectedItems(positions)
finishActMode()
}
}
}

private fun addNumberToContact() {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/menu/cab_recent_calls.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_block_number"
android:icon="@drawable/ic_minus_circle_vector"
android:title="@string/block_number"
app:showAsAction="ifRoom" />

<item
android:id="@+id/cab_add_number"
android:icon="@drawable/ic_add_person_vector"
android:title="@string/add_number_to_contact"
app:showAsAction="ifRoom" />

<item
android:id="@+id/cab_block_number"
android:icon="@drawable/ic_minus_circle_vector"
android:title="@string/block_number"
app:showAsAction="ifRoom" />

<item
android:id="@+id/cab_remove"
android:icon="@drawable/ic_delete_vector"
Expand Down

0 comments on commit 931af9c

Please sign in to comment.