feat: reviews in info page
This commit is contained in:
parent
91f728150c
commit
d12ddc9c0d
10 changed files with 97 additions and 50 deletions
|
@ -5,6 +5,7 @@ import ani.dantotsu.connections.anilist.api.FuzzyDate
|
|||
import ani.dantotsu.connections.anilist.api.MediaEdge
|
||||
import ani.dantotsu.connections.anilist.api.MediaList
|
||||
import ani.dantotsu.connections.anilist.api.MediaType
|
||||
import ani.dantotsu.connections.anilist.api.Query
|
||||
import ani.dantotsu.media.anime.Anime
|
||||
import ani.dantotsu.media.manga.Manga
|
||||
import ani.dantotsu.profile.User
|
||||
|
@ -62,6 +63,7 @@ data class Media(
|
|||
var timeUntilAiring: Long? = null,
|
||||
|
||||
var characters: ArrayList<Character>? = null,
|
||||
var review: ArrayList<Query.Review>? = null,
|
||||
var staff: ArrayList<Author>? = null,
|
||||
var prequel: Media? = null,
|
||||
var sequel: Media? = null,
|
||||
|
|
|
@ -34,7 +34,6 @@ import ani.dantotsu.databinding.ItemChipBinding
|
|||
import ani.dantotsu.databinding.ItemQuelsBinding
|
||||
import ani.dantotsu.databinding.ItemTitleChipgroupBinding
|
||||
import ani.dantotsu.databinding.ItemTitleRecyclerBinding
|
||||
import ani.dantotsu.databinding.ItemTitleSearchBinding
|
||||
import ani.dantotsu.databinding.ItemTitleTextBinding
|
||||
import ani.dantotsu.databinding.ItemTitleTrailerBinding
|
||||
import ani.dantotsu.displayTimer
|
||||
|
@ -46,6 +45,7 @@ import ani.dantotsu.px
|
|||
import ani.dantotsu.setSafeOnClickListener
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import com.xwray.groupie.GroupieAdapter
|
||||
import io.noties.markwon.Markwon
|
||||
import io.noties.markwon.SoftBreakAddsNewLinePlugin
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -81,7 +81,8 @@ class MediaInfoFragment : Fragment() {
|
|||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val model: MediaDetailsViewModel by activityViewModels()
|
||||
val offline: Boolean = PrefManager.getVal(PrefName.OfflineMode) || !isOnline(requireContext())
|
||||
val offline: Boolean =
|
||||
PrefManager.getVal(PrefName.OfflineMode) || !isOnline(requireContext())
|
||||
binding.mediaInfoProgressBar.isGone = loaded
|
||||
binding.mediaInfoContainer.isVisible = loaded
|
||||
binding.mediaInfoContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += 128f.px + navBarHeight }
|
||||
|
@ -254,7 +255,8 @@ class MediaInfoFragment : Fragment() {
|
|||
if (!media.users.isNullOrEmpty() && !offline) {
|
||||
val users: ArrayList<User> = media.users ?: arrayListOf()
|
||||
if (Anilist.token != null && media.userStatus != null) {
|
||||
users.add(0,
|
||||
users.add(
|
||||
0,
|
||||
User(
|
||||
id = Anilist.userid!!,
|
||||
name = getString(R.string.you),
|
||||
|
@ -263,7 +265,8 @@ class MediaInfoFragment : Fragment() {
|
|||
status = media.userStatus,
|
||||
score = media.userScore.toFloat(),
|
||||
progress = media.userProgress,
|
||||
totalEpisodes = media.anime?.totalEpisodes ?: media.manga?.totalChapters,
|
||||
totalEpisodes = media.anime?.totalEpisodes
|
||||
?: media.manga?.totalChapters,
|
||||
nextAiringEpisode = media.anime?.nextAiringEpisode
|
||||
)
|
||||
)
|
||||
|
@ -519,22 +522,41 @@ class MediaInfoFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
ItemTitleSearchBinding.inflate(
|
||||
LayoutInflater.from(context),
|
||||
parent,
|
||||
false
|
||||
).apply {
|
||||
|
||||
titleSearchImage.loadImage(media.banner ?: media.cover)
|
||||
titleSearchText.text =
|
||||
getString(R.string.reviews)
|
||||
titleSearchCard.setSafeOnClickListener {
|
||||
val query = Intent(requireContext(), ReviewActivity::class.java)
|
||||
.putExtra("mediaId", media.id)
|
||||
ContextCompat.startActivity(requireContext(), query, null)
|
||||
if (!media.review.isNullOrEmpty()) {
|
||||
ItemTitleRecyclerBinding.inflate(
|
||||
LayoutInflater.from(context),
|
||||
parent,
|
||||
false
|
||||
).apply {
|
||||
fun onUserClick(userId: Int) {
|
||||
val review = media.review!!.find { i -> i.id == userId }
|
||||
if (review != null) {
|
||||
startActivity(
|
||||
Intent(requireContext(), ReviewViewActivity::class.java)
|
||||
.putExtra("review", review)
|
||||
)
|
||||
}
|
||||
}
|
||||
val adapter = GroupieAdapter()
|
||||
media.review!!.forEach {
|
||||
adapter.add(ReviewAdapter(it, ::onUserClick))
|
||||
}
|
||||
itemTitle.setText(R.string.reviews)
|
||||
itemRecycler.adapter = adapter
|
||||
itemRecycler.layoutManager = LinearLayoutManager(
|
||||
requireContext(),
|
||||
LinearLayoutManager.VERTICAL,
|
||||
false
|
||||
)
|
||||
itemMore.visibility = View.VISIBLE
|
||||
itemMore.setSafeOnClickListener {
|
||||
startActivity(
|
||||
Intent(requireContext(), ReviewActivity::class.java)
|
||||
.putExtra("mediaId", media.id)
|
||||
)
|
||||
}
|
||||
parent.addView(root)
|
||||
}
|
||||
|
||||
parent.addView(root)
|
||||
}
|
||||
|
||||
ItemTitleRecyclerBinding.inflate(
|
||||
|
|
|
@ -125,7 +125,6 @@ class ReviewActivity : AppCompatActivity() {
|
|||
adapter.add(
|
||||
ReviewAdapter(
|
||||
it,
|
||||
this,
|
||||
this::onUserClick
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,30 +1,24 @@
|
|||
package ani.dantotsu.media
|
||||
|
||||
|
||||
import android.content.Context
|
||||
import android.text.SpannableString
|
||||
import android.view.View
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.blurImage
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.connections.anilist.api.Query
|
||||
import ani.dantotsu.databinding.ItemFollowerBinding
|
||||
import ani.dantotsu.databinding.ItemReviewsBinding
|
||||
import ani.dantotsu.getThemeColor
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.profile.activity.ActivityItemBuilder
|
||||
import ani.dantotsu.toast
|
||||
import com.xwray.groupie.viewbinding.BindableItem
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class ReviewAdapter(
|
||||
private var review: Query.Review,
|
||||
val context: ReviewActivity,
|
||||
val clickCallback: (Int) -> Unit
|
||||
|
||||
) : BindableItem<ItemReviewsBinding>() {
|
||||
private lateinit var binding: ItemReviewsBinding
|
||||
|
||||
|
@ -34,7 +28,8 @@ class ReviewAdapter(
|
|||
binding.reviewUserAvatar.loadImage(review.user?.avatar?.medium)
|
||||
binding.reviewText.text = review.summary
|
||||
binding.reviewPostTime.text = ActivityItemBuilder.getDateTime(review.createdAt)
|
||||
binding.reviewTag.text = "[${review.score}]"
|
||||
val text = "[${review.score/ 10.0f}]"
|
||||
binding.reviewTag.text = text
|
||||
binding.root.setOnClickListener { clickCallback(review.id) }
|
||||
userVote(review.userRating)
|
||||
enableVote()
|
||||
|
@ -75,7 +70,8 @@ class ReviewAdapter(
|
|||
|
||||
private fun rateReview(rating: String) {
|
||||
disableVote()
|
||||
context.lifecycleScope.launch {
|
||||
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
scope.launch {
|
||||
val result = Anilist.mutation.rateReview(review.id, rating)
|
||||
if (result != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
|
@ -91,7 +87,7 @@ class ReviewAdapter(
|
|||
} else {
|
||||
withContext(Dispatchers.Main) {
|
||||
toast(
|
||||
context.getString(R.string.error_message, "response is null")
|
||||
binding.root.context.getString(R.string.error_message, "response is null")
|
||||
)
|
||||
enableVote()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue