tweak the DateTime field at recent calls

This commit is contained in:
tibbi 2018-08-04 09:50:01 +02:00
parent 29c59f498a
commit 2a987a640e
4 changed files with 18 additions and 6 deletions

View File

@ -71,7 +71,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
}
recent_call_date_time.apply {
text = recentCall.date.toString()
text = recentCall.dateTime
setTextColor(textColor)
}
}

View File

@ -1332,7 +1332,12 @@ class ContactsHelper(val activity: Activity) {
CallLog.Calls.TYPE
)
val sorting = "${CallLog.Calls._ID} DESC LIMIT 100"
val sorting = "${CallLog.Calls._ID} DESC LIMIT 50"
val currentDate = Date(System.currentTimeMillis())
val currentYear = SimpleDateFormat("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 yesterday = activity.getString(R.string.yesterday)
var cursor: Cursor? = null
try {
@ -1345,7 +1350,14 @@ class ContactsHelper(val activity: Activity) {
val name = cursor.getStringValue(CallLog.Calls.CACHED_NAME)
val type = cursor.getIntValue(CallLog.Calls.TYPE)
val formattedDate = SimpleDateFormat("dd.MM.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)
when {
datePart == todayDate -> formattedDate = formattedDate.substring(12)
datePart == yesterdayDate -> formattedDate = yesterday + formattedDate.substring(11)
formattedDate.substring(7, 11) == currentYear -> formattedDate = formattedDate.substring(0, 6) + formattedDate.substring(11)
}
val recentCall = RecentCall(id, number, formattedDate, name, type)
calls.add(recentCall)
} while (cursor.moveToNext())

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.contacts.models
data class RecentCall(var id: Int, var number: String, var date: String, var name: String?, var type: Int)
data class RecentCall(var id: Int, var number: String, var dateTime: String, var name: String?, var type: Int)

View File

@ -45,8 +45,8 @@
android:layout_below="@+id/recent_call_name"
android:gravity="right"
android:maxLines="1"
android:textSize="@dimen/bigger_text_size"
tools:text="Today, 17:00"/>
android:textSize="@dimen/normal_text_size"
tools:text="Yesterday, 17:00"/>
</RelativeLayout>
</FrameLayout>