Skip to content

Commit f8ed8e5

Browse files
committed
# Change
Added FEEDGROUP Tab Code to - ChooseTabsFragment - Tab Added strings: - feed_group_page_summary
1 parent 436626f commit f8ed8e5

3 files changed

Lines changed: 111 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.schabi.newpipe.settings.SelectChannelFragment;
3535
import org.schabi.newpipe.settings.SelectKioskFragment;
3636
import org.schabi.newpipe.settings.SelectPlaylistFragment;
37+
import org.schabi.newpipe.settings.SelectFeedGroupFragment;
3738
import org.schabi.newpipe.settings.tabs.AddTabDialog.ChooseTabListItem;
3839
import org.schabi.newpipe.util.ThemeHelper;
3940

@@ -203,6 +204,14 @@ public void onRemotePlaylistSelected(
203204
});
204205
selectPlaylistFragment.show(getParentFragmentManager(), "select_playlist");
205206
return;
207+
case FEEDGROUP:
208+
final SelectFeedGroupFragment selectFeedGroupFragment =
209+
new SelectFeedGroupFragment();
210+
selectFeedGroupFragment.setOnSelectedListener(
211+
(groupId, name, iconId) ->
212+
addTab(new Tab.FeedGroupTab(groupId, name, iconId)));
213+
selectFeedGroupFragment.show(getParentFragmentManager(), "select_feed_group");
214+
return;
206215
default:
207216
addTab(type.getTab());
208217
break;
@@ -244,6 +253,11 @@ private ChooseTabListItem[] getAvailableTabs(final Context context) {
244253
getString(R.string.playlist_page_summary),
245254
tab.getTabIconRes(context)));
246255
break;
256+
case FEEDGROUP:
257+
returnList.add(new ChooseTabListItem(tab.getTabId(),
258+
getString(R.string.feed_group_page_summary),
259+
tab.getTabIconRes(context)));
260+
break;
247261
default:
248262
if (!tabList.contains(tab)) {
249263
returnList.add(new ChooseTabListItem(context, tab));
@@ -396,6 +410,9 @@ private String getTabName(@NonNull final Tab.Type type, @NonNull final Tab tab)
396410
? getString(R.string.local)
397411
: getNameOfServiceById(serviceId);
398412
return serviceName + "/" + tab.getTabName(requireContext());
413+
case FEEDGROUP:
414+
return getString(R.string.feed_groups_header_title)
415+
+ "/" + tab.getTabName(requireContext());
399416
default:
400417
return tab.getTabName(requireContext());
401418
}

app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ private static Tab from(final int tabId, @Nullable final JsonObject jsonObject)
9393
return new ChannelTab(jsonObject);
9494
case PLAYLIST:
9595
return new PlaylistTab(jsonObject);
96+
case FEEDGROUP:
97+
return new FeedGroupTab(jsonObject);
9698
}
9799
}
98100

@@ -162,7 +164,8 @@ public enum Type {
162164
HISTORY(new HistoryTab()),
163165
KIOSK(new KioskTab()),
164166
CHANNEL(new ChannelTab()),
165-
PLAYLIST(new PlaylistTab());
167+
PLAYLIST(new PlaylistTab()),
168+
FEEDGROUP(new FeedGroupTab());
166169

167170
private final Tab tab;
168171

@@ -652,4 +655,93 @@ public LocalItemType getPlaylistType() {
652655
return playlistType;
653656
}
654657
}
658+
public static class FeedGroupTab extends Tab {
659+
public static final int ID = 9;
660+
private static final String JSON_FEED_GROUP_ID_KEY = "feed_group_id";
661+
private static final String JSON_FEED_GROUP_NAME_KEY = "feed_group_name";
662+
private static final String JSON_FEED_GROUP_ICON_KEY = "feed_group_icon";
663+
private Long feedGroupId;
664+
private String feedGroupName;
665+
private int iconId;
666+
667+
private FeedGroupTab() {
668+
this((long) -1, NO_NAME, R.drawable.ic_asterisk);
669+
}
670+
671+
public FeedGroupTab(final Long feedGroupId, final String feedGroupName,
672+
final int iconId) {
673+
this.feedGroupId = feedGroupId;
674+
this.feedGroupName = feedGroupName;
675+
this.iconId = iconId;
676+
677+
}
678+
679+
public FeedGroupTab(final JsonObject jsonObject) {
680+
super(jsonObject);
681+
}
682+
683+
@Override
684+
public int getTabId() {
685+
return ID;
686+
}
687+
688+
@Override
689+
public String getTabName(final Context context) {
690+
return feedGroupName;
691+
}
692+
693+
@DrawableRes
694+
@Override
695+
public int getTabIconRes(final Context context) {
696+
return this.iconId;
697+
}
698+
699+
@Override
700+
public FeedFragment getFragment(final Context context) {
701+
return FeedFragment.newInstance(feedGroupId, feedGroupName);
702+
}
703+
704+
@Override
705+
protected void writeDataToJson(final JsonStringWriter writerSink) {
706+
writerSink.value(JSON_FEED_GROUP_ID_KEY, feedGroupId)
707+
.value(JSON_FEED_GROUP_NAME_KEY, feedGroupName)
708+
.value(JSON_FEED_GROUP_ICON_KEY, iconId);
709+
}
710+
711+
@Override
712+
protected void readDataFromJson(final JsonObject jsonObject) {
713+
feedGroupId = jsonObject.getLong(JSON_FEED_GROUP_ID_KEY, -1);
714+
feedGroupName = jsonObject.getString(JSON_FEED_GROUP_NAME_KEY, NO_NAME);
715+
iconId = jsonObject.getInt(JSON_FEED_GROUP_ICON_KEY, R.drawable.ic_asterisk);
716+
}
717+
718+
@Override
719+
public boolean equals(final Object obj) {
720+
if (!(obj instanceof FeedGroupTab)) {
721+
return false;
722+
}
723+
final FeedGroupTab other = (FeedGroupTab) obj;
724+
return super.equals(obj)
725+
&& feedGroupId.equals(other.feedGroupId)
726+
&& feedGroupName.equals(other.feedGroupName)
727+
&& iconId == other.iconId;
728+
}
729+
730+
@Override
731+
public int hashCode() {
732+
return Objects.hash(getTabId(), feedGroupId, feedGroupName, iconId);
733+
}
734+
735+
public Long getFeedGroupId() {
736+
return feedGroupId;
737+
}
738+
739+
public String getFeedGroupName() {
740+
return feedGroupName;
741+
}
742+
743+
public int getIconId() {
744+
return iconId;
745+
}
746+
}
655747
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@
689689
</plurals>
690690
<!-- Feed -->
691691
<string name="fragment_feed_title">What\'s New</string>
692+
<string name="feed_group_page_summary">Channel group page</string>
692693
<string name="feed_groups_header_title">Channel groups</string>
693694
<string name="feed_oldest_subscription_update">Feed last updated: %s</string>
694695
<string name="feed_subscription_not_loaded_count">Not loaded: %d</string>

0 commit comments

Comments
 (0)