1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-09 22:10:27 -06:00

Fix html entities parsing in school announcements (#2086)

This commit is contained in:
Mikołaj Pich 2022-12-25 04:40:58 +01:00 committed by GitHub
parent 63d6a0b325
commit 510e2d5b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -240,6 +240,7 @@ dependencies {
implementation "io.github.wulkanowy:AppKillerManager:3.0.1"
implementation 'me.xdrop:fuzzywuzzy:1.4.0'
implementation 'com.fredporciuncula:flow-preferences:1.8.0'
implementation 'org.apache.commons:commons-text:1.10.0'
playImplementation platform('com.google.firebase:firebase-bom:31.1.1')
playImplementation 'com.google.firebase:firebase-analytics-ktx'

View File

@ -2,10 +2,10 @@ package io.github.wulkanowy.ui.modules.schoolannouncement
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.text.parseAsHtml
import androidx.recyclerview.widget.RecyclerView
import io.github.wulkanowy.data.db.entities.SchoolAnnouncement
import io.github.wulkanowy.databinding.ItemSchoolAnnouncementBinding
import io.github.wulkanowy.utils.parseUonetHtml
import io.github.wulkanowy.utils.toFormattedString
import javax.inject.Inject
@ -28,7 +28,7 @@ class SchoolAnnouncementAdapter @Inject constructor() :
with(holder.binding) {
schoolAnnouncementItemDate.text = item.date.toFormattedString()
schoolAnnouncementItemType.text = item.subject
schoolAnnouncementItemContent.text = item.content.parseAsHtml()
schoolAnnouncementItemContent.text = item.content.parseUonetHtml()
root.setOnClickListener { onItemClickListener(item) }
}

View File

@ -5,11 +5,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import io.github.wulkanowy.data.db.entities.SchoolAnnouncement
import io.github.wulkanowy.databinding.DialogSchoolAnnouncementBinding
import io.github.wulkanowy.utils.lifecycleAwareVariable
import io.github.wulkanowy.utils.parseUonetHtml
import io.github.wulkanowy.utils.serializable
import io.github.wulkanowy.utils.toFormattedString
@ -46,7 +46,7 @@ class SchoolAnnouncementDialog : DialogFragment() {
with(binding) {
announcementDialogSubjectValue.text = announcement.subject
announcementDialogDateValue.text = announcement.date.toFormattedString()
announcementDialogDescriptionValue.text = announcement.content.parseAsHtml()
announcementDialogDescriptionValue.text = announcement.content.parseUonetHtml()
announcementDialogClose.setOnClickListener { dismiss() }
}

View File

@ -1,7 +1,15 @@
package io.github.wulkanowy.utils
import androidx.core.text.parseAsHtml
import org.apache.commons.text.StringEscapeUtils
inline fun String?.ifNullOrBlank(defaultValue: () -> String) =
if (isNullOrBlank()) defaultValue() else this
fun String.capitalise() =
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
fun String.parseUonetHtml() = this
.let(StringEscapeUtils::unescapeHtml4)
.replace("\n", "<br/>")
.parseAsHtml()