fix: some anilist markdown
This commit is contained in:
parent
eb5e2623a0
commit
1028ac66cb
6 changed files with 119 additions and 71 deletions
|
@ -27,7 +27,7 @@ import ani.dantotsu.media.MediaAdaptor
|
|||
import ani.dantotsu.media.user.ListActivity
|
||||
import ani.dantotsu.setSlideIn
|
||||
import ani.dantotsu.setSlideUp
|
||||
import ani.dantotsu.util.ColorEditor.Companion.toCssColor
|
||||
import ani.dantotsu.util.AniMarkdown.Companion.getFullAniHTML
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
@ -72,8 +72,8 @@ class ProfileFragment : Fragment() {
|
|||
binding.profileUserBio.settings.loadWithOverviewMode = true
|
||||
binding.profileUserBio.settings.useWideViewPort = true
|
||||
binding.profileUserBio.setInitialScale(1)
|
||||
val styledHtml = styled(
|
||||
convertMarkdownToHtml(user.about ?: ""),
|
||||
val styledHtml = getFullAniHTML(
|
||||
user.about ?: "",
|
||||
backGroundColorTypedValue.data,
|
||||
textColorTypedValue.data
|
||||
)
|
||||
|
@ -175,16 +175,6 @@ class ProfileFragment : Fragment() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun convertMarkdownToHtml(markdown: String): String {
|
||||
val regex = """\[\!\[(.*?)\]\((.*?)\)\]\((.*?)\)""".toRegex()
|
||||
return regex.replace(markdown) { matchResult ->
|
||||
val altText = matchResult.groupValues[1]
|
||||
val imageUrl = matchResult.groupValues[2]
|
||||
val linkUrl = matchResult.groupValues[3]
|
||||
"""<a href="$linkUrl"><img src="$imageUrl" alt="$altText"></a>"""
|
||||
}
|
||||
}
|
||||
|
||||
private fun initRecyclerView(
|
||||
mode: LiveData<ArrayList<Media>>,
|
||||
container: View,
|
||||
|
@ -221,56 +211,6 @@ class ProfileFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun styled(html: String, backGroundColor: Int, textColor: Int): String { //istg anilist has the worst api
|
||||
//remove some of the html entities
|
||||
val step1 = html.replace(" ", " ")
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(""", "\"")
|
||||
.replace("'", "'")
|
||||
.replace("<pre>", "")
|
||||
.replace("`", "")
|
||||
.replace("~", "")
|
||||
|
||||
val step2 = step1.replace("(?s)___(.*?)___".toRegex(), "<br><em><strong>$1</strong></em><br>")
|
||||
val step3 = step2.replace("(?s)__(.*?)__".toRegex(), "<br><strong>$1</strong><br>")
|
||||
|
||||
|
||||
return """
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, charset=UTF-8">
|
||||
<style>
|
||||
body {
|
||||
background-color: ${backGroundColor.toCssColor()};
|
||||
color: ${textColor.toCssColor()};
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
max-width: 100%;
|
||||
overflow-x: hidden; /* Prevent horizontal scrolling */
|
||||
}
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto; /* Maintain aspect ratio */
|
||||
}
|
||||
video {
|
||||
max-width: 100%;
|
||||
height: auto; /* Maintain aspect ratio */
|
||||
}
|
||||
a {
|
||||
color: ${textColor.toCssColor()};
|
||||
}
|
||||
/* Add responsive design elements for other content as needed */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
$step3
|
||||
</body>
|
||||
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(query: Query.UserProfile): ProfileFragment {
|
||||
val args = Bundle().apply {
|
||||
|
|
|
@ -11,6 +11,7 @@ import ani.dantotsu.connections.anilist.api.Activity
|
|||
import ani.dantotsu.databinding.ItemActivityBinding
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
|
@ -96,7 +97,7 @@ class ActivityItem(
|
|||
binding.activityContent.visibility = View.VISIBLE
|
||||
if (!(context as android.app.Activity).isDestroyed) {
|
||||
val markwon = buildMarkwon(context, false)
|
||||
markwon.setMarkdown(binding.activityContent, activity.text ?: "")
|
||||
markwon.setMarkdown(binding.activityContent, getBasicAniHTML(activity.text ?: ""))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class FeedActivity: AppCompatActivity() {
|
|||
setContentView(binding.root)
|
||||
navBar = binding.feedNavBar
|
||||
navBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += navBarHeight }
|
||||
val personalTab = navBar.createTab(R.drawable.ic_round_person_24, "Personal")
|
||||
val personalTab = navBar.createTab(R.drawable.ic_round_person_24, "Following")
|
||||
val globalTab = navBar.createTab(R.drawable.ic_globe_24, "Global")
|
||||
navBar.addTab(personalTab)
|
||||
navBar.addTab(globalTab)
|
||||
|
|
|
@ -64,14 +64,17 @@ class FeedFragment : Fragment() {
|
|||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList = activities
|
||||
adapter.update(activityList.map { ActivityItem(it) { _, _ -> } })
|
||||
val filtered = activities.filterNot { //filter out messages that are not directed to the user
|
||||
it.recipient?.id != null && it.recipient.id != Anilist.userid
|
||||
}
|
||||
adapter.update(filtered.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.listProgressBar.visibility = ViewGroup.GONE
|
||||
val scrollView = binding.listRecyclerView
|
||||
|
||||
binding.listRecyclerView.setOnTouchListener { _, event ->
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (adapter.itemCount % AnilistQueries.ITEMS_PER_PAGE != 0 && !global) {
|
||||
if (activityList.size % AnilistQueries.ITEMS_PER_PAGE != 0 && !global) {
|
||||
snackString("No more activities")
|
||||
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
|
||||
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
|
||||
|
@ -84,7 +87,10 @@ class FeedFragment : Fragment() {
|
|||
withContext(Dispatchers.Main) {
|
||||
res?.data?.page?.activities?.let { activities ->
|
||||
activityList += activities
|
||||
adapter.addAll(activities.map { ActivityItem(it) { _, _ -> } })
|
||||
val filtered = activities.filterNot {
|
||||
it.recipient?.id != null && it.recipient.id != Anilist.userid
|
||||
}
|
||||
adapter.addAll(filtered.map { ActivityItem(it) { _, _ -> } })
|
||||
}
|
||||
binding.feedRefresh.visibility = ViewGroup.GONE
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue