Decode title of articles from html (#312)

* Decode the title of the articles from html.

* Remove unused imports.

Closes #300
This commit is contained in:
davidoskky 2020-12-07 22:22:54 +01:00 committed by GitHub
parent 36a43b3861
commit a1e4f89cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 7 deletions

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Context import android.content.Context
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import android.text.Html
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -69,7 +68,7 @@ class ItemCardAdapter(
holder.mView.favButton.isLiked = itm.starred holder.mView.favButton.isLiked = itm.starred
holder.mView.title.text = Html.fromHtml(itm.title) holder.mView.title.text = itm.getTitleDecoded()
holder.mView.title.setOnTouchListener(LinkOnTouchListener()) holder.mView.title.setOnTouchListener(LinkOnTouchListener())
holder.mView.title.setLinkTextColor(appColors.colorAccent) holder.mView.title.setLinkTextColor(appColors.colorAccent)
@ -181,7 +180,7 @@ class ItemCardAdapter(
mView.shareBtn.setOnClickListener { mView.shareBtn.setOnClickListener {
val item = items[adapterPosition] val item = items[adapterPosition]
c.shareLink(item.getLinkDecoded(), item.title) c.shareLink(item.getLinkDecoded(), item.getTitleDecoded())
} }
mView.browserBtn.setOnClickListener { mView.browserBtn.setOnClickListener {

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Context import android.content.Context
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import android.text.Html
import android.text.Spannable import android.text.Spannable
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.util.TypedValue import android.util.TypedValue
@ -71,7 +70,7 @@ class ItemListAdapter(
val itm = items[position] val itm = items[position]
holder.mView.title.text = Html.fromHtml(itm.title) holder.mView.title.text = itm.getTitleDecoded()
holder.mView.title.setOnTouchListener(LinkOnTouchListener()) holder.mView.title.setOnTouchListener(LinkOnTouchListener())

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.net.Uri import android.net.Uri
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import android.text.Html
import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.Config
import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString
@ -127,6 +128,10 @@ data class Item(
return constructUrl(config, "thumbnails", thumbnail) return constructUrl(config, "thumbnails", thumbnail)
} }
fun getTitleDecoded(): String {
return Html.fromHtml(title).toString()
}
// TODO: maybe find a better way to handle these kind of urls // TODO: maybe find a better way to handle these kind of urls
fun getLinkDecoded(): String { fun getLinkDecoded(): String {
var stringUrl: String var stringUrl: String

View File

@ -113,7 +113,7 @@ class ArticleFragment : Fragment() {
url = allItems[pageNumber.toInt()].getLinkDecoded() url = allItems[pageNumber.toInt()].getLinkDecoded()
contentText = allItems[pageNumber.toInt()].content contentText = allItems[pageNumber.toInt()].content
contentTitle = allItems[pageNumber.toInt()].title contentTitle = allItems[pageNumber.toInt()].getTitleDecoded()
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!) contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
contentSource = allItems[pageNumber.toInt()].sourceAndDateText() contentSource = allItems[pageNumber.toInt()].sourceAndDateText()

View File

@ -61,7 +61,7 @@ fun Item.toEntity(): ItemEntity =
ItemEntity( ItemEntity(
this.id, this.id,
this.datetime, this.datetime,
this.title, this.getTitleDecoded(),
this.content, this.content,
this.unread, this.unread,
this.starred, this.starred,