Skip to content

Commit

Permalink
Render HTML text properly by using parseText from HTMLTextView
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAGhost23 committed Feb 25, 2024
1 parent d512990 commit 3686a51
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CourseSectionDelegate(activity: Activity) : AdapterDelegate<List<CourseCon
val vh = holder as CourseSectionViewHolder
val section = items[position] as CourseSection
vh.sectionName.text = section.name
val summary = Utils.trimWhiteSpace(HtmlCompat.fromHtml(section.summary.trim { it <= ' ' },
val summary = Utils.trimWhiteSpace(HtmlCompat.fromHtml(section.summary,
HtmlCompat.FROM_HTML_MODE_COMPACT))
if (summary.isNotEmpty()) {
vh.sectionDescription.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package crux.bphc.cms.fragments

import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -24,9 +23,9 @@ import crux.bphc.cms.helper.CourseRequestHandler
import crux.bphc.cms.models.forum.Attachment
import crux.bphc.cms.models.forum.Discussion
import crux.bphc.cms.utils.Utils
import crux.bphc.cms.widgets.HtmlTextView
import crux.bphc.cms.widgets.PropertiesAlertDialog
import io.realm.Realm
import io.realm.RealmList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -92,7 +91,7 @@ class DiscussionFragment : Fragment() {
binding.subject.text = discussion.subject
binding.userName.text = discussion.userFullName
binding.modifiedTime.text = Utils.formatDate(discussion.timeModified)
binding.message.text = discussion.message
binding.message.text = HtmlTextView.parseHtml(discussion.message)
Glide.with(requireContext())
.load(Urls.getProfilePicUrl(discussion.userPictureUrl))
.into(binding.userPic)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/crux/bphc/cms/fragments/ForumFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import crux.bphc.cms.helper.CourseRequestHandler
import crux.bphc.cms.interfaces.ClickListener
import crux.bphc.cms.models.forum.Discussion
import crux.bphc.cms.utils.Utils
import crux.bphc.cms.widgets.HtmlTextView
import io.realm.Realm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -185,7 +186,7 @@ class ForumFragment : Fragment() {

itemBinding.subject.text = discussion.subject
itemBinding.userName.text = discussion.userFullName
itemBinding.message.text = discussion.message
itemBinding.message.text = HtmlTextView.parseHtml(discussion.message)
itemBinding.modifiedTime.text = Utils.formatDate(discussion.timeModified)

if (!discussion.isPinned) {
Expand Down

0 comments on commit 3686a51

Please sign in to comment.