Shikimori interaction implementation
parent
0695103589
commit
ec89ba0155
@ -0,0 +1,25 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
class Migration11To12 : Migration(11, 12) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS `scrobblings` (
|
||||||
|
`scrobbler` INTEGER NOT NULL,
|
||||||
|
`id` INTEGER NOT NULL,
|
||||||
|
`manga_id` INTEGER NOT NULL,
|
||||||
|
`target_id` INTEGER NOT NULL,
|
||||||
|
`status` TEXT,
|
||||||
|
`chapter` INTEGER NOT NULL,
|
||||||
|
`comment` TEXT,
|
||||||
|
`rating` REAL NOT NULL,
|
||||||
|
PRIMARY KEY(`scrobbler`, `id`, `manga_id`)
|
||||||
|
)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,119 @@
|
|||||||
|
package org.koitharu.kotatsu.details.ui.scrobbling
|
||||||
|
|
||||||
|
import android.app.ActivityOptions
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.RatingBar
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import coil.ImageLoader
|
||||||
|
import coil.request.ImageRequest
|
||||||
|
import coil.size.Scale
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
||||||
|
import org.koitharu.kotatsu.databinding.SheetScrobblingBinding
|
||||||
|
import org.koitharu.kotatsu.details.ui.DetailsViewModel
|
||||||
|
import org.koitharu.kotatsu.image.ui.ImageActivity
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingStatus
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
|
||||||
|
class ScrobblingInfoBottomSheet :
|
||||||
|
BaseBottomSheet<SheetScrobblingBinding>(),
|
||||||
|
AdapterView.OnItemSelectedListener,
|
||||||
|
RatingBar.OnRatingBarChangeListener,
|
||||||
|
View.OnClickListener {
|
||||||
|
|
||||||
|
private val viewModel by sharedViewModel<DetailsViewModel>()
|
||||||
|
private val coil by inject<ImageLoader>(mode = LazyThreadSafetyMode.NONE)
|
||||||
|
|
||||||
|
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetScrobblingBinding {
|
||||||
|
return SheetScrobblingBinding.inflate(inflater, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
viewModel.scrobblingInfo.observe(viewLifecycleOwner, ::onScrobblingInfoChanged)
|
||||||
|
viewModel.onError.observe(viewLifecycleOwner) {
|
||||||
|
Toast.makeText(view.context, it.getDisplayMessage(view.resources), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.spinnerStatus.onItemSelectedListener = this
|
||||||
|
binding.ratingBar.onRatingBarChangeListener = this
|
||||||
|
binding.buttonOpen.setOnClickListener(this)
|
||||||
|
binding.imageViewCover.setOnClickListener(this)
|
||||||
|
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
viewModel.updateScrobbling(
|
||||||
|
rating = binding.ratingBar.rating / binding.ratingBar.numStars,
|
||||||
|
status = enumValues<ScrobblingStatus>().getOrNull(position),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
||||||
|
|
||||||
|
override fun onRatingChanged(ratingBar: RatingBar, rating: Float, fromUser: Boolean) {
|
||||||
|
if (fromUser) {
|
||||||
|
viewModel.updateScrobbling(
|
||||||
|
rating = rating / ratingBar.numStars,
|
||||||
|
status = enumValues<ScrobblingStatus>().getOrNull(binding.spinnerStatus.selectedItemPosition),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View) {
|
||||||
|
when (v.id) {
|
||||||
|
R.id.button_open -> {
|
||||||
|
val url = viewModel.scrobblingInfo.value?.externalUrl ?: return
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||||
|
startActivity(
|
||||||
|
Intent.createChooser(intent, getString(R.string.open_in_browser))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
R.id.imageView_cover -> {
|
||||||
|
val coverUrl = viewModel.scrobblingInfo.value?.coverUrl ?: return
|
||||||
|
val options = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.width, v.height)
|
||||||
|
startActivity(ImageActivity.newIntent(v.context, coverUrl), options.toBundle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onScrobblingInfoChanged(scrobbling: ScrobblingInfo?) {
|
||||||
|
if (scrobbling == null) {
|
||||||
|
dismissAllowingStateLoss()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
binding.textViewTitle.text = scrobbling.title
|
||||||
|
binding.ratingBar.rating = scrobbling.rating * binding.ratingBar.numStars
|
||||||
|
binding.textViewDescription.text = scrobbling.description
|
||||||
|
binding.spinnerStatus.setSelection(scrobbling.status?.ordinal ?: -1)
|
||||||
|
ImageRequest.Builder(context ?: return)
|
||||||
|
.target(binding.imageViewCover)
|
||||||
|
.data(scrobbling.coverUrl)
|
||||||
|
.crossfade(true)
|
||||||
|
.lifecycle(viewLifecycleOwner)
|
||||||
|
.placeholder(R.drawable.ic_placeholder)
|
||||||
|
.fallback(R.drawable.ic_placeholder)
|
||||||
|
.error(R.drawable.ic_placeholder)
|
||||||
|
.scale(Scale.FILL)
|
||||||
|
.enqueueWith(coil)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val TAG = "ScrobblingInfoBottomSheet"
|
||||||
|
|
||||||
|
fun show(fm: FragmentManager) = ScrobblingInfoBottomSheet().show(fm, TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.data
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class ScrobblingDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM scrobblings WHERE scrobbler = :scrobbler AND manga_id = :mangaId")
|
||||||
|
abstract suspend fun find(scrobbler: Int, mangaId: Long): ScrobblingEntity?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM scrobblings WHERE scrobbler = :scrobbler AND manga_id = :mangaId")
|
||||||
|
abstract fun observe(scrobbler: Int, mangaId: Long): Flow<ScrobblingEntity?>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract suspend fun insert(entity: ScrobblingEntity)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
abstract suspend fun update(entity: ScrobblingEntity)
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.data
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
tableName = "scrobblings",
|
||||||
|
primaryKeys = ["scrobbler", "id", "manga_id"],
|
||||||
|
)
|
||||||
|
class ScrobblingEntity(
|
||||||
|
@ColumnInfo(name = "scrobbler") val scrobbler: Int,
|
||||||
|
@ColumnInfo(name = "id") val id: Int,
|
||||||
|
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
||||||
|
@ColumnInfo(name = "target_id") val targetId: Long,
|
||||||
|
@ColumnInfo(name = "status") val status: String?,
|
||||||
|
@ColumnInfo(name = "chapter") val chapter: Int,
|
||||||
|
@ColumnInfo(name = "comment") val comment: String?,
|
||||||
|
@ColumnInfo(name = "rating") val rating: Float,
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun copy(
|
||||||
|
status: String?,
|
||||||
|
comment: String?,
|
||||||
|
rating: Float,
|
||||||
|
) = ScrobblingEntity(
|
||||||
|
scrobbler = scrobbler,
|
||||||
|
id = id,
|
||||||
|
mangaId = mangaId,
|
||||||
|
targetId = targetId,
|
||||||
|
status = status,
|
||||||
|
chapter = chapter,
|
||||||
|
comment = comment,
|
||||||
|
rating = rating,
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.domain
|
||||||
|
|
||||||
|
import androidx.collection.LongSparseArray
|
||||||
|
import androidx.collection.getOrElse
|
||||||
|
import androidx.core.text.parseAsHtml
|
||||||
|
import java.util.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.scrobbling.data.ScrobblingEntity
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.*
|
||||||
|
import org.koitharu.kotatsu.utils.ext.findKey
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
|
abstract class Scrobbler(
|
||||||
|
protected val db: MangaDatabase,
|
||||||
|
val scrobblerService: ScrobblerService,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val infoCache = LongSparseArray<ScrobblerMangaInfo>()
|
||||||
|
protected val statuses = EnumMap<ScrobblingStatus, String>(ScrobblingStatus::class.java)
|
||||||
|
|
||||||
|
abstract val isAvailable: Boolean
|
||||||
|
|
||||||
|
abstract suspend fun findManga(query: String, offset: Int): List<ScrobblerManga>
|
||||||
|
|
||||||
|
abstract suspend fun linkManga(mangaId: Long, targetId: Long)
|
||||||
|
|
||||||
|
abstract suspend fun scrobble(mangaId: Long, chapter: MangaChapter)
|
||||||
|
|
||||||
|
suspend fun getScrobblingInfoOrNull(mangaId: Long): ScrobblingInfo? {
|
||||||
|
val entity = db.scrobblingDao.find(scrobblerService.id, mangaId) ?: return null
|
||||||
|
return entity.toScrobblingInfo(mangaId)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract suspend fun updateScrobblingInfo(mangaId: Long, rating: Float, status: ScrobblingStatus?, comment: String?)
|
||||||
|
|
||||||
|
fun observeScrobblingInfo(mangaId: Long): Flow<ScrobblingInfo?> {
|
||||||
|
return db.scrobblingDao.observe(scrobblerService.id, mangaId)
|
||||||
|
.map { it?.toScrobblingInfo(mangaId) }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract suspend fun getMangaInfo(id: Long): ScrobblerMangaInfo
|
||||||
|
|
||||||
|
private suspend fun ScrobblingEntity.toScrobblingInfo(mangaId: Long): ScrobblingInfo? {
|
||||||
|
val mangaInfo = infoCache.getOrElse(targetId) {
|
||||||
|
runCatching {
|
||||||
|
getMangaInfo(targetId)
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
|
}.onSuccess {
|
||||||
|
infoCache.put(targetId, it)
|
||||||
|
}.getOrNull() ?: return null
|
||||||
|
}
|
||||||
|
return ScrobblingInfo(
|
||||||
|
scrobbler = scrobblerService,
|
||||||
|
mangaId = mangaId,
|
||||||
|
targetId = targetId,
|
||||||
|
status = statuses.findKey(status),
|
||||||
|
chapter = chapter,
|
||||||
|
comment = comment,
|
||||||
|
rating = rating,
|
||||||
|
title = mangaInfo.name,
|
||||||
|
coverUrl = mangaInfo.cover,
|
||||||
|
description = mangaInfo.descriptionHtml.parseAsHtml(),
|
||||||
|
externalUrl = mangaInfo.url,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun Scrobbler.tryScrobble(mangaId: Long, chapter: MangaChapter): Boolean {
|
||||||
|
return runCatching {
|
||||||
|
scrobble(mangaId, chapter)
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
|
}.isSuccess
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.domain.model
|
||||||
|
|
||||||
|
class ScrobblerMangaInfo(
|
||||||
|
val id: Long,
|
||||||
|
val name: String,
|
||||||
|
val cover: String,
|
||||||
|
val url: String,
|
||||||
|
val descriptionHtml: String,
|
||||||
|
)
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.domain.model
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
enum class ScrobblerService(
|
||||||
|
val id: Int,
|
||||||
|
@StringRes val titleResId: Int,
|
||||||
|
@DrawableRes val iconResId: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
|
SHIKIMORI(1, R.string.shikimori, R.drawable.ic_shikimori)
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.domain.model
|
||||||
|
|
||||||
|
class ScrobblingInfo(
|
||||||
|
val scrobbler: ScrobblerService,
|
||||||
|
val mangaId: Long,
|
||||||
|
val targetId: Long,
|
||||||
|
val status: ScrobblingStatus?,
|
||||||
|
val chapter: Int,
|
||||||
|
val comment: String?,
|
||||||
|
val rating: Float,
|
||||||
|
val title: String,
|
||||||
|
val coverUrl: String,
|
||||||
|
val description: CharSequence?,
|
||||||
|
val externalUrl: String,
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as ScrobblingInfo
|
||||||
|
|
||||||
|
if (scrobbler != other.scrobbler) return false
|
||||||
|
if (mangaId != other.mangaId) return false
|
||||||
|
if (targetId != other.targetId) return false
|
||||||
|
if (status != other.status) return false
|
||||||
|
if (chapter != other.chapter) return false
|
||||||
|
if (comment != other.comment) return false
|
||||||
|
if (rating != other.rating) return false
|
||||||
|
if (title != other.title) return false
|
||||||
|
if (coverUrl != other.coverUrl) return false
|
||||||
|
if (description != other.description) return false
|
||||||
|
if (externalUrl != other.externalUrl) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = scrobbler.hashCode()
|
||||||
|
result = 31 * result + mangaId.hashCode()
|
||||||
|
result = 31 * result + targetId.hashCode()
|
||||||
|
result = 31 * result + (status?.hashCode() ?: 0)
|
||||||
|
result = 31 * result + chapter
|
||||||
|
result = 31 * result + (comment?.hashCode() ?: 0)
|
||||||
|
result = 31 * result + rating.hashCode()
|
||||||
|
result = 31 * result + title.hashCode()
|
||||||
|
result = 31 * result + coverUrl.hashCode()
|
||||||
|
result = 31 * result + (description?.hashCode() ?: 0)
|
||||||
|
result = 31 * result + externalUrl.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.domain.model
|
||||||
|
|
||||||
|
enum class ScrobblingStatus {
|
||||||
|
|
||||||
|
PLANNED,
|
||||||
|
READING,
|
||||||
|
RE_READING,
|
||||||
|
COMPLETED,
|
||||||
|
ON_HOLD,
|
||||||
|
DROPPED,
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.shikimori
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||||
|
import org.koin.dsl.bind
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.Scrobbler
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriAuthenticator
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriInterceptor
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriRepository
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriStorage
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.domain.ShikimoriScrobbler
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.ui.ShikimoriSettingsViewModel
|
||||||
|
import org.koitharu.kotatsu.scrobbling.ui.selector.ScrobblingSelectorViewModel
|
||||||
|
|
||||||
|
val shikimoriModule
|
||||||
|
get() = module {
|
||||||
|
single { ShikimoriStorage(androidContext()) }
|
||||||
|
factory {
|
||||||
|
val okHttp = OkHttpClient.Builder().apply {
|
||||||
|
authenticator(ShikimoriAuthenticator(get(), ::get))
|
||||||
|
addInterceptor(ShikimoriInterceptor(get()))
|
||||||
|
}.build()
|
||||||
|
ShikimoriRepository(okHttp, get(), get())
|
||||||
|
}
|
||||||
|
factory { ShikimoriScrobbler(get(), get()) } bind Scrobbler::class
|
||||||
|
viewModel { params ->
|
||||||
|
ShikimoriSettingsViewModel(get(), params.getOrNull())
|
||||||
|
}
|
||||||
|
viewModel { params -> ScrobblingSelectorViewModel(params[0], get()) }
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.shikimori.data
|
package org.koitharu.kotatsu.scrobbling.shikimori.data
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import okhttp3.Authenticator
|
import okhttp3.Authenticator
|
||||||
@ -0,0 +1,196 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.shikimori.data
|
||||||
|
|
||||||
|
import okhttp3.FormBody
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
|
import org.koitharu.kotatsu.parsers.util.json.getStringOrNull
|
||||||
|
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
||||||
|
import org.koitharu.kotatsu.parsers.util.parseJson
|
||||||
|
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
||||||
|
import org.koitharu.kotatsu.parsers.util.toAbsoluteUrl
|
||||||
|
import org.koitharu.kotatsu.scrobbling.data.ScrobblingEntity
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerManga
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerMangaInfo
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerService
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.model.ShikimoriUser
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toRequestBody
|
||||||
|
|
||||||
|
private const val CLIENT_ID = "Mw6F0tPEOgyV7F9U9Twg50Q8SndMY7hzIOfXg0AX_XU"
|
||||||
|
private const val CLIENT_SECRET = "euBMt1GGRSDpVIFQVPxZrO7Kh6X4gWyv0dABuj4B-M8"
|
||||||
|
private const val REDIRECT_URI = "kotatsu://shikimori-auth"
|
||||||
|
private const val BASE_URL = "https://shikimori.one/"
|
||||||
|
private const val MANGA_PAGE_SIZE = 10
|
||||||
|
|
||||||
|
class ShikimoriRepository(
|
||||||
|
private val okHttp: OkHttpClient,
|
||||||
|
private val storage: ShikimoriStorage,
|
||||||
|
private val db: MangaDatabase,
|
||||||
|
) {
|
||||||
|
|
||||||
|
val oauthUrl: String
|
||||||
|
get() = "${BASE_URL}oauth/authorize?client_id=$CLIENT_ID&" +
|
||||||
|
"redirect_uri=$REDIRECT_URI&response_type=code&scope="
|
||||||
|
|
||||||
|
val isAuthorized: Boolean
|
||||||
|
get() = storage.accessToken != null
|
||||||
|
|
||||||
|
suspend fun authorize(code: String?) {
|
||||||
|
val body = FormBody.Builder()
|
||||||
|
body.add("grant_type", "authorization_code")
|
||||||
|
body.add("client_id", CLIENT_ID)
|
||||||
|
body.add("client_secret", CLIENT_SECRET)
|
||||||
|
if (code != null) {
|
||||||
|
body.add("redirect_uri", REDIRECT_URI)
|
||||||
|
body.add("code", code)
|
||||||
|
} else {
|
||||||
|
body.add("refresh_token", checkNotNull(storage.refreshToken))
|
||||||
|
}
|
||||||
|
val request = Request.Builder()
|
||||||
|
.post(body.build())
|
||||||
|
.url("${BASE_URL}oauth/token")
|
||||||
|
val response = okHttp.newCall(request.build()).await().parseJson()
|
||||||
|
storage.accessToken = response.getString("access_token")
|
||||||
|
storage.refreshToken = response.getString("refresh_token")
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun loadUser(): ShikimoriUser {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.get()
|
||||||
|
.url("${BASE_URL}api/users/whoami")
|
||||||
|
val response = okHttp.newCall(request.build()).await().parseJson()
|
||||||
|
return ShikimoriUser(response).also { storage.user = it }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCachedUser(): ShikimoriUser? {
|
||||||
|
return storage.user
|
||||||
|
}
|
||||||
|
|
||||||
|
fun logout() {
|
||||||
|
storage.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun findManga(query: String, offset: Int): List<ScrobblerManga> {
|
||||||
|
val page = offset / MANGA_PAGE_SIZE
|
||||||
|
val pageOffset = offset % MANGA_PAGE_SIZE
|
||||||
|
val url = BASE_URL.toHttpUrl().newBuilder()
|
||||||
|
.addPathSegment("api")
|
||||||
|
.addPathSegment("mangas")
|
||||||
|
.addEncodedQueryParameter("page", (page + 1).toString())
|
||||||
|
.addEncodedQueryParameter("limit", MANGA_PAGE_SIZE.toString())
|
||||||
|
.addEncodedQueryParameter("censored", false.toString())
|
||||||
|
.addQueryParameter("search", query)
|
||||||
|
.build()
|
||||||
|
val request = Request.Builder().url(url).get().build()
|
||||||
|
val response = okHttp.newCall(request).await().parseJsonArray()
|
||||||
|
val list = response.mapJSON { ScrobblerManga(it) }
|
||||||
|
return if (pageOffset != 0) list.drop(pageOffset) else list
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun createRate(mangaId: Long, shikiMangaId: Long) {
|
||||||
|
val user = getCachedUser() ?: loadUser()
|
||||||
|
val payload = JSONObject()
|
||||||
|
payload.put(
|
||||||
|
"user_rate",
|
||||||
|
JSONObject().apply {
|
||||||
|
put("target_id", shikiMangaId)
|
||||||
|
put("target_type", "Manga")
|
||||||
|
put("user_id", user.id)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val url = BASE_URL.toHttpUrl().newBuilder()
|
||||||
|
.addPathSegment("api")
|
||||||
|
.addPathSegment("v2")
|
||||||
|
.addPathSegment("user_rates")
|
||||||
|
.build()
|
||||||
|
val request = Request.Builder().url(url).post(payload.toRequestBody()).build()
|
||||||
|
val response = okHttp.newCall(request).await().parseJson()
|
||||||
|
saveRate(response, mangaId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun updateRate(rateId: Int, mangaId: Long, chapter: MangaChapter) {
|
||||||
|
val payload = JSONObject()
|
||||||
|
payload.put(
|
||||||
|
"user_rate",
|
||||||
|
JSONObject().apply {
|
||||||
|
put("chapters", chapter.number)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val url = BASE_URL.toHttpUrl().newBuilder()
|
||||||
|
.addPathSegment("api")
|
||||||
|
.addPathSegment("v2")
|
||||||
|
.addPathSegment("user_rates")
|
||||||
|
.addPathSegment(rateId.toString())
|
||||||
|
.build()
|
||||||
|
val request = Request.Builder().url(url).patch(payload.toRequestBody()).build()
|
||||||
|
val response = okHttp.newCall(request).await().parseJson()
|
||||||
|
saveRate(response, mangaId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun updateRate(rateId: Int, mangaId: Long, rating: Float, status: String?, comment: String?) {
|
||||||
|
val payload = JSONObject()
|
||||||
|
payload.put(
|
||||||
|
"user_rate",
|
||||||
|
JSONObject().apply {
|
||||||
|
put("score", rating.toString())
|
||||||
|
if (comment != null) {
|
||||||
|
put("text", comment)
|
||||||
|
}
|
||||||
|
if (status != null) {
|
||||||
|
put("status", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val url = BASE_URL.toHttpUrl().newBuilder()
|
||||||
|
.addPathSegment("api")
|
||||||
|
.addPathSegment("v2")
|
||||||
|
.addPathSegment("user_rates")
|
||||||
|
.addPathSegment(rateId.toString())
|
||||||
|
.build()
|
||||||
|
val request = Request.Builder().url(url).patch(payload.toRequestBody()).build()
|
||||||
|
val response = okHttp.newCall(request).await().parseJson()
|
||||||
|
saveRate(response, mangaId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getMangaInfo(id: Long): ScrobblerMangaInfo {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.get()
|
||||||
|
.url("${BASE_URL}api/mangas/$id")
|
||||||
|
val response = okHttp.newCall(request.build()).await().parseJson()
|
||||||
|
return ScrobblerMangaInfo(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun saveRate(json: JSONObject, mangaId: Long) {
|
||||||
|
val entity = ScrobblingEntity(
|
||||||
|
scrobbler = ScrobblerService.SHIKIMORI.id,
|
||||||
|
id = json.getInt("id"),
|
||||||
|
mangaId = mangaId,
|
||||||
|
targetId = json.getLong("target_id"),
|
||||||
|
status = json.getString("status"),
|
||||||
|
chapter = json.getInt("chapters"),
|
||||||
|
comment = json.getString("text"),
|
||||||
|
rating = json.getDouble("score").toFloat() / 10f,
|
||||||
|
)
|
||||||
|
db.scrobblingDao.insert(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ScrobblerManga(json: JSONObject) = ScrobblerManga(
|
||||||
|
id = json.getLong("id"),
|
||||||
|
name = json.getString("name"),
|
||||||
|
altName = json.getStringOrNull("russian"),
|
||||||
|
cover = json.getJSONObject("image").getString("preview").toAbsoluteUrl("shikimori.one"),
|
||||||
|
url = json.getString("url").toAbsoluteUrl("shikimori.one"),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun ScrobblerMangaInfo(json: JSONObject) = ScrobblerMangaInfo(
|
||||||
|
id = json.getLong("id"),
|
||||||
|
name = json.getString("name"),
|
||||||
|
cover = json.getJSONObject("image").getString("preview").toAbsoluteUrl("shikimori.one"),
|
||||||
|
url = json.getString("url").toAbsoluteUrl("shikimori.one"),
|
||||||
|
descriptionHtml = json.getString("description_html"),
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.shikimori.data
|
package org.koitharu.kotatsu.scrobbling.shikimori.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.koitharu.kotatsu.shikimori.data.model.ShikimoriUser
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.model.ShikimoriUser
|
||||||
|
|
||||||
private const val PREF_NAME = "shikimori"
|
private const val PREF_NAME = "shikimori"
|
||||||
private const val KEY_ACCESS_TOKEN = "access_token"
|
private const val KEY_ACCESS_TOKEN = "access_token"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.shikimori.data.model
|
package org.koitharu.kotatsu.scrobbling.shikimori.data.model
|
||||||
|
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.shikimori.domain
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.Scrobbler
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerManga
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerMangaInfo
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerService
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingStatus
|
||||||
|
import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriRepository
|
||||||
|
|
||||||
|
private const val RATING_MAX = 10f
|
||||||
|
|
||||||
|
class ShikimoriScrobbler(
|
||||||
|
private val repository: ShikimoriRepository,
|
||||||
|
db: MangaDatabase,
|
||||||
|
) : Scrobbler(db, ScrobblerService.SHIKIMORI) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
statuses[ScrobblingStatus.PLANNED] = "planned"
|
||||||
|
statuses[ScrobblingStatus.READING] = "watching"
|
||||||
|
statuses[ScrobblingStatus.RE_READING] = "rewatching"
|
||||||
|
statuses[ScrobblingStatus.COMPLETED] = "completed"
|
||||||
|
statuses[ScrobblingStatus.ON_HOLD] = "on_hold"
|
||||||
|
statuses[ScrobblingStatus.DROPPED] = "dropped"
|
||||||
|
}
|
||||||
|
|
||||||
|
override val isAvailable: Boolean
|
||||||
|
get() = repository.isAuthorized
|
||||||
|
|
||||||
|
override suspend fun findManga(query: String, offset: Int): List<ScrobblerManga> {
|
||||||
|
return repository.findManga(query, offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun linkManga(mangaId: Long, targetId: Long) {
|
||||||
|
repository.createRate(mangaId, targetId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun scrobble(mangaId: Long, chapter: MangaChapter) {
|
||||||
|
val entity = db.scrobblingDao.find(scrobblerService.id, mangaId) ?: return
|
||||||
|
repository.updateRate(entity.id, entity.mangaId, chapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateScrobblingInfo(
|
||||||
|
mangaId: Long,
|
||||||
|
rating: Float,
|
||||||
|
status: ScrobblingStatus?,
|
||||||
|
comment: String?,
|
||||||
|
) {
|
||||||
|
val entity = db.scrobblingDao.find(scrobblerService.id, mangaId)
|
||||||
|
requireNotNull(entity) { "Scrobbling info for manga $mangaId not found" }
|
||||||
|
repository.updateRate(
|
||||||
|
rateId = entity.id,
|
||||||
|
mangaId = entity.mangaId,
|
||||||
|
rating = rating * RATING_MAX,
|
||||||
|
status = statuses[status],
|
||||||
|
comment = comment,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getMangaInfo(id: Long): ScrobblerMangaInfo {
|
||||||
|
return repository.getMangaInfo(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,155 @@
|
|||||||
|
package org.koitharu.kotatsu.scrobbling.ui.selector
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.*
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.widget.SearchView
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import org.koin.android.ext.android.get
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
|
import org.koin.core.parameter.parametersOf
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.PaginationScrollListener
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
|
import org.koitharu.kotatsu.databinding.SheetScrobblingSelectorBinding
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblerManga
|
||||||
|
import org.koitharu.kotatsu.scrobbling.ui.selector.adapter.ShikiMangaSelectionDecoration
|
||||||
|
import org.koitharu.kotatsu.scrobbling.ui.selector.adapter.ShikimoriSelectorAdapter
|
||||||
|
import org.koitharu.kotatsu.utils.BottomSheetToolbarController
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
|
||||||
|
class ScrobblingSelectorBottomSheet :
|
||||||
|
BaseBottomSheet<SheetScrobblingSelectorBinding>(),
|
||||||
|
OnListItemClickListener<ScrobblerManga>,
|
||||||
|
PaginationScrollListener.Callback,
|
||||||
|
View.OnClickListener,
|
||||||
|
MenuItem.OnActionExpandListener,
|
||||||
|
SearchView.OnQueryTextListener,
|
||||||
|
DialogInterface.OnKeyListener {
|
||||||
|
|
||||||
|
private val viewModel by viewModel<ScrobblingSelectorViewModel> {
|
||||||
|
parametersOf(requireNotNull(requireArguments().getParcelable<ParcelableManga>(MangaIntent.KEY_MANGA)).manga)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetScrobblingSelectorBinding {
|
||||||
|
return SheetScrobblingSelectorBinding.inflate(inflater, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
return super.onCreateDialog(savedInstanceState).also {
|
||||||
|
it.setOnKeyListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
binding.toolbar.setNavigationOnClickListener { dismiss() }
|
||||||
|
addBottomSheetCallback(BottomSheetToolbarController(binding.toolbar))
|
||||||
|
val listAdapter = ShikimoriSelectorAdapter(viewLifecycleOwner, get(), this)
|
||||||
|
val decoration = ShikiMangaSelectionDecoration(view.context)
|
||||||
|
with(binding.recyclerView) {
|
||||||
|
adapter = listAdapter
|
||||||
|
addItemDecoration(decoration)
|
||||||
|
addOnScrollListener(PaginationScrollListener(4, this@ScrobblingSelectorBottomSheet))
|
||||||
|
}
|
||||||
|
binding.buttonDone.setOnClickListener(this)
|
||||||
|
initOptionsMenu()
|
||||||
|
|
||||||
|
viewModel.content.observe(viewLifecycleOwner) { listAdapter.items = it }
|
||||||
|
viewModel.selectedItemId.observe(viewLifecycleOwner) {
|
||||||
|
decoration.checkedItemId = it
|
||||||
|
binding.recyclerView.invalidateItemDecorations()
|
||||||
|
}
|
||||||
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
||||||
|
viewModel.onClose.observe(viewLifecycleOwner) {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
viewModel.searchQuery.observe(viewLifecycleOwner) {
|
||||||
|
binding.toolbar.subtitle = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View) {
|
||||||
|
when (v.id) {
|
||||||
|
R.id.button_done -> viewModel.onDoneClick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemClick(item: ScrobblerManga, view: View) {
|
||||||
|
viewModel.selectedItemId.value = item.id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onScrolledToEnd() {
|
||||||
|
viewModel.loadList(append = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||||
|
setExpanded(isExpanded = true, isLocked = true)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||||
|
val searchView = (item.actionView as? SearchView) ?: return false
|
||||||
|
searchView.setQuery("", false)
|
||||||
|
searchView.post { setExpanded(isExpanded = false, isLocked = false) }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
|
if (query == null || query.length < 3) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
viewModel.search(query)
|
||||||
|
binding.toolbar.menu.findItem(R.id.action_search)?.collapseActionView()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQueryTextChange(newText: String?): Boolean = false
|
||||||
|
|
||||||
|
override fun onKey(dialog: DialogInterface?, keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
val menuItem = binding.toolbar.menu.findItem(R.id.action_search) ?: return false
|
||||||
|
if (menuItem.isActionViewExpanded) {
|
||||||
|
if (event?.action == KeyEvent.ACTION_UP) {
|
||||||
|
menuItem.collapseActionView()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onError(e: Throwable) {
|
||||||
|
Toast.makeText(requireContext(), e.getDisplayMessage(resources), Toast.LENGTH_LONG).show()
|
||||||
|
if (viewModel.isEmpty) {
|
||||||
|
dismissAllowingStateLoss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initOptionsMenu() {
|
||||||
|
binding.toolbar.inflateMenu(R.menu.opt_shiki_selector)
|
||||||
|
val searchMenuItem = binding.toolbar.menu.findItem(R.id.action_search)
|
||||||
|
searchMenuItem.setOnActionExpandListener(this)
|
||||||
|
val searchView = searchMenuItem.actionView as SearchView
|
||||||
|
searchView.setOnQueryTextListener(this)
|
||||||
|
searchView.setIconifiedByDefault(false)
|
||||||
|
searchView.queryHint = searchMenuItem.title
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val TAG = "ScrobblingSelectorBottomSheet"
|
||||||
|
|
||||||
|
fun show(fm: FragmentManager, manga: Manga) =
|
||||||
|
ScrobblingSelectorBottomSheet().withArgs(1) {
|
||||||
|
putParcelable(MangaIntent.KEY_MANGA, ParcelableManga(manga, withChapters = false))
|
||||||
|
}.show(fm, TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shikimori
|
|
||||||
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import org.koin.android.ext.koin.androidContext
|
|
||||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
|
||||||
import org.koin.dsl.module
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.ShikimoriAuthenticator
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.ShikimoriInterceptor
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.ShikimoriRepository
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.ShikimoriStorage
|
|
||||||
import org.koitharu.kotatsu.shikimori.ui.ShikimoriSettingsViewModel
|
|
||||||
import org.koitharu.kotatsu.shikimori.ui.selector.ShikimoriSelectorViewModel
|
|
||||||
|
|
||||||
val shikimoriModule
|
|
||||||
get() = module {
|
|
||||||
single { ShikimoriStorage(androidContext()) }
|
|
||||||
factory {
|
|
||||||
val okHttp = OkHttpClient.Builder().apply {
|
|
||||||
authenticator(ShikimoriAuthenticator(get(), ::get))
|
|
||||||
addInterceptor(ShikimoriInterceptor(get()))
|
|
||||||
}.build()
|
|
||||||
ShikimoriRepository(okHttp, get())
|
|
||||||
}
|
|
||||||
viewModel { params ->
|
|
||||||
ShikimoriSettingsViewModel(get(), params.getOrNull())
|
|
||||||
}
|
|
||||||
viewModel { params -> ShikimoriSelectorViewModel(params[0], get()) }
|
|
||||||
}
|
|
||||||
@ -1,145 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shikimori.data
|
|
||||||
|
|
||||||
import okhttp3.FormBody
|
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.Request
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
|
||||||
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
|
||||||
import org.koitharu.kotatsu.parsers.util.parseJson
|
|
||||||
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
|
||||||
import org.koitharu.kotatsu.parsers.util.urlEncoded
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.model.ShikimoriManga
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.model.ShikimoriMangaInfo
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.model.ShikimoriUser
|
|
||||||
import org.koitharu.kotatsu.utils.ext.toRequestBody
|
|
||||||
|
|
||||||
private const val CLIENT_ID = "Mw6F0tPEOgyV7F9U9Twg50Q8SndMY7hzIOfXg0AX_XU"
|
|
||||||
private const val CLIENT_SECRET = "euBMt1GGRSDpVIFQVPxZrO7Kh6X4gWyv0dABuj4B-M8"
|
|
||||||
private const val REDIRECT_URI = "kotatsu://shikimori-auth"
|
|
||||||
private const val BASE_URL = "https://shikimori.one/"
|
|
||||||
private const val MANGA_PAGE_SIZE = 10
|
|
||||||
|
|
||||||
class ShikimoriRepository(
|
|
||||||
private val okHttp: OkHttpClient,
|
|
||||||
private val storage: ShikimoriStorage,
|
|
||||||
) {
|
|
||||||
|
|
||||||
val oauthUrl: String
|
|
||||||
get() = "${BASE_URL}oauth/authorize?client_id=$CLIENT_ID&" +
|
|
||||||
"redirect_uri=$REDIRECT_URI&response_type=code&scope="
|
|
||||||
|
|
||||||
val isAuthorized: Boolean
|
|
||||||
get() = storage.accessToken != null
|
|
||||||
|
|
||||||
suspend fun authorize(code: String?) {
|
|
||||||
val body = FormBody.Builder()
|
|
||||||
body.add("grant_type", "authorization_code")
|
|
||||||
body.add("client_id", CLIENT_ID)
|
|
||||||
body.add("client_secret", CLIENT_SECRET)
|
|
||||||
if (code != null) {
|
|
||||||
body.add("redirect_uri", REDIRECT_URI)
|
|
||||||
body.add("code", code)
|
|
||||||
} else {
|
|
||||||
body.add("refresh_token", checkNotNull(storage.refreshToken))
|
|
||||||
}
|
|
||||||
val request = Request.Builder()
|
|
||||||
.post(body.build())
|
|
||||||
.url("${BASE_URL}oauth/token")
|
|
||||||
val response = okHttp.newCall(request.build()).await().parseJson()
|
|
||||||
storage.accessToken = response.getString("access_token")
|
|
||||||
storage.refreshToken = response.getString("refresh_token")
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getUser(): ShikimoriUser {
|
|
||||||
val request = Request.Builder()
|
|
||||||
.get()
|
|
||||||
.url("${BASE_URL}api/users/whoami")
|
|
||||||
val response = okHttp.newCall(request.build()).await().parseJson()
|
|
||||||
return ShikimoriUser(response).also { storage.user = it }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCachedUser(): ShikimoriUser? {
|
|
||||||
return storage.user
|
|
||||||
}
|
|
||||||
|
|
||||||
fun logout() {
|
|
||||||
storage.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun findManga(query: String, offset: Int): List<ShikimoriManga> {
|
|
||||||
val page = offset / MANGA_PAGE_SIZE
|
|
||||||
val pageOffset = offset % MANGA_PAGE_SIZE
|
|
||||||
val url = BASE_URL.toHttpUrl().newBuilder()
|
|
||||||
.addPathSegment("api")
|
|
||||||
.addPathSegment("mangas")
|
|
||||||
.addEncodedQueryParameter("page", (page + 1).toString())
|
|
||||||
.addEncodedQueryParameter("limit", MANGA_PAGE_SIZE.toString())
|
|
||||||
.addEncodedQueryParameter("censored", false.toString())
|
|
||||||
.addQueryParameter("search", query)
|
|
||||||
.build()
|
|
||||||
val request = Request.Builder().url(url).get().build()
|
|
||||||
val response = okHttp.newCall(request).await().parseJsonArray()
|
|
||||||
val list = response.mapJSON { ShikimoriManga(it) }
|
|
||||||
return if (pageOffset != 0) list.drop(pageOffset) else list
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun trackManga(manga: Manga, shikiMangaId: Long) {
|
|
||||||
val user = getCachedUser() ?: getUser()
|
|
||||||
val payload = JSONObject()
|
|
||||||
payload.put(
|
|
||||||
"user_rate",
|
|
||||||
JSONObject().apply {
|
|
||||||
put("target_id", shikiMangaId)
|
|
||||||
put("target_type", "Manga")
|
|
||||||
put("user_id", user.id)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
val url = BASE_URL.toHttpUrl().newBuilder()
|
|
||||||
.addPathSegment("api")
|
|
||||||
.addPathSegment("v2")
|
|
||||||
.addPathSegment("user_rates")
|
|
||||||
.build()
|
|
||||||
val request = Request.Builder().url(url).post(payload.toRequestBody()).build()
|
|
||||||
val response = okHttp.newCall(request).await().parseJson()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun findMangaInfo(manga: Manga): ShikimoriMangaInfo? {
|
|
||||||
val q = manga.title.urlEncoded()
|
|
||||||
val request = Request.Builder()
|
|
||||||
.get()
|
|
||||||
.url("${BASE_URL}api/mangas?limit=5&search=$q&censored=false")
|
|
||||||
val response = okHttp.newCall(request.build()).await().parseJsonArray()
|
|
||||||
val candidates = response.mapJSON { ShikimoriManga(it) }
|
|
||||||
val bestCandidate = candidates.filter {
|
|
||||||
it.name.equals(manga.title, ignoreCase = true) || it.name.equals(manga.altTitle, ignoreCase = true)
|
|
||||||
}.singleOrNull() ?: return null
|
|
||||||
return getMangaInfo(bestCandidate.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getRelatedManga(id: Long): List<ShikimoriManga> {
|
|
||||||
val request = Request.Builder()
|
|
||||||
.get()
|
|
||||||
.url("${BASE_URL}api/mangas/$id/related")
|
|
||||||
val response = okHttp.newCall(request.build()).await().parseJsonArray()
|
|
||||||
return response.mapJSON { jo -> ShikimoriManga(jo) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getSimilarManga(id: Long): List<ShikimoriManga> {
|
|
||||||
val request = Request.Builder()
|
|
||||||
.get()
|
|
||||||
.url("${BASE_URL}api/mangas/$id/similar")
|
|
||||||
val response = okHttp.newCall(request.build()).await().parseJsonArray()
|
|
||||||
return response.mapJSON { jo -> ShikimoriManga(jo) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getMangaInfo(id: Long): ShikimoriMangaInfo {
|
|
||||||
val request = Request.Builder()
|
|
||||||
.get()
|
|
||||||
.url("${BASE_URL}api/mangas/$id")
|
|
||||||
val response = okHttp.newCall(request.build()).await().parseJson()
|
|
||||||
return ShikimoriMangaInfo(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shikimori.data.model
|
|
||||||
|
|
||||||
import org.json.JSONObject
|
|
||||||
|
|
||||||
class ShikimoriMangaInfo(
|
|
||||||
val id: Long,
|
|
||||||
val name: String,
|
|
||||||
val cover: String,
|
|
||||||
val url: String,
|
|
||||||
val descriptionHtml: String,
|
|
||||||
) {
|
|
||||||
|
|
||||||
constructor(json: JSONObject) : this(
|
|
||||||
id = json.getLong("id"),
|
|
||||||
name = json.getString("name"),
|
|
||||||
cover = json.getJSONObject("image").getString("preview"),
|
|
||||||
url = json.getString("url"),
|
|
||||||
descriptionHtml = json.getString("description_html"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,106 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shikimori.ui.selector
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import coil.transform.CircleCropTransformation
|
|
||||||
import org.koin.android.ext.android.get
|
|
||||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
|
||||||
import org.koin.core.parameter.parametersOf
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.PaginationScrollListener
|
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
|
||||||
import org.koitharu.kotatsu.databinding.SheetShikiSelectorBinding
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
|
||||||
import org.koitharu.kotatsu.shikimori.data.model.ShikimoriManga
|
|
||||||
import org.koitharu.kotatsu.shikimori.ui.selector.adapter.ShikiMangaSelectionDecoration
|
|
||||||
import org.koitharu.kotatsu.shikimori.ui.selector.adapter.ShikimoriSelectorAdapter
|
|
||||||
import org.koitharu.kotatsu.utils.BottomSheetToolbarController
|
|
||||||
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
|
||||||
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
|
||||||
|
|
||||||
class ShikimoriSelectorBottomSheet :
|
|
||||||
BaseBottomSheet<SheetShikiSelectorBinding>(),
|
|
||||||
OnListItemClickListener<ShikimoriManga>,
|
|
||||||
PaginationScrollListener.Callback,
|
|
||||||
View.OnClickListener {
|
|
||||||
|
|
||||||
private val viewModel by viewModel<ShikimoriSelectorViewModel> {
|
|
||||||
parametersOf(requireNotNull(requireArguments().getParcelable<ParcelableManga>(MangaIntent.KEY_MANGA)).manga)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetShikiSelectorBinding {
|
|
||||||
return SheetShikiSelectorBinding.inflate(inflater, container, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
binding.toolbar.subtitle = viewModel.manga.title
|
|
||||||
binding.toolbar.setNavigationOnClickListener { dismiss() }
|
|
||||||
addBottomSheetCallback(BottomSheetToolbarController(binding.toolbar))
|
|
||||||
val listAdapter = ShikimoriSelectorAdapter(viewLifecycleOwner, get(), this)
|
|
||||||
val decoration = ShikiMangaSelectionDecoration(view.context)
|
|
||||||
with(binding.recyclerView) {
|
|
||||||
adapter = listAdapter
|
|
||||||
addItemDecoration(decoration)
|
|
||||||
addOnScrollListener(PaginationScrollListener(4, this@ShikimoriSelectorBottomSheet))
|
|
||||||
}
|
|
||||||
binding.imageViewUser.setOnClickListener(this)
|
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner) { listAdapter.items = it }
|
|
||||||
viewModel.selectedItemId.observe(viewLifecycleOwner) {
|
|
||||||
decoration.checkedItemId = it
|
|
||||||
binding.recyclerView.invalidateItemDecorations()
|
|
||||||
}
|
|
||||||
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
|
||||||
viewModel.avatar.observe(viewLifecycleOwner, ::setUserAvatar)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
|
||||||
when (v.id) {
|
|
||||||
R.id.imageView_user -> startActivity(SettingsActivity.newShikimoriSettingsIntent(v.context))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemClick(item: ShikimoriManga, view: View) {
|
|
||||||
viewModel.selectedItemId.value = item.id
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onScrolledToEnd() {
|
|
||||||
viewModel.loadList(append = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
|
||||||
Toast.makeText(requireContext(), e.getDisplayMessage(resources), Toast.LENGTH_LONG).show()
|
|
||||||
if (viewModel.isEmpty) {
|
|
||||||
dismissAllowingStateLoss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setUserAvatar(url: String?) {
|
|
||||||
val iconSize = resources.getDimensionPixelSize(R.dimen.action_bar_item_size)
|
|
||||||
binding.imageViewUser.newImageRequest(url)
|
|
||||||
.transformations(CircleCropTransformation())
|
|
||||||
.size(iconSize, iconSize)
|
|
||||||
.enqueueWith(get())
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val TAG = "ShikimoriSelectorBottomSheet"
|
|
||||||
|
|
||||||
fun show(fm: FragmentManager, manga: Manga) =
|
|
||||||
ShikimoriSelectorBottomSheet().withArgs(1) {
|
|
||||||
putParcelable(MangaIntent.KEY_MANGA, ParcelableManga(manga, withChapters = false))
|
|
||||||
}.show(fm, TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 723 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/scrobbling_layout"
|
||||||
|
style="@style/Widget.Material3.CardView.Filled"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:contentPadding="8dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="2dp">
|
||||||
|
|
||||||
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
|
android:id="@+id/imageView_cover"
|
||||||
|
android:layout_width="46dp"
|
||||||
|
android:layout_height="46dp"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Kotatsu.Cover.Small"
|
||||||
|
tools:src="@tools:sample/avatars" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_toEndOf="@id/imageView_cover"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textAppearance="@style/TextAppearance.Material3.TitleSmall"
|
||||||
|
app:drawableTint="?colorControlNormal"
|
||||||
|
tools:drawableEndCompat="@drawable/ic_shikimori"
|
||||||
|
tools:text="@string/tracking" />
|
||||||
|
|
||||||
|
<RatingBar
|
||||||
|
android:id="@+id/ratingBar"
|
||||||
|
style="@style/Widget.AppCompat.RatingBar.Small"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/textView_title"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:layout_toEndOf="@id/imageView_cover"
|
||||||
|
android:isIndicator="true"
|
||||||
|
android:max="1"
|
||||||
|
android:numStars="5" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_status"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/ratingBar"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginBottom="-2dp"
|
||||||
|
android:layout_toEndOf="@id/ratingBar"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
|
tools:text="Reading" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
|
android:id="@+id/imageView_cover"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:foreground="?selectableItemBackground"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
app:layout_constraintDimensionRatio="H,13:18"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintWidth_percent="0.3"
|
||||||
|
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Kotatsu.Cover"
|
||||||
|
tools:background="@tools:sample/backgrounds/scenic"
|
||||||
|
tools:ignore="ContentDescription,UnusedAttribute" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textAppearance="?attr/textAppearanceHeadlineSmall"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/button_open"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/imageView_cover"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:text="@tools:sample/lorem[15]" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/button_open"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/open_in_browser"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:src="@drawable/ic_open_external"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:tint="?android:colorControlNormal" />
|
||||||
|
|
||||||
|
<RatingBar
|
||||||
|
android:id="@+id/ratingBar"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:numStars="5"
|
||||||
|
android:stepSize="0.5"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/imageView_cover"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/textView_title"
|
||||||
|
tools:rating="3.5"
|
||||||
|
tools:text="@tools:sample/lorem[12]" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinner_status"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:entries="@array/scrobbling_statuses"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/imageView_cover"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/ratingBar" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Barrier
|
||||||
|
android:id="@+id/barrier_header"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:barrierDirection="bottom"
|
||||||
|
app:barrierMargin="8dp"
|
||||||
|
app:constraint_referenced_ids="imageView_cover,spinner_status" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_description"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/barrier_header"
|
||||||
|
tools:ignore="UnusedAttribute"
|
||||||
|
tools:text="@tools:sample/lorem/random[250]" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_search"
|
||||||
|
android:icon="?actionModeWebSearchDrawable"
|
||||||
|
android:title="@string/search"
|
||||||
|
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||||
|
app:showAsAction="ifRoom|collapseActionView" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
Loading…
Reference in New Issue