Add preference for marking items read on scroll

This commit is contained in:
Shinokuni 2021-11-01 18:26:38 +01:00
parent 1bfed8306d
commit 11f87d14a5
5 changed files with 26 additions and 1 deletions

View File

@ -444,6 +444,23 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
} else {
binding.addFeedFab.show();
}
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
if (firstVisibleItemPosition - 2 >= 0) {
Item item = adapter.getItemWithFeed(firstVisibleItemPosition - 2).getItem();
// Might be better to have a global variable updated when going back from settings
if (!item.isRead() && SharedPreferencesManager.readBoolean(SharedPreferencesManager
.SharedPrefKey.MARK_ITEMS_READ_ON_SCROLL)) {
item.setRead(!item.isRead());
viewModel.setItemReadState(item)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(throwable -> Utils.showSnackbar(binding.mainRoot, throwable.getMessage()))
.subscribe();
}
}
}
});
}

View File

@ -58,7 +58,8 @@ public final class SharedPreferencesManager {
OPEN_ITEMS_IN("open_items_in", "0"),
DARK_THEME("dark_theme", "false"),
AUTO_SYNCHRO("auto_synchro", "0"),
HIDE_SHOW_FEEDS("show_hide_feeds", "true");
HIDE_SHOW_FEEDS("show_hide_feeds", "true"),
MARK_ITEMS_READ_ON_SCROLL("mark_items_read", false);
@NonNull
private String key;

View File

@ -141,5 +141,6 @@
<string name="hide">Cacher</string>
<string name="show">Afficher</string>
<string name="show_hide_feeds">Afficher ou cacher les flux sans nouveaux items</string>
<string name="mark_items_read">Marquer les items comme lus pendant le défilement</string>
</resources>

View File

@ -147,4 +147,5 @@
<string name="hide">Hide</string>
<string name="show">Show</string>
<string name="show_hide_feeds">Show or hide feeds without new items</string>
<string name="mark_items_read">Mark items read on scroll</string>
</resources>

View File

@ -43,6 +43,11 @@
android:key="show_hide_feeds"
android:title="@string/show_hide_feeds" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="mark_items_read"
android:title="@string/mark_items_read" />
</PreferenceCategory>