Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Nov 7, 2024
1 parent b590be3 commit 8f22dcb
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ private static Fragment _instantiate(final String fragmentClassName,
final Context context) {
return FragmentFactory
.instantiate(src, context)
.orElseGet(() -> {
final Fragment fragment = new DefaultFragmentFactory().instantiate(fragmentClassName, src, context);
src.ifPresent(_src -> configureFragment(fragment, _src));
return fragment;
});
.orElseGet(() -> createDefaultInstance(fragmentClassName, src, context));
}

private static Optional<Fragment> instantiate(final Optional<PreferenceWithHost> src, final Context context) {
Expand All @@ -43,6 +39,14 @@ private static Optional<Fragment> instantiate(final Optional<PreferenceWithHost>
.map(preferenceFragmentHandler -> preferenceFragmentHandler.createPreferenceFragment(context, null));
}

private static Fragment createDefaultInstance(final String fragmentClassName,
final Optional<PreferenceWithHost> src,
final Context context) {
final Fragment fragment = new DefaultFragmentFactory().instantiate(fragmentClassName, src, context);
src.ifPresent(_src -> configureFragment(fragment, _src));
return fragment;
}

private static void configureFragment(final Fragment fragment, final PreferenceWithHost src) {
if (src.host() instanceof final BaseSettingsFragment baseSettingsFragment) {
fragment.setArguments(baseSettingsFragment.buildArguments());
Expand Down

0 comments on commit 8f22dcb

Please sign in to comment.