HistoryAdapter: show last visits

This commit is contained in:
dece 2022-02-13 19:10:39 +01:00
parent c4d0e66322
commit 3aea6f42c9
2 changed files with 36 additions and 13 deletions

View file

@ -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<HistoryAdapter.ViewHolder>() {
@ -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

View file

@ -18,16 +18,33 @@
android:fontFamily="@font/preformatted"
android:typeface="monospace" />
<TextView
android:id="@+id/titleText"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/text"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="8dp"
android:textAppearance="?attr/textAppearanceListItem" />
android:layout_marginBottom="8dp">
<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>