allow blocking numbers directly from Recents screen
This commit is contained in:
parent
6fae60381f
commit
de096cb8c8
|
@ -10,6 +10,7 @@ import com.simplemobiletools.commons.views.FastScroller
|
|||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.pro.extensions.addBlockedNumber
|
||||
import com.simplemobiletools.contacts.pro.extensions.config
|
||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.pro.helpers.RECENTS_TAB_MASK
|
||||
|
@ -28,7 +29,11 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
|||
|
||||
override fun getActionMenuId() = R.menu.cab_recent_calls
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
menu.apply {
|
||||
findItem(R.id.cab_block_number).title = activity.getString(if (isOneItemSelected()) R.string.block_number else R.string.block_numbers)
|
||||
}
|
||||
}
|
||||
|
||||
override fun actionItemPressed(id: Int) {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
|
@ -38,6 +43,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
|||
when (id) {
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
R.id.cab_block_number -> blockNumber()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +98,18 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
|||
}
|
||||
}
|
||||
|
||||
private fun blockNumber() {
|
||||
Thread {
|
||||
getSelectedItems().forEach {
|
||||
activity.addBlockedNumber(it.number)
|
||||
}
|
||||
refreshListener?.refreshContacts(RECENTS_TAB_MASK)
|
||||
activity.runOnUiThread {
|
||||
finishActMode()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun getSelectedItems() = recentCalls.filter { selectedKeys.contains(it.id) } as ArrayList<RecentCall>
|
||||
|
||||
private fun setupView(view: View, recentCall: RecentCall) {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.simplemobiletools.contacts.pro.extensions
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.BlockedNumberContract.BlockedNumbers
|
||||
import android.provider.ContactsContract
|
||||
import android.telecom.TelecomManager
|
||||
import androidx.core.content.FileProvider
|
||||
|
@ -25,6 +27,7 @@ import com.simplemobiletools.contacts.pro.models.ContactSource
|
|||
import com.simplemobiletools.contacts.pro.models.Organization
|
||||
import java.io.File
|
||||
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||
|
||||
val Context.contactsDB: ContactsDao get() = ContactsDatabase.getInstance(applicationContext).ContactsDao()
|
||||
|
@ -283,3 +286,10 @@ fun Context.getVisibleContactSources(): ArrayList<String> {
|
|||
sourceNames.removeAll(config.ignoredContactSources)
|
||||
return sourceNames
|
||||
}
|
||||
|
||||
fun Context.addBlockedNumber(number: String) {
|
||||
ContentValues().apply {
|
||||
put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, number)
|
||||
contentResolver.insert(BlockedNumbers.CONTENT_URI, this)
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 495 B |
Binary file not shown.
After Width: | Height: | Size: 624 B |
Binary file not shown.
After Width: | Height: | Size: 928 B |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -11,4 +11,9 @@
|
|||
android:icon="@drawable/ic_select_all"
|
||||
android:title="@string/select_all"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_block_number"
|
||||
android:icon="@drawable/ic_block"
|
||||
android:title="@string/block_number"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
||||
|
|
Loading…
Reference in New Issue