Refactor duplicated code into method

This commit is contained in:
ktprograms 2021-08-14 17:32:38 +08:00
parent 241054fd26
commit bd0427c79f
1 changed files with 15 additions and 9 deletions

View File

@ -45,21 +45,14 @@ public enum StreamDialogEntry {
NewPipeDatabase.getInstance(fragment.getContext()).streamDAO() NewPipeDatabase.getInstance(fragment.getContext()).streamDAO()
.setUploaderUrl(serviceId, url, result.getUploaderUrl()) .setUploaderUrl(serviceId, url, result.getUploaderUrl())
.subscribeOn(Schedulers.io()).subscribe(); .subscribeOn(Schedulers.io()).subscribe();
// For some reason `getParentFragmentManager()` doesn't work, but this does. openChannelFragment(fragment, item, result.getUploaderUrl());
NavigationHelper.openChannelFragment(
fragment.requireActivity().getSupportFragmentManager(),
item.getServiceId(), result.getUploaderUrl(),
item.getUploaderName());
}, throwable -> Toast.makeText( }, throwable -> Toast.makeText(
fragment.getContext(), fragment.getContext(),
R.string.error_show_channel_details, R.string.error_show_channel_details,
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show()); ).show());
} else { } else {
// For some reason `getParentFragmentManager()` doesn't work, but this does. openChannelFragment(fragment, item, item.getUploaderUrl());
NavigationHelper.openChannelFragment(
fragment.requireActivity().getSupportFragmentManager(),
item.getServiceId(), item.getUploaderUrl(), item.getUploaderName());
} }
}), }),
@ -206,4 +199,17 @@ public enum StreamDialogEntry {
public interface StreamDialogEntryAction { public interface StreamDialogEntryAction {
void onClick(Fragment fragment, StreamInfoItem infoItem); 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());
}
} }