mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-04-03 13:01:49 +02:00
adding a menu button for clearing the call history quicker
This commit is contained in:
parent
4cbba2457b
commit
e477dedf9f
@ -17,6 +17,7 @@ import android.view.MenuItem
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.MenuItemCompat
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.FAQItem
|
||||
@ -25,6 +26,7 @@ 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.RecentsHelper
|
||||
import com.simplemobiletools.dialer.helpers.tabsList
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||
@ -101,13 +103,18 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu, menu)
|
||||
setupSearch(menu)
|
||||
updateMenuItemColors(menu)
|
||||
menu.apply {
|
||||
findItem(R.id.clear_call_history).isVisible = getCurrentFragment() == recents_fragment
|
||||
|
||||
setupSearch(this)
|
||||
updateMenuItemColors(this)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.clear_call_history -> clearCallHistory()
|
||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
R.id.about -> launchAbout()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
@ -176,6 +183,16 @@ class MainActivity : SimpleActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun clearCallHistory() {
|
||||
ConfirmationDialog(this, "", R.string.clear_history_confirmation) {
|
||||
RecentsHelper(this).removeAllRecentCalls {
|
||||
runOnUiThread {
|
||||
recents_fragment?.refreshItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun checkShortcuts() {
|
||||
val appIconColor = config.appIconColor
|
||||
|
@ -119,4 +119,13 @@ class RecentsHelper(private val context: Context) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun removeAllRecentCalls(callback: () -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
val uri = Calls.CONTENT_URI
|
||||
context.contentResolver.delete(uri, null, null)
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
<?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/clear_call_history"
|
||||
android:icon="@drawable/ic_delete_vector"
|
||||
android:title="@string/clear_call_history"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/search"
|
||||
android:icon="@drawable/ic_search_vector"
|
||||
|
Loading…
x
Reference in New Issue
Block a user