Add a special view to replace descriptions for integrated and delegated sources!
As the integrated and delegated websites don't actually have descriptions, just info, I decided to make a special view for them! with all the info you need available to you in front of your face, there is now no need to go searching through the description! This is likely the most work I have put into 1 feature in the whole time I have been developing TachiyomiSY!
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package exh.ui.metadata
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.databinding.MetadataViewItemBinding
|
||||
import kotlin.math.floor
|
||||
|
||||
class MetadataViewAdapter(private var data: List<Pair<String, String>>) :
|
||||
RecyclerView.Adapter<MetadataViewAdapter.ViewHolder>() {
|
||||
|
||||
private lateinit var binding: MetadataViewItemBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MetadataViewAdapter.ViewHolder {
|
||||
binding = MetadataViewItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding.root)
|
||||
}
|
||||
|
||||
fun update(data: List<Pair<String, String>>) {
|
||||
this.data = data
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
// binds the data to the TextView in each cell
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(position)
|
||||
}
|
||||
|
||||
// total number of cells
|
||||
override fun getItemCount(): Int = data.size * 2
|
||||
|
||||
// stores and recycles views as they are scrolled off screen
|
||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind(position: Int) {
|
||||
if (data.isEmpty()) return
|
||||
val dataPosition = floor(position / 2F).toInt()
|
||||
binding.infoText.text = if (position % 2 == 0) data[dataPosition].first else data[dataPosition].second
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package exh.ui.metadata
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.databinding.MetadataViewControllerBinding
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.LewdSource.Companion.getLewdSource
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.metadata.base.FlatMetadata
|
||||
import exh.metadata.metadata.base.RaisedSearchMetadata
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class MetadataViewController : NucleusController<MetadataViewControllerBinding, MetadataViewPresenter> {
|
||||
constructor(manga: Manga?) : super(
|
||||
Bundle().apply {
|
||||
putLong(MangaController.MANGA_EXTRA, manga?.id ?: 0)
|
||||
}
|
||||
) {
|
||||
this.manga = manga
|
||||
if (manga != null) {
|
||||
source = Injekt.get<SourceManager>().getOrStub(manga.source)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(mangaId: Long) : this(
|
||||
Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking()
|
||||
)
|
||||
|
||||
@Suppress("unused")
|
||||
constructor(bundle: Bundle) : this(bundle.getLong(MangaController.MANGA_EXTRA))
|
||||
|
||||
var data = emptyList<Pair<String, String>>()
|
||||
|
||||
var adapter: MetadataViewAdapter? = null
|
||||
|
||||
var manga: Manga? = null
|
||||
private set
|
||||
var source: Source? = null
|
||||
private set
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return manga?.title
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
binding = MetadataViewControllerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun createPresenter(): MetadataViewPresenter {
|
||||
return MetadataViewPresenter(
|
||||
manga!!,
|
||||
source!!
|
||||
)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
|
||||
if (manga == null || source == null) return
|
||||
binding.recycler.layoutManager = GridLayoutManager(view.context, 2)
|
||||
adapter = MetadataViewAdapter(data)
|
||||
binding.recycler.adapter = adapter
|
||||
binding.recycler.setHasFixedSize(true)
|
||||
}
|
||||
|
||||
fun onNextMetaInfo(flatMetadata: FlatMetadata) {
|
||||
val thisSourceAsLewdSource = presenter.source.getLewdSource()
|
||||
if (thisSourceAsLewdSource != null) {
|
||||
presenter.meta = flatMetadata.raise(thisSourceAsLewdSource.metaClass)
|
||||
}
|
||||
}
|
||||
|
||||
fun onNextMangaInfo(meta: RaisedSearchMetadata?) {
|
||||
val context = view?.context ?: return
|
||||
data = meta?.getExtraInfoPairs(context) ?: emptyList()
|
||||
adapter?.update(data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package exh.ui.metadata
|
||||
|
||||
import android.os.Bundle
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import exh.metadata.metadata.base.FlatMetadata
|
||||
import exh.metadata.metadata.base.RaisedSearchMetadata
|
||||
import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class MetadataViewPresenter(
|
||||
val manga: Manga,
|
||||
val source: Source,
|
||||
val preferences: PreferencesHelper = Injekt.get(),
|
||||
private val db: DatabaseHelper = Injekt.get()
|
||||
) : BasePresenter<MetadataViewController>() {
|
||||
|
||||
var meta: RaisedSearchMetadata? = null
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
|
||||
getMangaMetaObservable().subscribeLatestCache({ view, flatMetadata -> if (flatMetadata != null) view.onNextMetaInfo(flatMetadata) else Timber.d("Invalid metadata") })
|
||||
|
||||
getMangaObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeLatestCache({ view, _ -> view.onNextMangaInfo(meta) })
|
||||
}
|
||||
|
||||
private fun getMangaObservable(): Observable<Manga> {
|
||||
return db.getManga(manga.url, manga.source).asRxObservable()
|
||||
}
|
||||
|
||||
private fun getMangaMetaObservable(): Observable<FlatMetadata?> {
|
||||
val mangaId = manga.id
|
||||
return if (mangaId != null) {
|
||||
db.getFlatMetadataForManga(mangaId).asRxObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
} else Observable.just(null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterEhBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import exh.metadata.EX_DATE_FORMAT
|
||||
import exh.metadata.humanReadableByteCount
|
||||
import exh.metadata.metadata.EHentaiSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import java.util.Date
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class EHentaiDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<EHentaiDescriptionAdapter.EHentaiDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterEhBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EHentaiDescriptionViewHolder {
|
||||
binding = DescriptionAdapterEhBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return EHentaiDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: EHentaiDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class EHentaiDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is EHentaiSearchMetadata) return
|
||||
|
||||
val genre = meta.genre
|
||||
if (genre != null) {
|
||||
val pair = when (genre) {
|
||||
"doujinshi" -> Pair("#fc4e4e", R.string.doujinshi)
|
||||
"manga" -> Pair("#e78c1a", R.string.manga)
|
||||
"artistcg" -> Pair("#dde500", R.string.artist_cg)
|
||||
"gamecg" -> Pair("#05bf0b", R.string.game_cg)
|
||||
"western" -> Pair("#14e723", R.string.western)
|
||||
"non-h" -> Pair("#08d7e2", R.string.non_h)
|
||||
"imageset" -> Pair("#5f5fff", R.string.image_set)
|
||||
"cosplay" -> Pair("#9755f5", R.string.cosplay)
|
||||
"asianporn" -> Pair("#fe93ff", R.string.asian_porn)
|
||||
"misc" -> Pair("#9e9e9e", R.string.misc)
|
||||
else -> Pair("", 0)
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
binding.genre.text = itemView.context.getString(pair.second)
|
||||
} else binding.genre.text = genre
|
||||
} else binding.genre.setText(R.string.unknown)
|
||||
|
||||
binding.visible.text = itemView.context.getString(R.string.is_visible, meta.visible ?: itemView.context.getString(R.string.unknown))
|
||||
|
||||
binding.favorites.text = (meta.favorites ?: 0).toString()
|
||||
val drawable = itemView.context.getDrawable(R.drawable.ic_favorite_24dp)
|
||||
drawable?.setTint(itemView.context.getResourceColor(R.attr.colorAccent))
|
||||
binding.favorites.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
|
||||
binding.whenPosted.text = EX_DATE_FORMAT.format(Date(meta.datePosted ?: 0))
|
||||
|
||||
binding.uploader.text = meta.uploader ?: itemView.context.getString(R.string.unknown)
|
||||
binding.size.text = humanReadableByteCount(meta.size ?: 0, true)
|
||||
binding.pages.text = itemView.context.getString(R.string.num_pages, meta.length ?: 0)
|
||||
val language = meta.language ?: itemView.context.getString(R.string.unknown)
|
||||
binding.language.text = if (meta.translated == true) {
|
||||
itemView.context.getString(R.string.language_translated, language)
|
||||
} else {
|
||||
language
|
||||
}
|
||||
|
||||
val ratingFloat = meta.averageRating?.toFloat()
|
||||
val name = when (((ratingFloat ?: 100F) * 2).roundToInt()) {
|
||||
0 -> R.string.rating0
|
||||
1 -> R.string.rating1
|
||||
2 -> R.string.rating2
|
||||
3 -> R.string.rating3
|
||||
4 -> R.string.rating4
|
||||
5 -> R.string.rating5
|
||||
6 -> R.string.rating6
|
||||
7 -> R.string.rating7
|
||||
8 -> R.string.rating8
|
||||
9 -> R.string.rating9
|
||||
10 -> R.string.rating10
|
||||
else -> R.string.no_rating
|
||||
}
|
||||
binding.ratingBar.rating = ratingFloat ?: 0F
|
||||
binding.rating.text = if (meta.ratingCount != null) {
|
||||
itemView.context.getString(R.string.rating_view, itemView.context.getString(name), (ratingFloat ?: 0F).toString(), meta.ratingCount ?: 0)
|
||||
} else {
|
||||
itemView.context.getString(R.string.rating_view_no_count, itemView.context.getString(name), (ratingFloat ?: 0F).toString())
|
||||
}
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapter8mBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.metadata.EightMusesSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class EightMusesDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<EightMusesDescriptionAdapter.EightMusesDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapter8mBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EightMusesDescriptionViewHolder {
|
||||
binding = DescriptionAdapter8mBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return EightMusesDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: EightMusesDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class EightMusesDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is EightMusesSearchMetadata) return
|
||||
|
||||
binding.title.text = meta.title ?: itemView.context.getString(R.string.unknown)
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterHbBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.metadata.HBrowseSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class HBrowseDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<HBrowseDescriptionAdapter.HBrowseDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterHbBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HBrowseDescriptionViewHolder {
|
||||
binding = DescriptionAdapterHbBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return HBrowseDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: HBrowseDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class HBrowseDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is HBrowseSearchMetadata) return
|
||||
|
||||
binding.pages.text = itemView.context.getString(R.string.num_pages, meta.length ?: 0)
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterHcBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.metadata.HentaiCafeSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class HentaiCafeDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<HentaiCafeDescriptionAdapter.HentaiCafeDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterHcBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HentaiCafeDescriptionViewHolder {
|
||||
binding = DescriptionAdapterHcBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return HentaiCafeDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: HentaiCafeDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class HentaiCafeDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is HentaiCafeSearchMetadata) return
|
||||
|
||||
binding.artist.text = meta.artist ?: itemView.context.getString(R.string.unknown)
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterHiBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.EX_DATE_FORMAT
|
||||
import exh.metadata.metadata.HitomiSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import java.util.Date
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class HitomiDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<HitomiDescriptionAdapter.HitomiDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterHiBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HitomiDescriptionViewHolder {
|
||||
binding = DescriptionAdapterHiBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return HitomiDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: HitomiDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class HitomiDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is HitomiSearchMetadata) return
|
||||
|
||||
val genre = meta.type
|
||||
if (genre != null) {
|
||||
val pair = when (genre) {
|
||||
"doujinshi" -> Pair("#fc4e4e", R.string.doujinshi)
|
||||
"manga" -> Pair("#e78c1a", R.string.manga)
|
||||
"artist CG" -> Pair("#dde500", R.string.artist_cg)
|
||||
"game CG" -> Pair("#05bf0b", R.string.game_cg)
|
||||
"western" -> Pair("#14e723", R.string.western)
|
||||
"non-H" -> Pair("#08d7e2", R.string.non_h)
|
||||
"image Set" -> Pair("#5f5fff", R.string.image_set)
|
||||
"cosplay" -> Pair("#9755f5", R.string.cosplay)
|
||||
"asian Porn" -> Pair("#fe93ff", R.string.asian_porn)
|
||||
"misc" -> Pair("#9e9e9e", R.string.misc)
|
||||
else -> Pair("", 0)
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
binding.genre.text = itemView.context.getString(pair.second)
|
||||
} else binding.genre.text = genre
|
||||
} else binding.genre.setText(R.string.unknown)
|
||||
|
||||
binding.whenPosted.text = EX_DATE_FORMAT.format(Date(meta.uploadDate ?: 0))
|
||||
binding.group.text = meta.group ?: itemView.context.getString(R.string.unknown)
|
||||
binding.language.text = meta.language ?: itemView.context.getString(R.string.unknown)
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterNhBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import exh.metadata.EX_DATE_FORMAT
|
||||
import exh.metadata.metadata.NHentaiSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import java.util.Date
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class NHentaiDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<NHentaiDescriptionAdapter.NHentaiDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterNhBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NHentaiDescriptionViewHolder {
|
||||
binding = DescriptionAdapterNhBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return NHentaiDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: NHentaiDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class NHentaiDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is NHentaiSearchMetadata) return
|
||||
|
||||
var category: String? = null
|
||||
meta.tags.filter { it.namespace == NHentaiSearchMetadata.NHENTAI_CATEGORIES_NAMESPACE }.let {
|
||||
if (it.isNotEmpty()) category = it.joinToString(transform = { it.name })
|
||||
}
|
||||
|
||||
if (category != null) {
|
||||
val pair = when (category) {
|
||||
"doujinshi" -> Pair("#fc4e4e", R.string.doujinshi)
|
||||
"manga" -> Pair("#e78c1a", R.string.manga)
|
||||
"artistcg" -> Pair("#dde500", R.string.artist_cg)
|
||||
"gamecg" -> Pair("#05bf0b", R.string.game_cg)
|
||||
"western" -> Pair("#14e723", R.string.western)
|
||||
"non-h" -> Pair("#08d7e2", R.string.non_h)
|
||||
"imageset" -> Pair("#5f5fff", R.string.image_set)
|
||||
"cosplay" -> Pair("#9755f5", R.string.cosplay)
|
||||
"asianporn" -> Pair("#fe93ff", R.string.asian_porn)
|
||||
"misc" -> Pair("#9e9e9e", R.string.misc)
|
||||
else -> Pair("", 0)
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
binding.genre.text = itemView.context.getString(pair.second)
|
||||
} else binding.genre.text = category
|
||||
} else binding.genre.setText(R.string.unknown)
|
||||
|
||||
meta.favoritesCount?.let {
|
||||
if (it == 0L) return@let
|
||||
binding.favorites.text = it.toString()
|
||||
|
||||
val drawable = itemView.context.getDrawable(R.drawable.ic_favorite_24dp)
|
||||
drawable?.setTint(itemView.context.getResourceColor(R.attr.colorAccent))
|
||||
|
||||
binding.favorites.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
}
|
||||
|
||||
binding.whenPosted.text = EX_DATE_FORMAT.format(Date((meta.uploadDate ?: 0) * 1000))
|
||||
|
||||
binding.pages.text = itemView.context.getString(R.string.num_pages, meta.pageImageTypes.size)
|
||||
@SuppressLint("SetTextI18n")
|
||||
binding.id.text = "#" + (meta.nhId ?: 0)
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterPeBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.metadata.PervEdenSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import java.util.Locale
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class PervEdenDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<PervEdenDescriptionAdapter.PervEdenDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterPeBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PervEdenDescriptionViewHolder {
|
||||
binding = DescriptionAdapterPeBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return PervEdenDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: PervEdenDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class PervEdenDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is PervEdenSearchMetadata) return
|
||||
|
||||
val genre = meta.type
|
||||
if (genre != null) {
|
||||
val pair = when (genre) {
|
||||
"Doujinshi" -> Pair("#fc4e4e", R.string.doujinshi)
|
||||
"Japanese Manga" -> Pair("#e78c1a", R.string.manga)
|
||||
"Korean Manhwa" -> Pair("#dde500", R.string.manhwa)
|
||||
"Chinese Manhua" -> Pair("#05bf0b", R.string.manhua)
|
||||
"Comic" -> Pair("#14e723", R.string.comic)
|
||||
else -> Pair("", 0)
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
binding.genre.text = itemView.context.getString(pair.second)
|
||||
} else binding.genre.text = genre
|
||||
} else binding.genre.setText(R.string.unknown)
|
||||
|
||||
val language = meta.lang
|
||||
binding.language.text = if (language != null) {
|
||||
val local = Locale(language)
|
||||
local.displayName
|
||||
} else itemView.context.getString(R.string.unknown)
|
||||
|
||||
val name = when (((meta.rating ?: 100F) * 2).roundToInt()) {
|
||||
0 -> R.string.rating0
|
||||
1 -> R.string.rating1
|
||||
2 -> R.string.rating2
|
||||
3 -> R.string.rating3
|
||||
4 -> R.string.rating4
|
||||
5 -> R.string.rating5
|
||||
6 -> R.string.rating6
|
||||
7 -> R.string.rating7
|
||||
8 -> R.string.rating8
|
||||
9 -> R.string.rating9
|
||||
10 -> R.string.rating10
|
||||
else -> R.string.no_rating
|
||||
}
|
||||
binding.ratingBar.rating = meta.rating ?: 0F
|
||||
binding.rating.text = itemView.context.getString(R.string.rating_view_no_count, itemView.context.getString(name), (meta.rating ?: 0F).toString())
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterPuBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import exh.metadata.metadata.PururinSearchMetadata
|
||||
import exh.metadata.metadata.PururinSearchMetadata.Companion.TAG_NAMESPACE_CATEGORY
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class PururinDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<PururinDescriptionAdapter.PururinDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterPuBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PururinDescriptionViewHolder {
|
||||
binding = DescriptionAdapterPuBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return PururinDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: PururinDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class PururinDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is PururinSearchMetadata) return
|
||||
|
||||
val genre = meta.tags.find { it.namespace == TAG_NAMESPACE_CATEGORY }
|
||||
if (genre != null) {
|
||||
val pair = when (genre.name) {
|
||||
"doujinshi" -> Pair("#fc4e4e", R.string.doujinshi)
|
||||
"manga" -> Pair("#e78c1a", R.string.manga)
|
||||
"artist-cg" -> Pair("#dde500", R.string.artist_cg)
|
||||
"game-cg" -> Pair("#05bf0b", R.string.game_cg)
|
||||
"artbook" -> Pair("#5f5fff", R.string.artbook)
|
||||
"webtoon" -> Pair("#5f5fff", R.string.webtoon)
|
||||
else -> Pair("", 0)
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
binding.genre.text = itemView.context.getString(pair.second)
|
||||
} else binding.genre.text = genre.name
|
||||
} else binding.genre.setText(R.string.unknown)
|
||||
|
||||
binding.uploader.text = meta.uploaderDisp ?: meta.uploader ?: ""
|
||||
binding.size.text = meta.fileSize ?: itemView.context.getString(R.string.unknown)
|
||||
binding.pages.text = itemView.context.getString(R.string.num_pages, meta.pages ?: 0)
|
||||
|
||||
val ratingFloat = meta.averageRating?.toFloat()
|
||||
val name = when (((ratingFloat ?: 100F) * 2).roundToInt()) {
|
||||
0 -> R.string.rating0
|
||||
1 -> R.string.rating1
|
||||
2 -> R.string.rating2
|
||||
3 -> R.string.rating3
|
||||
4 -> R.string.rating4
|
||||
5 -> R.string.rating5
|
||||
6 -> R.string.rating6
|
||||
7 -> R.string.rating7
|
||||
8 -> R.string.rating8
|
||||
9 -> R.string.rating9
|
||||
10 -> R.string.rating10
|
||||
else -> R.string.no_rating
|
||||
}
|
||||
binding.ratingBar.rating = ratingFloat ?: 0F
|
||||
binding.rating.text = if (meta.ratingCount != null) {
|
||||
itemView.context.getString(R.string.rating_view, itemView.context.getString(name), (ratingFloat ?: 0F).toString(), meta.ratingCount ?: 0)
|
||||
} else {
|
||||
itemView.context.getString(R.string.rating_view_no_count, itemView.context.getString(name), (ratingFloat ?: 0F).toString())
|
||||
}
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package exh.ui.metadata.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.DescriptionAdapterTsBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import exh.metadata.metadata.TsuminoSearchMetadata
|
||||
import exh.ui.metadata.MetadataViewController
|
||||
import java.util.Date
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class TsuminoDescriptionAdapter(
|
||||
private val controller: MangaController
|
||||
) :
|
||||
RecyclerView.Adapter<TsuminoDescriptionAdapter.TsuminoDescriptionViewHolder>() {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private lateinit var binding: DescriptionAdapterTsBinding
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TsuminoDescriptionViewHolder {
|
||||
binding = DescriptionAdapterTsBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return TsuminoDescriptionViewHolder(binding.root)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 1
|
||||
|
||||
override fun onBindViewHolder(holder: TsuminoDescriptionViewHolder, position: Int) {
|
||||
holder.bind()
|
||||
}
|
||||
|
||||
inner class TsuminoDescriptionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind() {
|
||||
val meta = controller.presenter.meta
|
||||
if (meta == null || meta !is TsuminoSearchMetadata) return
|
||||
|
||||
val genre = meta.category
|
||||
if (genre != null) {
|
||||
val pair = when (genre) {
|
||||
"Doujinshi" -> Pair("#fc4e4e", R.string.doujinshi)
|
||||
"Manga" -> Pair("#e78c1a", R.string.manga)
|
||||
"Artist CG" -> Pair("#dde500", R.string.artist_cg)
|
||||
"Game CG" -> Pair("#05bf0b", R.string.game_cg)
|
||||
"Video" -> Pair("#14e723", R.string.video)
|
||||
else -> Pair("", 0)
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
binding.genre.text = itemView.context.getString(pair.second)
|
||||
} else binding.genre.text = genre
|
||||
} else binding.genre.setText(R.string.unknown)
|
||||
|
||||
binding.favorites.text = (meta.favorites ?: 0).toString()
|
||||
val drawable = itemView.context.getDrawable(R.drawable.ic_favorite_24dp)
|
||||
drawable?.setTint(itemView.context.getResourceColor(R.attr.colorAccent))
|
||||
binding.favorites.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
|
||||
binding.whenPosted.text = TsuminoSearchMetadata.TSUMINO_DATE_FORMAT.format(Date(meta.uploadDate ?: 0))
|
||||
|
||||
binding.uploader.text = meta.uploader ?: itemView.context.getString(R.string.unknown)
|
||||
binding.pages.text = itemView.context.getString(R.string.num_pages, meta.length ?: 0)
|
||||
|
||||
val name = when (((meta.averageRating ?: 100F) * 2).roundToInt()) {
|
||||
0 -> R.string.rating0
|
||||
1 -> R.string.rating1
|
||||
2 -> R.string.rating2
|
||||
3 -> R.string.rating3
|
||||
4 -> R.string.rating4
|
||||
5 -> R.string.rating5
|
||||
6 -> R.string.rating6
|
||||
7 -> R.string.rating7
|
||||
8 -> R.string.rating8
|
||||
9 -> R.string.rating9
|
||||
10 -> R.string.rating10
|
||||
else -> R.string.no_rating
|
||||
}
|
||||
binding.ratingBar.rating = meta.averageRating ?: 0F
|
||||
binding.rating.text = if (meta.userRatings != null) {
|
||||
itemView.context.getString(R.string.rating_view, itemView.context.getString(name), (meta.averageRating ?: 0F).toString(), meta.userRatings ?: 0L)
|
||||
} else {
|
||||
itemView.context.getString(R.string.rating_view_no_count, itemView.context.getString(name), (meta.averageRating ?: 0F).toString())
|
||||
}
|
||||
|
||||
binding.moreInfo.clicks()
|
||||
.onEach {
|
||||
controller.router?.pushController(
|
||||
MetadataViewController(
|
||||
controller.manga
|
||||
).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user