Cache shikimori user
parent
c2ba716916
commit
82efa8298d
@ -0,0 +1,52 @@
|
||||
package org.koitharu.kotatsu.shikimori.ui.selector.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.NO_ID
|
||||
import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration
|
||||
import org.koitharu.kotatsu.shikimori.data.model.ShikimoriManga
|
||||
import org.koitharu.kotatsu.utils.ext.getItem
|
||||
|
||||
class ShikiMangaSelectionDecoration(context: Context) : MangaSelectionDecoration(context) {
|
||||
|
||||
var checkedItemId: Long
|
||||
get() = selection.singleOrNull() ?: NO_ID
|
||||
set(value) {
|
||||
clearSelection()
|
||||
if (value != NO_ID) {
|
||||
selection.add(value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemId(parent: RecyclerView, child: View): Long {
|
||||
val holder = parent.getChildViewHolder(child) ?: return NO_ID
|
||||
val item = holder.getItem(ShikimoriManga::class.java) ?: return NO_ID
|
||||
return item.id
|
||||
}
|
||||
|
||||
override fun onDrawForeground(
|
||||
canvas: Canvas,
|
||||
parent: RecyclerView,
|
||||
child: View,
|
||||
bounds: RectF,
|
||||
state: RecyclerView.State,
|
||||
) {
|
||||
paint.color = strokeColor
|
||||
paint.style = Paint.Style.STROKE
|
||||
canvas.drawRoundRect(bounds, defaultRadius, defaultRadius, paint)
|
||||
checkIcon?.run {
|
||||
val offset = (bounds.height() - intrinsicHeight) / 2
|
||||
setBounds(
|
||||
(bounds.right - offset - intrinsicWidth).toInt(),
|
||||
(bounds.top + offset).toInt(),
|
||||
(bounds.right - offset).toInt(),
|
||||
(bounds.top + offset + intrinsicHeight).toInt(),
|
||||
)
|
||||
draw(canvas)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.json.JSONObject
|
||||
|
||||
private val TYPE_JSON = "application/json".toMediaType()
|
||||
|
||||
fun JSONObject.toRequestBody() = toString().toRequestBody(TYPE_JSON)
|
||||
Loading…
Reference in New Issue