feat: statistics (wip)

This commit is contained in:
rebelonion 2024-03-02 04:54:02 -06:00
parent 533148069f
commit 500de4e45e
12 changed files with 690 additions and 356 deletions

View file

@ -10,12 +10,8 @@ import ani.dantotsu.R
import ani.dantotsu.connections.comments.Comment
import ani.dantotsu.connections.comments.CommentsAPI
import ani.dantotsu.copyToClipboard
import ani.dantotsu.currActivity
import ani.dantotsu.currContext
import ani.dantotsu.databinding.ItemCommentsBinding
import ani.dantotsu.loadImage
import ani.dantotsu.media.user.ListActivity
import ani.dantotsu.openLinkInBrowser
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.snackString
import com.xwray.groupie.GroupieAdapter
@ -56,7 +52,7 @@ class CommentItem(val comment: Comment,
@SuppressLint("SetTextI18n")
override fun bind(viewBinding: ItemCommentsBinding, position: Int) {
binding = viewBinding
viewBinding.commentRepliesList.layoutManager = LinearLayoutManager(currActivity())
viewBinding.commentRepliesList.layoutManager = LinearLayoutManager(commentsFragment.activity)
viewBinding.commentRepliesList.adapter = adapter
val isUserComment = CommentsAPI.userId == comment.userId
val node = markwon.parse(comment.content)
@ -101,7 +97,7 @@ class CommentItem(val comment: Comment,
viewBinding.commentUserName.setOnClickListener {
ContextCompat.startActivity(
currContext()!!, Intent(currContext()!!, ProfileActivity::class.java)
commentsFragment.activity, Intent(commentsFragment.activity, ProfileActivity::class.java)
.putExtra("userId", comment.userId.toInt())
.putExtra("username","[${levelColor.second}]"), null
)
@ -215,12 +211,12 @@ class CommentItem(val comment: Comment,
}
fun replying(isReplying: Boolean) {
binding?.commentReply?.text = if (isReplying) currActivity()!!.getString(R.string.cancel) else "Reply"
binding?.commentReply?.text = if (isReplying) commentsFragment.activity.getString(R.string.cancel) else "Reply"
this.isReplying = isReplying
}
fun editing(isEditing: Boolean) {
binding?.commentEdit?.text = if (isEditing) currActivity()!!.getString(R.string.cancel) else currActivity()!!.getString(R.string.edit)
binding?.commentEdit?.text = if (isEditing) commentsFragment.activity.getString(R.string.cancel) else commentsFragment.activity.getString(R.string.edit)
this.isEditing = isEditing
}

View file

@ -22,6 +22,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.buildMarkwon
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.comments.Comment
import ani.dantotsu.connections.comments.CommentResponse
@ -100,7 +101,7 @@ class CommentsFragment : Fragment() {
this.mediaId = mediaId
backgroundColor = (binding.root.background as? ColorDrawable)?.color ?: 0
val markwon = buildMarkwon()
val markwon = buildMarkwon(activity)
binding.commentUserAvatar.loadImage(Anilist.avatar)
val markwonEditor = MarkwonEditor.create(markwon)
@ -235,7 +236,7 @@ class CommentsFragment : Fragment() {
section.add(
CommentItem(
comment,
buildMarkwon(),
buildMarkwon(activity),
section,
this@CommentsFragment,
backgroundColor,
@ -386,7 +387,7 @@ class CommentsFragment : Fragment() {
section.add(
CommentItem(
it,
buildMarkwon(),
buildMarkwon(activity),
section,
this@CommentsFragment,
backgroundColor,
@ -416,7 +417,7 @@ class CommentsFragment : Fragment() {
section.add(
CommentItem(
comment,
buildMarkwon(),
buildMarkwon(activity),
section,
this@CommentsFragment,
backgroundColor,
@ -539,7 +540,7 @@ class CommentsFragment : Fragment() {
if (depth >= comment.MAX_DEPTH) comment.registerSubComment(it.commentId)
val newCommentItem = CommentItem(
it,
buildMarkwon(),
buildMarkwon(activity),
section,
this@CommentsFragment,
backgroundColor,
@ -664,7 +665,7 @@ class CommentsFragment : Fragment() {
if (commentWithInteraction!!.commentDepth + 1 > commentWithInteraction!!.MAX_DEPTH) 0 else section.itemCount,
CommentItem(
it,
buildMarkwon(),
buildMarkwon(activity),
section,
this@CommentsFragment,
backgroundColor,
@ -676,7 +677,7 @@ class CommentsFragment : Fragment() {
0,
CommentItem(
it,
buildMarkwon(),
buildMarkwon(activity),
section,
this@CommentsFragment,
backgroundColor,
@ -686,68 +687,4 @@ class CommentsFragment : Fragment() {
}
}
}
/**
* Builds the markwon instance with all the plugins
* @return the markwon instance
*/
private fun buildMarkwon(): Markwon {
val markwon = Markwon.builder(activity)
.usePlugin(object : AbstractMarkwonPlugin() {
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
builder.linkResolver { view, link ->
copyToClipboard(link, true)
}
}
})
.usePlugin(SoftBreakAddsNewLinePlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(TablePlugin.create(activity))
.usePlugin(TaskListPlugin.create(activity))
.usePlugin(HtmlPlugin.create { plugin ->
plugin.addHandler(
TagHandlerNoOp.create("h1", "h2", "h3", "h4", "h5", "h6", "hr", "pre", "a")
)
})
.usePlugin(GlideImagesPlugin.create(object : GlideImagesPlugin.GlideStore {
private val requestManager: RequestManager =
Glide.with(this@CommentsFragment).apply {
addDefaultRequestListener(object : RequestListener<Any> {
override fun onResourceReady(
resource: Any,
model: Any,
target: Target<Any>,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
if (resource is GifDrawable) {
resource.start()
}
return false
}
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Any>,
isFirstResource: Boolean
): Boolean {
return false
}
})
}
override fun load(drawable: AsyncDrawable): RequestBuilder<Drawable> {
return requestManager.load(drawable.destination)
}
override fun cancel(target: Target<*>) {
requestManager.clear(target)
}
}))
.build()
return markwon
}
}