From 7bda896e2d8845358991d5b76cb3dead89d34a43 Mon Sep 17 00:00:00 2001 From: Amine Date: Sat, 26 Aug 2017 21:36:19 +0200 Subject: [PATCH] Added the ability to choose the number of items loaded. --- CHANGELOG.md | 4 ++++ .../bou/readerforselfoss/HomeActivity.kt | 4 +++- .../api/selfoss/SelfossApi.kt | 12 ++++++------ .../api/selfoss/SelfossService.kt | 3 ++- .../settings/SettingsActivity.java | 19 +++++++++++++++++++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-nl/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_general.xml | 14 +++++++++++++- 9 files changed, 53 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea10207..7f4fef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +**1.5.2.07** + +- Added the ability to choose the number of items loaded (the maximum value is 200 and is imposed by the selfoss api) + **1.5.2.06** - Fix problem introduced in 1.5.2.04. SVG file not working on older versions of android. 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 77a2508..db13798 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -86,6 +86,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var displayUnreadCount = false private var displayAllCount = false private var fullHeightCards: Boolean = false + private var itemsNumber: Int = 200 private var elementsShown: Int = 0 private var maybeTagFilter: Tag? = null private var maybeSourceFilter: Sources? = null @@ -283,6 +284,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { displayUnreadCount = sharedPref.getBoolean("display_unread_count", true) displayAllCount = sharedPref.getBoolean("display_other_count", false) fullHeightCards = sharedPref.getBoolean("full_height_cards", false) + itemsNumber = sharedPref.getString("prefer_api_items_number", "200").toInt() } private fun handleDrawer() { @@ -612,7 +614,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private fun getUnRead() { elementsShown = UNREAD_SHOWN - doCallTo(R.string.cant_get_new_elements){t, id, f -> api.newItems(t, id, f)} + doCallTo(R.string.cant_get_new_elements){t, id, f -> api.newItems(t, id, f, itemsNumber)} } private fun getRead() { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt index 7063ea3..83752f5 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt @@ -124,16 +124,16 @@ class SelfossApi(c: Context, callingActivity: Activity, isWithSelfSignedCert: Bo service.loginToSelfoss(config.userLogin, config.userPassword) fun readItems(tag: String?, sourceId: Long?, search: String?): Call> = - getItems("read", tag, sourceId, search) + getItems("read", tag, sourceId, search, 200) - fun newItems(tag: String?, sourceId: Long?, search: String?): Call> = - getItems("unread", tag, sourceId, search) + fun newItems(tag: String?, sourceId: Long?, search: String?, itemsNumber: Int): Call> = + getItems("unread", tag, sourceId, search, itemsNumber) fun starredItems(tag: String?, sourceId: Long?, search: String?): Call> = - getItems("starred", tag, sourceId, search) + getItems("starred", tag, sourceId, search, 200) - private fun getItems(type: String, tag: String?, sourceId: Long?, search: String?): Call> = - service.getItems(type, tag, sourceId, search, userName, password) + private fun getItems(type: String, tag: String?, sourceId: Long?, search: String?, items: Int): Call> = + service.getItems(type, tag, sourceId, search, userName, password, items) fun markItem(itemId: String): Call = service.markAsRead(itemId, userName, password) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt index ae69d90..0114d0b 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt @@ -22,7 +22,8 @@ internal interface SelfossService { @Query("source") source: Long?, @Query("search") search: String?, @Query("username") username: String, - @Query("password") password: String): Call> + @Query("password") password: String, + @Query("items") items: Int): Call> @POST("mark/{id}") fun markAsRead(@Path("id") id: String, diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java index 85280c0..b797be4 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java @@ -8,6 +8,7 @@ import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; @@ -15,6 +16,8 @@ import android.preference.SwitchPreference; import android.support.v7.app.ActionBar; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; +import android.text.InputFilter; +import android.text.Spanned; import android.view.MenuItem; import java.util.List; @@ -145,6 +148,22 @@ public class SettingsActivity extends AppCompatPreferenceActivity { return true; } }); + + EditTextPreference itemsNumber = (EditTextPreference) findPreference("prefer_api_items_number"); + itemsNumber.getEditText().setFilters(new InputFilter[]{ + new InputFilter (){ + + @Override + public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { + try { + int input = Integer.parseInt(dest.toString() + source.toString()); + if (input <= 200 && input >0) + return null; + } catch (NumberFormatException nfe) { } + return ""; + } + } + }); } @Override diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9f51417..ce5c79b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -138,4 +138,6 @@ Debug Certificat auto-signé ? 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 \ 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 33c767b..55c12e5 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -138,4 +138,6 @@ Debug Using a self hosted certificate ? 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 \ 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 2cb1517..bb27c64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -140,4 +140,6 @@ Debug Using a self hosted certificate ? 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 \ No newline at end of file diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 5c84739..3a550b9 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -1,4 +1,5 @@ - + + + + +