From f1bb7ba9adf133947088227f388aa6bac744db2e Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Sat, 27 Jan 2018 12:27:55 +0100 Subject: [PATCH] Should fix #174. Added the ability to set the font size of the content of the article reader. --- CHANGELOG.md | 4 +- .../fragments/ArticleFragment.kt | 6 +- .../settings/SettingsActivity.java | 53 ++++++++++++++++++ .../bou/readerforselfoss/utils/SizeUtils.kt | 9 +++ .../ic_chrome_reader_mode_black_24.png | Bin 0 -> 206 bytes .../ic_chrome_reader_mode_black_24.png | Bin 0 -> 134 bytes .../ic_chrome_reader_mode_black_24.png | Bin 0 -> 174 bytes .../ic_chrome_reader_mode_black_24.png | Bin 0 -> 255 bytes .../ic_chrome_reader_mode_black_24.png | Bin 0 -> 311 bytes app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_general.xml | 4 -- app/src/main/res/xml/pref_headers.xml | 6 ++ app/src/main/res/xml/pref_viewer.xml | 14 +++++ 13 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/apps/amine/bou/readerforselfoss/utils/SizeUtils.kt create mode 100644 app/src/main/res/drawable-hdpi/ic_chrome_reader_mode_black_24.png create mode 100644 app/src/main/res/drawable-mdpi/ic_chrome_reader_mode_black_24.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_chrome_reader_mode_black_24.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_chrome_reader_mode_black_24.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_chrome_reader_mode_black_24.png create mode 100644 app/src/main/res/xml/pref_viewer.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 4803e85..6474fc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Added an option to use a webview in the article viewer (see #149) -- Fixes (#151 #152 #155 #157 #160) +- Fixes (#151 #152 #155 #157 #160 #174) - New year fixes !!! @@ -20,6 +20,8 @@ - Better handling for articles update. (See #169) +- Ability to change the article viewer content font size (see #153) + **1.5.5.x (didn't last long) AND 1.5.6.x** - Toolbar in reader activity. 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 435c9db..bb75f3a 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 @@ -25,6 +25,7 @@ import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString 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.toPx import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.crashlytics.android.Crashlytics @@ -39,6 +40,7 @@ import java.net.URL class ArticleFragment : Fragment() { private lateinit var pageNumber: Number + private var fontSize: Int = 14 private lateinit var allItems: ArrayList private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper private lateinit var url: String @@ -84,6 +86,8 @@ class ArticleFragment : Fragment() { mCustomTabActivityHelper.bindCustomTabsService(activity) val prefs = PreferenceManager.getDefaultSharedPreferences(activity) + fontSize = prefs.getString("reader_font_size", "14").toInt() + mFloatingToolbar.setClickListener( object : FloatingToolbar.ItemClickListener { @@ -321,7 +325,7 @@ class ArticleFragment : Fragment() { rootView.webcontent.loadDataWithBaseURL( baseUrl, - "$c", + "$c", "text/html; charset=utf-8", "utf-8", null 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 087aeab..91b1102 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 @@ -20,8 +20,10 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.SwitchPreference; import android.support.v7.app.ActionBar; +import android.text.Editable; import android.text.InputFilter; import android.text.Spanned; +import android.text.TextWatcher; import android.view.MenuItem; import android.widget.Toast; @@ -131,6 +133,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName) + || ArticleViewerPreferenceFragment.class.getName().equals(fragmentName) || DebugPreferenceFragment.class.getName().equals(fragmentName) || LinksPreferenceFragment.class.getName().equals(fragmentName); } @@ -188,6 +191,56 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public static class ArticleViewerPreferenceFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_viewer); + setHasOptionsMenu(true); + + final EditTextPreference fontSize = (EditTextPreference) findPreference("reader_font_size"); + fontSize.getEditText().addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void afterTextChanged(Editable editable) { + try { + fontSize.getEditText().setTextSize(Integer.parseInt(editable.toString())); + } catch (NumberFormatException e) {} + } + }); + fontSize.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 > 0) + return null; + } catch (NumberFormatException nfe) {} + return ""; + } + } + }); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == android.R.id.home) { + getActivity().finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static class DebugPreferenceFragment extends PreferenceFragment { @Override diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/SizeUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/SizeUtils.kt new file mode 100644 index 0000000..46518ba --- /dev/null +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/SizeUtils.kt @@ -0,0 +1,9 @@ +package apps.amine.bou.readerforselfoss.utils + +import android.content.res.Resources + +val Int.toPx: Int + get() = (this * Resources.getSystem().displayMetrics.density).toInt() + +val Int.toDp: Int + get() = (this / Resources.getSystem().displayMetrics.density).toInt() diff --git a/app/src/main/res/drawable-hdpi/ic_chrome_reader_mode_black_24.png b/app/src/main/res/drawable-hdpi/ic_chrome_reader_mode_black_24.png new file mode 100644 index 0000000000000000000000000000000000000000..3d3ccd52bcad77c279487922ef18ddfd19a5c6d5 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8LpR8JSjkcwN$2@y=5 zVLs0f{uP(m(t30bi*Mp-JgCoOB+&dx(}<1bvm%?RKuCwQ!xyt2DHq>nAql>O#uSMw z4dHWGnq?YR89a1o6TG^|&9qshVPOj=`=td3#od%`zh4(LS;44o!!T`qtHcxc!iVpf z4Lc?#+PWTF!#3*xgYhZx7kk)@5_B(^_AJ)rdBni5{Yt$G{|Xj$paU5^UHx3vIVCg! E06*76_y7O^ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_chrome_reader_mode_black_24.png b/app/src/main/res/drawable-mdpi/ic_chrome_reader_mode_black_24.png new file mode 100644 index 0000000000000000000000000000000000000000..6eb0b6b082df3a7b657972d7a3666ba8d12a5056 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1Ur!gukcwN$2@-M&6CSD_u2*`X z%~s#R_Gn7;1Md#DHwI`;<_i^v+jSyfk}}@-f1UAYJw-Mo!@uQFVdQ&MBb@0G*^krvLx| literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_chrome_reader_mode_black_24.png b/app/src/main/res/drawable-xxhdpi/ic_chrome_reader_mode_black_24.png new file mode 100644 index 0000000000000000000000000000000000000000..7c4feddbc899618f76f91c85d3620013ff10dfb4 GIT binary patch literal 255 zcmV>P`PliJwJ#uhnaz412-cBL&IbV1_r+*kk|tm5D5Yi>@(_L zp1+noeJ=kBAI3a81@kYjJ}xo&GGj^_!}SlvbwSxle|ArLTQ4wW;(d?FzrRlY``0XZ q;l148kGXT^R+j|-Q+5G@FE4pNRP5jIS=#m{$WTvLKbLh*2~7a5#Cu!- literal 0 HcmV?d00001 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba594ba..8b7cc0f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -164,4 +164,6 @@ Mark articles as read when swiping between articles. Add to favorites Remove from favorites + Article reader content font size + Article viewer diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 244b2c1..f34aa1d 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -76,9 +76,5 @@ android:summaryOff="@string/pref_switch_actions_tap_off" android:summaryOn="@string/pref_switch_actions_tap_on" android:title="@string/pref_switch_actions_tap_title" /> - diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml index 3bcc108..07b54ab 100644 --- a/app/src/main/res/xml/pref_headers.xml +++ b/app/src/main/res/xml/pref_headers.xml @@ -5,6 +5,12 @@ android:icon="@drawable/ic_settings_black_24dp" android:title="@string/pref_header_general"/> + +
+
+ + + +