Skip to content

Commit

Permalink
Merge pull request #1262 from mkanilsson/move-unread-option
Browse files Browse the repository at this point in the history
Add shortcut to "Show only unread articles" in the toolbar
  • Loading branch information
David-Development authored Sep 13, 2023
2 parents c8a4fca + b794dab commit 813e447
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements

public static HashSet<Long> stayUnreadItems = new HashSet<>();

private MenuItem menuItemOnlyUnread;
private MenuItem menuItemDownloadMoreItems;

private Long currentFolderId;

@VisibleForTesting(otherwise = PROTECTED)
public ActivityNewsreaderBinding binding;

Expand Down Expand Up @@ -671,19 +674,31 @@ private NewsReaderDetailFragment updateDetailFragment(long id, Boolean folder, L
Long folderId;
String title = null;

if (menuItemOnlyUnread != null) {
menuItemOnlyUnread.setVisible(true);
}

if(!folder) {
currentFolderId = null;
feedId = id;
folderId = optional_folder_id;
title = dbConn.getFeedById(id).getFeedTitle();
} else {
currentFolderId = id;
folderId = id;
int idFolder = (int) id;
if(idFolder >= 0) {
title = dbConn.getFolderById(id).getLabel();
} else if(idFolder == -10) {
title = getString(R.string.allUnreadFeeds);
if (menuItemOnlyUnread != null) {
menuItemOnlyUnread.setVisible(false);
}
} else if(idFolder == -11) {
title = getString(R.string.starredFeeds);
if (menuItemOnlyUnread != null) {
menuItemOnlyUnread.setVisible(false);
}
}
}

Expand Down Expand Up @@ -789,6 +804,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
menuItemDownloadMoreItems.setEnabled(false);

MenuItem searchItem = menu.findItem(R.id.menu_search);
menuItemOnlyUnread = menu.findItem(R.id.menu_toggleShowOnlyUnread);
menuItemOnlyUnread.setChecked(mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false));
menuItemOnlyUnread.setVisible(!(currentFolderId == -11 || currentFolderId == -10));

//Set expand listener to close keyboard
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
Expand Down Expand Up @@ -857,7 +875,15 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
return true;
} else if (itemId == R.id.menu_update) {
startSync();
} else if (itemId == R.id.menu_StartImageCaching) {
}
else if (itemId == R.id.menu_toggleShowOnlyUnread) {
boolean newValue = !mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false);
mPrefs.edit().putBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, newValue).commit();
item.setChecked(newValue);
getSlidingListFragment().reloadAdapter();
updateCurrentRssView();
}
else if (itemId == R.id.menu_StartImageCaching) {
final DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);

long highestItemId = dbConn.getLowestRssItemIdUnread();
Expand Down
7 changes: 7 additions & 0 deletions News-Android-App/src/main/res/menu/news_reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
android:orderInCategory="97"
android:title="@string/menu_markAllAsRead"/>

<item
android:id="@+id/menu_toggleShowOnlyUnread"
android:orderInCategory="98"
android:title="@string/pref_title_ShowOnlyUnread"
android:checkable="true"
app:showAsAction="never" />

<item
android:id="@+id/action_add_new_feed"
android:orderInCategory="101"
Expand Down

0 comments on commit 813e447

Please sign in to comment.