|
|
|
@ -1,21 +1,26 @@
|
|
|
|
package org.koitharu.kotatsu.settings.sources.adapter
|
|
|
|
package org.koitharu.kotatsu.settings.sources.adapter
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
|
|
|
|
import android.view.MotionEvent
|
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import android.widget.CompoundButton
|
|
|
|
import androidx.core.view.isGone
|
|
|
|
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
import coil.ImageLoader
|
|
|
|
import coil.ImageLoader
|
|
|
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegate
|
|
|
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegate
|
|
|
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|
|
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.base.ui.list.OnTipCloseListener
|
|
|
|
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
|
|
|
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemExpandableBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemExpandableBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemFilterHeaderBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemFilterHeaderBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemSourceConfigBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemSourceConfigBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemSourceConfigDraggableBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemSourceConfigCheckableBinding
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.databinding.ItemTipBinding
|
|
|
|
import org.koitharu.kotatsu.settings.sources.model.SourceConfigItem
|
|
|
|
import org.koitharu.kotatsu.settings.sources.model.SourceConfigItem
|
|
|
|
import org.koitharu.kotatsu.utils.ext.*
|
|
|
|
import org.koitharu.kotatsu.utils.ext.crossfade
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
|
|
|
import org.koitharu.kotatsu.utils.image.FaviconFallbackDrawable
|
|
|
|
import org.koitharu.kotatsu.utils.image.FaviconFallbackDrawable
|
|
|
|
|
|
|
|
|
|
|
|
fun sourceConfigHeaderDelegate() =
|
|
|
|
fun sourceConfigHeaderDelegate() =
|
|
|
|
@ -44,13 +49,12 @@ fun sourceConfigGroupDelegate(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun sourceConfigItemDelegate(
|
|
|
|
fun sourceConfigItemCheckableDelegate(
|
|
|
|
listener: SourceConfigListener,
|
|
|
|
listener: SourceConfigListener,
|
|
|
|
coil: ImageLoader,
|
|
|
|
coil: ImageLoader,
|
|
|
|
lifecycleOwner: LifecycleOwner,
|
|
|
|
lifecycleOwner: LifecycleOwner,
|
|
|
|
) = adapterDelegateViewBinding<SourceConfigItem.SourceItem, SourceConfigItem, ItemSourceConfigBinding>(
|
|
|
|
) = adapterDelegateViewBinding<SourceConfigItem.SourceItem, SourceConfigItem, ItemSourceConfigCheckableBinding>(
|
|
|
|
{ layoutInflater, parent -> ItemSourceConfigBinding.inflate(layoutInflater, parent, false) },
|
|
|
|
{ layoutInflater, parent -> ItemSourceConfigCheckableBinding.inflate(layoutInflater, parent, false) },
|
|
|
|
on = { item, _, _ -> item is SourceConfigItem.SourceItem && !item.isDraggable },
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
binding.switchToggle.setOnCheckedChangeListener { _, isChecked ->
|
|
|
|
binding.switchToggle.setOnCheckedChangeListener { _, isChecked ->
|
|
|
|
@ -77,42 +81,60 @@ fun sourceConfigItemDelegate(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
fun sourceConfigItemDelegate2(
|
|
|
|
fun sourceConfigDraggableItemDelegate(
|
|
|
|
|
|
|
|
listener: SourceConfigListener,
|
|
|
|
listener: SourceConfigListener,
|
|
|
|
) = adapterDelegateViewBinding<SourceConfigItem.SourceItem, SourceConfigItem, ItemSourceConfigDraggableBinding>(
|
|
|
|
coil: ImageLoader,
|
|
|
|
{ layoutInflater, parent -> ItemSourceConfigDraggableBinding.inflate(layoutInflater, parent, false) },
|
|
|
|
lifecycleOwner: LifecycleOwner,
|
|
|
|
on = { item, _, _ -> item is SourceConfigItem.SourceItem && item.isDraggable },
|
|
|
|
) = adapterDelegateViewBinding<SourceConfigItem.SourceItem, SourceConfigItem, ItemSourceConfigBinding>(
|
|
|
|
|
|
|
|
{ layoutInflater, parent -> ItemSourceConfigBinding.inflate(layoutInflater, parent, false) },
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
val eventListener = object :
|
|
|
|
val eventListener = View.OnClickListener { v ->
|
|
|
|
View.OnClickListener,
|
|
|
|
when (v.id) {
|
|
|
|
View.OnTouchListener,
|
|
|
|
R.id.imageView_add -> listener.onItemEnabledChanged(item, true)
|
|
|
|
CompoundButton.OnCheckedChangeListener {
|
|
|
|
R.id.imageView_remove -> listener.onItemEnabledChanged(item, false)
|
|
|
|
override fun onClick(v: View?) = listener.onItemSettingsClick(item)
|
|
|
|
R.id.imageView_config -> listener.onItemSettingsClick(item)
|
|
|
|
|
|
|
|
|
|
|
|
override fun onTouch(v: View?, event: MotionEvent): Boolean {
|
|
|
|
|
|
|
|
return if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
|
|
|
|
|
|
|
listener.onDragHandleTouch(this@adapterDelegateViewBinding)
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.imageViewRemove.setOnClickListener(eventListener)
|
|
|
|
|
|
|
|
binding.imageViewAdd.setOnClickListener(eventListener)
|
|
|
|
|
|
|
|
binding.imageViewConfig.setOnClickListener(eventListener)
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
|
|
|
|
bind {
|
|
|
|
listener.onItemEnabledChanged(item, isChecked)
|
|
|
|
binding.textViewTitle.text = item.source.title
|
|
|
|
|
|
|
|
binding.imageViewAdd.isGone = item.isEnabled
|
|
|
|
|
|
|
|
binding.imageViewRemove.isVisible = item.isEnabled
|
|
|
|
|
|
|
|
binding.imageViewConfig.isVisible = item.isEnabled
|
|
|
|
|
|
|
|
binding.textViewDescription.textAndVisible = item.summary
|
|
|
|
|
|
|
|
val fallbackIcon = FaviconFallbackDrawable(context, item.source.name)
|
|
|
|
|
|
|
|
binding.imageViewIcon.newImageRequest(item.source.faviconUri(), item.source)?.run {
|
|
|
|
|
|
|
|
crossfade(context)
|
|
|
|
|
|
|
|
error(fallbackIcon)
|
|
|
|
|
|
|
|
placeholder(fallbackIcon)
|
|
|
|
|
|
|
|
fallback(fallbackIcon)
|
|
|
|
|
|
|
|
lifecycle(lifecycleOwner)
|
|
|
|
|
|
|
|
enqueueWith(coil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
binding.imageViewConfig.setOnClickListener(eventListener)
|
|
|
|
onViewRecycled {
|
|
|
|
binding.switchToggle.setOnCheckedChangeListener(eventListener)
|
|
|
|
binding.imageViewIcon.disposeImageRequest()
|
|
|
|
binding.imageViewHandle.setOnTouchListener(eventListener)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun sourceConfigTipDelegate(
|
|
|
|
|
|
|
|
listener: OnTipCloseListener<SourceConfigItem.Tip>
|
|
|
|
|
|
|
|
) = adapterDelegateViewBinding<SourceConfigItem.Tip, SourceConfigItem, ItemTipBinding>(
|
|
|
|
|
|
|
|
{ layoutInflater, parent -> ItemTipBinding.inflate(layoutInflater, parent, false) },
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.buttonClose.setOnClickListener {
|
|
|
|
|
|
|
|
listener.onCloseTip(item)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bind {
|
|
|
|
bind {
|
|
|
|
binding.textViewTitle.text = item.source.title
|
|
|
|
binding.imageViewIcon.setImageResource(item.iconResId)
|
|
|
|
binding.textViewDescription.text = item.summary ?: getString(R.string.various_languages)
|
|
|
|
binding.textView.setText(item.textResId)
|
|
|
|
binding.switchToggle.isChecked = item.isEnabled
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|