Merge pull request #1 from rmtilde/fix-related-items-enqueue-on-video-change

Fix Crash on Related Items Modal
This commit is contained in:
rmtilde 2024-10-17 13:37:19 +11:00 committed by GitHub
commit 678f0a786a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 32 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import org.schabi.newpipe.R;
@ -18,8 +19,10 @@ import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.info_list.ItemViewMode;
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
import org.schabi.newpipe.ktx.ViewUtils;
import java.io.Serializable;
@ -173,4 +176,33 @@ public class RelatedItemsFragment extends BaseListInfoFragment<InfoItem, Related
}
return mode;
}
@Override
protected void showInfoItemDialog(final StreamInfoItem item) {
try {
final Fragment parentFragment = getParentFragment();
// Try and attach the InfoItemDialog to the parent fragment of the RelatedItemsFragment
// so that its context is not lost when the RelatedItemsFragment is reinitialized.
if (parentFragment != null) {
new InfoItemDialog.Builder(
parentFragment.getActivity(),
parentFragment.getContext(),
parentFragment,
item
).create().show();
} else {
new InfoItemDialog.Builder(
getActivity(),
getContext(),
this,
item)
.create().show();
}
} catch (final IllegalArgumentException e) {
InfoItemDialog.Builder.reportErrorDuringInitialization(e, item);
}
}
}