Skip to content

Commit a22c73b

Browse files
committed
Minor improvements
1 parent 295aa57 commit a22c73b

File tree

15 files changed

+77
-57
lines changed

15 files changed

+77
-57
lines changed

app/build.gradle

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdk 36
4+
compileSdk = 36
55

66
defaultConfig {
77
applicationId "livio.rssreader"
88
minSdkVersion 23
99
targetSdkVersion 36
10-
versionCode 111
11-
versionName "1.11"
10+
versionCode 112
11+
versionName "1.12"
1212
}
1313

1414
compileOptions {
@@ -30,15 +30,14 @@ android {
3030
}
3131

3232
dependencies {
33-
implementation 'androidx.appcompat:appcompat:1.7.0'
34-
implementation 'androidx.appcompat:appcompat-resources:1.7.0'
33+
implementation 'androidx.appcompat:appcompat:1.7.1'
34+
implementation 'androidx.appcompat:appcompat-resources:1.7.1'
3535

3636
implementation 'androidx.cardview:cardview:1.0.0'
3737
implementation 'androidx.recyclerview:recyclerview:1.4.0'
3838
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
3939
implementation 'androidx.preference:preference:1.2.1'
40-
implementation 'androidx.work:work-runtime:2.10.0'
41-
42-
implementation 'com.google.android.material:material:1.12.0'
40+
implementation 'androidx.work:work-runtime:2.10.5'
4341

42+
implementation 'com.google.android.material:material:1.13.0'
4443
}

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@
3131
<data android:scheme="https" android:mimeType="application/atom+xml" />
3232
</intent-filter>
3333
</activity>
34-
<activity android:name=".PreferencesFragXML" android:exported="false" android:configChanges="screenSize|screenLayout|orientation" android:label="@string/set_preferences"/>
34+
<activity android:name=".PreferencesFragXML"
35+
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
36+
android:exported="false"
37+
android:label="@string/set_preferences">
38+
<intent-filter>
39+
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
40+
<category android:name="android.intent.category.DEFAULT" />
41+
</intent-filter>
42+
</activity>
3543
<activity android:name=".SelectCategory" android:exported="false" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
3644
android:label="@string/sel_cat_label"/>
3745
<activity android:name=".ListFeeds" android:exported="false" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"

app/src/main/java/livio/rssreader/ListFeeds.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262

6363
import javax.xml.parsers.ParserConfigurationException;
6464

65-
import static livio.rssreader.backend.UserDB.DEFAULT_FEED_ID;
6665
import static livio.rssreader.backend.UserDB.FEED_SIZE;
6766

6867
// called by SelectCategory activity
@@ -128,7 +127,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
128127
for (int k = 0; k < size; k++)
129128
itemList.add(new Item(getFeed(k)[0], false));
130129

131-
String feed_id = prefs.getString(RSSReader.PREF_FEED_ID, DEFAULT_FEED_ID);
130+
String feed_lang = prefs.getString(RSSReader.PREF_FEEDS_LANGUAGE, getString(R.string.default_feed_language_code));
131+
String defaultFeedId = FeedsDB.getDefaultFeedId(feed_lang);
132+
133+
String feed_id = prefs.getString(RSSReader.PREF_FEED_ID, defaultFeedId);
132134

133135
setListAdapter(new ItemArrayAdapter(act, itemList, this, feed_id, catIdx == 0));
134136
ListView lv = getListView();
@@ -261,6 +263,8 @@ public boolean decodeFile(@NonNull InputStream is) {//zzimport
261263
assert iaa != null;
262264
ArrayList<OPMLOutline> outlines = op.parse(is);
263265
// Log.d(tag, "Number of outlines: " + outlines.size());
266+
if (outlines.isEmpty())//invalid input file
267+
return false;
264268
int count = 0;
265269
for (OPMLOutline outline: outlines) {
266270
// Log.d(tag, outline.getType() + " - " + outline.getText() + " - " + outline.getUrl());
@@ -274,7 +278,7 @@ public boolean decodeFile(@NonNull InputStream is) {//zzimport
274278
iaa.add(new Item(feed[0], false));
275279
if (++count >= MAX_NUM_OPML_IMPORT)
276280
break;
277-
}
281+
} else Log.d(tag, "duplicate url: "+url);
278282
}
279283
if (count > 0) {
280284
udb.synctoFile(getActivity());

app/src/main/java/livio/rssreader/NewCategoryDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
public final class NewCategoryDialog extends AppCompatDialogFragment {
3232

33-
private NewCategoryDialog() {//new feed
33+
public NewCategoryDialog() {//new feed
3434
// Empty constructor required for DialogFragment
3535
}
3636

app/src/main/java/livio/rssreader/NewFeedDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
public final class NewFeedDialog extends AppCompatDialogFragment {
3333

34-
private NewFeedDialog() {//new feed
34+
public NewFeedDialog() {//new feed
3535
// Empty constructor required for DialogFragment
3636
}
3737

app/src/main/java/livio/rssreader/RSSReader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,7 @@ public boolean decodeFile(String content) throws JSONException {
902902
}
903903
//sync to file if needed
904904
if (listUserFeeds.size() + listUserCats.size() + deletedNativeFeeds.size() > 0) {
905-
FeedsDB feedsDB = FeedsDB.getInstance();
906-
UserDB ft = UserDB.getInstance(this, prefs, feedsDB, listUserFeeds, listUserCats, deletedNativeFeeds); //create feedstree with restored user feeds
905+
UserDB ft = UserDB.getInstance(this, prefs, listUserFeeds, listUserCats, deletedNativeFeeds); //create feedstree with restored user feeds
907906
ft.synctoFile(this); //write restored user feeds to file
908907
}
909908

app/src/main/java/livio/rssreader/ShowHelp.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import android.content.ActivityNotFoundException;
55
import android.content.Context;
66
import android.content.Intent;
7+
import android.content.res.Configuration;
78
import android.content.res.Resources;
9+
import android.graphics.Color;
810
import android.net.Uri;
911
import android.os.Build;
1012
import android.os.Bundle;
@@ -304,17 +306,23 @@ class SmartPager extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
304306
final Context context;
305307
final int n_items;
306308
final LinearLayout indicators;
309+
final boolean dark;//zzdark
307310

308311
private final static int defaultSizeInDp = 12;
309-
private static final String help_style = "body{margin-right:32px;word-wrap:break-word;background-color:#E8E8E8} hr{height:1px;border:0px;} img{max-width:100%;height:auto; display:block;margin-left:auto;margin-right:auto} A{text-decoration:none}";
310-
private static final String help_style_API_M = "#main{display:flex;}#section1{order:1;margin:10px}#section2{order:2;}@media screen and (max-width: 560px) {#main{flex-wrap:wrap;}} img{max-width:100%;height:auto; display:block;margin-left:auto;margin-right:auto} A{text-decoration:none}";
312+
private static final String dark_style = "body{background-color:#%06x;color:#%06x;}A{color:#%06x;}";
313+
private static final String help_style = "#main{display:flex;}#section1{order:1;margin:10px}#section2{order:2;}@media screen and (max-width: 560px) {#main{flex-wrap:wrap;}} img{max-width:100%;height:auto; display:block;margin-left:auto;margin-right:auto} A{text-decoration:none}";
311314

312315
SmartPager(ViewPager2 vpager, Context ctx, int position, LinearLayout indicators) {
313316
viewPager = vpager;
314317
n_items = help_content.size();
315318
vpager.setAdapter(this);
316319
Resources res = getResources();
317320
show_nav_buttons(position);
321+
if ((android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)) {//zzdark
322+
int nightModeFlags = res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; //zzdark
323+
// Log.d(tag, "nightModeFlags="+nightModeFlags);
324+
dark = nightModeFlags == Configuration.UI_MODE_NIGHT_YES;
325+
} else dark = false;
318326
this.indicators = indicators;
319327
if (indicators != null)
320328
if (n_items > 1) { //activates position indicators only if the number of elements is low but greater than 1
@@ -331,7 +339,7 @@ public void onPageSelected(int pos) {
331339
show_nav_buttons(pos);
332340
}
333341
});
334-
int dimens = ((int) res.getDisplayMetrics().density * defaultSizeInDp);
342+
int dimens = ((int) (res.getDisplayMetrics().density * defaultSizeInDp));
335343
View filler1 = new View(ctx);//filler
336344
filler1.setLayoutParams((new LinearLayout.LayoutParams(dimens, dimens, 1)));
337345
indicators.addView(filler1);
@@ -359,6 +367,8 @@ public void onPageSelected(int pos) {
359367
@Override
360368
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {//17-10-2021: ViewPager2
361369
WebView wv = new WebView(context);
370+
if (dark)
371+
wv.setBackgroundColor(getColor(R.color.gray75));//zzdark
362372
wv.setWebViewClient(new WebViewClient() {
363373
@Override
364374
public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -389,7 +399,14 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
389399
<div id="main"><div id="section1">blocco testo</div><img id="section2" src="images/blabla.png" alt="blabla" width="240px" height="400px"></div>
390400
391401
*/
392-
String html = "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>" + help_style_API_M + "</style></head><body>" + help + "</body></html>";
402+
String darkstyle = "";//zzdark
403+
if (dark) {//zzdark
404+
int background = getColor(R.color.gray75);//zzdark
405+
int textcolor = Color.WHITE;//zzdark
406+
int linkcolor = Color.YELLOW;//zzdark
407+
darkstyle = String.format(dark_style, background & 0xFFFFFF, textcolor & 0xFFFFFF, linkcolor & 0xFFFFFF);//zzdark
408+
}
409+
String html = "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>" + darkstyle + help_style + "</style></head><body>" + help + "</body></html>";//zzdark
393410
wv.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);
394411
}
395412

app/src/main/java/livio/rssreader/ShowItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public void onDestroy() {
196196
if (mTts != null) {
197197
mTts.stop();
198198
mTts.shutdown();
199+
mTts = null;
199200
}
200201

201202
if (smartPager != null)

app/src/main/java/livio/rssreader/backend/RSSItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ void setDescription(String description) {
5252
_description = description.trim();
5353
}
5454
void setLink(String link) {
55-
_link = link;
55+
if (_link.isEmpty())//28-09-2025, added to support properly links in feed https://www.dday.it/rss
56+
_link = link;
5657
}
5758
void setCategory(String category) {
5859
_category = category;

app/src/main/java/livio/rssreader/backend/UserDB.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,31 @@ public final class UserDB {
6060
private HashSet<String> deletedNativeFeeds;//deleted native feeds, hash of {feed_id}
6161

6262
private static String[][][] nativeFeeds;
63-
public static String DEFAULT_FEED_ID;// the default feed_id can be used at start and in case of problems
6463

6564
public synchronized static UserDB getInstance(Context context, SharedPreferences prefs) {
66-
FeedsDB feedsDB = FeedsDB.getInstance();
6765
if (singleton == null) {
68-
singleton = new UserDB(context, prefs, feedsDB);
66+
singleton = new UserDB(context, prefs);
6967
} else {
7068
String feed_lang = prefs.getString(RSSReader.PREF_FEEDS_LANGUAGE, context.getString(R.string.default_feed_language_code));
7169
if (!pref_lang.equals(feed_lang)) {//update according to effective feed language
7270
pref_lang = feed_lang;
73-
int lang_idx = feedsDB.getLanguageIndex(pref_lang);
71+
int lang_idx = FeedsDB.getLanguageIndex(pref_lang);
7472
nativeFeeds = FeedsDB.nativeFeeds[lang_idx];
75-
DEFAULT_FEED_ID = feedsDB.getDefaultFeedId(pref_lang);
7673
}
7774
}
7875
return singleton;
7976
}
8077

81-
public synchronized static UserDB getInstance(Context context, SharedPreferences prefs, FeedsDB feedsDB,
78+
public synchronized static UserDB getInstance(Context context, SharedPreferences prefs,
8279
ArrayList<String[]> listUserFeeds, ArrayList<String[]> listUserCats, HashSet<String> deletedNativeFeeds) {
8380
if (singleton == null) {
84-
singleton = new UserDB(context, prefs, listUserFeeds, listUserCats, feedsDB, deletedNativeFeeds);
81+
singleton = new UserDB(context, prefs, listUserFeeds, listUserCats, deletedNativeFeeds);
8582
} else {
8683
String feed_lang = prefs.getString(RSSReader.PREF_FEEDS_LANGUAGE, context.getString(R.string.default_feed_language_code));
8784
if (!pref_lang.equals(feed_lang)) {//update according to effective feed language
8885
pref_lang = feed_lang;
89-
int lang_idx = feedsDB.getLanguageIndex(pref_lang);
86+
int lang_idx = FeedsDB.getLanguageIndex(pref_lang);
9087
nativeFeeds = FeedsDB.nativeFeeds[lang_idx];
91-
DEFAULT_FEED_ID = feedsDB.getDefaultFeedId(pref_lang);
9288
}
9389
singleton.userFeeds = listUserFeeds;
9490
singleton.userCats = listUserCats;
@@ -98,7 +94,7 @@ public synchronized static UserDB getInstance(Context context, SharedPreferences
9894
}
9995

10096
/** @noinspection unchecked*/
101-
private UserDB(Context context, SharedPreferences prefs, FeedsDB feedsDB) {
97+
private UserDB(Context context, SharedPreferences prefs) {
10298
if (BuildConfig.DEBUG)
10399
Log.d(tag, "new UserDB from file in feedListfn");
104100
userFeeds = new ArrayList<>();
@@ -107,9 +103,8 @@ private UserDB(Context context, SharedPreferences prefs, FeedsDB feedsDB) {
107103

108104
pref_lang = prefs.getString(RSSReader.PREF_FEEDS_LANGUAGE, context.getString(R.string.default_feed_language_code));
109105

110-
int lang_idx = feedsDB.getLanguageIndex(pref_lang);
106+
int lang_idx = FeedsDB.getLanguageIndex(pref_lang);
111107
nativeFeeds = FeedsDB.nativeFeeds[lang_idx];
112-
DEFAULT_FEED_ID = feedsDB.getDefaultFeedId(pref_lang);
113108
try (FileInputStream fis = context.openFileInput(userDBfn)) {
114109
ObjectInputStream is = new ObjectInputStream(fis);
115110
int nobjects = is.readInt();
@@ -137,15 +132,14 @@ private UserDB(Context context, SharedPreferences prefs, FeedsDB feedsDB) {
137132
}
138133

139134
private UserDB(Context context, SharedPreferences prefs, ArrayList<String[]> listUserFeeds,
140-
ArrayList<String[]> listUserCats, FeedsDB feedsDB, HashSet<String> deletedNativeFeeds) {
135+
ArrayList<String[]> listUserCats, HashSet<String> deletedNativeFeeds) {
141136
if (BuildConfig.DEBUG)
142137
Log.d(tag, "new UserDB from restore file");
143138
pref_lang = prefs.getString(RSSReader.PREF_FEEDS_LANGUAGE, context.getString(R.string.default_feed_language_code));
144139
userCats = listUserCats;
145140

146-
int lang_idx = feedsDB.getLanguageIndex(pref_lang);
141+
int lang_idx = FeedsDB.getLanguageIndex(pref_lang);
147142
nativeFeeds = FeedsDB.nativeFeeds[lang_idx];
148-
DEFAULT_FEED_ID = feedsDB.getDefaultFeedId(pref_lang);
149143
userFeeds = listUserFeeds;
150144
this.deletedNativeFeeds = deletedNativeFeeds;
151145
}

0 commit comments

Comments
 (0)