Items marked as read on open. Closes #208.
This commit is contained in:
parent
7fda0a04a1
commit
70ba9b20da
@ -1,15 +1,11 @@
|
||||
package apps.amine.bou.readerforselfoss
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentStatePagerAdapter
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.view.ViewPager
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@ -22,14 +18,10 @@ import apps.amine.bou.readerforselfoss.fragments.ArticleFragment
|
||||
import apps.amine.bou.readerforselfoss.themes.AppColors
|
||||
import apps.amine.bou.readerforselfoss.themes.Toppings
|
||||
import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer
|
||||
import apps.amine.bou.readerforselfoss.utils.Config
|
||||
import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException
|
||||
import apps.amine.bou.readerforselfoss.utils.succeeded
|
||||
import apps.amine.bou.readerforselfoss.utils.toggleStar
|
||||
import com.ftinc.scoop.Scoop
|
||||
import kotlinx.android.synthetic.main.activity_reader.*
|
||||
import me.relex.circleindicator.CircleIndicator
|
||||
import org.acra.ACRA
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
@ -37,9 +29,7 @@ import retrofit2.Response
|
||||
class ReaderActivity : AppCompatActivity() {
|
||||
|
||||
private var markOnScroll: Boolean = false
|
||||
private var debugReadingItems: Boolean = false
|
||||
private var currentItem: Int = 0
|
||||
private lateinit var userIdentifier: String
|
||||
|
||||
private lateinit var api: SelfossApi
|
||||
|
||||
@ -73,24 +63,11 @@ class ReaderActivity : AppCompatActivity() {
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||
|
||||
val settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||
val sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
debugReadingItems = sharedPref.getBoolean("read_debug", false)
|
||||
userIdentifier = sharedPref.getString("unique_id", "")
|
||||
markOnScroll = sharedPref.getBoolean("mark_on_scroll", false)
|
||||
|
||||
if (allItems.isEmpty()) {
|
||||
finish()
|
||||
}
|
||||
|
||||
api = SelfossApi(
|
||||
this,
|
||||
this@ReaderActivity,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
sharedPref.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
currentItem = intent.getIntExtra("currentItem", 0)
|
||||
|
||||
pager.adapter = ScreenSlidePagerAdapter(supportFragmentManager, AppColors(this@ReaderActivity))
|
||||
@ -104,56 +81,6 @@ class ReaderActivity : AppCompatActivity() {
|
||||
|
||||
pager.setPageTransformer(true, DepthPageTransformer())
|
||||
(indicator as CircleIndicator).setViewPager(pager)
|
||||
|
||||
pager.addOnPageChangeListener(
|
||||
object : ViewPager.SimpleOnPageChangeListener() {
|
||||
var isLastItem = false
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
isLastItem = (position === (allItems.size - 1))
|
||||
|
||||
if (allItems[position].starred) {
|
||||
canRemoveFromFavorite()
|
||||
} else {
|
||||
canFavorite()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
if (markOnScroll && (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem))) {
|
||||
api.markItem(allItems[pager.currentItem].id).enqueue(
|
||||
object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (!response.succeeded() && debugReadingItems) {
|
||||
val message =
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), this@ReaderActivity)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
if (debugReadingItems) {
|
||||
ACRA.getErrorReporter().maybeHandleSilentException(t, this@ReaderActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package apps.amine.bou.readerforselfoss.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.ColorStateList
|
||||
@ -23,6 +24,8 @@ import apps.amine.bou.readerforselfoss.R
|
||||
import apps.amine.bou.readerforselfoss.api.mercury.MercuryApi
|
||||
import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||
import apps.amine.bou.readerforselfoss.themes.AppColors
|
||||
import apps.amine.bou.readerforselfoss.utils.Config
|
||||
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
|
||||
@ -32,6 +35,7 @@ import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException
|
||||
import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
|
||||
import apps.amine.bou.readerforselfoss.utils.succeeded
|
||||
import apps.amine.bou.readerforselfoss.utils.toPx
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
@ -90,6 +94,22 @@ class ArticleFragment : Fragment() {
|
||||
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
|
||||
contentSource = allItems[pageNumber.toInt()].sourceAndDateText()
|
||||
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
editor = prefs.edit()
|
||||
fontSize = prefs.getString("reader_font_size", "14").toInt()
|
||||
showMalformedUrl = prefs.getBoolean("show_error_malformed_url", true)
|
||||
|
||||
val settings = activity!!.getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||
val debugReadingItems = prefs.getBoolean("read_debug", false)
|
||||
val markOnScroll = prefs.getBoolean("mark_on_scroll", false)
|
||||
|
||||
val api = SelfossApi(
|
||||
context!!,
|
||||
activity!!,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
fab = rootView.fab
|
||||
|
||||
fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent)
|
||||
@ -105,11 +125,6 @@ class ArticleFragment : Fragment() {
|
||||
mCustomTabActivityHelper = CustomTabActivityHelper()
|
||||
mCustomTabActivityHelper.bindCustomTabsService(activity)
|
||||
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
editor = prefs.edit()
|
||||
fontSize = prefs.getString("reader_font_size", "14").toInt()
|
||||
showMalformedUrl = prefs.getBoolean("show_error_malformed_url", true)
|
||||
|
||||
|
||||
floatingToolbar.setClickListener(
|
||||
object : FloatingToolbar.ItemClickListener {
|
||||
@ -126,6 +141,35 @@ class ArticleFragment : Fragment() {
|
||||
false,
|
||||
activity!!
|
||||
)
|
||||
R.id.unread_action -> api.unmarkItem(allItems[pageNumber.toInt()].id).enqueue(
|
||||
object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (!response.succeeded() && debugReadingItems) {
|
||||
val message =
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), activity!!)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
if (debugReadingItems) {
|
||||
ACRA.getErrorReporter().maybeHandleSilentException(t, activity!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
@ -167,6 +211,38 @@ class ArticleFragment : Fragment() {
|
||||
}
|
||||
)
|
||||
|
||||
if (markOnScroll) {
|
||||
api.markItem(allItems[pageNumber.toInt()].id).enqueue(
|
||||
object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (!response.succeeded() && debugReadingItems) {
|
||||
val message =
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), activity!!)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
if (debugReadingItems) {
|
||||
ACRA.getErrorReporter().maybeHandleSilentException(t, activity!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return rootView
|
||||
}
|
||||
|
||||
@ -325,8 +401,8 @@ class ArticleFragment : Fragment() {
|
||||
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.BUTTON_POSITIVE,
|
||||
"Send mail",
|
||||
{ dialog, _ ->
|
||||
"Send mail"
|
||||
) { dialog, _ ->
|
||||
|
||||
// This won't be translated because it should only be temporary.
|
||||
val to = Config.feedbackEmail
|
||||
@ -340,21 +416,18 @@ class ArticleFragment : Fragment() {
|
||||
|
||||
dialog.dismiss()
|
||||
}
|
||||
)
|
||||
alertDialog.setButton(
|
||||
AlertDialog.BUTTON_NEUTRAL,
|
||||
"Not now",
|
||||
{ dialog, _ -> dialog.dismiss() }
|
||||
)
|
||||
"Not now"
|
||||
) { dialog, _ -> dialog.dismiss() }
|
||||
alertDialog.setButton(
|
||||
AlertDialog.BUTTON_NEGATIVE,
|
||||
"Don't show anymore.",
|
||||
{ dialog, _ ->
|
||||
"Don't show anymore."
|
||||
) { dialog, _ ->
|
||||
editor.putBoolean("show_error_malformed_url", false)
|
||||
editor.apply()
|
||||
dialog.dismiss()
|
||||
}
|
||||
)
|
||||
alertDialog.show()
|
||||
}
|
||||
}
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_fiber_new.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_fiber_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 324 B |
BIN
app/src/main/res/drawable-mdpi/ic_fiber_new.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_fiber_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 B |
BIN
app/src/main/res/drawable-xhdpi/ic_fiber_new.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_fiber_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 327 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_fiber_new.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_fiber_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 490 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_fiber_new.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_fiber_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 567 B |
@ -2,6 +2,12 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/unread_action"
|
||||
android:icon="@drawable/ic_fiber_new"
|
||||
android:title="@string/unmark"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/more_action"
|
||||
android:icon="@drawable/ic_chrome_reader_mode"
|
||||
|
@ -171,4 +171,5 @@
|
||||
<string name="pref_debug_debug_logs">Debug logging (these will be sent without a dialog)</string>
|
||||
<string name="acra_login">Enable logging</string>
|
||||
<string name="drawer_item_hidden_tags">Hidden Tags</string>
|
||||
<string name="unmark">Mark item as unread</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user