Changed to Textview to disaply the simple content from the API.

This commit is contained in:
Amine 2017-11-11 16:50:17 +01:00
parent ccf406ae68
commit 9e3fde744e
6 changed files with 188 additions and 76 deletions

View File

@ -2,6 +2,8 @@ package apps.amine.bou.readerforselfoss
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.customtabs.CustomTabsIntent
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
@ -12,6 +14,7 @@ import apps.amine.bou.readerforselfoss.api.mercury.MercuryApi
import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString
import apps.amine.bou.readerforselfoss.utils.openItemUrl import apps.amine.bou.readerforselfoss.utils.openItemUrl
import apps.amine.bou.readerforselfoss.utils.shareLink import apps.amine.bou.readerforselfoss.utils.shareLink
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
@ -27,6 +30,18 @@ import xyz.klinker.android.drag_dismiss.activity.DragDismissActivity
class ReaderActivity : DragDismissActivity() { class ReaderActivity : DragDismissActivity() {
private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper
private lateinit var image: ImageView
private lateinit var source: TextView
private lateinit var title: TextView
private lateinit var content: TextView
//private lateinit var content: HtmlTextView
private lateinit var url: String
private lateinit var contentText: String
private lateinit var contentSource: String
private lateinit var contentImage: String
private lateinit var contentTitle: String
private lateinit var browserBtn: ImageButton
private lateinit var shareBtn: ImageButton
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
@ -42,16 +57,18 @@ class ReaderActivity : DragDismissActivity() {
Scoop.getInstance().apply(this) Scoop.getInstance().apply(this)
val v = inflater.inflate(R.layout.activity_reader, parent, false) val v = inflater.inflate(R.layout.activity_reader, parent, false)
showProgressBar() showProgressBar()
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
val image: ImageView = v.findViewById(R.id.imageView) image = v.findViewById(R.id.imageView)
val source: TextView = v.findViewById(R.id.source) source = v.findViewById(R.id.source)
val title: TextView = v.findViewById(R.id.title) title = v.findViewById(R.id.title)
val content: HtmlTextView = v.findViewById(R.id.content) content = v.findViewById(R.id.content)
val url = intent.getStringExtra("url") browserBtn = v.findViewById(R.id.browserBtn)
val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false)) shareBtn = v.findViewById(R.id.shareBtn)
val browserBtn: ImageButton = v.findViewById(R.id.browserBtn) url = intent.getStringExtra("url")
val shareBtn: ImageButton = v.findViewById(R.id.shareBtn) contentText = intent.getStringExtra("content")
contentTitle = intent.getStringExtra("title")
contentImage = intent.getStringExtra("image")
contentSource = intent.getStringExtra("source")
val customTabsIntent = this@ReaderActivity.buildCustomTabsIntent() val customTabsIntent = this@ReaderActivity.buildCustomTabsIntent()
@ -59,6 +76,49 @@ class ReaderActivity : DragDismissActivity() {
mCustomTabActivityHelper.bindCustomTabsService(this) mCustomTabActivityHelper.bindCustomTabsService(this)
if (contentText.isEmptyOrNullOrNullString()) {
getContentFromMercury(customTabsIntent)
} else {
source.text = contentSource
title.text = contentTitle
content.text = Html.fromHtml(contentText, HtmlHttpImageGetter(content, null, true), null)
//content.setHtml(contentText, HtmlHttpImageGetter(content, null, true))
if (!contentImage.isEmptyOrNullOrNullString())
Glide
.with(baseContext)
.asBitmap()
.load(contentImage)
.apply(RequestOptions.fitCenterTransform())
.into(image)
shareBtn.setOnClickListener {
this@ReaderActivity.shareLink(url)
}
browserBtn.setOnClickListener {
this@ReaderActivity.openItemUrl(
url,
contentText,
contentImage,
contentTitle,
contentSource,
customTabsIntent,
false,
false,
this@ReaderActivity)
}
hideProgressBar()
}
return v
}
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false))
parser.parseUrl(url).enqueue(object : Callback<ParsedContent> { parser.parseUrl(url).enqueue(object : Callback<ParsedContent> {
override fun onResponse(call: Call<ParsedContent>, response: Response<ParsedContent>) { override fun onResponse(call: Call<ParsedContent>, response: Response<ParsedContent>) {
if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) {
@ -66,7 +126,9 @@ class ReaderActivity : DragDismissActivity() {
title.text = response.body()!!.title title.text = response.body()!!.title
if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) { if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) {
try { try {
content.setHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true)) content.text = Html.fromHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true), null)
//content.setHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true))
} catch (e: IndexOutOfBoundsException) { } catch (e: IndexOutOfBoundsException) {
openInBrowserAfterFailing() openInBrowserAfterFailing()
} }
@ -86,6 +148,10 @@ class ReaderActivity : DragDismissActivity() {
browserBtn.setOnClickListener { browserBtn.setOnClickListener {
this@ReaderActivity.openItemUrl( this@ReaderActivity.openItemUrl(
response.body()!!.url, response.body()!!.url,
contentText,
contentImage,
contentTitle,
contentSource,
customTabsIntent, customTabsIntent,
false, false,
false, false,
@ -101,6 +167,10 @@ class ReaderActivity : DragDismissActivity() {
private fun openInBrowserAfterFailing() { private fun openInBrowserAfterFailing() {
this@ReaderActivity.openItemUrl( this@ReaderActivity.openItemUrl(
url, url,
contentText,
contentImage,
contentTitle,
contentSource,
customTabsIntent, customTabsIntent,
true, true,
false, false,
@ -109,6 +179,5 @@ class ReaderActivity : DragDismissActivity() {
finish() finish()
} }
}) })
return v
} }
} }

View File

@ -229,6 +229,10 @@ class ItemCardAdapter(private val app: Activity,
mView.setOnClickListener { mView.setOnClickListener {
c.openItemUrl(items[adapterPosition].getLinkDecoded(), c.openItemUrl(items[adapterPosition].getLinkDecoded(),
items[adapterPosition].content,
items[adapterPosition].getIcon(c),
items[adapterPosition].title,
items[adapterPosition].sourceAndDateText(),
customTabsIntent, customTabsIntent,
internalBrowser, internalBrowser,
articleViewer, articleViewer,

View File

@ -247,6 +247,10 @@ class ItemListAdapter(private val app: Activity,
if (!clickBehavior) { if (!clickBehavior) {
mView.setOnClickListener { mView.setOnClickListener {
c.openItemUrl(items[adapterPosition].getLinkDecoded(), c.openItemUrl(items[adapterPosition].getLinkDecoded(),
items[adapterPosition].content,
items[adapterPosition].getIcon(c),
items[adapterPosition].title,
items[adapterPosition].sourceAndDateText(),
customTabsIntent, customTabsIntent,
internalBrowser, internalBrowser,
articleViewer, articleViewer,
@ -260,6 +264,10 @@ class ItemListAdapter(private val app: Activity,
mView.setOnClickListener { actionBarShowHide() } mView.setOnClickListener { actionBarShowHide() }
mView.setOnLongClickListener { mView.setOnLongClickListener {
c.openItemUrl(items[adapterPosition].getLinkDecoded(), c.openItemUrl(items[adapterPosition].getLinkDecoded(),
items[adapterPosition].content,
items[adapterPosition].getIcon(c),
items[adapterPosition].title,
items[adapterPosition].sourceAndDateText(),
customTabsIntent, customTabsIntent,
internalBrowser, internalBrowser,
articleViewer, articleViewer,

View File

@ -55,6 +55,7 @@ data class Sources(@SerializedName("id") val id: String,
data class Item(@SerializedName("id") val id: String, data class Item(@SerializedName("id") val id: String,
@SerializedName("datetime") val datetime: String, @SerializedName("datetime") val datetime: String,
@SerializedName("title") val title: String, @SerializedName("title") val title: String,
@SerializedName("content") val content: String,
@SerializedName("unread") val unread: Boolean, @SerializedName("unread") val unread: Boolean,
@SerializedName("starred") val starred: Boolean, @SerializedName("starred") val starred: Boolean,
@SerializedName("thumbnail") val thumbnail: String, @SerializedName("thumbnail") val thumbnail: String,
@ -75,6 +76,7 @@ data class Item(@SerializedName("id") val id: String,
id = source.readString(), id = source.readString(),
datetime = source.readString(), datetime = source.readString(),
title = source.readString(), title = source.readString(),
content = source.readString(),
unread = 0.toByte() != source.readByte(), unread = 0.toByte() != source.readByte(),
starred = 0.toByte() != source.readByte(), starred = 0.toByte() != source.readByte(),
thumbnail = source.readString(), thumbnail = source.readString(),
@ -89,6 +91,7 @@ data class Item(@SerializedName("id") val id: String,
dest.writeString(id) dest.writeString(id)
dest.writeString(datetime) dest.writeString(datetime)
dest.writeString(title) dest.writeString(title)
dest.writeString(content)
dest.writeByte((if (unread) 1 else 0)) dest.writeByte((if (unread) 1 else 0))
dest.writeByte((if (starred) 1 else 0)) dest.writeByte((if (starred) 1 else 0))
dest.writeString(thumbnail) dest.writeString(thumbnail)

View File

@ -51,6 +51,10 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent {
} }
fun Context.openItemUrlInternally(linkDecoded: String, fun Context.openItemUrlInternally(linkDecoded: String,
content: String,
image: String,
title: String,
source: String,
customTabsIntent: CustomTabsIntent, customTabsIntent: CustomTabsIntent,
articleViewer: Boolean, articleViewer: Boolean,
app: Activity) { app: Activity) {
@ -63,7 +67,12 @@ fun Context.openItemUrlInternally(linkDecoded: String,
.setDrawUnderStatusBar(true) .setDrawUnderStatusBar(true)
.build(intent) .build(intent)
intent.putExtra("url", linkDecoded) intent.putExtra("url", linkDecoded)
intent.putExtra("content", content)
intent.putExtra("title", title)
intent.putExtra("image", image)
intent.putExtra("source", source)
app.startActivity(intent) app.startActivity(intent)
} else { } else {
try { try {
@ -80,6 +89,10 @@ fun Context.openItemUrlInternally(linkDecoded: String,
} }
fun Context.openItemUrl(linkDecoded: String, fun Context.openItemUrl(linkDecoded: String,
content: String,
image: String,
title: String,
source: String,
customTabsIntent: CustomTabsIntent, customTabsIntent: CustomTabsIntent,
internalBrowser: Boolean, internalBrowser: Boolean,
articleViewer: Boolean, articleViewer: Boolean,
@ -91,7 +104,7 @@ fun Context.openItemUrl(linkDecoded: String,
if (!internalBrowser) { if (!internalBrowser) {
openInBrowser(linkDecoded, app) openInBrowser(linkDecoded, app)
} else { } else {
this.openItemUrlInternally(linkDecoded, customTabsIntent, articleViewer, app) this.openItemUrlInternally(linkDecoded, content, image, title, source, customTabsIntent, articleViewer, app)
} }
} }
} }

View File

@ -50,7 +50,23 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/source" /> app:layout_constraintTop_toBottomOf="@+id/source" />
<org.sufficientlysecure.htmltextview.HtmlTextView <TextView
android:id="@+id/content"
android:autoLink="web"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:paddingBottom="48dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
<!--<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="@+id/content" android:id="@+id/content"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -63,8 +79,7 @@
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" app:layout_constraintTop_toBottomOf="@+id/title" />-->
tools:text="Some text @android:string/fingerprint_icon_content_description" />
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"