improving the UI of section date time
This commit is contained in:
parent
59c5d16f62
commit
a9ba3ada0c
|
@ -1,28 +1,18 @@
|
||||||
package com.simplemobiletools.smsmessenger.adapters
|
package com.simplemobiletools.smsmessenger.adapters
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.text.format.DateFormat
|
|
||||||
import android.text.format.DateUtils
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.extensions.baseConfig
|
|
||||||
import com.simplemobiletools.commons.extensions.formatDate
|
|
||||||
import com.simplemobiletools.commons.extensions.getTimeFormat
|
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||||
import com.simplemobiletools.smsmessenger.extensions.formatDateOrTime
|
import com.simplemobiletools.smsmessenger.extensions.formatDateOrTime
|
||||||
import com.simplemobiletools.smsmessenger.extensions.formatTime
|
|
||||||
import com.simplemobiletools.smsmessenger.models.Message
|
import com.simplemobiletools.smsmessenger.models.Message
|
||||||
import kotlinx.android.synthetic.main.item_message.view.*
|
import kotlinx.android.synthetic.main.item_message.view.*
|
||||||
import java.util.*
|
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
class MessagesAdapter(
|
class MessagesAdapter(
|
||||||
activity: SimpleActivity, var messages: ArrayList<Message>,
|
activity: SimpleActivity, var messages: ArrayList<Message>,
|
||||||
|
@ -83,7 +73,7 @@ class MessagesAdapter(
|
||||||
|
|
||||||
message_address.text = message.address
|
message_address.text = message.address
|
||||||
message_body_short.text = message.body
|
message_body_short.text = message.body
|
||||||
message_date.text = message.date.formatDateOrTime(context)
|
message_date.text = message.date.formatDateOrTime(context, true)
|
||||||
|
|
||||||
if (message.read) {
|
if (message.read) {
|
||||||
message_address.setTypeface(null, Typeface.NORMAL)
|
message_address.setTypeface(null, Typeface.NORMAL)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.smsmessenger.extensions.formatDateOrTime
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_DATE_TIME
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_DATE_TIME
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_RECEIVED_MESSAGE
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_RECEIVED_MESSAGE
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_SENT_MESSAGE
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_SENT_MESSAGE
|
||||||
|
@ -18,6 +19,7 @@ import com.simplemobiletools.smsmessenger.models.Message
|
||||||
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
|
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
|
||||||
import com.simplemobiletools.smsmessenger.models.ThreadItem
|
import com.simplemobiletools.smsmessenger.models.ThreadItem
|
||||||
import kotlinx.android.synthetic.main.item_received_message.view.*
|
import kotlinx.android.synthetic.main.item_received_message.view.*
|
||||||
|
import kotlinx.android.synthetic.main.item_thread_date_time.view.*
|
||||||
|
|
||||||
class ThreadAdapter(
|
class ThreadAdapter(
|
||||||
activity: SimpleActivity, var messages: ArrayList<ThreadItem>,
|
activity: SimpleActivity, var messages: ArrayList<ThreadItem>,
|
||||||
|
@ -104,6 +106,9 @@ class ThreadAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupDateTime(view: View, dateTime: ThreadDateTime) {
|
private fun setupDateTime(view: View, dateTime: ThreadDateTime) {
|
||||||
|
view.apply {
|
||||||
|
thread_date_time.text = dateTime.date.formatDateOrTime(context, false)
|
||||||
|
thread_date_time.setTextColor(textColor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,8 @@ import android.text.format.Time
|
||||||
import com.simplemobiletools.commons.extensions.getTimeFormat
|
import com.simplemobiletools.commons.extensions.getTimeFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun Int.formatTime(context: Context): String {
|
|
||||||
val cal = Calendar.getInstance(Locale.ENGLISH)
|
|
||||||
cal.timeInMillis = this * 1000L
|
|
||||||
return DateFormat.format("${context.getTimeFormat()}", cal).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the given date is today, we show only the time. Else we show only the date
|
// if the given date is today, we show only the time. Else we show only the date
|
||||||
fun Int.formatDateOrTime(context: Context): String {
|
fun Int.formatDateOrTime(context: Context, hideTimeAtOtherDays: Boolean): String {
|
||||||
val cal = Calendar.getInstance(Locale.ENGLISH)
|
val cal = Calendar.getInstance(Locale.ENGLISH)
|
||||||
cal.timeInMillis = this * 1000L
|
cal.timeInMillis = this * 1000L
|
||||||
|
|
||||||
|
@ -26,6 +20,10 @@ fun Int.formatDateOrTime(context: Context): String {
|
||||||
format = format.replace("y", "").trim().trim('-').trim('.').trim('/')
|
format = format.replace("y", "").trim().trim('-').trim('.').trim('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hideTimeAtOtherDays) {
|
||||||
|
format += ", ${context.getTimeFormat()}"
|
||||||
|
}
|
||||||
|
|
||||||
DateFormat.format(format, cal).toString()
|
DateFormat.format(format, cal).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package com.simplemobiletools.smsmessenger.models
|
package com.simplemobiletools.smsmessenger.models
|
||||||
|
|
||||||
open class ThreadDateTime(val date: Int)
|
open class ThreadDateTime(val date: Int) : ThreadItem()
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/thread_date_time"
|
android:id="@+id/thread_date_time"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
android:textSize="@dimen/normal_text_size"
|
android:textSize="@dimen/normal_text_size"
|
||||||
tools:text="13 March, 13:30" />
|
tools:text="13 March, 13:30" />
|
||||||
|
|
Loading…
Reference in New Issue