From 774d3160a918652a7cd9b565114e04032b683401 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 8 Mar 2022 17:13:48 +0800 Subject: [PATCH] android: fix Fragment be created twice --- .../java/pub/doric/DoricPanelFragment.java | 29 ++++++++++++++++--- .../src/main/res/layout/doric_fragment.xml | 3 +- .../java/pub/doric/android/MainActivity.java | 4 ++- .../java/pub/doric/android/MainActivity.java | 4 ++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java index 31c3f6ac..7c48eec0 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java @@ -143,6 +143,9 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { AsyncCall.ensureRunInHandler(uiHandler, new Callable() { @Override public Object call() { + if (maskView == null) { + return null; + } maskView.setVisibility(View.GONE); return null; } @@ -153,9 +156,18 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { AsyncCall.ensureRunInHandler(uiHandler, new Callable() { @Override public Object call() { + if (maskView == null) { + return null; + } maskView.setVisibility(View.VISIBLE); - maskView.findViewById(R.id.doric_mask_loading).setVisibility(View.VISIBLE); - maskView.findViewById(R.id.doric_mask_error).setVisibility(View.GONE); + View loading = maskView.findViewById(R.id.doric_mask_loading); + View error = maskView.findViewById(R.id.doric_mask_error); + if (loading != null) { + loading.setVisibility(View.VISIBLE); + } + if (error != null) { + error.setVisibility(View.GONE); + } return null; } }); @@ -165,9 +177,18 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { AsyncCall.ensureRunInHandler(uiHandler, new Callable() { @Override public Object call() { + if (maskView == null) { + return null; + } + View loading = maskView.findViewById(R.id.doric_mask_loading); + View error = maskView.findViewById(R.id.doric_mask_error); maskView.setVisibility(View.VISIBLE); - maskView.findViewById(R.id.doric_mask_loading).setVisibility(View.GONE); - maskView.findViewById(R.id.doric_mask_error).setVisibility(View.VISIBLE); + if (loading != null) { + loading.setVisibility(View.GONE); + } + if (error != null) { + error.setVisibility(View.VISIBLE); + } View retryView = maskView.findViewById(R.id.doric_mask_error_retry); if (retryView != null) { retryView.setOnClickListener(new View.OnClickListener() { diff --git a/doric-android/doric/src/main/res/layout/doric_fragment.xml b/doric-android/doric/src/main/res/layout/doric_fragment.xml index 7b6d46f5..40711b11 100644 --- a/doric-android/doric/src/main/res/layout/doric_fragment.xml +++ b/doric-android/doric/src/main/res/layout/doric_fragment.xml @@ -9,8 +9,7 @@ android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" - app:defaultNavHost="true" - app:navGraph="@navigation/doric_navigation" /> + app:defaultNavHost="true" />