Enhancements. Three first items of #108.
This commit is contained in:
parent
8fc5fab67b
commit
6f7f475a6b
@ -1,20 +1,19 @@
|
|||||||
package apps.amine.bou.readerforselfoss
|
package apps.amine.bou.readerforselfoss
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.PersistableBundle
|
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.support.customtabs.CustomTabsIntent
|
import android.support.customtabs.CustomTabsIntent
|
||||||
import android.support.design.widget.FloatingActionButton
|
import android.support.design.widget.FloatingActionButton
|
||||||
|
import android.support.v4.widget.NestedScrollView
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageButton
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.ProgressBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import apps.amine.bou.readerforselfoss.R.id.fab
|
|
||||||
import apps.amine.bou.readerforselfoss.api.mercury.MercuryApi
|
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
|
||||||
@ -24,14 +23,13 @@ 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
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import com.crashlytics.android.Crashlytics
|
||||||
import com.ftinc.scoop.Scoop
|
import com.ftinc.scoop.Scoop
|
||||||
import com.github.rubensousa.floatingtoolbar.FloatingToolbar
|
import com.github.rubensousa.floatingtoolbar.FloatingToolbar
|
||||||
import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter
|
import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter
|
||||||
import org.sufficientlysecure.htmltextview.HtmlTextView
|
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import xyz.klinker.android.drag_dismiss.activity.DragDismissActivity
|
|
||||||
|
|
||||||
|
|
||||||
class ReaderActivity : AppCompatActivity() {
|
class ReaderActivity : AppCompatActivity() {
|
||||||
@ -40,6 +38,8 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
private lateinit var source: TextView
|
private lateinit var source: TextView
|
||||||
private lateinit var title: TextView
|
private lateinit var title: TextView
|
||||||
private lateinit var content: TextView
|
private lateinit var content: TextView
|
||||||
|
private lateinit var progress: FrameLayout
|
||||||
|
private lateinit var nestedScrollView: NestedScrollView
|
||||||
//private lateinit var content: HtmlTextView
|
//private lateinit var content: HtmlTextView
|
||||||
private lateinit var url: String
|
private lateinit var url: String
|
||||||
private lateinit var contentText: String
|
private lateinit var contentText: String
|
||||||
@ -56,36 +56,35 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
Scoop.getInstance().apply(this)
|
Scoop.getInstance().apply(this)
|
||||||
val v = this
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_reader)
|
setContentView(R.layout.activity_reader)
|
||||||
|
|
||||||
|
image = findViewById(R.id.imageView)
|
||||||
image = v.findViewById(R.id.imageView)
|
source = findViewById(R.id.source)
|
||||||
source = v.findViewById(R.id.source)
|
title = findViewById(R.id.title)
|
||||||
title = v.findViewById(R.id.title)
|
content = findViewById(R.id.content)
|
||||||
content = v.findViewById(R.id.content)
|
progress = findViewById(R.id.progressBar)
|
||||||
|
nestedScrollView = findViewById(R.id.nestedScrollView)
|
||||||
url = intent.getStringExtra("url")
|
url = intent.getStringExtra("url")
|
||||||
contentText = intent.getStringExtra("content")
|
contentText = intent.getStringExtra("content")
|
||||||
contentTitle = intent.getStringExtra("title")
|
contentTitle = intent.getStringExtra("title")
|
||||||
contentImage = intent.getStringExtra("image")
|
contentImage = intent.getStringExtra("image")
|
||||||
contentSource = intent.getStringExtra("source")
|
contentSource = intent.getStringExtra("source")
|
||||||
|
|
||||||
fab = v.findViewById(R.id.fab)
|
fab = findViewById(R.id.fab)
|
||||||
val mFloatingToolbar: FloatingToolbar = v.findViewById(R.id.floatingToolbar)
|
val mFloatingToolbar: FloatingToolbar = findViewById(R.id.floatingToolbar)
|
||||||
mFloatingToolbar.attachFab(fab)
|
mFloatingToolbar.attachFab(fab)
|
||||||
|
|
||||||
val customTabsIntent = this@ReaderActivity.buildCustomTabsIntent()
|
val customTabsIntent = this@ReaderActivity.buildCustomTabsIntent()
|
||||||
mCustomTabActivityHelper = CustomTabActivityHelper()
|
mCustomTabActivityHelper = CustomTabActivityHelper()
|
||||||
mCustomTabActivityHelper.bindCustomTabsService(this)
|
mCustomTabActivityHelper.bindCustomTabsService(this)
|
||||||
|
|
||||||
|
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
|
||||||
mFloatingToolbar.setClickListener(object : FloatingToolbar.ItemClickListener {
|
mFloatingToolbar.setClickListener(object : FloatingToolbar.ItemClickListener {
|
||||||
override fun onItemClick(item: MenuItem) {
|
override fun onItemClick(item: MenuItem) {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.more_action -> getContentFromMercury(customTabsIntent)
|
R.id.more_action -> getContentFromMercury(customTabsIntent, prefs)
|
||||||
R.id.share_action -> this@ReaderActivity.shareLink(url)
|
R.id.share_action -> this@ReaderActivity.shareLink(url)
|
||||||
R.id.open_action -> this@ReaderActivity.openItemUrl(
|
R.id.open_action -> this@ReaderActivity.openItemUrl(
|
||||||
url,
|
url,
|
||||||
@ -107,26 +106,28 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
|
|
||||||
if (contentText.isEmptyOrNullOrNullString()) {
|
if (contentText.isEmptyOrNullOrNullString()) {
|
||||||
getContentFromMercury(customTabsIntent)
|
getContentFromMercury(customTabsIntent, prefs)
|
||||||
} else {
|
} else {
|
||||||
source.text = contentSource
|
source.text = contentSource
|
||||||
title.text = contentTitle
|
title.text = contentTitle
|
||||||
content.text = Html.fromHtml(contentText, HtmlHttpImageGetter(content, null, true), null)
|
tryToHandleHtml(contentText, customTabsIntent, prefs)
|
||||||
//content.setHtml(contentText, HtmlHttpImageGetter(content, null, true))
|
|
||||||
|
|
||||||
if (!contentImage.isEmptyOrNullOrNullString())
|
if (!contentImage.isEmptyOrNullOrNullString()) {
|
||||||
|
image.visibility = View.VISIBLE
|
||||||
Glide
|
Glide
|
||||||
.with(baseContext)
|
.with(baseContext)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(contentImage)
|
.load(contentImage)
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
.into(image)
|
.into(image)
|
||||||
|
} else {
|
||||||
|
image.visibility = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
|
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent, prefs: SharedPreferences) {
|
||||||
|
progress.visibility = View.VISIBLE
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
|
||||||
val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false))
|
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> {
|
||||||
@ -135,29 +136,48 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
source.text = response.body()!!.domain
|
source.text = response.body()!!.domain
|
||||||
title.text = response.body()!!.title
|
title.text = response.body()!!.title
|
||||||
this@ReaderActivity.url = response.body()!!.url
|
this@ReaderActivity.url = response.body()!!.url
|
||||||
if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) {
|
|
||||||
try {
|
|
||||||
content.text = Html.fromHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true), null)
|
|
||||||
|
|
||||||
//content.setHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true))
|
if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) {
|
||||||
} catch (e: IndexOutOfBoundsException) {
|
tryToHandleHtml(response.body()!!.content, customTabsIntent, prefs)
|
||||||
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()) {
|
||||||
|
image.visibility = View.VISIBLE
|
||||||
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)
|
||||||
|
} else {
|
||||||
} else openInBrowserAfterFailing()
|
image.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(call: Call<ParsedContent>, t: Throwable) = openInBrowserAfterFailing()
|
nestedScrollView.scrollTo(0, 0)
|
||||||
|
|
||||||
private fun openInBrowserAfterFailing() {
|
progress.visibility = View.GONE
|
||||||
|
} else openInBrowserAfterFailing(customTabsIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<ParsedContent>, t: Throwable) = openInBrowserAfterFailing(customTabsIntent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun tryToHandleHtml(c: String, customTabsIntent: CustomTabsIntent, prefs: SharedPreferences) {
|
||||||
|
try {
|
||||||
|
content.text = Html.fromHtml(c, HtmlHttpImageGetter(content, null, true), null)
|
||||||
|
|
||||||
|
//content.setHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||||
|
Crashlytics.log(100, "CANT_TRANSFORM_TO_HTML", e.message)
|
||||||
|
Crashlytics.logException(e)
|
||||||
|
openInBrowserAfterFailing(customTabsIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) {
|
||||||
|
progress.visibility = View.GONE
|
||||||
this@ReaderActivity.openItemUrl(
|
this@ReaderActivity.openItemUrl(
|
||||||
url,
|
url,
|
||||||
contentText,
|
contentText,
|
||||||
@ -171,6 +191,4 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ 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].content,
|
||||||
items[adapterPosition].getIcon(c),
|
items[adapterPosition].getThumbnail(c),
|
||||||
items[adapterPosition].title,
|
items[adapterPosition].title,
|
||||||
items[adapterPosition].sourceAndDateText(),
|
items[adapterPosition].sourceAndDateText(),
|
||||||
customTabsIntent,
|
customTabsIntent,
|
||||||
|
@ -248,7 +248,7 @@ class ItemListAdapter(private val app: Activity,
|
|||||||
mView.setOnClickListener {
|
mView.setOnClickListener {
|
||||||
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
||||||
items[adapterPosition].content,
|
items[adapterPosition].content,
|
||||||
items[adapterPosition].getIcon(c),
|
items[adapterPosition].getThumbnail(c),
|
||||||
items[adapterPosition].title,
|
items[adapterPosition].title,
|
||||||
items[adapterPosition].sourceAndDateText(),
|
items[adapterPosition].sourceAndDateText(),
|
||||||
customTabsIntent,
|
customTabsIntent,
|
||||||
@ -265,7 +265,7 @@ class ItemListAdapter(private val app: Activity,
|
|||||||
mView.setOnLongClickListener {
|
mView.setOnLongClickListener {
|
||||||
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
c.openItemUrl(items[adapterPosition].getLinkDecoded(),
|
||||||
items[adapterPosition].content,
|
items[adapterPosition].content,
|
||||||
items[adapterPosition].getIcon(c),
|
items[adapterPosition].getThumbnail(c),
|
||||||
items[adapterPosition].title,
|
items[adapterPosition].title,
|
||||||
items[adapterPosition].sourceAndDateText(),
|
items[adapterPosition].sourceAndDateText(),
|
||||||
customTabsIntent,
|
customTabsIntent,
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<android.support.v4.widget.NestedScrollView
|
<android.support.v4.widget.NestedScrollView
|
||||||
|
android:id="@+id/nestedScrollView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -124,5 +125,23 @@
|
|||||||
app:rippleColor="?attr/colorAccentDark" />
|
app:rippleColor="?attr/colorAccentDark" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:background="@color/black"
|
||||||
|
android:clickable="false">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
style="?android:attr/progressBarStyleLarge"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:progressTint="?attr/colorAccent" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user