[Upgrade module]针对Fragment 增加getTagName ,后续涉及到的Fragment进行重构加载方式
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -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() {
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ public interface MainView extends IView {
|
||||
*/
|
||||
void hideCoverUpLayout();
|
||||
|
||||
/**
|
||||
* 加载各模块中的Fragment
|
||||
*/
|
||||
void loadFunctionFragment();
|
||||
|
||||
/**
|
||||
* 加载模块
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 --------> ");
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user