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,18 +126,20 @@ 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()
} }
} }
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty())
Glide Glide
.with(baseContext) .with(baseContext)
.asBitmap() .asBitmap()
.load(response.body()!!.lead_image_url) .load(response.body()!!.lead_image_url)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(image) .into(image)
shareBtn.setOnClickListener { shareBtn.setOnClickListener {
this@ReaderActivity.shareLink(response.body()!!.url) this@ReaderActivity.shareLink(response.body()!!.url)
@ -85,11 +147,15 @@ class ReaderActivity : DragDismissActivity() {
browserBtn.setOnClickListener { browserBtn.setOnClickListener {
this@ReaderActivity.openItemUrl( this@ReaderActivity.openItemUrl(
response.body()!!.url, response.body()!!.url,
customTabsIntent, contentText,
false, contentImage,
false, contentTitle,
this@ReaderActivity) contentSource,
customTabsIntent,
false,
false,
this@ReaderActivity)
} }
hideProgressBar() hideProgressBar()
@ -100,15 +166,18 @@ class ReaderActivity : DragDismissActivity() {
private fun openInBrowserAfterFailing() { private fun openInBrowserAfterFailing() {
this@ReaderActivity.openItemUrl( this@ReaderActivity.openItemUrl(
url, url,
customTabsIntent, contentText,
true, contentImage,
false, contentTitle,
this@ReaderActivity contentSource,
customTabsIntent,
true,
false,
this@ReaderActivity
) )
finish() finish()
} }
}) })
return v
} }
} }

View File

@ -77,10 +77,10 @@ class ItemCardAdapter(private val app: Activity,
val color = generator.getColor(itm.sourcetitle) val color = generator.getColor(itm.sourcetitle)
val drawable = val drawable =
TextDrawable TextDrawable
.builder() .builder()
.round() .round()
.build(itm.sourcetitle.toTextDrawableString(), color) .build(itm.sourcetitle.toTextDrawableString(), color)
holder.sourceImage.setImageDrawable(drawable) holder.sourceImage.setImageDrawable(drawable)
} else { } else {
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage) c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage)
@ -128,13 +128,13 @@ class ItemCardAdapter(private val app: Activity,
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) { override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {
if (!response.succeeded() && debugReadingItems) { if (!response.succeeded() && debugReadingItems) {
val message = val message =
"message: ${response.message()} " + "message: ${response.message()} " +
"response isSuccess: ${response.isSuccessful} " + "response isSuccess: ${response.isSuccessful} " +
"response code: ${response.code()} " + "response code: ${response.code()} " +
"response message: ${response.message()} " + "response message: ${response.message()} " +
"response errorBody: ${response.errorBody()?.string()} " + "response errorBody: ${response.errorBody()?.string()} " +
"body success: ${response.body()?.success} " + "body success: ${response.body()?.success} " +
"body isSuccess: ${response.body()?.isSuccess}" "body isSuccess: ${response.body()?.isSuccess}"
Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) Crashlytics.log(100, "READ_DEBUG_SUCCESS", message)
Crashlytics.logException(Exception("Was success, but did it work ?")) Crashlytics.logException(Exception("Was success, but did it work ?"))
@ -229,10 +229,14 @@ class ItemCardAdapter(private val app: Activity,
mView.setOnClickListener { mView.setOnClickListener {
c.openItemUrl(items[adapterPosition].getLinkDecoded(), c.openItemUrl(items[adapterPosition].getLinkDecoded(),
customTabsIntent, items[adapterPosition].content,
internalBrowser, items[adapterPosition].getIcon(c),
articleViewer, items[adapterPosition].title,
app) items[adapterPosition].sourceAndDateText(),
customTabsIntent,
internalBrowser,
articleViewer,
app)
} }
} }
} }

View File

@ -72,8 +72,8 @@ class ItemListAdapter(private val app: Activity,
if (itm.getThumbnail(c).isEmpty()) { if (itm.getThumbnail(c).isEmpty()) {
val sizeInInt = 46 val sizeInInt = 46
val sizeInDp = TypedValue.applyDimension( val sizeInDp = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, sizeInInt.toFloat(), c.resources TypedValue.COMPLEX_UNIT_DIP, sizeInInt.toFloat(), c.resources
.displayMetrics).toInt() .displayMetrics).toInt()
val marginInInt = 16 val marginInInt = 16
val marginInDp = TypedValue.applyDimension( val marginInDp = TypedValue.applyDimension(
@ -147,13 +147,13 @@ class ItemListAdapter(private val app: Activity,
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) { override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {
if (!response.succeeded() && debugReadingItems) { if (!response.succeeded() && debugReadingItems) {
val message = val message =
"message: ${response.message()} " + "message: ${response.message()} " +
"response isSuccess: ${response.isSuccessful} " + "response isSuccess: ${response.isSuccessful} " +
"response code: ${response.code()} " + "response code: ${response.code()} " +
"response message: ${response.message()} " + "response message: ${response.message()} " +
"response errorBody: ${response.errorBody()?.string()} " + "response errorBody: ${response.errorBody()?.string()} " +
"body success: ${response.body()?.success} " + "body success: ${response.body()?.success} " +
"body isSuccess: ${response.body()?.isSuccess}" "body isSuccess: ${response.body()?.isSuccess}"
Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) Crashlytics.log(100, "READ_DEBUG_SUCCESS", message)
Crashlytics.logException(Exception("Was success, but did it work ?")) Crashlytics.logException(Exception("Was success, but did it work ?"))
@ -247,10 +247,14 @@ class ItemListAdapter(private val app: Activity,
if (!clickBehavior) { if (!clickBehavior) {
mView.setOnClickListener { mView.setOnClickListener {
c.openItemUrl(items[adapterPosition].getLinkDecoded(), c.openItemUrl(items[adapterPosition].getLinkDecoded(),
customTabsIntent, items[adapterPosition].content,
internalBrowser, items[adapterPosition].getIcon(c),
articleViewer, items[adapterPosition].title,
app) items[adapterPosition].sourceAndDateText(),
customTabsIntent,
internalBrowser,
articleViewer,
app)
} }
mView.setOnLongClickListener { mView.setOnLongClickListener {
actionBarShowHide() actionBarShowHide()
@ -260,10 +264,14 @@ 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(),
customTabsIntent, items[adapterPosition].content,
internalBrowser, items[adapterPosition].getIcon(c),
articleViewer, items[adapterPosition].title,
app) items[adapterPosition].sourceAndDateText(),
customTabsIntent,
internalBrowser,
articleViewer,
app)
true true
} }
} }

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,
@ -72,15 +73,16 @@ data class Item(@SerializedName("id") val id: String,
} }
constructor(source: Parcel) : this( constructor(source: Parcel) : this(
id = source.readString(), id = source.readString(),
datetime = source.readString(), datetime = source.readString(),
title = source.readString(), title = source.readString(),
unread = 0.toByte() != source.readByte(), content = source.readString(),
starred = 0.toByte() != source.readByte(), unread = 0.toByte() != source.readByte(),
thumbnail = source.readString(), starred = 0.toByte() != source.readByte(),
icon = source.readString(), thumbnail = source.readString(),
link = source.readString(), icon = source.readString(),
sourcetitle = source.readString() link = source.readString(),
sourcetitle = source.readString()
) )
override fun describeContents() = 0 override fun describeContents() = 0
@ -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) {
@ -58,12 +62,17 @@ fun Context.openItemUrlInternally(linkDecoded: String,
val intent = Intent(this, ReaderActivity::class.java) val intent = Intent(this, ReaderActivity::class.java)
DragDismissIntentBuilder(this) DragDismissIntentBuilder(this)
.setFullscreenOnTablets(true) // defaults to false, tablets will have padding on each side .setFullscreenOnTablets(true) // defaults to false, tablets will have padding on each side
.setDragElasticity(DragDismissIntentBuilder.DragElasticity.NORMAL) // Larger elasticities will make it easier to dismiss. .setDragElasticity(DragDismissIntentBuilder.DragElasticity.NORMAL) // Larger elasticities will make it easier to dismiss.
.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)
} }
} }
} }
@ -103,7 +116,7 @@ private fun openInBrowser(linkDecoded: String, app: Activity) {
} }
fun String.isUrlValid(): Boolean = fun String.isUrlValid(): Boolean =
HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches() HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches()
fun String.isBaseUrlValid(): Boolean { fun String.isBaseUrlValid(): Boolean {
val baseUrl = HttpUrl.parse(this) val baseUrl = HttpUrl.parse(this)

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"