Skip to content

Commit

Permalink
QMUISchemeFragmentFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Jun 8, 2020
1 parent 1ae3c33 commit b18a860
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,23 @@ public boolean handle(@NonNull QMUISchemeHandler handler,
}

QMUIFragmentActivity fragmentActivity = (QMUIFragmentActivity) activity;
Bundle args = factory.factory(scheme);
Fragment currentFragment = fragmentActivity.getCurrentFragment();
if(isUseRefreshIfMatchedCurrent()
&& currentFragment != null
&& currentFragment.getClass() == mFragmentCls
&& currentFragment instanceof FragmentSchemeRefreshable){
((FragmentSchemeRefreshable) currentFragment).refreshFromScheme(args);
((FragmentSchemeRefreshable) currentFragment).refreshFromScheme(factory.factory(scheme));
return true;
}

try {
QMUIFragment fragment = mFragmentCls.newInstance();
fragment.setArguments(args);
QMUIFragment fragment = factory.factory(mFragmentCls, scheme);
if(fragment != null){
int commitId = fragmentActivity.startFragment(fragment);
if (commitId == -1) {
QMUILog.d(QMUISchemeHandler.TAG, "start fragment failed.");
return false;
}
return true;
} catch (Exception e) {
QMUILog.printErrStackTrace(QMUISchemeHandler.TAG, e,
"Error to create fragment: %s", mFragmentCls.getSimpleName());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@

public class QMUIDefaultSchemeFragmentFactory implements QMUISchemeFragmentFactory {

@Override
@Nullable
public QMUIFragment factory(@NonNull Class<? extends QMUIFragment> fragmentCls,
@Nullable Map<String, SchemeValue> scheme) {
try {
QMUIFragment fragment = fragmentCls.newInstance();
fragment.setArguments(factory(scheme));
return fragment;
} catch (Exception e) {
QMUILog.printErrStackTrace(QMUISchemeHandler.TAG, e,
"Error to create fragment: %s", fragmentCls.getSimpleName());
return null;
}
}


@Override
@Nullable
public Bundle factory(@Nullable Map<String, SchemeValue> scheme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
import java.util.Map;

public interface QMUISchemeFragmentFactory {

@Nullable
QMUIFragment factory(@NonNull Class<? extends QMUIFragment> fragmentCls,
@Nullable Map<String, SchemeValue> scheme);

@Nullable
Bundle factory(@Nullable Map<String, SchemeValue> scheme);

Expand Down

0 comments on commit b18a860

Please sign in to comment.