diff --git a/app/src/main/java/dev/lowrespalmtree/comet/HistoryAdapter.kt b/app/src/main/java/dev/lowrespalmtree/comet/HistoryAdapter.kt index aa82b2e..a56e24b 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/HistoryAdapter.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/HistoryAdapter.kt @@ -1,13 +1,14 @@ package dev.lowrespalmtree.comet import android.annotation.SuppressLint +import android.text.format.DateFormat import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import dev.lowrespalmtree.comet.History.HistoryEntry import dev.lowrespalmtree.comet.databinding.FragmentHistoryItemBinding import dev.lowrespalmtree.comet.utils.getFancySelectBgRes +import java.util.* class HistoryAdapter(private val listener: Listener) : RecyclerView.Adapter() { @@ -27,12 +28,17 @@ class HistoryAdapter(private val listener: Listener) : ) override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val item = items[position] - holder.binding.uriText.text = item.uri - holder.binding.titleText.visibility = - if (item.title.isNullOrBlank()) View.GONE else View.VISIBLE - holder.binding.titleText.text = item.title ?: "" - holder.binding.container.setOnClickListener { listener.onItemClick(item.uri) } + val entry = items[position] + // URI is always show. + holder.binding.uriText.text = entry.uri + // Main title is shown if one was found when record the entry. + holder.binding.titleText.text = entry.title ?: "" + // 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 diff --git a/app/src/main/res/layout/fragment_history_item.xml b/app/src/main/res/layout/fragment_history_item.xml index 384bd05..1746fad 100644 --- a/app/src/main/res/layout/fragment_history_item.xml +++ b/app/src/main/res/layout/fragment_history_item.xml @@ -18,16 +18,33 @@ android:fontFamily="@font/preformatted" android:typeface="monospace" /> - + android:layout_marginBottom="8dp"> + + + + + \ No newline at end of file