mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-12 21:35:18 +01:00
Binding for the other manga details views
This commit is contained in:
parent
fa01471728
commit
e5405ac381
@ -7,6 +7,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
|
import eu.kanade.tachiyomi.databinding.ChapterSortBottomSheetBinding
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.view.invisible
|
import eu.kanade.tachiyomi.util.view.invisible
|
||||||
@ -27,13 +28,13 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
|
|||||||
|
|
||||||
private val presenter = controller.presenter
|
private val presenter = controller.presenter
|
||||||
|
|
||||||
|
private val binding = ChapterSortBottomSheetBinding.inflate(activity.layoutInflater)
|
||||||
init {
|
init {
|
||||||
// Use activity theme for this layout
|
// Use activity theme for this layout
|
||||||
val view = activity.layoutInflater.inflate(R.layout.chapter_sort_bottom_sheet, null)
|
setContentView(binding.root)
|
||||||
setContentView(view)
|
|
||||||
|
|
||||||
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
|
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
|
||||||
setEdgeToEdge(activity, view)
|
setEdgeToEdge(activity, binding.root)
|
||||||
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
|
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
|
||||||
sheetBehavior.peekHeight = 415.dpToPx + height
|
sheetBehavior.peekHeight = 415.dpToPx + height
|
||||||
|
|
||||||
|
@ -6,48 +6,49 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Track
|
import eu.kanade.tachiyomi.data.database.models.Track
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.databinding.TrackItemBinding
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder
|
import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder
|
||||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
import kotlinx.android.synthetic.main.track_item.*
|
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
|
|
||||||
class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
|
class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
|
||||||
|
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
private val binding = TrackItemBinding.bind(view)
|
||||||
private val dateFormat: DateFormat by lazy {
|
private val dateFormat: DateFormat by lazy {
|
||||||
preferences.dateFormat()
|
preferences.dateFormat()
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val listener = adapter.rowClickListener
|
val listener = adapter.rowClickListener
|
||||||
logo_container.setOnClickListener { listener.onLogoClick(bindingAdapterPosition) }
|
binding.logoContainer.setOnClickListener { listener.onLogoClick(bindingAdapterPosition) }
|
||||||
add_tracking.setOnClickListener { listener.onSetClick(bindingAdapterPosition) }
|
binding.addTracking.setOnClickListener { listener.onSetClick(bindingAdapterPosition) }
|
||||||
track_title.setOnClickListener { listener.onSetClick(bindingAdapterPosition) }
|
binding.trackTitle.setOnClickListener { listener.onSetClick(bindingAdapterPosition) }
|
||||||
track_remove.setOnClickListener { listener.onRemoveClick(bindingAdapterPosition) }
|
binding.trackRemove.setOnClickListener { listener.onRemoveClick(bindingAdapterPosition) }
|
||||||
track_status.setOnClickListener { listener.onStatusClick(bindingAdapterPosition) }
|
binding.trackStatus.setOnClickListener { listener.onStatusClick(bindingAdapterPosition) }
|
||||||
track_chapters.setOnClickListener { listener.onChaptersClick(bindingAdapterPosition) }
|
binding.trackChapters.setOnClickListener { listener.onChaptersClick(bindingAdapterPosition) }
|
||||||
score_container.setOnClickListener { listener.onScoreClick(bindingAdapterPosition) }
|
binding.scoreContainer.setOnClickListener { listener.onScoreClick(bindingAdapterPosition) }
|
||||||
track_start_date.setOnClickListener { listener.onStartDateClick(bindingAdapterPosition) }
|
binding.trackStartDate.setOnClickListener { listener.onStartDateClick(bindingAdapterPosition) }
|
||||||
track_finish_date.setOnClickListener { listener.onFinishDateClick(bindingAdapterPosition) }
|
binding.trackFinishDate.setOnClickListener { listener.onFinishDateClick(bindingAdapterPosition) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun bind(item: TrackItem) {
|
fun bind(item: TrackItem) {
|
||||||
val track = item.track
|
val track = item.track
|
||||||
track_logo.setImageResource(item.service.getLogo())
|
binding.trackLogo.setImageResource(item.service.getLogo())
|
||||||
logo_container.setBackgroundColor(item.service.getLogoColor())
|
binding.logoContainer.setBackgroundColor(item.service.getLogoColor())
|
||||||
logo_container.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
binding.logoContainer.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||||
bottomToBottom = if (track != null) divider.id else track_details.id
|
bottomToBottom = if (track != null) binding.divider.id else binding.trackDetails.id
|
||||||
}
|
}
|
||||||
val serviceName = track_logo.context.getString(item.service.nameRes())
|
val serviceName = binding.trackLogo.context.getString(item.service.nameRes())
|
||||||
track_logo.contentDescription = serviceName
|
binding.trackLogo.contentDescription = serviceName
|
||||||
track_group.visibleIf(track != null)
|
binding.trackGroup.visibleIf(track != null)
|
||||||
add_tracking.visibleIf(track == null)
|
binding.addTracking.visibleIf(track == null)
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
track_title.text = track.title
|
binding.trackTitle.text = track.title
|
||||||
with(track_chapters) {
|
with(binding.trackChapters) {
|
||||||
text = when {
|
text = when {
|
||||||
track.total_chapters > 0 && track.last_chapter_read == track.total_chapters -> context.getString(
|
track.total_chapters > 0 && track.last_chapter_read == track.total_chapters -> context.getString(
|
||||||
R.string.all_chapters_read
|
R.string.all_chapters_read
|
||||||
@ -65,15 +66,15 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val status = item.service.getStatus(track.status)
|
val status = item.service.getStatus(track.status)
|
||||||
if (status.isEmpty()) track_status.setText(R.string.unknown_status)
|
if (status.isEmpty()) binding.trackStatus.setText(R.string.unknown_status)
|
||||||
else track_status.text = item.service.getStatus(track.status)
|
else binding.trackStatus.text = item.service.getStatus(track.status)
|
||||||
track_score.text = if (track.score == 0f) "-" else item.service.displayScore(track)
|
binding.trackScore.text = if (track.score == 0f) "-" else item.service.displayScore(track)
|
||||||
track_score.setCompoundDrawablesWithIntrinsicBounds(0, 0, starIcon(track), 0)
|
binding.trackScore.setCompoundDrawablesWithIntrinsicBounds(0, 0, starIcon(track), 0)
|
||||||
date_group.visibleIf(item.service.supportsReadingDates)
|
binding.dateGroup.visibleIf(item.service.supportsReadingDates)
|
||||||
if (item.service.supportsReadingDates) {
|
if (item.service.supportsReadingDates) {
|
||||||
track_start_date.text =
|
binding.trackStartDate.text =
|
||||||
if (track.started_reading_date != 0L) dateFormat.format(track.started_reading_date) else "-"
|
if (track.started_reading_date != 0L) dateFormat.format(track.started_reading_date) else "-"
|
||||||
track_finish_date.text =
|
binding.trackFinishDate.text =
|
||||||
if (track.finished_reading_date != 0L) dateFormat.format(track.finished_reading_date) else "-"
|
if (track.finished_reading_date != 0L) dateFormat.format(track.finished_reading_date) else "-"
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
@ -81,7 +82,7 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun starIcon(track: Track): Int {
|
private fun starIcon(track: Track): Int {
|
||||||
return if (track.score == 0f || track_score.text.toString().toFloatOrNull() != null) {
|
return if (track.score == 0f || binding.trackScore.text.toString().toFloatOrNull() != null) {
|
||||||
R.drawable.ic_star_12dp
|
R.drawable.ic_star_12dp
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
@ -89,7 +90,7 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setProgress(enabled: Boolean) {
|
fun setProgress(enabled: Boolean) {
|
||||||
progress.visibleIf(enabled)
|
binding.progress.visibleIf(enabled)
|
||||||
track_logo.visibleIf(!enabled)
|
binding.trackLogo.visibleIf(!enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,12 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.track.TrackService
|
import eu.kanade.tachiyomi.data.track.TrackService
|
||||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||||
|
import eu.kanade.tachiyomi.databinding.TrackingBottomSheetBinding
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
|
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
|
||||||
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
|
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
|
||||||
import kotlinx.android.synthetic.main.tracking_bottom_sheet.*
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
||||||
@ -37,13 +37,14 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
|||||||
|
|
||||||
private var adapter: TrackAdapter? = null
|
private var adapter: TrackAdapter? = null
|
||||||
|
|
||||||
|
private val binding = TrackingBottomSheetBinding.inflate(activity.layoutInflater)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// Use activity theme for this layout
|
// Use activity theme for this layout
|
||||||
val view = activity.layoutInflater.inflate(R.layout.tracking_bottom_sheet, null)
|
setContentView(binding.root)
|
||||||
setContentView(view)
|
|
||||||
|
|
||||||
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
|
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
|
||||||
setEdgeToEdge(activity, view, 0)
|
setEdgeToEdge(activity, binding.root, 0)
|
||||||
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
|
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
|
||||||
sheetBehavior.peekHeight = 500.dpToPx + height
|
sheetBehavior.peekHeight = 500.dpToPx + height
|
||||||
|
|
||||||
@ -71,9 +72,9 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
adapter = TrackAdapter(this)
|
adapter = TrackAdapter(this)
|
||||||
track_recycler.layoutManager = LinearLayoutManager(context)
|
binding.trackRecycler.layoutManager = LinearLayoutManager(context)
|
||||||
track_recycler.adapter = adapter
|
binding.trackRecycler.adapter = adapter
|
||||||
track_recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)
|
binding.trackRecycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)
|
||||||
|
|
||||||
adapter?.items = presenter.trackList
|
adapter?.items = presenter.trackList
|
||||||
}
|
}
|
||||||
@ -100,13 +101,13 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
|||||||
|
|
||||||
fun onRefreshDone() {
|
fun onRefreshDone() {
|
||||||
for (i in adapter!!.items.indices) {
|
for (i in adapter!!.items.indices) {
|
||||||
(track_recycler.findViewHolderForAdapterPosition(i) as? TrackHolder)?.setProgress(false)
|
(binding.trackRecycler.findViewHolderForAdapterPosition(i) as? TrackHolder)?.setProgress(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRefreshError(error: Throwable) {
|
fun onRefreshError(error: Throwable) {
|
||||||
for (i in adapter!!.items.indices) {
|
for (i in adapter!!.items.indices) {
|
||||||
(track_recycler.findViewHolderForAdapterPosition(i) as? TrackHolder)?.setProgress(false)
|
(binding.trackRecycler.findViewHolderForAdapterPosition(i) as? TrackHolder)?.setProgress(false)
|
||||||
}
|
}
|
||||||
activity.toast(error.message)
|
activity.toast(error.message)
|
||||||
}
|
}
|
||||||
@ -223,13 +224,13 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun refreshItem(index: Int) {
|
fun refreshItem(index: Int) {
|
||||||
(track_recycler.findViewHolderForAdapterPosition(index) as? TrackHolder)?.setProgress(true)
|
(binding.trackRecycler.findViewHolderForAdapterPosition(index) as? TrackHolder)?.setProgress(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshTrack(item: TrackService?) {
|
fun refreshTrack(item: TrackService?) {
|
||||||
val index = adapter?.indexOf(item) ?: -1
|
val index = adapter?.indexOf(item) ?: -1
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
(track_recycler.findViewHolderForAdapterPosition(index) as? TrackHolder)
|
(binding.trackRecycler.findViewHolderForAdapterPosition(index) as? TrackHolder)
|
||||||
?.setProgress(true)
|
?.setProgress(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user