From b39d510e07f1acec880e3190026b9ea3b90fbe5f Mon Sep 17 00:00:00 2001 From: Amine Date: Tue, 29 Aug 2017 22:49:20 +0200 Subject: [PATCH] Added reading article log. --- .../bou/readerforselfoss/HomeActivity.kt | 8 ++++-- .../adapters/ItemCardAdapter.kt | 24 ++++++++++------- .../adapters/ItemListAdapter.kt | 26 +++++++++++-------- app/src/main/res/values-fr/strings.xml | 3 +++ app/src/main/res/values-nl/strings.xml | 3 +++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/pref_debug.xml | 8 ++++++ 7 files changed, 53 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index db13798..7564828 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -80,6 +80,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var items: ArrayList = ArrayList() private var clickBehavior = false + private var debugReadingItems = false private var internalBrowser = false private var articleViewer = false private var shouldBeCardView = false @@ -277,6 +278,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private fun handleSharedPrefs() { + debugReadingItems = sharedPref.getBoolean("read_debug", false) clickBehavior = sharedPref.getBoolean("tab_on_tap", false) internalBrowser = sharedPref.getBoolean("prefer_internal_browser", true) articleViewer = sharedPref.getBoolean("prefer_article_viewer", true) @@ -641,7 +643,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { internalBrowser, articleViewer, fullHeightCards, - appColors) + appColors, + debugReadingItems) } else { mAdapter = ItemListAdapter( @@ -651,7 +654,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { customTabActivityHelper, clickBehavior, internalBrowser, - articleViewer) + articleViewer, + debugReadingItems) } recyclerView.adapter = mAdapter mAdapter.notifyDataSetChanged() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt index e106596..f10ce52 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt @@ -2,15 +2,12 @@ package apps.amine.bou.readerforselfoss.adapters import android.app.Activity import android.content.Context -import android.graphics.Bitmap import android.graphics.Color import android.support.constraint.ConstraintLayout import android.support.design.widget.Snackbar -import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory import android.support.v7.widget.CardView import android.support.v7.widget.RecyclerView import android.text.Html -import android.text.format.DateUtils import android.view.LayoutInflater import android.view.ViewGroup import android.widget.ImageButton @@ -22,15 +19,11 @@ import android.widget.Toast import com.amulyakhare.textdrawable.TextDrawable import com.amulyakhare.textdrawable.util.ColorGenerator import com.bumptech.glide.Glide -import com.bumptech.glide.request.target.BitmapImageViewTarget import com.like.LikeButton import com.like.OnLikeListener import retrofit2.Call import retrofit2.Callback import retrofit2.Response -import java.text.ParseException -import java.text.SimpleDateFormat -import java.util.* import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.api.selfoss.Item @@ -39,6 +32,8 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.themes.AppColors import apps.amine.bou.readerforselfoss.utils.* import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper +import com.crashlytics.android.Crashlytics +import kotlin.collections.ArrayList class ItemCardAdapter(private val app: Activity, private val items: ArrayList, @@ -47,7 +42,8 @@ class ItemCardAdapter(private val app: Activity, private val internalBrowser: Boolean, private val articleViewer: Boolean, private val fullHeightCards: Boolean, - private val appColors: AppColors) : RecyclerView.Adapter() { + private val appColors: AppColors, + val debugReadingItems: Boolean) : RecyclerView.Adapter() { private val c: Context = app.baseContext private val generator: ColorGenerator = ColorGenerator.MATERIAL @@ -130,11 +126,21 @@ class ItemCardAdapter(private val app: Activity, api.markItem(i.id).enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { - + if (debugReadingItems) { + val message = + "message: ${response.message()} body: ${response.body()} raw body string: ${response.raw()?.body()?.toString()}" + Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) + Toast.makeText(c, message, Toast.LENGTH_LONG).show() + } doUnmark(i, position) } override fun onFailure(call: Call, t: Throwable) { + if (debugReadingItems) { + Crashlytics.log(100, "READ_DEBUG_ERROR", t.message) + Crashlytics.logException(t) + Toast.makeText(c, t.message, Toast.LENGTH_LONG).show() + } Toast.makeText(app, app.getString(R.string.cant_mark_read), Toast.LENGTH_SHORT).show() items.add(i) notifyItemInserted(position) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt index fd60fd8..1cc6d87 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt @@ -3,16 +3,11 @@ package apps.amine.bou.readerforselfoss.adapters import android.app.Activity import android.content.Context -import android.content.Intent -import android.graphics.Bitmap import android.graphics.Color -import android.net.Uri import android.support.constraint.ConstraintLayout import android.support.design.widget.Snackbar -import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory import android.support.v7.widget.RecyclerView import android.text.Html -import android.text.format.DateUtils import android.util.TypedValue import android.view.LayoutInflater import android.view.View @@ -21,24 +16,21 @@ import android.widget.* import com.amulyakhare.textdrawable.TextDrawable import com.amulyakhare.textdrawable.util.ColorGenerator -import com.bumptech.glide.Glide -import com.bumptech.glide.request.target.BitmapImageViewTarget import com.like.LikeButton import com.like.OnLikeListener import retrofit2.Call import retrofit2.Callback import retrofit2.Response -import java.text.ParseException -import java.text.SimpleDateFormat import java.util.* import apps.amine.bou.readerforselfoss.R 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.* import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper +import com.crashlytics.android.Crashlytics +import kotlin.collections.ArrayList class ItemListAdapter(private val app: Activity, @@ -47,7 +39,8 @@ class ItemListAdapter(private val app: Activity, private val helper: CustomTabActivityHelper, private val clickBehavior: Boolean, private val internalBrowser: Boolean, - private val articleViewer: Boolean) : RecyclerView.Adapter() { + private val articleViewer: Boolean, + val debugReadingItems: Boolean) : RecyclerView.Adapter() { private val generator: ColorGenerator = ColorGenerator.MATERIAL private val c: Context = app.baseContext private val bars: ArrayList = ArrayList(Collections.nCopies(items.size + 1, false)) @@ -142,11 +135,22 @@ class ItemListAdapter(private val app: Activity, api.markItem(i.id).enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { + if (debugReadingItems) { + val message = + "message: ${response.message()} body: ${response.body()} raw body string: ${response.raw()?.body()?.toString()}" + Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) + Toast.makeText(c, message, Toast.LENGTH_LONG).show() + } doUnmark(i, position) } override fun onFailure(call: Call, t: Throwable) { + if (debugReadingItems) { + Crashlytics.log(100, "READ_DEBUG_ERROR", t.message) + Crashlytics.logException(t) + Toast.makeText(c, t.message, Toast.LENGTH_LONG).show() + } Toast.makeText(app, app.getString(R.string.cant_mark_read), Toast.LENGTH_SHORT).show() items.add(i) notifyItemInserted(position) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index ce5c79b..6e6c052 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -140,4 +140,7 @@ Pour des raisons de sécurités, les certificats auto-signés sont désactivés par défaut. En les activant, je ne serais pas responsable de quelconques problèmes de sécurité rencontrés. Api Selfoss Nombre d\'articles chargés + Des articles lus marqués comme non lus ? + Les appels API vont être logués lorsequ\'un article est marqué comme lu + Aucun log quand un article est marqué comme lu \ No newline at end of file diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 55c12e5..259a049 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -140,4 +140,7 @@ Due to security reasons, self signed certificates are not supported by default. By activating this, I\'ll not be responsible of any security problem you encounter. Selfoss Api Loaded items number + Read articles appearing as unread ? + Api calls will be logged when marking an article as read + No log when marking an item as read \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb27c64..0630839 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -142,4 +142,7 @@ Due to security reasons, self signed certificates are not supported by default. By activating this, I\'ll not be responsible of any security problem you encounter. Selfoss Api Loaded items number + Read articles appearing as unread ? + No log when marking an item as read + Api calls will be logged when marking an article as read \ No newline at end of file diff --git a/app/src/main/res/xml/pref_debug.xml b/app/src/main/res/xml/pref_debug.xml index aede6d3..43291d9 100644 --- a/app/src/main/res/xml/pref_debug.xml +++ b/app/src/main/res/xml/pref_debug.xml @@ -7,4 +7,12 @@ android:summaryOff="@string/login_debug_off" android:summaryOn="@string/login_debug_on" android:title="@string/login_debug_title" /> + + + \ No newline at end of file