Should fix #174. Added the ability to set the font size of the content of the article reader.

This commit is contained in:
Amine Bou 2018-01-27 12:27:55 +01:00
parent 279f229166
commit f1bb7ba9ad
13 changed files with 92 additions and 6 deletions

View File

@ -4,7 +4,7 @@
- Added an option to use a webview in the article viewer (see #149) - 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 !!! - New year fixes !!!
@ -20,6 +20,8 @@
- Better handling for articles update. (See #169) - 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** **1.5.5.x (didn't last long) AND 1.5.6.x**
- Toolbar in reader activity. - Toolbar in reader activity.

View File

@ -25,6 +25,7 @@ import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString
import apps.amine.bou.readerforselfoss.utils.openItemUrl import apps.amine.bou.readerforselfoss.utils.openItemUrl
import apps.amine.bou.readerforselfoss.utils.shareLink import apps.amine.bou.readerforselfoss.utils.shareLink
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
import apps.amine.bou.readerforselfoss.utils.toPx
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
@ -39,6 +40,7 @@ import java.net.URL
class ArticleFragment : Fragment() { class ArticleFragment : Fragment() {
private lateinit var pageNumber: Number private lateinit var pageNumber: Number
private var fontSize: Int = 14
private lateinit var allItems: ArrayList<Item> private lateinit var allItems: ArrayList<Item>
private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper
private lateinit var url: String private lateinit var url: String
@ -84,6 +86,8 @@ class ArticleFragment : Fragment() {
mCustomTabActivityHelper.bindCustomTabsService(activity) mCustomTabActivityHelper.bindCustomTabsService(activity)
val prefs = PreferenceManager.getDefaultSharedPreferences(activity) val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
fontSize = prefs.getString("reader_font_size", "14").toInt()
mFloatingToolbar.setClickListener( mFloatingToolbar.setClickListener(
object : FloatingToolbar.ItemClickListener { object : FloatingToolbar.ItemClickListener {
@ -321,7 +325,7 @@ class ArticleFragment : Fragment() {
rootView.webcontent.loadDataWithBaseURL( rootView.webcontent.loadDataWithBaseURL(
baseUrl, baseUrl,
"<style>img{display: inline-block;height: auto; width: 100%; max-width: 100%;} a{color: $stringColor;} *:not(a){color: $stringTextColor;}</style>$c", "<style>img {display: inline-block;height: auto;width: 100%;max-width: 100%;}a {color: $stringColor;}*:not(a) {color: $stringTextColor;}* {word-break: break-word;font-size: ${fontSize.toPx}px;text-align: justify;}</style>$c",
"text/html; charset=utf-8", "text/html; charset=utf-8",
"utf-8", "utf-8",
null null

View File

@ -20,8 +20,10 @@ import android.preference.PreferenceFragment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.SwitchPreference; import android.preference.SwitchPreference;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.text.Editable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextWatcher;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
@ -131,6 +133,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
protected boolean isValidFragment(String fragmentName) { protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName) return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName)
|| ArticleViewerPreferenceFragment.class.getName().equals(fragmentName)
|| DebugPreferenceFragment.class.getName().equals(fragmentName) || DebugPreferenceFragment.class.getName().equals(fragmentName)
|| LinksPreferenceFragment.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) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class DebugPreferenceFragment extends PreferenceFragment { public static class DebugPreferenceFragment extends PreferenceFragment {
@Override @Override

View File

@ -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()

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

View File

@ -164,4 +164,6 @@
<string name="pref_switch_actions_pager_scroll">Mark articles as read when swiping between articles.</string> <string name="pref_switch_actions_pager_scroll">Mark articles as read when swiping between articles.</string>
<string name="add_to_favs_reader">Add to favorites</string> <string name="add_to_favs_reader">Add to favorites</string>
<string name="remove_to_favs_reader">Remove from favorites</string> <string name="remove_to_favs_reader">Remove from favorites</string>
<string name="pref_content_reader_font_size">Article reader content font size</string>
<string name="pref_header_viewer">Article viewer</string>
</resources> </resources>

View File

@ -76,9 +76,5 @@
android:summaryOff="@string/pref_switch_actions_tap_off" android:summaryOff="@string/pref_switch_actions_tap_off"
android:summaryOn="@string/pref_switch_actions_tap_on" android:summaryOn="@string/pref_switch_actions_tap_on"
android:title="@string/pref_switch_actions_tap_title" /> android:title="@string/pref_switch_actions_tap_title" />
<SwitchPreference
android:defaultValue="false"
android:key="mark_on_scroll"
android:title="@string/pref_switch_actions_pager_scroll" />
</PreferenceScreen> </PreferenceScreen>

View File

@ -5,6 +5,12 @@
android:icon="@drawable/ic_settings_black_24dp" android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/pref_header_general"/> android:title="@string/pref_header_general"/>
<header
android:fragment="apps.amine.bou.readerforselfoss.settings.SettingsActivity$ArticleViewerPreferenceFragment"
android:icon="@drawable/ic_chrome_reader_mode_black_24"
android:title="@string/pref_header_viewer"/>
<header <header
android:fragment="apps.amine.bou.readerforselfoss.settings.SettingsActivity$DebugPreferenceFragment" android:fragment="apps.amine.bou.readerforselfoss.settings.SettingsActivity$DebugPreferenceFragment"
android:icon="@drawable/ic_bug_report" android:icon="@drawable/ic_bug_report"

View File

@ -0,0 +1,14 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="false"
android:key="mark_on_scroll"
android:title="@string/pref_switch_actions_pager_scroll" />
<EditTextPreference
android:defaultValue="14"
android:inputType="number"
android:key="reader_font_size"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_content_reader_font_size" />
</PreferenceScreen>