Compare commits

..

3 Commits

Author SHA1 Message Date
8dc25c527d Trying to fix issues with Glide, fragment, and destroyed activity. 2018-05-31 22:41:23 +02:00
46d6bd57c1 Changelog. 2018-05-31 12:46:45 +02:00
db014fe13d Fixed issue on pre lolipop devices. 2018-05-31 12:42:06 +02:00
7 changed files with 99 additions and 59 deletions

View File

@ -1,5 +1,7 @@
**1.6.x** **1.6.x**
- Fixed pre-lolipop issue with automatic theme changes.
- Removed all Build config things. - Removed all Build config things.
- Removed firebase and fabric. - Removed firebase and fabric.

View File

@ -44,10 +44,11 @@ class AddSourceActivity : AppCompatActivity() {
setContentView(R.layout.activity_add_source) setContentView(R.layout.activity_add_source)
// TODO: input bubble cursor val scoop = Scoop.getInstance()
Scoop.getInstance() scoop.bind(this, Toppings.PRIMARY.value, toolbar)
.bind(this, Toppings.PRIMARY.value, toolbar) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
.bindStatusBar(this, Toppings.PRIMARY_DARK.value) scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
}
val drawable = nameInput.background val drawable = nameInput.background
drawable.setColorFilter(appColors.colorAccent, PorterDuff.Mode.SRC_ATOP) drawable.setColorFilter(appColors.colorAccent, PorterDuff.Mode.SRC_ATOP)

View File

@ -6,6 +6,7 @@ import android.content.SharedPreferences
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.v4.view.MenuItemCompat import android.support.v4.view.MenuItemCompat
@ -389,16 +390,21 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} }
private fun handleThemeBinding() { private fun handleThemeBinding() {
Scoop.getInstance() val scoop = Scoop.getInstance()
.bind(this, Toppings.PRIMARY.value, toolBar) scoop.bind(this, Toppings.PRIMARY.value, toolBar)
.bindStatusBar(this, Toppings.PRIMARY_DARK.value) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
}
} }
private fun handleThemeUpdate() { private fun handleThemeUpdate() {
Scoop.getInstance() val scoop = Scoop.getInstance()
.update(Toppings.PRIMARY.value, appColors.colorPrimary) scoop.update(Toppings.PRIMARY.value, appColors.colorPrimary)
.update(Toppings.PRIMARY_DARK.value, appColors.colorPrimaryDark)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scoop.update(Toppings.PRIMARY_DARK.value, appColors.colorPrimaryDark)
}
} }
private fun handleDrawer() { private fun handleDrawer() {

View File

@ -3,6 +3,7 @@ package apps.amine.bou.readerforselfoss
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
@ -62,9 +63,11 @@ class ReaderActivity : AppCompatActivity() {
setContentView(R.layout.activity_reader) setContentView(R.layout.activity_reader)
Scoop.getInstance() val scoop = Scoop.getInstance()
.bind(this, Toppings.PRIMARY.value, toolBar) scoop.bind(this, Toppings.PRIMARY.value, toolBar)
.bindStatusBar(this, Toppings.PRIMARY_DARK.value) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
}
setSupportActionBar(toolBar) setSupportActionBar(toolBar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)

View File

@ -2,6 +2,7 @@ package apps.amine.bou.readerforselfoss
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
@ -29,9 +30,11 @@ class SourcesActivity : AppCompatActivity() {
setContentView(R.layout.activity_sources) setContentView(R.layout.activity_sources)
Scoop.getInstance() val scoop = Scoop.getInstance()
.bind(this, Toppings.PRIMARY.value, toolbar) scoop.bind(this, Toppings.PRIMARY.value, toolbar)
.bindStatusBar(this, Toppings.PRIMARY_DARK.value) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
}
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)

View File

@ -1,6 +1,5 @@
package apps.amine.bou.readerforselfoss.fragments package apps.amine.bou.readerforselfoss.fragments
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.res.ColorStateList import android.content.res.ColorStateList
@ -20,7 +19,6 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.webkit.WebSettings import android.webkit.WebSettings
import apps.amine.bou.readerforselfoss.BuildConfig
import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.R
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
@ -86,8 +84,6 @@ class ArticleFragment : Fragment() {
rootView = inflater rootView = inflater
.inflate(R.layout.fragment_article, container, false) as ViewGroup .inflate(R.layout.fragment_article, container, false) as ViewGroup
val context: Context = activity!!
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()].title
@ -119,7 +115,7 @@ class ArticleFragment : Fragment() {
object : FloatingToolbar.ItemClickListener { 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, prefs, context) R.id.more_action -> getContentFromMercury(customTabsIntent, prefs)
R.id.share_action -> activity!!.shareLink(url) R.id.share_action -> activity!!.shareLink(url)
R.id.open_action -> activity!!.openItemUrl( R.id.open_action -> activity!!.openItemUrl(
allItems, allItems,
@ -142,16 +138,16 @@ class ArticleFragment : Fragment() {
rootView.source.text = contentSource rootView.source.text = contentSource
if (contentText.isEmptyOrNullOrNullString()) { if (contentText.isEmptyOrNullOrNullString()) {
getContentFromMercury(customTabsIntent, prefs, context) getContentFromMercury(customTabsIntent, prefs)
} else { } else {
rootView.titleView.text = contentTitle rootView.titleView.text = contentTitle
htmlToWebview(contentText, prefs, context) htmlToWebview(contentText, prefs)
if (!contentImage.isEmptyOrNullOrNullString()) { if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
rootView.imageView.visibility = View.VISIBLE rootView.imageView.visibility = View.VISIBLE
Glide Glide
.with(context) .with(context!!)
.asBitmap() .asBitmap()
.load(contentImage) .load(contentImage)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
@ -176,8 +172,7 @@ class ArticleFragment : Fragment() {
private fun getContentFromMercury( private fun getContentFromMercury(
customTabsIntent: CustomTabsIntent, customTabsIntent: CustomTabsIntent,
prefs: SharedPreferences, prefs: SharedPreferences
context: Context
) { ) {
rootView.progressBar.visibility = View.VISIBLE rootView.progressBar.visibility = View.VISIBLE
val parser = MercuryApi( val parser = MercuryApi(
@ -197,33 +192,39 @@ class ArticleFragment : Fragment() {
rootView.titleView.text = response.body()!!.title rootView.titleView.text = response.body()!!.title
url = response.body()!!.url url = response.body()!!.url
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) if (context != null) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
}
} }
try { try {
htmlToWebview(response.body()!!.content.orEmpty(), prefs, context) htmlToWebview(response.body()!!.content.orEmpty(), prefs)
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) if (context != null) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
}
} }
try { try {
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty()) { if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty() && context != null) {
rootView.imageView.visibility = View.VISIBLE rootView.imageView.visibility = View.VISIBLE
try { try {
Glide Glide
.with(context) .with(context!!)
.asBitmap() .asBitmap()
.load(response.body()!!.lead_image_url) .load(response.body()!!.lead_image_url)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(rootView.imageView) .into(rootView.imageView)
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
} }
} else { } else {
rootView.imageView.visibility = View.GONE rootView.imageView.visibility = View.GONE
} }
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) if (context != null) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
}
} }
try { try {
@ -231,17 +232,23 @@ class ArticleFragment : Fragment() {
rootView.progressBar.visibility = View.GONE rootView.progressBar.visibility = View.GONE
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) if (context != null) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
}
} }
} else { } else {
try { try {
openInBrowserAfterFailing(customTabsIntent) openInBrowserAfterFailing(customTabsIntent)
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) if (context != null) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
}
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context) if (context != null) {
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
}
} }
} }
@ -253,31 +260,47 @@ class ArticleFragment : Fragment() {
) )
} }
private fun htmlToWebview(c: String, prefs: SharedPreferences, context: Context) { private fun htmlToWebview(c: String, prefs: SharedPreferences) {
val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent) val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent)
rootView.webcontent.visibility = View.VISIBLE rootView.webcontent.visibility = View.VISIBLE
val (textColor, backgroundColor) = if (appColors.isDarkTheme) { val (textColor, backgroundColor) = if (appColors.isDarkTheme) {
rootView.webcontent.setBackgroundColor( if (context != null) {
ContextCompat.getColor( rootView.webcontent.setBackgroundColor(
context, ContextCompat.getColor(
R.color.dark_webview context!!,
R.color.dark_webview
)
) )
) Pair(ContextCompat.getColor(context!!, R.color.dark_webview_text), ContextCompat.getColor(context!!, R.color.light_webview_text))
Pair(ContextCompat.getColor(context, R.color.dark_webview_text), ContextCompat.getColor(context, R.color.light_webview_text)) } else {
Pair(null, null)
}
} else { } else {
rootView.webcontent.setBackgroundColor( if (context != null) {
ContextCompat.getColor( rootView.webcontent.setBackgroundColor(
context, ContextCompat.getColor(
R.color.light_webview context!!,
R.color.light_webview
)
) )
) Pair(ContextCompat.getColor(context!!, R.color.light_webview_text), ContextCompat.getColor(context!!, R.color.dark_webview_text))
Pair(ContextCompat.getColor(context, R.color.light_webview_text), ContextCompat.getColor(context, R.color.dark_webview_text)) } else {
Pair(null, null)
}
} }
val stringTextColor = String.format("#%06X", 0xFFFFFF and textColor) val stringTextColor: String = if (textColor != null) {
val stringBackgroundColor = String.format("#%06X", 0xFFFFFF and backgroundColor) String.format("#%06X", 0xFFFFFF and textColor)
} else {
"#000000"
}
val stringBackgroundColor = if (backgroundColor != null) {
String.format("#%06X", 0xFFFFFF and backgroundColor)
} else {
"#FFFFFF"
}
rootView.webcontent.settings.useWideViewPort = true rootView.webcontent.settings.useWideViewPort = true
rootView.webcontent.settings.loadWithOverviewMode = true rootView.webcontent.settings.loadWithOverviewMode = true
@ -296,8 +319,8 @@ class ArticleFragment : Fragment() {
val itemUrl = URL(url) val itemUrl = URL(url)
baseUrl = itemUrl.protocol + "://" + itemUrl.host baseUrl = itemUrl.protocol + "://" + itemUrl.host
} catch (e: MalformedURLException) { } catch (e: MalformedURLException) {
if (showMalformedUrl) { if (showMalformedUrl && context != null) {
val alertDialog = AlertDialog.Builder(context).create() val alertDialog = AlertDialog.Builder(context!!).create()
alertDialog.setTitle("Error") alertDialog.setTitle("Error")
alertDialog.setMessage("You are encountering a bug that I can't solve. Can you please contact me to solve the issue, please ?") alertDialog.setMessage("You are encountering a bug that I can't solve. Can you please contact me to solve the issue, please ?")
alertDialog.setButton( alertDialog.setButton(

View File

@ -1,6 +1,7 @@
package apps.amine.bou.readerforselfoss.settings; package apps.amine.bou.readerforselfoss.settings;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
@ -48,10 +49,11 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
AppBarLayout bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); AppBarLayout bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
Toolbar toolbar = bar.findViewById(R.id.toolbar); Toolbar toolbar = bar.findViewById(R.id.toolbar);
// TODO: all switches Scoop scoop = Scoop.getInstance();
Scoop.getInstance() scoop.bind(this, Toppings.PRIMARY.getValue(), toolbar);
.bind(this, Toppings.PRIMARY.getValue(), toolbar) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
.bindStatusBar(this, Toppings.PRIMARY_DARK.getValue()); scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.getValue());
}
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);