Skip to content

Commit

Permalink
Added option to clear all recent calls.
Browse files Browse the repository at this point in the history
alvi-khan authored and roeiedri committed Jun 19, 2023
1 parent fdf481b commit 42a398a
Showing 6 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ interface RecentsInteractor : BaseInteractor<RecentsInteractor.Listener> {
interface Listener

fun deleteRecent(recentId: Long)
fun deleteAllRecents()
fun getRecents(): Flow<List<RecentAccount>>
fun getRecent(recentId: Long): Flow<RecentAccount?>
fun getCallTypeImage(@RecentAccount.CallType callType: Int): Int
Original file line number Diff line number Diff line change
@@ -27,6 +27,15 @@ class RecentsInteractorImpl @Inject constructor(
)
}

@RequiresPermission(WRITE_CALL_LOG)
override fun deleteAllRecents() {
context.contentResolver.delete(
CallLog.Calls.CONTENT_URI,
null,
null
)
}

override fun getRecent(recentId: Long) = recentsRepository.getRecent(recentId)

override fun getRecents() = recentsRepository.getRecents()
2 changes: 2 additions & 0 deletions chooloolib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
<string name="action_block_number">Block Number</string>
<string name="action_delete_contact">Delete Contact</string>
<string name="action_delete_recent">Delete Recent</string>
<string name="action_clear_recents">Delete All Recent Calls</string>
<string name="action_set_favorite">Set As Favorite</string>
<string name="action_unset_favorite">Unset As Favorite</string>
<string name="action_open_in_whatsapp">Open In Whatsapp</string>
@@ -75,6 +76,7 @@
<string name="explain_choose_phone_account">Continue the current call using a specific phone account</string>
<string name="explain_delete_contact">This contact will be deleted permanently</string>
<string name="explain_delete_recent">This call log will be deleted permanently</string>
<string name="explain_clear_recents">All call history will be deleted permanently</string>
<string name="explain_choose_default_page">This page will be selected whenever you reopen Koler</string>
<!--endregion-->

Original file line number Diff line number Diff line change
@@ -59,6 +59,14 @@ class SettingsFragment @Inject constructor() : ChoolooSettingsFragment() {
}
}

clearRecentsEvent.observe(this@SettingsFragment) {
it.ifNew?.let {
dialogs.askForValidation(R.string.explain_clear_recents) { bl ->
if (bl) viewState.onClearRecents()
}
}
}

askForIncomingCallModeEvent.observe(this@SettingsFragment) {
it.ifNew?.let {
dialogs.askForIncomingCallMode {
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.chooloo.www.koler.ui.settings

import android.Manifest
import com.chooloo.www.chooloolib.interactor.color.ColorsInteractor
import com.chooloo.www.chooloolib.interactor.navigation.NavigationsInteractor
import com.chooloo.www.chooloolib.interactor.permission.PermissionsInteractor
import com.chooloo.www.chooloolib.interactor.preferences.PreferencesInteractor
import com.chooloo.www.chooloolib.interactor.preferences.PreferencesInteractor.Companion.IncomingCallMode
import com.chooloo.www.chooloolib.interactor.preferences.PreferencesInteractor.Companion.Page
import com.chooloo.www.chooloolib.interactor.recents.RecentsInteractor
import com.chooloo.www.chooloolib.interactor.string.StringsInteractor
import com.chooloo.www.chooloolib.interactor.theme.ThemesInteractor
import com.chooloo.www.chooloolib.ui.settings.SettingsViewState
@@ -22,7 +25,9 @@ class SettingsViewState @Inject constructor(
themes: ThemesInteractor,
strings: StringsInteractor,
navigations: NavigationsInteractor,
preferences: PreferencesInteractor
preferences: PreferencesInteractor,
private val recents: RecentsInteractor,
private val permissions: PermissionsInteractor
) :
SettingsViewState(themes, colors, strings, navigations, preferences) {

@@ -32,11 +37,13 @@ class SettingsViewState @Inject constructor(
private val _askForIncomingCallModeEvent = MutableLiveEvent()
private val _askForDialpadTonesEvent = MutableDataLiveEvent<Boolean>()
private val _askForGroupRecentsEvent = MutableDataLiveEvent<Boolean>()
private val _clearRecentsEvent = MutableLiveEvent()
private val _askForDialpadVibrateEvent = MutableDataLiveEvent<Boolean>()

val askForDefaultPageEvent = _askForDefaultPageEvent as LiveEvent
val askForIncomingCallModeEvent = _askForIncomingCallModeEvent as LiveEvent
val askForGroupRecentsEvent = _askForGroupRecentsEvent as DataLiveEvent<Boolean>
val clearRecentsEvent = _clearRecentsEvent as LiveEvent
val askForDialpadTonesEvent = _askForDialpadTonesEvent as DataLiveEvent<Boolean>
val askForDialpadVibrateEvent = _askForDialpadVibrateEvent as DataLiveEvent<Boolean>

@@ -47,6 +54,7 @@ class SettingsViewState @Inject constructor(
R.id.menu_koler_incoming_call_mode -> _askForIncomingCallModeEvent.call()
R.id.menu_koler_dialpad_tones -> _askForDialpadTonesEvent.call(preferences.isDialpadTones)
R.id.menu_koler_group_recents -> _askForGroupRecentsEvent.call(preferences.isGroupRecents)
R.id.menu_koler_clear_recents -> _clearRecentsEvent.call()
R.id.menu_koler_dialpad_vibrate -> _askForDialpadVibrateEvent.call(preferences.isDialpadVibrate)
else -> super.onMenuItemClick(itemId)
}
@@ -70,6 +78,15 @@ class SettingsViewState @Inject constructor(
navigations.goToLauncherActivity()
}

fun onClearRecents() {
permissions.runWithPermissions(arrayOf(Manifest.permission.WRITE_CALL_LOG), {
recents.deleteAllRecents()
onFinish()
}, {
onError(com.chooloo.www.chooloolib.R.string.error_no_permissions_edit_call_log)
})
}

fun onIncomingCallMode(response: IncomingCallMode) {
preferences.incomingCallMode = response
}
5 changes: 5 additions & 0 deletions koler/src/main/res/menu/menu_koler.xml
Original file line number Diff line number Diff line change
@@ -20,6 +20,11 @@
android:icon="@drawable/recent_actors"
android:title="@string/pref_title_group_recents" />

<item
android:id="@+id/menu_koler_clear_recents"
android:icon="@drawable/delete"
android:title="@string/action_clear_recents" />

<item
android:id="@+id/menu_koler_incoming_call_mode"
android:icon="@drawable/phone_msg"

0 comments on commit 42a398a

Please sign in to comment.