Skip to content

Commit 678f0a7

Browse files
authored
Merge pull request #1 from rmtilde/fix-related-items-enqueue-on-video-change
Fix Crash on Related Items Modal
2 parents eb9f300 + b14f658 commit 678f0a7

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedItemsFragment.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import androidx.annotation.NonNull;
1212
import androidx.annotation.Nullable;
13+
import androidx.fragment.app.Fragment;
1314
import androidx.preference.PreferenceManager;
1415

1516
import org.schabi.newpipe.R;
@@ -18,8 +19,10 @@
1819
import org.schabi.newpipe.extractor.InfoItem;
1920
import org.schabi.newpipe.extractor.ListExtractor;
2021
import org.schabi.newpipe.extractor.stream.StreamInfo;
22+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2123
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
2224
import org.schabi.newpipe.info_list.ItemViewMode;
25+
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
2326
import org.schabi.newpipe.ktx.ViewUtils;
2427

2528
import java.io.Serializable;
@@ -173,4 +176,33 @@ protected ItemViewMode getItemViewMode() {
173176
}
174177
return mode;
175178
}
179+
180+
@Override
181+
protected void showInfoItemDialog(final StreamInfoItem item) {
182+
try {
183+
final Fragment parentFragment = getParentFragment();
184+
185+
// Try and attach the InfoItemDialog to the parent fragment of the RelatedItemsFragment
186+
// so that its context is not lost when the RelatedItemsFragment is reinitialized.
187+
if (parentFragment != null) {
188+
new InfoItemDialog.Builder(
189+
parentFragment.getActivity(),
190+
parentFragment.getContext(),
191+
parentFragment,
192+
item
193+
).create().show();
194+
} else {
195+
new InfoItemDialog.Builder(
196+
getActivity(),
197+
getContext(),
198+
this,
199+
item)
200+
.create().show();
201+
}
202+
203+
} catch (final IllegalArgumentException e) {
204+
InfoItemDialog.Builder.reportErrorDuringInitialization(e, item);
205+
}
206+
}
207+
176208
}

0 commit comments

Comments
 (0)