[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

3
.idea/misc.xml generated
View File

@@ -22,6 +22,7 @@
<entry key="core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_check_status.xml" value="0.18996305418719212" />
<entry key="core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_traffic_light_vr.xml" value="0.18996305418719212" />
<entry key="core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_vip_identification.xml" value="0.45" />
<entry key="core/function-impl/mogo-core-function-map/src/main/res/layout/function_map_fragment_hd_map.xml" value="0.29322916666666665" />
<entry key="foudations/mogo-commons/src/main/res/layout/module_commons_layout_toast.xml" value="0.3117283950617284" />
<entry key="modules/mogo-module-authorize/src/main/res/layout/module_authorize_fragment.xml" value="0.273046875" />
<entry key="modules/mogo-module-carchatting/src/main/res/drawable/module_carchatting_vr_calling_bg.xml" value="0.231875" />
@@ -76,7 +77,7 @@
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="16" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
</project>

View File

@@ -54,6 +54,11 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
return R.layout.module_mogo_och_base_fragment;
}
@Override
public String getTagName() {
return TAG;
}
private View panelView;
@Override

View File

@@ -58,6 +58,10 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
return R.layout.fragment_hmi
}
override fun getTagName(): String {
return TAG
}
override fun createPresenter(): WaringPresenter {
return WaringPresenter(this)
}

View File

@@ -0,0 +1,41 @@
package com.mogo.eagle.core.function.map;
import androidx.annotation.NonNull;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths;
import com.mogo.utils.logger.Logger;
/**
* @author donghongyu
* @since 2021-11-09
* 高精度地图层UI
*/
@Route(path = MoGoFragmentPaths.PATH_FRAGMENT_MAP)
public class MoGoHDMapFragment extends MvpFragment<MoGoMapView, MoGoMapPresenter> implements MoGoMapView {
private static final String TAG = "MoGoHDMapFragment";
@Override
protected int getLayoutId() {
return R.layout.function_map_fragment_hd_map;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
Logger.d(TAG, "initViews");
}
@NonNull
@Override
protected MoGoMapPresenter createPresenter() {
return new MoGoMapPresenter(this);
}
}

View File

@@ -0,0 +1,9 @@
package com.mogo.eagle.core.function.map;
import com.mogo.commons.mvp.Presenter;
public class MoGoMapPresenter extends Presenter<MoGoMapView> {
public MoGoMapPresenter(MoGoMapView view) {
super(view);
}
}

View File

@@ -0,0 +1,6 @@
package com.mogo.eagle.core.function.map;
import com.mogo.commons.mvp.IView;
public interface MoGoMapView extends IView {
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,25 @@
package com.mogo.eagle.core.data.constants;
import androidx.annotation.Keep;
/**
* 有关UI的路径
*/
@Keep
public class MoGoFragmentPaths {
/**
* 高精地图Fragment
*/
@Keep
@Deprecated
public static final String PATH_FRAGMENT_MAP = "/hd_map_ui/";
/**
* HMI 业务相关的
*/
@Keep
@Deprecated
public static final String PATH_FRAGMENT_HMI = "/hmi_ui/";
}

View File

@@ -1,8 +1,11 @@
package com.mogo.commons.mvp;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
@@ -13,6 +16,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
import com.mogo.utils.SoftKeyBoardJobber;
/**

View File

@@ -56,6 +56,12 @@ public abstract class MvpFragment<V extends IView, P extends Presenter<V>> exten
*/
protected abstract int getLayoutId();
/**
* 获取绑定的TAG标记
* @return 返回唯一TAG标记
*/
public abstract String getTagName();
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

View File

@@ -56,6 +56,11 @@ public class AppNavigatorFragment extends MvpFragment< AppNavigatorView, AppNavi
return R.layout.module_apps_fragment_apps_navigator;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {

View File

@@ -39,6 +39,11 @@ public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > impleme
return R.layout.module_apps_fragment_apps;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
mAppsPager = findViewById( R.id.module_apps_id_apps_pager );

View File

@@ -23,6 +23,8 @@ import java.util.List;
* describe:车队信息
*/
public class VehicleTeamFragment extends MvpFragment<VehicleTeamView, VehicleTeamPresenter> implements VehicleTeamView {
private static final String TAG = "VehicleTeamFragment";
private TextView tvNum;
private ImageView ivClose;
private RecyclerView rvTeammates;
@@ -40,6 +42,11 @@ public class VehicleTeamFragment extends MvpFragment<VehicleTeamView, VehicleTea
return R.layout.module_car_chatting_fragment_team_view;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
tvNum = findViewById(R.id.tv_num);

View File

@@ -235,6 +235,11 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
}
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
mApis = MogoApisHandler.getInstance().getApis();

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

View File

@@ -36,6 +36,11 @@ public class MapFragment extends MvpFragment< MapView, MapPresenter > implements
return R.layout.module_map_fragment_map;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
MogoApisHandler.getInstance().getApis().getMapFrameControllerApi().initDelegate( this );

View File

@@ -56,6 +56,11 @@ class MessageHistoryFragment extends MvpFragment< MessageHistoryView, MessageHis
return R.layout.module_push_message_hisotry_fragment;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
mClear = findViewById( R.id.module_push_id_clear );

View File

@@ -27,6 +27,7 @@ import java.util.Map;
* 描述
*/
public class OnlineCarPanelFragment extends MvpFragment< IOnlineCarPanelView, OnlineCarPanelPresenter > implements IOnlineCarPanelView {
private String TAG = "OnlineCarPanelFragment";
private RecyclerView mList;
private View mErrorPanel;
@@ -45,6 +46,11 @@ public class OnlineCarPanelFragment extends MvpFragment< IOnlineCarPanelView, On
return R.layout.module_services_fragment_online_car_panel;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
findViewById( R.id.module_services_id_close ).setOnClickListener( new OnPreventFastClickListener() {

View File

@@ -55,7 +55,7 @@ import org.greenrobot.eventbus.ThreadMode
*/
class V2XEventPanelFragment : MvpFragment<V2XEventPanelFragment, EventPanelPresenter>(), SurroundingDetailItemListener ,IMogoStatusChangedListener{
private val TAG = "EventPanelFragment"
private val TAG = "V2XEventPanelFragment"
private var isFirstLoad = false
@@ -143,6 +143,10 @@ class V2XEventPanelFragment : MvpFragment<V2XEventPanelFragment, EventPanelPrese
return R.layout.module_v2x_event_panel_fragment_event_panel
}
override fun getTagName(): String {
return TAG
}
override fun initViews() {
Logger.d(MODULE_NAME, "事件面板初始化……")
try {

View File

@@ -37,7 +37,7 @@ import java.util.List;
*/
public class V2XScenarioHistoryFragment
extends MvpFragment<V2XScenarioHistoryFragment, ScenarioHistoryPresenter> {
private String TAG = "ScenarioHistoryFragment";
private String TAG = "V2XScenarioHistoryFragment";
public Boolean fromVoice = false;
private V2XListEmptyView mEmptyView;
private LinearLayout mClHistoryList;
@@ -51,6 +51,11 @@ public class V2XScenarioHistoryFragment
return R.layout.module_v2x_event_panel_fragment_scenario_history;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
Log.d(TAG, "initViews --------> ");

View File

@@ -33,7 +33,7 @@ import java.util.ArrayList;
public class V2XShareEventsFragment extends MvpFragment<V2XShareEventsFragment, ShareEventsPresenter> implements AdapterCallback {
private static final String TAG = "ShareEventsFragment";
private static final String TAG = "V2XShareEventsFragment";
private RecyclerView recyclerView;
private V2XShareEventAdapter adapter;
private ArrayList dataArrayList = new ArrayList();
@@ -50,6 +50,11 @@ public class V2XShareEventsFragment extends MvpFragment<V2XShareEventsFragment,
return R.layout.module_v2x_event_share_recylerview;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
v2XShareNetworkModel = new V2XShareNetworkModel(getContext());

View File

@@ -69,7 +69,7 @@ import static android.view.View.OVER_SCROLL_NEVER;
*/
public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, SurroundingEventPresenter> implements SurroundingEventView,
View.OnClickListener, SurroundingItemClickListener {
private static final String TAG = "SurroundingFragment";
private static final String TAG = "V2XSurroundingFragment";
private RelativeLayout mSurroundingLayout;
private RecyclerView mRecyclerView;
private TextView mTotalTv;
@@ -90,6 +90,11 @@ public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, Su
return R.layout.module_event_panel_fragment_surrounding;
}
@Override
public String getTagName() {
return TAG;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {