From 70ba9b20da00c3d6417af88b4013ec221f96c3a0 Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 9 Sep 2018 20:39:27 +0200 Subject: [PATCH] Items marked as read on open. Closes #208. --- .../bou/readerforselfoss/ReaderActivity.kt | 73 ---------- .../fragments/ArticleFragment.kt | 129 ++++++++++++++---- .../main/res/drawable-hdpi/ic_fiber_new.png | Bin 0 -> 324 bytes .../main/res/drawable-mdpi/ic_fiber_new.png | Bin 0 -> 215 bytes .../main/res/drawable-xhdpi/ic_fiber_new.png | Bin 0 -> 327 bytes .../main/res/drawable-xxhdpi/ic_fiber_new.png | Bin 0 -> 490 bytes .../res/drawable-xxxhdpi/ic_fiber_new.png | Bin 0 -> 567 bytes app/src/main/res/menu/reader_toolbar.xml | 6 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 108 insertions(+), 101 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_fiber_new.png create mode 100644 app/src/main/res/drawable-mdpi/ic_fiber_new.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_fiber_new.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_fiber_new.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_fiber_new.png diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index 421fe6e..609d39e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -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 { - override fun onResponse( - call: Call, - response: Response - ) { - 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, - t: Throwable - ) { - if (debugReadingItems) { - ACRA.getErrorReporter().maybeHandleSilentException(t, this@ReaderActivity) - } - } - } - ) - } - } - } - ) } override fun onPause() { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt index bf45f55..bb72e91 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt @@ -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 { + override fun onResponse( + call: Call, + response: Response + ) { + 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, + 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 { + override fun onResponse( + call: Call, + response: Response + ) { + 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, + t: Throwable + ) { + if (debugReadingItems) { + ACRA.getErrorReporter().maybeHandleSilentException(t, activity!!) + } + } + } + ) + } + return rootView } @@ -325,36 +401,33 @@ 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 - val subject= "[ReaderForSelfoss MalformedURLException]" - val body= "Please specify the source, item and spout you are using for the url below : \n ${e.message}" - val mailTo = "mailto:" + to + "?&subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body) + // This won't be translated because it should only be temporary. + val to = Config.feedbackEmail + val subject= "[ReaderForSelfoss MalformedURLException]" + val body= "Please specify the source, item and spout you are using for the url below : \n ${e.message}" + val mailTo = "mailto:" + to + "?&subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body) - val emailIntent = Intent(Intent.ACTION_VIEW) - emailIntent.data = Uri.parse(mailTo) - startActivity(emailIntent) + val emailIntent = Intent(Intent.ACTION_VIEW) + emailIntent.data = Uri.parse(mailTo) + startActivity(emailIntent) - dialog.dismiss() - } - ) + 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, _ -> - editor.putBoolean("show_error_malformed_url", false) - editor.apply() - dialog.dismiss() - } - ) + "Don't show anymore." + ) { dialog, _ -> + editor.putBoolean("show_error_malformed_url", false) + editor.apply() + dialog.dismiss() + } alertDialog.show() } } diff --git a/app/src/main/res/drawable-hdpi/ic_fiber_new.png b/app/src/main/res/drawable-hdpi/ic_fiber_new.png new file mode 100644 index 0000000000000000000000000000000000000000..08208c303f7f6c4e57c019c170ad68198523648b GIT binary patch literal 324 zcmV-K0lWT*P)FlrF}4PyU4<^TKtq=Jt?UF@g^P5DnQn2c)Bd$JAsfNBsWU?dr|;D5vao6rDk z0P-LrF!%rn8~$%V3S@{HECx9MX@mbifvg8WmIG7-1`hxs!~X=J=->Z;kksHXh~a+` znn3|TdqMC8+@Js;eSxq+jQ@9`7}Nmw3`qu=0I}r%(?|w!{1*VjBcvI0=D#$MG)6Lr z?LQ9~9wyD82mkl~X99~*=(Ptxx(3A{)WDViiiv=Oz=E(rzyDidjs81Ow<2I7?gaS( z%zA(|LH_^07m45SzYka*jkHWl6@xyKZOnUW75)>@tE0)#s3*-e6M$K0wC*3W1_1!} W*Fqy0+%ql!00006@}{n literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_fiber_new.png b/app/src/main/res/drawable-mdpi/ic_fiber_new.png new file mode 100644 index 0000000000000000000000000000000000000000..262cae13cd48b166adb66ff527f9b69e64dab4b8 GIT binary patch literal 215 zcmV;|04V>7P)2n|F6`f6zS&;9=#cjgYvY&!)i&_AdcjCi*%+ zP4j-HMT2FTn3xoTDSX_ZniL@%s@}#0x^g859H29S48&T2LfWOWMEovl28?kg0BM*12H1Q-0Ff9f z0M;1r>#pV*GzMJk`L&OgPN2N6OSw#Si^@QZ2>~b_GQOVe6M7P`6@#jfnyP{P`}{rw z49WU&eIUcU67Vr1>cdK)%|AN>bO1=(e(?&m0-g*w?3GnlV%XG=+(CdueRJTE^(H1A Z&I==Z5{4`>tV#d?002ovPDHLkV1k;5hARL7 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_fiber_new.png b/app/src/main/res/drawable-xxhdpi/ic_fiber_new.png new file mode 100644 index 0000000000000000000000000000000000000000..30dacde3c2768ae14f6e9525f9afb5ab49e129ed GIT binary patch literal 490 zcmVYE90%}HlorHAgu1lo;w-v4h)*Ccu7Y$ep?!f2A_yXV0VRWuPQE}uM6jiUA>b@N zKnE!qj9*U)F^6}THvcZl?|ai-E|*V}Yq%tp3WY+UP$>T_sKdY`-jH`ZjL<_pj?;vL zBIBZ^;?(ejqT?#g5<1Y4t{n8B1vHd{##%rVIp|#r2y&25AOaDHKqUd0LA}lGX9ulj zw9l_GxUH}S$LGgUfKXbGIFUt&M<2G^wxGEkbngN|~ zYeRC$R=9GOH^{?=>Kx=dsl~%RW1(Ci;36^T2*<4K2em!6uZhF-AmBg&+Tn_&n(~4l zmJl??nhYd7%=r|cei{(iWA@w(pcj7L3HmMmtRs?vfRhas`YN&ZtA0~pG) gL!nS86w05>Cw7uP3AM1otN;K207*qoM6N<$f{%FARR910 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_fiber_new.png b/app/src/main/res/drawable-xxxhdpi/ic_fiber_new.png new file mode 100644 index 0000000000000000000000000000000000000000..f20eda65a5586950b55a3a5b958418bdaa127a23 GIT binary patch literal 567 zcmV-70?7S|P)O+*$^t|STU)gO1deM| zewUrQz-I60In&L;az8SA!?F{JFbu;m48t%C!*m53$fAS_!cN7hB8#}c;-ff21Deu6 z4pDje*U*@}kbqNYO;%F=nzF^yxsc4)0#2Yg88hHsHK1q)ys8G2&499M0L*|20R#|0 zK&XH!0R#~6X8>)p7hb25p1l7%y-W26_;5YNJf5uvIP+VmSq*TGBm)H0oS*UEqZS-s z0ylvHlD%Kk$N|o=<@WnEZ-Dbn_KvUt&e1(Fz~AZ~A)w~{;#Nbo70_&`mI7K0)c{Dk zjPL;1?`^1ByO2BJ4J+LZ)h+;Vi>c0rsufW0d$ApNHdOln4QxvbbLNg*M#uo*1xsQ; zXl=Ca`9YT$vl{>$+775DFbu;m48t)0ET8M#)51d + + Debug logging (these will be sent without a dialog) Enable logging Hidden Tags + Mark item as unread