Changed to Textview to disaply the simple content from the API.
This commit is contained in:
parent
ccf406ae68
commit
9e3fde744e
@ -2,6 +2,8 @@ package apps.amine.bou.readerforselfoss
|
||||
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.support.customtabs.CustomTabsIntent
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
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.utils.buildCustomTabsIntent
|
||||
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.shareLink
|
||||
import com.bumptech.glide.Glide
|
||||
@ -27,6 +30,18 @@ import xyz.klinker.android.drag_dismiss.activity.DragDismissActivity
|
||||
|
||||
class ReaderActivity : DragDismissActivity() {
|
||||
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() {
|
||||
super.onStart()
|
||||
@ -42,16 +57,18 @@ class ReaderActivity : DragDismissActivity() {
|
||||
Scoop.getInstance().apply(this)
|
||||
val v = inflater.inflate(R.layout.activity_reader, parent, false)
|
||||
showProgressBar()
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val image: ImageView = v.findViewById(R.id.imageView)
|
||||
val source: TextView = v.findViewById(R.id.source)
|
||||
val title: TextView = v.findViewById(R.id.title)
|
||||
val content: HtmlTextView = v.findViewById(R.id.content)
|
||||
val url = intent.getStringExtra("url")
|
||||
val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false))
|
||||
val browserBtn: ImageButton = v.findViewById(R.id.browserBtn)
|
||||
val shareBtn: ImageButton = v.findViewById(R.id.shareBtn)
|
||||
image = v.findViewById(R.id.imageView)
|
||||
source = v.findViewById(R.id.source)
|
||||
title = v.findViewById(R.id.title)
|
||||
content = v.findViewById(R.id.content)
|
||||
browserBtn = v.findViewById(R.id.browserBtn)
|
||||
shareBtn = v.findViewById(R.id.shareBtn)
|
||||
url = intent.getStringExtra("url")
|
||||
contentText = intent.getStringExtra("content")
|
||||
contentTitle = intent.getStringExtra("title")
|
||||
contentImage = intent.getStringExtra("image")
|
||||
contentSource = intent.getStringExtra("source")
|
||||
|
||||
|
||||
val customTabsIntent = this@ReaderActivity.buildCustomTabsIntent()
|
||||
@ -59,6 +76,49 @@ class ReaderActivity : DragDismissActivity() {
|
||||
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> {
|
||||
override fun onResponse(call: Call<ParsedContent>, response: Response<ParsedContent>) {
|
||||
if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) {
|
||||
@ -66,7 +126,9 @@ class ReaderActivity : DragDismissActivity() {
|
||||
title.text = response.body()!!.title
|
||||
if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) {
|
||||
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) {
|
||||
openInBrowserAfterFailing()
|
||||
}
|
||||
@ -86,6 +148,10 @@ class ReaderActivity : DragDismissActivity() {
|
||||
browserBtn.setOnClickListener {
|
||||
this@ReaderActivity.openItemUrl(
|
||||
response.body()!!.url,
|
||||
contentText,
|
||||
contentImage,
|
||||
contentTitle,
|
||||
contentSource,
|
||||
customTabsIntent,
|
||||
false,
|
||||
false,
|
||||
@ -101,6 +167,10 @@ class ReaderActivity : DragDismissActivity() {
|
||||
private fun openInBrowserAfterFailing() {
|
||||
this@ReaderActivity.openItemUrl(
|
||||
url,
|
||||
contentText,
|
||||
contentImage,
|
||||
contentTitle,
|
||||
contentSource,
|
||||
customTabsIntent,
|
||||
true,
|
||||
false,
|
||||
@ -109,6 +179,5 @@ class ReaderActivity : DragDismissActivity() {
|
||||
finish()
|
||||
}
|
||||
})
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
@ -229,6 +229,10 @@ class ItemCardAdapter(private val app: Activity,
|
||||
|
||||
mView.setOnClickListener {
|
||||
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
||||
items[adapterPosition].content,
|
||||
items[adapterPosition].getIcon(c),
|
||||
items[adapterPosition].title,
|
||||
items[adapterPosition].sourceAndDateText(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
|
@ -247,6 +247,10 @@ class ItemListAdapter(private val app: Activity,
|
||||
if (!clickBehavior) {
|
||||
mView.setOnClickListener {
|
||||
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
||||
items[adapterPosition].content,
|
||||
items[adapterPosition].getIcon(c),
|
||||
items[adapterPosition].title,
|
||||
items[adapterPosition].sourceAndDateText(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
@ -260,6 +264,10 @@ class ItemListAdapter(private val app: Activity,
|
||||
mView.setOnClickListener { actionBarShowHide() }
|
||||
mView.setOnLongClickListener {
|
||||
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
||||
items[adapterPosition].content,
|
||||
items[adapterPosition].getIcon(c),
|
||||
items[adapterPosition].title,
|
||||
items[adapterPosition].sourceAndDateText(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
|
@ -55,6 +55,7 @@ data class Sources(@SerializedName("id") val id: String,
|
||||
data class Item(@SerializedName("id") val id: String,
|
||||
@SerializedName("datetime") val datetime: String,
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("content") val content: String,
|
||||
@SerializedName("unread") val unread: Boolean,
|
||||
@SerializedName("starred") val starred: Boolean,
|
||||
@SerializedName("thumbnail") val thumbnail: String,
|
||||
@ -75,6 +76,7 @@ data class Item(@SerializedName("id") val id: String,
|
||||
id = source.readString(),
|
||||
datetime = source.readString(),
|
||||
title = source.readString(),
|
||||
content = source.readString(),
|
||||
unread = 0.toByte() != source.readByte(),
|
||||
starred = 0.toByte() != source.readByte(),
|
||||
thumbnail = source.readString(),
|
||||
@ -89,6 +91,7 @@ data class Item(@SerializedName("id") val id: String,
|
||||
dest.writeString(id)
|
||||
dest.writeString(datetime)
|
||||
dest.writeString(title)
|
||||
dest.writeString(content)
|
||||
dest.writeByte((if (unread) 1 else 0))
|
||||
dest.writeByte((if (starred) 1 else 0))
|
||||
dest.writeString(thumbnail)
|
||||
|
@ -51,6 +51,10 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent {
|
||||
}
|
||||
|
||||
fun Context.openItemUrlInternally(linkDecoded: String,
|
||||
content: String,
|
||||
image: String,
|
||||
title: String,
|
||||
source: String,
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
articleViewer: Boolean,
|
||||
app: Activity) {
|
||||
@ -63,7 +67,12 @@ fun Context.openItemUrlInternally(linkDecoded: String,
|
||||
.setDrawUnderStatusBar(true)
|
||||
.build(intent)
|
||||
|
||||
|
||||
intent.putExtra("url", linkDecoded)
|
||||
intent.putExtra("content", content)
|
||||
intent.putExtra("title", title)
|
||||
intent.putExtra("image", image)
|
||||
intent.putExtra("source", source)
|
||||
app.startActivity(intent)
|
||||
} else {
|
||||
try {
|
||||
@ -80,6 +89,10 @@ fun Context.openItemUrlInternally(linkDecoded: String,
|
||||
}
|
||||
|
||||
fun Context.openItemUrl(linkDecoded: String,
|
||||
content: String,
|
||||
image: String,
|
||||
title: String,
|
||||
source: String,
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
internalBrowser: Boolean,
|
||||
articleViewer: Boolean,
|
||||
@ -91,7 +104,7 @@ fun Context.openItemUrl(linkDecoded: String,
|
||||
if (!internalBrowser) {
|
||||
openInBrowser(linkDecoded, app)
|
||||
} else {
|
||||
this.openItemUrlInternally(linkDecoded, customTabsIntent, articleViewer, app)
|
||||
this.openItemUrlInternally(linkDecoded, content, image, title, source, customTabsIntent, articleViewer, app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,23 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
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:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@ -63,8 +79,7 @@
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title"
|
||||
tools:text="Some text @android:string/fingerprint_icon_content_description" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/title" />-->
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user