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
|
package apps.amine.bou.readerforselfoss
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.res.Resources
|
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.preference.PreferenceManager
|
|
||||||
import android.support.v4.app.FragmentManager
|
import android.support.v4.app.FragmentManager
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter
|
import android.support.v4.app.FragmentStatePagerAdapter
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.support.v4.view.ViewPager
|
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
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.AppColors
|
||||||
import apps.amine.bou.readerforselfoss.themes.Toppings
|
import apps.amine.bou.readerforselfoss.themes.Toppings
|
||||||
import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer
|
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 apps.amine.bou.readerforselfoss.utils.toggleStar
|
||||||
import com.ftinc.scoop.Scoop
|
import com.ftinc.scoop.Scoop
|
||||||
import kotlinx.android.synthetic.main.activity_reader.*
|
import kotlinx.android.synthetic.main.activity_reader.*
|
||||||
import me.relex.circleindicator.CircleIndicator
|
import me.relex.circleindicator.CircleIndicator
|
||||||
import org.acra.ACRA
|
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
@ -37,9 +29,7 @@ import retrofit2.Response
|
|||||||
class ReaderActivity : AppCompatActivity() {
|
class ReaderActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private var markOnScroll: Boolean = false
|
private var markOnScroll: Boolean = false
|
||||||
private var debugReadingItems: Boolean = false
|
|
||||||
private var currentItem: Int = 0
|
private var currentItem: Int = 0
|
||||||
private lateinit var userIdentifier: String
|
|
||||||
|
|
||||||
private lateinit var api: SelfossApi
|
private lateinit var api: SelfossApi
|
||||||
|
|
||||||
@ -73,24 +63,11 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(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()) {
|
if (allItems.isEmpty()) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
api = SelfossApi(
|
|
||||||
this,
|
|
||||||
this@ReaderActivity,
|
|
||||||
settings.getBoolean("isSelfSignedCert", false),
|
|
||||||
sharedPref.getBoolean("should_log_everything", false)
|
|
||||||
)
|
|
||||||
|
|
||||||
currentItem = intent.getIntExtra("currentItem", 0)
|
currentItem = intent.getIntExtra("currentItem", 0)
|
||||||
|
|
||||||
pager.adapter = ScreenSlidePagerAdapter(supportFragmentManager, AppColors(this@ReaderActivity))
|
pager.adapter = ScreenSlidePagerAdapter(supportFragmentManager, AppColors(this@ReaderActivity))
|
||||||
@ -104,56 +81,6 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
pager.setPageTransformer(true, DepthPageTransformer())
|
pager.setPageTransformer(true, DepthPageTransformer())
|
||||||
(indicator as CircleIndicator).setViewPager(pager)
|
(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() {
|
override fun onPause() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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
|
||||||
@ -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.MercuryApi
|
||||||
import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent
|
import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
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.themes.AppColors
|
||||||
import apps.amine.bou.readerforselfoss.utils.Config
|
import apps.amine.bou.readerforselfoss.utils.Config
|
||||||
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
|
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.openItemUrl
|
||||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||||
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
|
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
|
||||||
|
import apps.amine.bou.readerforselfoss.utils.succeeded
|
||||||
import apps.amine.bou.readerforselfoss.utils.toPx
|
import apps.amine.bou.readerforselfoss.utils.toPx
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
@ -90,6 +94,22 @@ class ArticleFragment : Fragment() {
|
|||||||
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
|
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
|
||||||
contentSource = allItems[pageNumber.toInt()].sourceAndDateText()
|
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 = rootView.fab
|
||||||
|
|
||||||
fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent)
|
fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent)
|
||||||
@ -105,11 +125,6 @@ class ArticleFragment : Fragment() {
|
|||||||
mCustomTabActivityHelper = CustomTabActivityHelper()
|
mCustomTabActivityHelper = CustomTabActivityHelper()
|
||||||
mCustomTabActivityHelper.bindCustomTabsService(activity)
|
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(
|
floatingToolbar.setClickListener(
|
||||||
object : FloatingToolbar.ItemClickListener {
|
object : FloatingToolbar.ItemClickListener {
|
||||||
@ -126,6 +141,35 @@ class ArticleFragment : Fragment() {
|
|||||||
false,
|
false,
|
||||||
activity!!
|
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
|
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
|
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.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(
|
||||||
AlertDialog.BUTTON_POSITIVE,
|
AlertDialog.BUTTON_POSITIVE,
|
||||||
"Send mail",
|
"Send mail"
|
||||||
{ dialog, _ ->
|
) { dialog, _ ->
|
||||||
|
|
||||||
// This won't be translated because it should only be temporary.
|
// This won't be translated because it should only be temporary.
|
||||||
val to = Config.feedbackEmail
|
val to = Config.feedbackEmail
|
||||||
@ -340,21 +416,18 @@ class ArticleFragment : Fragment() {
|
|||||||
|
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
)
|
|
||||||
alertDialog.setButton(
|
alertDialog.setButton(
|
||||||
AlertDialog.BUTTON_NEUTRAL,
|
AlertDialog.BUTTON_NEUTRAL,
|
||||||
"Not now",
|
"Not now"
|
||||||
{ dialog, _ -> dialog.dismiss() }
|
) { dialog, _ -> dialog.dismiss() }
|
||||||
)
|
|
||||||
alertDialog.setButton(
|
alertDialog.setButton(
|
||||||
AlertDialog.BUTTON_NEGATIVE,
|
AlertDialog.BUTTON_NEGATIVE,
|
||||||
"Don't show anymore.",
|
"Don't show anymore."
|
||||||
{ dialog, _ ->
|
) { dialog, _ ->
|
||||||
editor.putBoolean("show_error_malformed_url", false)
|
editor.putBoolean("show_error_malformed_url", false)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
)
|
|
||||||
alertDialog.show()
|
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"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
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
|
<item
|
||||||
android:id="@+id/more_action"
|
android:id="@+id/more_action"
|
||||||
android:icon="@drawable/ic_chrome_reader_mode"
|
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="pref_debug_debug_logs">Debug logging (these will be sent without a dialog)</string>
|
||||||
<string name="acra_login">Enable logging</string>
|
<string name="acra_login">Enable logging</string>
|
||||||
<string name="drawer_item_hidden_tags">Hidden Tags</string>
|
<string name="drawer_item_hidden_tags">Hidden Tags</string>
|
||||||
|
<string name="unmark">Mark item as unread</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user