2019-06-09 16:55:34 +02:00
|
|
|
/* Copyright 2019 Joel Pyska
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky.components.report.adapter
|
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
2021-06-20 10:58:19 +02:00
|
|
|
import androidx.paging.PagingDataAdapter
|
2019-06-09 16:55:34 +02:00
|
|
|
import androidx.recyclerview.widget.DiffUtil
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import com.keylesspalace.tusky.components.report.model.StatusViewState
|
2021-03-21 12:42:28 +01:00
|
|
|
import com.keylesspalace.tusky.databinding.ItemReportStatusBinding
|
2019-12-30 21:37:20 +01:00
|
|
|
import com.keylesspalace.tusky.util.StatusDisplayOptions
|
2022-04-15 13:20:27 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData
|
2019-06-09 16:55:34 +02:00
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
class StatusesAdapter(
|
2021-06-28 21:13:24 +02:00
|
|
|
private val statusDisplayOptions: StatusDisplayOptions,
|
|
|
|
private val statusViewState: StatusViewState,
|
|
|
|
private val adapterHandler: AdapterHandler
|
2022-04-15 13:20:27 +02:00
|
|
|
) : PagingDataAdapter<StatusViewData.Concrete, StatusViewHolder>(STATUS_COMPARATOR) {
|
2019-06-09 16:55:34 +02:00
|
|
|
|
2022-04-15 13:20:27 +02:00
|
|
|
private val statusForPosition: (Int) -> StatusViewData.Concrete? = { position: Int ->
|
2019-06-09 16:55:34 +02:00
|
|
|
if (position != RecyclerView.NO_POSITION) getItem(position) else null
|
|
|
|
}
|
|
|
|
|
2021-03-21 12:42:28 +01:00
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StatusViewHolder {
|
2024-01-04 17:00:55 +01:00
|
|
|
val binding = ItemReportStatusBinding.inflate(
|
|
|
|
LayoutInflater.from(parent.context),
|
|
|
|
parent,
|
|
|
|
false
|
|
|
|
)
|
2021-06-28 21:13:24 +02:00
|
|
|
return StatusViewHolder(
|
2023-03-13 13:16:39 +01:00
|
|
|
binding,
|
|
|
|
statusDisplayOptions,
|
|
|
|
statusViewState,
|
|
|
|
adapterHandler,
|
2021-06-28 21:13:24 +02:00
|
|
|
statusForPosition
|
|
|
|
)
|
2019-06-09 16:55:34 +02:00
|
|
|
}
|
|
|
|
|
2021-03-21 12:42:28 +01:00
|
|
|
override fun onBindViewHolder(holder: StatusViewHolder, position: Int) {
|
2019-06-09 16:55:34 +02:00
|
|
|
getItem(position)?.let { status ->
|
2021-03-21 12:42:28 +01:00
|
|
|
holder.bind(status)
|
2019-06-09 16:55:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2022-04-15 13:20:27 +02:00
|
|
|
val STATUS_COMPARATOR = object : DiffUtil.ItemCallback<StatusViewData.Concrete>() {
|
2024-01-04 17:00:55 +01:00
|
|
|
override fun areContentsTheSame(
|
|
|
|
oldItem: StatusViewData.Concrete,
|
|
|
|
newItem: StatusViewData.Concrete
|
|
|
|
): Boolean = oldItem == newItem
|
2019-06-09 16:55:34 +02:00
|
|
|
|
2024-01-04 17:00:55 +01:00
|
|
|
override fun areItemsTheSame(
|
|
|
|
oldItem: StatusViewData.Concrete,
|
|
|
|
newItem: StatusViewData.Concrete
|
|
|
|
): Boolean = oldItem.id == newItem.id
|
2019-06-09 16:55:34 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-21 12:42:28 +01:00
|
|
|
}
|