HistoryAdapter: show last visits
This commit is contained in:
parent
c4d0e66322
commit
3aea6f42c9
|
@ -1,13 +1,14 @@
|
||||||
package dev.lowrespalmtree.comet
|
package dev.lowrespalmtree.comet
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.text.format.DateFormat
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import dev.lowrespalmtree.comet.History.HistoryEntry
|
import dev.lowrespalmtree.comet.History.HistoryEntry
|
||||||
import dev.lowrespalmtree.comet.databinding.FragmentHistoryItemBinding
|
import dev.lowrespalmtree.comet.databinding.FragmentHistoryItemBinding
|
||||||
import dev.lowrespalmtree.comet.utils.getFancySelectBgRes
|
import dev.lowrespalmtree.comet.utils.getFancySelectBgRes
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class HistoryAdapter(private val listener: Listener) :
|
class HistoryAdapter(private val listener: Listener) :
|
||||||
RecyclerView.Adapter<HistoryAdapter.ViewHolder>() {
|
RecyclerView.Adapter<HistoryAdapter.ViewHolder>() {
|
||||||
|
@ -27,12 +28,17 @@ class HistoryAdapter(private val listener: Listener) :
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val item = items[position]
|
val entry = items[position]
|
||||||
holder.binding.uriText.text = item.uri
|
// URI is always show.
|
||||||
holder.binding.titleText.visibility =
|
holder.binding.uriText.text = entry.uri
|
||||||
if (item.title.isNullOrBlank()) View.GONE else View.VISIBLE
|
// Main title is shown if one was found when record the entry.
|
||||||
holder.binding.titleText.text = item.title ?: ""
|
holder.binding.titleText.text = entry.title ?: ""
|
||||||
holder.binding.container.setOnClickListener { listener.onItemClick(item.uri) }
|
// Last visited date is properly formatted.
|
||||||
|
val lastVisit = Date(entry.lastVisit)
|
||||||
|
val dateFormatter = DateFormat.getMediumDateFormat(holder.binding.root.context)
|
||||||
|
holder.binding.lastVisitText.text = dateFormatter.format(lastVisit)
|
||||||
|
// Bind the click action.
|
||||||
|
holder.binding.container.setOnClickListener { listener.onItemClick(entry.uri) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = items.size
|
override fun getItemCount(): Int = items.size
|
||||||
|
|
|
@ -18,16 +18,33 @@
|
||||||
android:fontFamily="@font/preformatted"
|
android:fontFamily="@font/preformatted"
|
||||||
android:typeface="monospace" />
|
android:typeface="monospace" />
|
||||||
|
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:id="@+id/titleText"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="16sp"
|
|
||||||
android:textColor="@color/text"
|
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:layout_marginTop="0dp"
|
android:layout_marginTop="0dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp">
|
||||||
android:textAppearance="?attr/textAppearanceListItem" />
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/titleText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_toStartOf="@id/lastVisitText"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="@color/text" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/lastVisitText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_alignBaseline="@id/titleText"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:textColor="@color/text_light" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Reference in a new issue