From 73af5fdf5ad53f51fa7c236a23efd47a7beab998 Mon Sep 17 00:00:00 2001 From: Bindu Date: Sat, 9 Apr 2022 10:02:11 -0700 Subject: [PATCH 01/20] Group recent calls --- .../www/chooloolib/adapter/RecentsAdapter.kt | 14 +++++- .../chooloo/www/chooloolib/model/ListData.kt | 43 +++++++++++++++++-- .../www/chooloolib/model/RecentAccount.kt | 1 + .../ui/recents/RecentsHistoryFragment.kt | 11 +++++ .../ui/widgets/listitem/ListItem.kt | 4 +- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt index 3ad39f889..9072a0741 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt @@ -23,10 +23,19 @@ class RecentsAdapter @Inject constructor( private val preferences: PreferencesInteractor ) : ListAdapter(animations) { + private var _showHistory: Boolean = false + + var showHistory: Boolean + get() = _showHistory + set(value) { + _showHistory = value + } + override fun onBindListItem(listItem: ListItem, item: RecentAccount) { listItem.apply { isCompact = preferences.isCompact - captionText = if (item.date != null) context.getHoursString(item.date) else null + val date = if (item.date != null) context.getHoursString(item.date) else "" + captionText = if (item.callCount > 1) "(${item.callCount}) $date" else date phones.lookupAccount(item.number) { titleText = it?.name ?: item.number it?.let { @@ -42,5 +51,6 @@ class RecentsAdapter @Inject constructor( } } - override fun convertDataToListData(data: List) = ListData.fromRecents(data) + override fun convertDataToListData(data: List) = + ListData.fromRecents(data, !showHistory) } \ No newline at end of file diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/ListData.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/ListData.kt index ee875d9ea..497269a7d 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/ListData.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/ListData.kt @@ -24,10 +24,45 @@ data class ListData( return ListData(contacts, headersToCounts) } - fun fromRecents(recents: List) = ListData( - recents, - recents.groupingBy { getRelativeDateString(it.date) }.eachCount() - ) + fun fromRecents(recents: List, isGrouped: Boolean) = + if (isGrouped && recents.size > 1) getGroupedRecents(recents) + else ListData( + recents, + recents.groupingBy { getRelativeDateString(it.date) }.eachCount() + ) + + private fun getGroupedRecents(recents: List): ListData { + var prevItem: RecentAccount = recents[0] + var prevDate = getRelativeDateString(prevItem.date) + var count = 1 + val groupedRecents: MutableList = ArrayList() + recents.drop(1).forEach { + val date = getRelativeDateString(it.date) + if (prevItem.number == it.number && prevDate == date) { + count++ + } else { + groupedRecents.add( + RecentAccount( + prevItem.number, prevItem.type, prevItem.id, + prevItem.duration, prevItem.date, prevItem.cachedName, count + ) + ) + count = 1 + prevItem = it + } + prevDate = date + } + groupedRecents.add( + RecentAccount( + prevItem.number, prevItem.type, prevItem.id, + prevItem.duration, prevItem.date, prevItem.cachedName, count + ) + ) + return ListData( + groupedRecents, + groupedRecents.groupingBy { getRelativeDateString(it.date) }.eachCount() + ) + } fun fromPhones(phones: List): ListData { val phones = phones.toList().distinctBy { it.normalizedNumber } diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/RecentAccount.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/RecentAccount.kt index 7d780a926..e0534ed61 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/RecentAccount.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/RecentAccount.kt @@ -13,6 +13,7 @@ data class RecentAccount( val duration: Long = 0, val date: Date? = null, val cachedName: String? = null, + val callCount: Int = 1, ) : Serializable { @kotlin.annotation.Retention(AnnotationRetention.SOURCE) diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/recents/RecentsHistoryFragment.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/recents/RecentsHistoryFragment.kt index b4c6e9d46..c5e17477c 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/recents/RecentsHistoryFragment.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/recents/RecentsHistoryFragment.kt @@ -2,12 +2,23 @@ package com.chooloo.www.chooloolib.ui.recents import android.os.Bundle import androidx.fragment.app.activityViewModels +import com.chooloo.www.chooloolib.adapter.RecentsAdapter import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject @AndroidEntryPoint class RecentsHistoryFragment : RecentsFragment() { override val viewState: RecentsHistoryViewState by activityViewModels() + @Inject + override lateinit var adapter: RecentsAdapter + + override fun onSetup() { + super.onSetup() + + adapter.showHistory = true + } + companion object { fun newInstance(filter: String? = null) = RecentsHistoryFragment().apply { arguments = Bundle().apply { diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/widgets/listitem/ListItem.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/widgets/listitem/ListItem.kt index 75a5cc49c..f5f097340 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/widgets/listitem/ListItem.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/widgets/listitem/ListItem.kt @@ -297,13 +297,13 @@ open class ListItem : LinearLayout { caption.id.also { connect(it, TOP, title.id, BOTTOM) - connect(it, START, title.id, START) + connect(it, START, captionImage.id, END) connect(it, BOTTOM, PARENT_ID, BOTTOM) } captionImage.id.also { connect(it, TOP, caption.id, TOP) - connect(it, START, caption.id, END) + connect(it, START, title.id, START) connect(it, BOTTOM, caption.id, BOTTOM) } From ba437153cb3f2d4af4db040455353d77ec8424d3 Mon Sep 17 00:00:00 2001 From: Roei Edri Date: Wed, 6 Apr 2022 20:47:30 +0300 Subject: [PATCH 02/20] Fixed PRs code --- .../www/chooloolib/ui/dialpad/DialpadFragment.kt | 7 +------ .../www/chooloolib/ui/dialpad/DialpadViewState.kt | 6 +++++- .../www/chooloolib/ui/widgets/SearchBar.kt | 15 +++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialpad/DialpadFragment.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialpad/DialpadFragment.kt index 9461a2df8..3f4269c44 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialpad/DialpadFragment.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialpad/DialpadFragment.kt @@ -1,7 +1,5 @@ package com.chooloo.www.chooloolib.ui.dialpad -import android.content.ClipboardManager -import android.content.Context import android.view.View import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels @@ -77,9 +75,6 @@ open class DialpadFragment @Inject constructor() : BaseFragment - source.forEach { char -> - if (!(char.isLetterOrDigit() || char == ' ')) { - return@InputFilter "" - } + filters = arrayOf(InputFilter { source, _, _, _, _, _ -> + source.forEach { char -> + if (!(char.isLetterOrDigit() || char == ' ')) { + return@InputFilter "" } - return@InputFilter null - }) + } + return@InputFilter null + }) setTextAppearance(R.style.Chooloo_Text_Subtitle1) setPadding(spacingSmall, 0, spacingSmall, 0) From 86912a3dd50f957388d8ed73a881d5c3444ada8b Mon Sep 17 00:00:00 2001 From: Roei Edri Date: Wed, 6 Apr 2022 21:03:39 +0300 Subject: [PATCH 03/20] Fix numbers custom label showing as 'custom', Fixes #397 --- .../com/chooloo/www/chooloolib/adapter/PhonesAdapter.kt | 2 +- .../com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt | 5 ++--- .../contentresolver/PhoneLookupContentResolver.kt | 2 ++ .../www/chooloolib/contentresolver/PhonesContentResolver.kt | 2 ++ .../java/com/chooloo/www/chooloolib/model/PhoneAccount.kt | 1 + .../com/chooloo/www/chooloolib/model/PhoneLookupAccount.kt | 1 + .../com/chooloo/www/chooloolib/ui/dialer/DialerViewState.kt | 4 +++- chooloolib/src/main/res/values/styles.xml | 6 +++--- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/PhonesAdapter.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/PhonesAdapter.kt index 70d8943da..033a2257d 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/PhonesAdapter.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/PhonesAdapter.kt @@ -18,7 +18,7 @@ class PhonesAdapter @Inject constructor( imageVisibility = false titleText = item.number isRightButtonVisible = true - captionText = strings.getString(Phone.getTypeLabelResource(item.type)) + captionText = Phone.getTypeLabel(resources, item.type, item.label).toString() setTitleBold(true) setBackground(null) diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt index d57ef0381..8e96f675a 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/adapter/RecentsAdapter.kt @@ -28,9 +28,8 @@ class RecentsAdapter @Inject constructor( phones.lookupAccount(item.number) { titleText = it?.name ?: item.number it?.let { - captionText = "$captionText · ${ - strings.getString(Phone.getTypeLabelResource(it.type)) - }" + captionText = + "$captionText · ${Phone.getTypeLabel(resources, it.type, it.label)}" } } diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhoneLookupContentResolver.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhoneLookupContentResolver.kt index cc38d1864..e2a5353d2 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhoneLookupContentResolver.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhoneLookupContentResolver.kt @@ -17,6 +17,7 @@ class PhoneLookupContentResolver(context: Context, number: String?) : override val uri: Uri = PhoneLookup.CONTENT_FILTER_URI.buildUpon().appendPath(number).build() override val projection: Array = arrayOf( PhoneLookup.TYPE, + PhoneLookup.LABEL, PhoneLookup.NUMBER, PhoneLookup.STARRED, PhoneLookup.PHOTO_URI, @@ -26,6 +27,7 @@ class PhoneLookupContentResolver(context: Context, number: String?) : @SuppressLint("Range") override fun convertCursorToItem(cursor: Cursor) = PhoneLookupAccount( + label = cursor.getString(cursor.getColumnIndex(PhoneLookup.LABEL)), number = cursor.getString(cursor.getColumnIndex(PhoneLookup.NUMBER)), name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)), contactId = cursor.getLong(cursor.getColumnIndex(PhoneLookup.CONTACT_ID)), diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhonesContentResolver.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhonesContentResolver.kt index 2553ea3a0..e96cc70ab 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhonesContentResolver.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/contentresolver/PhonesContentResolver.kt @@ -18,6 +18,7 @@ class PhonesContentResolver(context: Context, contactId: Long? = null) : override val selection = SelectionBuilder().addSelection(Phone.CONTACT_ID, contactId).build() override val projection: Array = arrayOf( Phone.TYPE, + Phone.LABEL, Phone.NUMBER, Phone.CONTACT_ID, Phone.NORMALIZED_NUMBER, @@ -27,6 +28,7 @@ class PhonesContentResolver(context: Context, contactId: Long? = null) : @SuppressLint("Range") override fun convertCursorToItem(cursor: Cursor) = PhoneAccount( type = cursor.getInt(cursor.getColumnIndex(Phone.TYPE)), + label = cursor.getString(cursor.getColumnIndex(Phone.LABEL)), number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER)), contactId = cursor.getLong(cursor.getColumnIndex(Phone.CONTACT_ID)), displayName = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME_PRIMARY)), diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneAccount.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneAccount.kt index 8883e6c14..893b52d66 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneAccount.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneAccount.kt @@ -6,6 +6,7 @@ data class PhoneAccount( val number: String, val contactId: Long, val displayName: String, + val label: String? = null, val normalizedNumber: String?, val type: Int = Phone.TYPE_OTHER ) diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneLookupAccount.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneLookupAccount.kt index ef4db6715..b2518e530 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneLookupAccount.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/model/PhoneLookupAccount.kt @@ -4,6 +4,7 @@ import android.provider.ContactsContract.CommonDataKinds.Phone data class PhoneLookupAccount( val name: String?, + val label: String? = null, val number: String? = null, val contactId: Long? = null, val photoUri: String? = null, diff --git a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialer/DialerViewState.kt b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialer/DialerViewState.kt index d98a409fb..a23c900ad 100644 --- a/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialer/DialerViewState.kt +++ b/chooloolib/src/main/java/com/chooloo/www/chooloolib/ui/dialer/DialerViewState.kt @@ -1,5 +1,6 @@ package com.chooloo.www.chooloolib.ui.dialer +import android.content.ClipboardManager import androidx.lifecycle.MutableLiveData import com.chooloo.www.chooloolib.interactor.audio.AudiosInteractor import com.chooloo.www.chooloolib.interactor.navigation.NavigationsInteractor @@ -17,9 +18,10 @@ class DialerViewState @Inject constructor( audios: AudiosInteractor, preferences: PreferencesInteractor, private val recents: RecentsInteractor, + private val clipboardManager: ClipboardManager, private val navigations: NavigationsInteractor ) : - DialpadViewState(audios, preferences) { + DialpadViewState(audios, clipboardManager, preferences) { val callVoicemailEvent = LiveEvent() val callNumberEvent = DataLiveEvent() diff --git a/chooloolib/src/main/res/values/styles.xml b/chooloolib/src/main/res/values/styles.xml index dfb58413e..cd64acbb7 100644 --- a/chooloolib/src/main/res/values/styles.xml +++ b/chooloolib/src/main/res/values/styles.xml @@ -81,9 +81,9 @@