Added the ability to choose the number of items loaded.

This commit is contained in:
Amine 2017-08-26 21:36:19 +02:00
parent ba4feeea87
commit 7bda896e2d
9 changed files with 53 additions and 9 deletions

View File

@ -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** **1.5.2.06**
- Fix problem introduced in 1.5.2.04. SVG file not working on older versions of android. - Fix problem introduced in 1.5.2.04. SVG file not working on older versions of android.

View File

@ -86,6 +86,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var displayUnreadCount = false private var displayUnreadCount = false
private var displayAllCount = false private var displayAllCount = false
private var fullHeightCards: Boolean = false private var fullHeightCards: Boolean = false
private var itemsNumber: Int = 200
private var elementsShown: Int = 0 private var elementsShown: Int = 0
private var maybeTagFilter: Tag? = null private var maybeTagFilter: Tag? = null
private var maybeSourceFilter: Sources? = null private var maybeSourceFilter: Sources? = null
@ -283,6 +284,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
displayUnreadCount = sharedPref.getBoolean("display_unread_count", true) displayUnreadCount = sharedPref.getBoolean("display_unread_count", true)
displayAllCount = sharedPref.getBoolean("display_other_count", false) displayAllCount = sharedPref.getBoolean("display_other_count", false)
fullHeightCards = sharedPref.getBoolean("full_height_cards", false) fullHeightCards = sharedPref.getBoolean("full_height_cards", false)
itemsNumber = sharedPref.getString("prefer_api_items_number", "200").toInt()
} }
private fun handleDrawer() { private fun handleDrawer() {
@ -612,7 +614,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private fun getUnRead() { private fun getUnRead() {
elementsShown = UNREAD_SHOWN 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() { private fun getRead() {

View File

@ -124,16 +124,16 @@ class SelfossApi(c: Context, callingActivity: Activity, isWithSelfSignedCert: Bo
service.loginToSelfoss(config.userLogin, config.userPassword) service.loginToSelfoss(config.userLogin, config.userPassword)
fun readItems(tag: String?, sourceId: Long?, search: String?): Call<List<Item>> = fun readItems(tag: String?, sourceId: Long?, search: String?): Call<List<Item>> =
getItems("read", tag, sourceId, search) getItems("read", tag, sourceId, search, 200)
fun newItems(tag: String?, sourceId: Long?, search: String?): Call<List<Item>> = fun newItems(tag: String?, sourceId: Long?, search: String?, itemsNumber: Int): Call<List<Item>> =
getItems("unread", tag, sourceId, search) getItems("unread", tag, sourceId, search, itemsNumber)
fun starredItems(tag: String?, sourceId: Long?, search: String?): Call<List<Item>> = fun starredItems(tag: String?, sourceId: Long?, search: String?): Call<List<Item>> =
getItems("starred", tag, sourceId, search) getItems("starred", tag, sourceId, search, 200)
private fun getItems(type: String, tag: String?, sourceId: Long?, search: String?): Call<List<Item>> = private fun getItems(type: String, tag: String?, sourceId: Long?, search: String?, items: Int): Call<List<Item>> =
service.getItems(type, tag, sourceId, search, userName, password) service.getItems(type, tag, sourceId, search, userName, password, items)
fun markItem(itemId: String): Call<SuccessResponse> = fun markItem(itemId: String): Call<SuccessResponse> =
service.markAsRead(itemId, userName, password) service.markAsRead(itemId, userName, password)

View File

@ -22,7 +22,8 @@ internal interface SelfossService {
@Query("source") source: Long?, @Query("source") source: Long?,
@Query("search") search: String?, @Query("search") search: String?,
@Query("username") username: String, @Query("username") username: String,
@Query("password") password: String): Call<List<Item>> @Query("password") password: String,
@Query("items") items: Int): Call<List<Item>>
@POST("mark/{id}") @POST("mark/{id}")
fun markAsRead(@Path("id") id: String, fun markAsRead(@Path("id") id: String,

View File

@ -8,6 +8,7 @@ import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
@ -15,6 +16,8 @@ import android.preference.SwitchPreference;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.InputFilter;
import android.text.Spanned;
import android.view.MenuItem; import android.view.MenuItem;
import java.util.List; import java.util.List;
@ -145,6 +148,22 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
return true; 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 @Override

View File

@ -138,4 +138,6 @@
<string name="login_menu_debug">Debug</string> <string name="login_menu_debug">Debug</string>
<string name="self_hosted_cert_switch">Certificat auto-signé ?</string> <string name="self_hosted_cert_switch">Certificat auto-signé ?</string>
<string name="self_signed_cert_warning">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.</string> <string name="self_signed_cert_warning">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.</string>
<string name="pref_selfoss_category">Api Selfoss</string>
<string name="pref_api_items_number_title">Nombre d\'articles chargés</string>
</resources> </resources>

View File

@ -138,4 +138,6 @@
<string name="login_menu_debug">Debug</string> <string name="login_menu_debug">Debug</string>
<string name="self_hosted_cert_switch">Using a self hosted certificate ?</string> <string name="self_hosted_cert_switch">Using a self hosted certificate ?</string>
<string name="self_signed_cert_warning">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.</string> <string name="self_signed_cert_warning">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.</string>
<string name="pref_selfoss_category">Selfoss Api</string>
<string name="pref_api_items_number_title">Loaded items number</string>
</resources> </resources>

View File

@ -140,4 +140,6 @@
<string name="login_menu_debug">Debug</string> <string name="login_menu_debug">Debug</string>
<string name="self_hosted_cert_switch">Using a self hosted certificate ?</string> <string name="self_hosted_cert_switch">Using a self hosted certificate ?</string>
<string name="self_signed_cert_warning">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.</string> <string name="self_signed_cert_warning">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.</string>
<string name="pref_selfoss_category">Selfoss Api</string>
<string name="pref_api_items_number_title">Loaded items number</string>
</resources> </resources>

View File

@ -1,4 +1,5 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--<SwitchPreference <!--<SwitchPreference
android:defaultValue="false" android:defaultValue="false"
@ -6,6 +7,17 @@
android:summary="@string/pref_switch_browser" android:summary="@string/pref_switch_browser"
android:title="@string/pref_switch_browser_title"/>--> android:title="@string/pref_switch_browser_title"/>-->
<PreferenceCategory
android:title="@string/pref_selfoss_category">
</PreferenceCategory>
<EditTextPreference
android:defaultValue="200"
android:inputType="number"
android:key="prefer_api_items_number"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_api_items_number_title" />
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_general_category_links"> android:title="@string/pref_general_category_links">