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

View File

@ -1,6 +1,7 @@
package apps.amine.bou.readerforselfoss
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -41,13 +42,14 @@ 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)
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)

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
init {
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 gson = GsonBuilder()

View File

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

View File

@ -6,10 +6,8 @@ import android.content.SharedPreferences
import android.net.Uri
import android.support.v7.app.AlertDialog
import android.text.TextUtils
import android.util.Patterns
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import okhttp3.HttpUrl
import apps.amine.bou.readerforselfoss.BuildConfig
import apps.amine.bou.readerforselfoss.R
@ -36,20 +34,6 @@ fun Context.checkAndDisplayStoreApk() = {
} 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 =
this == null || this == "null" || this.isEmpty()

View File

@ -7,9 +7,11 @@ import android.content.Intent
import android.graphics.BitmapFactory
import android.net.Uri
import android.support.customtabs.CustomTabsIntent
import android.util.Patterns
import apps.amine.bou.readerforselfoss.R
import apps.amine.bou.readerforselfoss.ReaderActivity
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
import okhttp3.HttpUrl
import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder
@ -51,6 +53,7 @@ fun Context.openItemUrl(linkDecoded: String,
internalBrowser: Boolean,
articleViewer: Boolean,
app: Activity) {
if (!internalBrowser || !linkDecoded.isUrlValid()) {
openInBrowser(linkDecoded, app)
} else {
@ -85,3 +88,17 @@ private fun openInBrowser(linkDecoded: String, app: Activity) {
intent.data = Uri.parse(linkDecoded)
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
}