@@ -76,16 +76,39 @@ public void show() {
7676 */
7777 public static class Builder {
7878 @ NonNull private final Activity activity ;
79- @ NonNull private final StreamInfoItem item ;
79+ @ NonNull private final StreamInfoItem infoItem ;
8080 @ NonNull private final Fragment fragment ;
8181 @ NonNull private final List <StreamDialogEntry > entries = new ArrayList <>();
82+ private final boolean addDefaultEntriesAutomatically ;
8283
8384 public Builder (@ NonNull final Activity activity ,
8485 @ NonNull final Fragment fragment ,
85- @ NonNull final StreamInfoItem item ) {
86+ @ NonNull final StreamInfoItem infoItem ) {
87+ this (activity , fragment , infoItem , true );
88+ }
89+
90+ /**
91+ * <p>Create an instance of this Builder</p>
92+ * @param activity
93+ * @param fragment
94+ * @param infoItem
95+ * @param addDefaultEntriesAutomatically whether default entries added with
96+ * {@link #addDefaultEntriesAtBeginning()} and
97+ * {@link #addDefaultEntriesAtEnd()}
98+ * are added automatically when generating
99+ * the {@link InfoItemDialog}.
100+ */
101+ public Builder (@ NonNull final Activity activity ,
102+ @ NonNull final Fragment fragment ,
103+ @ NonNull final StreamInfoItem infoItem ,
104+ final boolean addDefaultEntriesAutomatically ) {
86105 this .activity = activity ;
87106 this .fragment = fragment ;
88- this .item = item ;
107+ this .infoItem = infoItem ;
108+ this .addDefaultEntriesAutomatically = addDefaultEntriesAutomatically ;
109+ if (addDefaultEntriesAutomatically ) {
110+ addDefaultEntriesAtBeginning ();
111+ }
89112 }
90113
91114 public void addEntry (@ NonNull final StreamDialogDefaultEntry entry ) {
@@ -98,17 +121,26 @@ public void addAllEntries(@NonNull final StreamDialogDefaultEntry... newEntries)
98121 }
99122 }
100123
124+ /**
125+ * <p>Change an entries' action that is called when the entry is selected.</p>
126+ * <p><strong>Warning:</strong> Only use this method when the entry has been already added.
127+ * Changing the action of an entry which has not been added to the Builder yet
128+ * does not have an effect.</p>
129+ * @param entry the entry to change
130+ * @param action the action to perform when the entry is selected
131+ */
101132 public void setAction (@ NonNull final StreamDialogDefaultEntry entry ,
102133 @ NonNull final StreamDialogEntry .StreamDialogEntryAction action ) {
103134 for (int i = 0 ; i < entries .size (); i ++) {
104135 if (entries .get (i ).resource == entry .resource ) {
105136 entries .set (i , new StreamDialogEntry (entry .resource , action ));
137+ return ;
106138 }
107139 }
108140 }
109141
110142 public void addChannelDetailsEntryIfPossible () {
111- if (!isNullOrEmpty (item .getUploaderUrl ())) {
143+ if (!isNullOrEmpty (infoItem .getUploaderUrl ())) {
112144 addEntry (StreamDialogDefaultEntry .SHOW_CHANNEL_DETAILS );
113145 }
114146 }
@@ -125,30 +157,29 @@ public void addEnqueueEntriesIfNeeded() {
125157
126158 public void addStartHereEntries () {
127159 addEntry (StreamDialogDefaultEntry .START_HERE_ON_BACKGROUND );
128- if (item .getStreamType () != StreamType .AUDIO_STREAM
129- && item .getStreamType () != StreamType .AUDIO_LIVE_STREAM ) {
160+ if (infoItem .getStreamType () != StreamType .AUDIO_STREAM
161+ && infoItem .getStreamType () != StreamType .AUDIO_LIVE_STREAM ) {
130162 addEntry (StreamDialogDefaultEntry .START_HERE_ON_POPUP );
131163 }
132164 }
133165
134166 /**
135167 * Adds {@link StreamDialogDefaultEntry.MARK_AS_WATCHED} if the watch history is enabled
136168 * and the stream is not a livestream.
137- * @param streamType the item's stream type
138169 */
139- public void addMarkAsWatchedEntryIfNeeded (final StreamType streamType ) {
170+ public void addMarkAsWatchedEntryIfNeeded () {
140171 final boolean isWatchHistoryEnabled = PreferenceManager
141172 .getDefaultSharedPreferences (activity )
142173 .getBoolean (activity .getString (R .string .enable_watch_history_key ), false );
143- if (streamType != StreamType . AUDIO_LIVE_STREAM
144- && streamType != StreamType .LIVE_STREAM
145- && isWatchHistoryEnabled ) {
174+ if (isWatchHistoryEnabled
175+ && infoItem . getStreamType () != StreamType .LIVE_STREAM
176+ && infoItem . getStreamType () != StreamType . AUDIO_LIVE_STREAM ) {
146177 addEntry (StreamDialogDefaultEntry .MARK_AS_WATCHED );
147178 }
148179 }
149180
150181 public void addPlayWithKodiEntryIfNeeded () {
151- if (KoreUtils .shouldShowPlayWithKodi (activity , item .getServiceId ())) {
182+ if (KoreUtils .shouldShowPlayWithKodi (activity , infoItem .getServiceId ())) {
152183 addEntry (StreamDialogDefaultEntry .PLAY_WITH_KODI );
153184 }
154185 }
@@ -165,7 +196,7 @@ public void addDefaultEntriesAtEnd() {
165196 StreamDialogDefaultEntry .OPEN_IN_BROWSER
166197 );
167198 addPlayWithKodiEntryIfNeeded ();
168- addMarkAsWatchedEntryIfNeeded (item . getStreamType () );
199+ addMarkAsWatchedEntryIfNeeded ();
169200 addChannelDetailsEntryIfPossible ();
170201 }
171202
@@ -174,7 +205,10 @@ public void addDefaultEntriesAtEnd() {
174205 * @return a new instance of {@link InfoItemDialog}
175206 */
176207 public InfoItemDialog create () {
177- return new InfoItemDialog (this .activity , this .fragment , this .item , this .entries );
208+ if (addDefaultEntriesAutomatically ) {
209+ addDefaultEntriesAtEnd ();
210+ }
211+ return new InfoItemDialog (this .activity , this .fragment , this .infoItem , this .entries );
178212 }
179213 }
180214}
0 commit comments