Commit 5b24f83e by amateur

修改多个模块支持同一个fragment

1 parent 4e6ad246
......@@ -2,16 +2,18 @@ package com.polysoft.nafmii.enums;
public enum ModulesEnum {
HOME("home", "file:///android_asset/webpage/fileChooser.html"),
MEMBER("member", "file:///android_asset/webpage/fileChooser.html"),
LEARN("learn", "http://debugtbs.qq.com"),
MY("my", "http://192.168.43.183:8080");
HOME("home", "home", "file:///android_asset/dist/index.html"),
MEMBER("member", "home","file:///android_asset/dict/index.html"),
LEARN("learn", "learn", "http://debugtbs.qq.com"),
MY("my", "home","file:///android_asset/dist/index.html/#/user/center");
public final String name;
public final String fmtKey;
public final String webUrl;
ModulesEnum(String tag, String url) {
this.name = tag;
ModulesEnum(String name, String fmtKey, String url) {
this.name = name;
this.fmtKey = fmtKey;
this.webUrl = url;
}
......
......@@ -25,17 +25,18 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
public void showInitFragment(ModulesEnum[] modules) {
for (int i = 1; i < modules.length; i++) {
for (int i = 0; i < modules.length; i++) {
this.addModuleFragment(modules[i]);
}
Fragment fragment = this.addModuleFragment(modules[0]);
Fragment fragment = this.manager.findFragmentByTag(modules[0].fmtKey);
FragmentTransaction transaction = this.manager.beginTransaction();
transaction.show(fragment).commitNow();
this.setCurrentModule(modules[0]);
}
public Fragment getCurrentFragment() {
String tag = this.currentModule.name;
String tag = this.currentModule.fmtKey;
return this.manager.findFragmentByTag(tag);
}
......@@ -54,13 +55,15 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
Fragment fragment = this.findFragment(module);
FragmentTransaction transaction = this.manager.beginTransaction();
transaction.hide(this.getCurrentFragment());
transaction.addToBackStack("").show(fragment).commit();
if (!module.fmtKey.equals(this.currentModule.fmtKey)) {
transaction.hide(this.getCurrentFragment());
transaction.addToBackStack("").show(fragment).commit();
}
this.setCurrentModule(module);
}
public Fragment findFragment(ModulesEnum module) {
Fragment fragment = this.manager.findFragmentByTag(module.name);
Fragment fragment = this.manager.findFragmentByTag(module.fmtKey);
if (null == fragment) {
return this.addModuleFragment(module);
}
......@@ -68,9 +71,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
private Fragment addModuleFragment(ModulesEnum module) {
FragmentTransaction transaction = this.manager.beginTransaction();
Fragment fragment = WebViewFragment.newInstances(module.webUrl);
transaction.add(this.containerId, fragment, module.name).hide(fragment).commitNow();
Fragment fragment = this.manager.findFragmentByTag(module.fmtKey);
if (null == fragment) {
FragmentTransaction transaction = this.manager.beginTransaction();
fragment = WebViewFragment.newInstances(module.webUrl);
transaction.add(this.containerId, fragment, module.fmtKey).hide(fragment).commitNow();
}
return fragment;
}
......@@ -89,7 +95,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
Fragment fragment = fragments.get(i);
if (fragment.isVisible()) {
setCurrentModule(ModulesEnum.findModule(fragment.getTag()));
return ;
return;
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!