From bd0427c79f4474bc2c3194672d11d8223f7d4520 Mon Sep 17 00:00:00 2001 From: ktprograms Date: Sat, 14 Aug 2021 17:32:38 +0800 Subject: [PATCH] Refactor duplicated code into method --- .../newpipe/util/StreamDialogEntry.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 978677083..f3c15b8b0 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -45,21 +45,14 @@ public enum StreamDialogEntry { NewPipeDatabase.getInstance(fragment.getContext()).streamDAO() .setUploaderUrl(serviceId, url, result.getUploaderUrl()) .subscribeOn(Schedulers.io()).subscribe(); - // For some reason `getParentFragmentManager()` doesn't work, but this does. - NavigationHelper.openChannelFragment( - fragment.requireActivity().getSupportFragmentManager(), - item.getServiceId(), result.getUploaderUrl(), - item.getUploaderName()); + openChannelFragment(fragment, item, result.getUploaderUrl()); }, throwable -> Toast.makeText( fragment.getContext(), R.string.error_show_channel_details, Toast.LENGTH_SHORT ).show()); } else { - // For some reason `getParentFragmentManager()` doesn't work, but this does. - NavigationHelper.openChannelFragment( - fragment.requireActivity().getSupportFragmentManager(), - item.getServiceId(), item.getUploaderUrl(), item.getUploaderName()); + openChannelFragment(fragment, item, item.getUploaderUrl()); } }), @@ -206,4 +199,17 @@ public enum StreamDialogEntry { public interface StreamDialogEntryAction { void onClick(Fragment fragment, StreamInfoItem infoItem); } + + ///////////////////////////////////////////// + // private method to open channel fragment // + ///////////////////////////////////////////// + + private static void openChannelFragment(final Fragment fragment, + final StreamInfoItem item, + final String uploaderUrl) { + // For some reason `getParentFragmentManager()` doesn't work, but this does. + NavigationHelper.openChannelFragment( + fragment.requireActivity().getSupportFragmentManager(), + item.getServiceId(), uploaderUrl, item.getUploaderName()); + } }