[Upgrade module]针对Fragment 增加getTagName ,后续涉及到的Fragment进行重构加载方式

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2021-11-09 18:51:27 +08:00
parent ec2c92fd33
commit c8f8a3d3bb
24 changed files with 220 additions and 6 deletions

View File

@@ -15,12 +15,17 @@ import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.context.ContextHolderUtil;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.mvp.MvpActivity;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.utilcode.mogo.toast.ResourcesHelper;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.api.CallChatApi;
@@ -238,6 +243,7 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
* 加载其它模块
*/
protected void loadOthersModules() {
//loadFunctionFragment();
// 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。
loadContainerModules();
MogoModulesManager.getInstance().loadModules();
@@ -276,6 +282,12 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
mServiceApis.getAdasControllerApi().showADAS();
}
@Override
public void loadFunctionFragment() {
MvpFragment fragmentHdMap = (MvpFragment) ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_MAP).navigation();
addFragment(fragmentHdMap, fragmentHdMap.getTagName(), R.id.module_main_id_hd_map_fragment_container);
}
@NonNull
@Override
protected MainPresenter createPresenter() {
@@ -454,4 +466,26 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
}
}
/**
* 由于应用是单页面的所以采用Fragment将各模块的UI进行分割解耦合
*
* @param newFragment 功能UI
* @param tagName UI绑定的Tag
* @param containerId 要加入的资源ID
*/
private void addFragment(Fragment newFragment, String tagName, int containerId) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(tagName);
if (fragment == null) {
fragment = newFragment;
}
if (fragment == null) {
Logger.e(TAG, "add fragment fail cause fragment == null, container is %s", ResourcesHelper.getResNameById(getApplicationContext(), containerId));
return;
}
getSupportFragmentManager().beginTransaction()
.replace(containerId, fragment, tagName)
.commitAllowingStateLoss();
}
}

View File

@@ -16,6 +16,11 @@ public interface MainView extends IView {
*/
void hideCoverUpLayout();
/**
* 加载各模块中的Fragment
*/
void loadFunctionFragment();
/**
* 加载模块
*/

View File

@@ -13,6 +13,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- 地图 -->
<FrameLayout
android:id="@+id/module_main_id_hd_map_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!--四个方向,碰撞预警-->
<FrameLayout