-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package element | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView.ViewHolder | ||
import element_comment.ElementComment | ||
import org.btcmap.databinding.ItemCommentBinding | ||
import java.time.OffsetDateTime | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.FormatStyle | ||
|
||
class CommentsAdapter : | ||
ListAdapter<ElementComment, CommentsAdapter.ItemViewHolder>(DiffCallback()) { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { | ||
val binding = ItemCommentBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false, | ||
) | ||
return ItemViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
class ItemViewHolder( | ||
private val binding: ItemCommentBinding, | ||
) : ViewHolder( | ||
binding.root, | ||
) { | ||
fun bind(item: ElementComment) { | ||
binding.apply { | ||
message.text = item.comment | ||
val dateFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) | ||
date.text = dateFormat.format(OffsetDateTime.parse(item.createdAt)) | ||
} | ||
} | ||
} | ||
|
||
class DiffCallback : DiffUtil.ItemCallback<ElementComment>() { | ||
|
||
override fun areItemsTheSame( | ||
oldItem: ElementComment, | ||
newItem: ElementComment, | ||
): Boolean { | ||
return newItem == oldItem | ||
} | ||
|
||
override fun areContentsTheSame( | ||
oldItem: ElementComment, | ||
newItem: ElementComment, | ||
): Boolean { | ||
return newItem == oldItem | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:autoMirrored="true" | ||
android:tint="?attr/colorControlNormal" | ||
android:viewportWidth="960" | ||
android:viewportHeight="960"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M240,560L720,560L720,480L240,480L240,560ZM240,440L720,440L720,360L240,360L240,440ZM240,320L720,320L720,240L240,240L240,320ZM880,880L720,720L160,720Q127,720 103.5,696.5Q80,673 80,640L80,160Q80,127 103.5,103.5Q127,80 160,80L800,80Q833,80 856.5,103.5Q880,127 880,160L880,880ZM160,640L754,640L800,685L800,160Q800,160 800,160Q800,160 800,160L160,160Q160,160 160,160Q160,160 160,160L160,640Q160,640 160,640Q160,640 160,640ZM160,640Q160,640 160,640Q160,640 160,640L160,160Q160,160 160,160Q160,160 160,160L160,160Q160,160 160,160Q160,160 160,160L160,640Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical" | ||
android:paddingVertical="8dp"> | ||
|
||
<ImageView | ||
android:id="@+id/icon" | ||
android:layout_width="24dp" | ||
android:layout_height="24dp" | ||
android:layout_gravity="center" | ||
android:layout_marginHorizontal="18dp" | ||
android:contentDescription="@string/icon" | ||
android:src="@drawable/person_alt" | ||
app:tint="?attr/colorOnSurfaceVariant" /> | ||
|
||
<LinearLayout | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/message" | ||
style="?attr/textAppearanceSubtitle1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingStart="0dp" | ||
android:paddingEnd="16dp" | ||
tools:text="Not verified" /> | ||
|
||
<TextView | ||
android:id="@+id/date" | ||
style="?textAppearanceCaption" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
tools:text="Severity: 5" /> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters