Multiple fixes.

This commit is contained in:
Amine 2017-10-23 14:31:04 +02:00
parent e30ea28e3f
commit e1476c5840
7 changed files with 68 additions and 44 deletions

View File

@ -1,3 +1,9 @@
**1.5.3.06**
- Fixed infinite scroll not working.
- Fixed logs not working.
**1.5.3.05** **1.5.3.05**
- Fixed an issue on older versions of Android. - Fixed an issue on older versions of Android.

View File

@ -118,6 +118,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var offset: Int = 0 private var offset: Int = 0
private var firstVisible: Int = 0 private var firstVisible: Int = 0
private var recyclerViewScrollListener: RecyclerView.OnScrollListener? = null private var recyclerViewScrollListener: RecyclerView.OnScrollListener? = null
private lateinit var settings: SharedPreferences
@ -151,15 +152,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
customTabActivityHelper = CustomTabActivityHelper() customTabActivityHelper = CustomTabActivityHelper()
val dirtyPref = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
api = SelfossApi(this, this@HomeActivity, dirtyPref.getBoolean("isSelfSignedCert", false), dirtyPref.getBoolean("should_log_everything", false)) sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
api = SelfossApi(this, this@HomeActivity, settings.getBoolean("isSelfSignedCert", false), sharedPref.getBoolean("should_log_everything", false))
items = ArrayList() items = ArrayList()
appColors = AppColors(this@HomeActivity) appColors = AppColors(this@HomeActivity)
handleBottomBar() handleBottomBar()
handleDrawer(dirtyPref) handleDrawer()
coordinatorLayout = findViewById(R.id.coordLayout) coordinatorLayout = findViewById(R.id.coordLayout)
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout) swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout)
@ -193,11 +196,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
val i = items[viewHolder.adapterPosition] val i = items[viewHolder.adapterPosition]
val position = items.indexOf(i) val position = items.indexOf(i)
if (shouldBeCardView) { val adapter = recyclerView.adapter
(recyclerView.adapter as ItemCardAdapter).removeItemAtIndex(position) when (adapter) {
} else { is ItemCardAdapter -> adapter.removeItemAtIndex(position)
(recyclerView.adapter as ItemListAdapter).removeItemAtIndex(position) is ItemListAdapter -> adapter.removeItemAtIndex(position)
} }
if (items.size > 0) if (items.size > 0)
tabNewBadge.setText("${items.size}").maybeShow() tabNewBadge.setText("${items.size}").maybeShow()
else else
@ -269,7 +273,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
sharedPref = PreferenceManager.getDefaultSharedPreferences(this) sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
val settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
editor = settings.edit() editor = settings.edit()
if (BuildConfig.GITHUB_VERSION) { if (BuildConfig.GITHUB_VERSION) {
@ -302,7 +305,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
infiniteScroll = sharedPref.getBoolean("infinite_loading", false) infiniteScroll = sharedPref.getBoolean("infinite_loading", false)
} }
private fun handleDrawer(dirtyPref: SharedPreferences) { private fun handleDrawer() {
displayAccountHeader = displayAccountHeader =
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("account_header_displaying", false) .getBoolean("account_header_displaying", false)
@ -313,7 +316,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
.addProfiles( .addProfiles(
ProfileDrawerItem() ProfileDrawerItem()
.withName( .withName(
dirtyPref.getString("url", "") settings.getString("url", "")
) )
.withIcon(resources.getDrawable(R.mipmap.ic_launcher)) .withIcon(resources.getDrawable(R.mipmap.ic_launcher))
) )
@ -579,9 +582,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
override fun onScrolled(localRecycler: RecyclerView?, dx: Int, dy: Int) { override fun onScrolled(localRecycler: RecyclerView?, dx: Int, dy: Int) {
if (dy > 0) { if (dy > 0) {
if (localRecycler != null) { if (localRecycler != null) {
val lastVisibleItem: Int = when (mLayoutManager) { val manager = recyclerView.layoutManager
is StaggeredGridLayoutManager -> mLayoutManager.findLastCompletelyVisibleItemPositions(null).last() val lastVisibleItem: Int = when (manager) {
is GridLayoutManager -> mLayoutManager.findLastCompletelyVisibleItemPosition() is StaggeredGridLayoutManager -> manager.findLastCompletelyVisibleItemPositions(null).last()
is GridLayoutManager -> manager.findLastCompletelyVisibleItemPosition()
else -> 0 else -> 0
} }
@ -601,18 +605,20 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
override fun onTabUnselected(position: Int) = Unit override fun onTabUnselected(position: Int) = Unit
override fun onTabReselected(position: Int) = override fun onTabReselected(position: Int) =
if (shouldBeCardView) { when (mLayoutManager) {
if ((mLayoutManager as StaggeredGridLayoutManager).findFirstCompletelyVisibleItemPositions(null)[0] == 0) { is StaggeredGridLayoutManager ->
if (mLayoutManager.findFirstCompletelyVisibleItemPositions(null)[0] == 0) {
getElementsAccordingToTab() getElementsAccordingToTab()
} else { } else {
mLayoutManager.scrollToPositionWithOffset(0, 0) mLayoutManager.scrollToPositionWithOffset(0, 0)
} }
} else { is GridLayoutManager ->
if ((mLayoutManager as GridLayoutManager).findFirstCompletelyVisibleItemPosition() == 0) { if (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) {
getElementsAccordingToTab() getElementsAccordingToTab()
} else { } else {
mLayoutManager.scrollToPositionWithOffset(0, 0) mLayoutManager.scrollToPositionWithOffset(0, 0)
} }
else -> Unit
} }
override fun onTabSelected(position: Int) = override fun onTabSelected(position: Int) =

View File

@ -1,6 +1,7 @@
package apps.amine.bou.readerforselfoss package apps.amine.bou.readerforselfoss
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -41,13 +42,14 @@ 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) val image: ImageView = v.findViewById(R.id.imageView)
val source: TextView = v.findViewById(R.id.source) val source: TextView = v.findViewById(R.id.source)
val title: TextView = v.findViewById(R.id.title) val title: TextView = v.findViewById(R.id.title)
val content: HtmlTextView = v.findViewById(R.id.content) val content: HtmlTextView = v.findViewById(R.id.content)
val url = intent.getStringExtra("url") val url = intent.getStringExtra("url")
val parser = MercuryApi(BuildConfig.MERCURY_KEY) val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false))
val browserBtn: ImageButton = v.findViewById(R.id.browserBtn) val browserBtn: ImageButton = v.findViewById(R.id.browserBtn)
val shareBtn: ImageButton = v.findViewById(R.id.shareBtn) val shareBtn: ImageButton = v.findViewById(R.id.shareBtn)

View File

@ -9,13 +9,16 @@ import retrofit2.converter.gson.GsonConverterFactory
class MercuryApi(private val key: String) { class MercuryApi(private val key: String, shouldLog: Boolean) {
private val service: MercuryService private val service: MercuryService
init { init {
val interceptor = HttpLoggingInterceptor() val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY interceptor.level = if (shouldLog)
HttpLoggingInterceptor.Level.BODY
else
HttpLoggingInterceptor.Level.NONE
val client = OkHttpClient.Builder().addInterceptor(interceptor).build() val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
val gson = GsonBuilder() val gson = GsonBuilder()

View File

@ -128,6 +128,12 @@ data class Item(@SerializedName("id") val id: String,
if (stringUrl.contains(":443")) { if (stringUrl.contains(":443")) {
stringUrl = stringUrl.replace(":443", "").replace("http://", "https://") stringUrl = stringUrl.replace(":443", "").replace("http://", "https://")
} }
// handle url not starting with http
if (stringUrl.startsWith("//")) {
stringUrl = "http:" + stringUrl
}
return stringUrl return stringUrl
} }

View File

@ -6,10 +6,8 @@ import android.content.SharedPreferences
import android.net.Uri import android.net.Uri
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.text.TextUtils import android.text.TextUtils
import android.util.Patterns
import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import okhttp3.HttpUrl
import apps.amine.bou.readerforselfoss.BuildConfig import apps.amine.bou.readerforselfoss.BuildConfig
import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.R
@ -36,20 +34,6 @@ fun Context.checkAndDisplayStoreApk() = {
} else Unit } else Unit
} }
fun String.isUrlValid(): Boolean =
HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches()
fun String.isBaseUrlValid(): Boolean {
val baseUrl = HttpUrl.parse(this)
var existsAndEndsWithSlash = false
if (baseUrl != null) {
val pathSegments = baseUrl.pathSegments()
existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1]
}
return Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash
}
fun String?.isEmptyOrNullOrNullString(): Boolean = fun String?.isEmptyOrNullOrNullString(): Boolean =
this == null || this == "null" || this.isEmpty() this == null || this == "null" || this.isEmpty()

View File

@ -7,9 +7,11 @@ import android.content.Intent
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.net.Uri import android.net.Uri
import android.support.customtabs.CustomTabsIntent import android.support.customtabs.CustomTabsIntent
import android.util.Patterns
import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.R
import apps.amine.bou.readerforselfoss.ReaderActivity import apps.amine.bou.readerforselfoss.ReaderActivity
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
import okhttp3.HttpUrl
import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder
@ -51,6 +53,7 @@ fun Context.openItemUrl(linkDecoded: String,
internalBrowser: Boolean, internalBrowser: Boolean,
articleViewer: Boolean, articleViewer: Boolean,
app: Activity) { app: Activity) {
if (!internalBrowser || !linkDecoded.isUrlValid()) { if (!internalBrowser || !linkDecoded.isUrlValid()) {
openInBrowser(linkDecoded, app) openInBrowser(linkDecoded, app)
} else { } else {
@ -85,3 +88,17 @@ private fun openInBrowser(linkDecoded: String, app: Activity) {
intent.data = Uri.parse(linkDecoded) intent.data = Uri.parse(linkDecoded)
app.startActivity(intent) app.startActivity(intent)
} }
fun String.isUrlValid(): Boolean =
HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches()
fun String.isBaseUrlValid(): Boolean {
val baseUrl = HttpUrl.parse(this)
var existsAndEndsWithSlash = false
if (baseUrl != null) {
val pathSegments = baseUrl.pathSegments()
existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1]
}
return Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash
}