avoid showing the same number Recent Call twice in a row

This commit is contained in:
tibbi 2018-08-04 16:07:14 +02:00
parent 3f0c87572f
commit 74c7acab84
1 changed files with 6 additions and 1 deletions

View File

@ -1332,12 +1332,13 @@ class ContactsHelper(val activity: Activity) {
CallLog.Calls.TYPE CallLog.Calls.TYPE
) )
val sorting = "${CallLog.Calls._ID} DESC LIMIT 50" val sorting = "${CallLog.Calls._ID} DESC LIMIT 100"
val currentDate = Date(System.currentTimeMillis()) val currentDate = Date(System.currentTimeMillis())
val currentYear = SimpleDateFormat("yyyy", Locale.getDefault()).format(currentDate) val currentYear = SimpleDateFormat("yyyy", Locale.getDefault()).format(currentDate)
val todayDate = SimpleDateFormat("dd MMM yyyy", Locale.getDefault()).format(currentDate) val todayDate = SimpleDateFormat("dd MMM yyyy", Locale.getDefault()).format(currentDate)
val yesterdayDate = SimpleDateFormat("dd MMM yyyy", Locale.getDefault()).format(Date(System.currentTimeMillis() - DAY_SECONDS * 1000)) val yesterdayDate = SimpleDateFormat("dd MMM yyyy", Locale.getDefault()).format(Date(System.currentTimeMillis() - DAY_SECONDS * 1000))
val yesterday = activity.getString(R.string.yesterday) val yesterday = activity.getString(R.string.yesterday)
var prevNumber = ""
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
@ -1349,6 +1350,9 @@ class ContactsHelper(val activity: Activity) {
val date = cursor.getLongValue(CallLog.Calls.DATE) val date = cursor.getLongValue(CallLog.Calls.DATE)
val name = cursor.getStringValue(CallLog.Calls.CACHED_NAME) val name = cursor.getStringValue(CallLog.Calls.CACHED_NAME)
val type = cursor.getIntValue(CallLog.Calls.TYPE) val type = cursor.getIntValue(CallLog.Calls.TYPE)
if (number == prevNumber) {
continue
}
var formattedDate = SimpleDateFormat("dd MMM yyyy, HH:mm", Locale.getDefault()).format(Date(date)) var formattedDate = SimpleDateFormat("dd MMM yyyy, HH:mm", Locale.getDefault()).format(Date(date))
val datePart = formattedDate.substring(0, 11) val datePart = formattedDate.substring(0, 11)
@ -1358,6 +1362,7 @@ class ContactsHelper(val activity: Activity) {
formattedDate.substring(7, 11) == currentYear -> formattedDate = formattedDate.substring(0, 6) + formattedDate.substring(11) formattedDate.substring(7, 11) == currentYear -> formattedDate = formattedDate.substring(0, 6) + formattedDate.substring(11)
} }
prevNumber = number
val recentCall = RecentCall(id, number, formattedDate, name, type) val recentCall = RecentCall(id, number, formattedDate, name, type)
calls.add(recentCall) calls.add(recentCall)
} while (cursor.moveToNext()) } while (cursor.moveToNext())