diff --git a/app/src/main/kotlin/org/fossify/phone/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/phone/activities/MainActivity.kt index 5e739b96..7b30e375 100644 --- a/app/src/main/kotlin/org/fossify/phone/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/phone/activities/MainActivity.kt @@ -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)) diff --git a/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt b/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt index f9bbc2d8..72a9fac9 100644 --- a/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt @@ -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) { + } + } +}