This commit is contained in:
parent
5ccd6a3368
commit
fd9c854893
@ -34,6 +34,7 @@ class ItemCardAdapter(
|
||||
override var items: ArrayList<SelfossModel.Item>,
|
||||
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit,
|
||||
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
||||
private lateinit var binding: CardItemBinding
|
||||
private val c: Context = app.baseContext
|
||||
private val imageMaxHeight: Int =
|
||||
c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
||||
@ -46,10 +47,48 @@ class ItemCardAdapter(
|
||||
parent: ViewGroup,
|
||||
viewType: Int,
|
||||
): ViewHolder {
|
||||
val binding = CardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding = CardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
private fun handleClickListeners(position: Int) {
|
||||
binding.favButton.setOnClickListener {
|
||||
val item = items[position]
|
||||
if (item.starred) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.unstarr(item)
|
||||
}
|
||||
binding.favButton.isSelected = false
|
||||
} else {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.starr(item)
|
||||
}
|
||||
binding.favButton.isSelected = true
|
||||
}
|
||||
}
|
||||
|
||||
binding.shareBtn.setOnClickListener {
|
||||
val item = items[position]
|
||||
c.shareLink(item.getLinkDecoded(), item.title.getHtmlDecoded())
|
||||
}
|
||||
|
||||
binding.browserBtn.setOnClickListener {
|
||||
c.openInBrowserAsNewTask(items[position])
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleLinkOpening(position: Int) {
|
||||
binding.root.setOnClickListener {
|
||||
repository.setReaderItems(items)
|
||||
c.openItemUrl(
|
||||
position,
|
||||
items[position].getLinkDecoded(),
|
||||
appSettingsService.isArticleViewerEnabled(),
|
||||
app,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(
|
||||
holder: ViewHolder,
|
||||
position: Int,
|
||||
@ -57,6 +96,9 @@ class ItemCardAdapter(
|
||||
with(holder) {
|
||||
val itm = items[position]
|
||||
|
||||
handleClickListeners(position)
|
||||
handleLinkOpening(position)
|
||||
|
||||
binding.favButton.isSelected = itm.starred
|
||||
if (appSettingsService.getPublicAccess()) {
|
||||
binding.favButton.visibility = View.GONE
|
||||
@ -96,48 +138,5 @@ class ItemCardAdapter(
|
||||
return items.size
|
||||
}
|
||||
|
||||
inner class ViewHolder(val binding: CardItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
handleClickListeners()
|
||||
handleLinkOpening()
|
||||
}
|
||||
|
||||
private fun handleClickListeners() {
|
||||
binding.favButton.setOnClickListener {
|
||||
val item = items[bindingAdapterPosition]
|
||||
if (item.starred) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.unstarr(item)
|
||||
}
|
||||
binding.favButton.isSelected = false
|
||||
} else {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.starr(item)
|
||||
}
|
||||
binding.favButton.isSelected = true
|
||||
}
|
||||
}
|
||||
|
||||
binding.shareBtn.setOnClickListener {
|
||||
val item = items[bindingAdapterPosition]
|
||||
c.shareLink(item.getLinkDecoded(), item.title.getHtmlDecoded())
|
||||
}
|
||||
|
||||
binding.browserBtn.setOnClickListener {
|
||||
c.openInBrowserAsNewTask(items[bindingAdapterPosition])
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleLinkOpening() {
|
||||
binding.root.setOnClickListener {
|
||||
repository.setReaderItems(items)
|
||||
c.openItemUrl(
|
||||
bindingAdapterPosition,
|
||||
items[bindingAdapterPosition].getLinkDecoded(),
|
||||
appSettingsService.isArticleViewerEnabled(),
|
||||
app,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
inner class ViewHolder(val binding: CardItemBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class ItemListAdapter(
|
||||
override var items: ArrayList<SelfossModel.Item>,
|
||||
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit,
|
||||
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
||||
private lateinit var binding: ListItemBinding
|
||||
private val c: Context = app.baseContext
|
||||
|
||||
override val di: DI by closestDI(app)
|
||||
@ -35,7 +36,7 @@ class ItemListAdapter(
|
||||
parent: ViewGroup,
|
||||
viewType: Int,
|
||||
): ViewHolder {
|
||||
val binding = ListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding = ListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
@ -46,6 +47,16 @@ class ItemListAdapter(
|
||||
with(holder) {
|
||||
val itm = items[position]
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
repository.setReaderItems(items)
|
||||
c.openItemUrl(
|
||||
bindingAdapterPosition,
|
||||
items[bindingAdapterPosition].getLinkDecoded(),
|
||||
appSettingsService.isArticleViewerEnabled(),
|
||||
app,
|
||||
)
|
||||
}
|
||||
|
||||
binding.title.text = itm.title.getHtmlDecoded()
|
||||
|
||||
binding.title.setOnTouchListener(LinkOnTouchListener())
|
||||
@ -68,21 +79,5 @@ class ItemListAdapter(
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
inner class ViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
handleLinkOpening()
|
||||
}
|
||||
|
||||
private fun handleLinkOpening() {
|
||||
binding.root.setOnClickListener {
|
||||
repository.setReaderItems(items)
|
||||
c.openItemUrl(
|
||||
bindingAdapterPosition,
|
||||
items[bindingAdapterPosition].getLinkDecoded(),
|
||||
appSettingsService.isArticleViewerEnabled(),
|
||||
app,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
inner class ViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
}
|
||||
|
@ -50,6 +50,33 @@ class SourcesListAdapter(
|
||||
) {
|
||||
val itm = items[position]
|
||||
|
||||
val deleteBtn: Button = holder.mView.findViewById(R.id.deleteBtn)
|
||||
|
||||
deleteBtn.setOnClickListener {
|
||||
val (id, title) = items[position]
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val successfullyDeletedSource = repository.deleteSource(id, title)
|
||||
if (successfullyDeletedSource) {
|
||||
items.removeAt(position)
|
||||
notifyItemRemoved(position)
|
||||
notifyItemRangeChanged(position, itemCount)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
app,
|
||||
R.string.can_delete_source,
|
||||
Toast.LENGTH_SHORT,
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.mView.setOnClickListener {
|
||||
val source = items[position]
|
||||
|
||||
repository.setSelectedSource(source)
|
||||
app.startActivity(Intent(app, UpsertSourceActivity::class.java))
|
||||
}
|
||||
|
||||
if (itm.getIcon(repository.baseUrl).isEmpty()) {
|
||||
binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded())
|
||||
} else {
|
||||
@ -72,38 +99,5 @@ class SourcesListAdapter(
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
inner class ViewHolder(private val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) {
|
||||
init {
|
||||
handleClickListeners()
|
||||
}
|
||||
|
||||
private fun handleClickListeners() {
|
||||
val deleteBtn: Button = mView.findViewById(R.id.deleteBtn)
|
||||
|
||||
deleteBtn.setOnClickListener {
|
||||
val (id, title) = items[bindingAdapterPosition]
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val successfullyDeletedSource = repository.deleteSource(id, title)
|
||||
if (successfullyDeletedSource) {
|
||||
items.removeAt(bindingAdapterPosition)
|
||||
notifyItemRemoved(bindingAdapterPosition)
|
||||
notifyItemRangeChanged(bindingAdapterPosition, itemCount)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
app,
|
||||
R.string.can_delete_source,
|
||||
Toast.LENGTH_SHORT,
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mView.setOnClickListener {
|
||||
val source = items[bindingAdapterPosition]
|
||||
|
||||
repository.setSelectedSource(source)
|
||||
app.startActivity(Intent(app, UpsertSourceActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
inner class ViewHolder(val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user