Clear missed calls notification when call log tab is selected

Closes https://github.com/FossifyOrg/Phone/issues/88
This commit is contained in:
Naveen
2024-05-03 02:28:05 +05:30
parent af3c970639
commit 8450bc0600
2 changed files with 19 additions and 15 deletions

View File

@@ -32,6 +32,7 @@ import org.fossify.phone.adapters.ViewPagerAdapter
import org.fossify.phone.databinding.ActivityMainBinding
import org.fossify.phone.dialogs.ChangeSortingDialog
import org.fossify.phone.dialogs.FilterContactSourcesDialog
import org.fossify.phone.extensions.clearMissedCalls
import org.fossify.phone.extensions.config
import org.fossify.phone.extensions.launchCreateNewContactIntent
import org.fossify.phone.fragments.ContactsFragment
@@ -385,10 +386,6 @@ class MainActivity : SimpleActivity() {
// open the Recents tab if we got here by clicking a missed call notification
if (intent.action == Intent.ACTION_VIEW && config.showTabs and TAB_CALL_HISTORY > 0) {
wantedTab = binding.mainTabsHolder.tabCount - 1
ensureBackgroundThread {
clearMissedCalls()
}
}
binding.mainTabsHolder.getTabAt(wantedTab)?.select()
@@ -432,6 +429,11 @@ class MainActivity : SimpleActivity() {
binding.mainMenu.closeSearch()
binding.viewPager.currentItem = it.position
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
val lastPosition = binding.mainTabsHolder.tabCount - 1
if (it.position == lastPosition && config.showTabs and TAB_CALL_HISTORY > 0) {
clearMissedCalls()
}
}
)
@@ -545,17 +547,6 @@ class MainActivity : SimpleActivity() {
}
}
@SuppressLint("MissingPermission")
private fun clearMissedCalls() {
try {
// notification cancellation triggers MissedCallNotifier.clearMissedCalls() which, in turn,
// should update the database and reset the cached missed call count in MissedCallNotifier.java
// https://android.googlesource.com/platform/packages/services/Telecomm/+/master/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java#170
telecomManager.cancelMissedCallsNotification()
} catch (ignored: Exception) {
}
}
private fun launchSettings() {
hideKeyboard()
startActivity(Intent(applicationContext, SettingsActivity::class.java))

View File

@@ -6,6 +6,7 @@ import android.media.AudioManager
import android.net.Uri
import android.os.PowerManager
import org.fossify.commons.extensions.telecomManager
import org.fossify.commons.helpers.ensureBackgroundThread
import org.fossify.phone.helpers.Config
import org.fossify.phone.models.SIMAccount
@@ -44,3 +45,15 @@ fun Context.areMultipleSIMsAvailable(): Boolean {
false
}
}
fun Context.clearMissedCalls() {
ensureBackgroundThread {
try {
// notification cancellation triggers MissedCallNotifier.clearMissedCalls() which, in turn,
// should update the database and reset the cached missed call count in MissedCallNotifier.java
// https://android.googlesource.com/platform/packages/services/Telecomm/+/master/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java#170
telecomManager.cancelMissedCallsNotification()
} catch (ignored: Exception) {
}
}
}