Skip to content

Commit 8f71602

Browse files
committed
save state avoid missing data
1 parent e155bad commit 8f71602

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

app/src/main/java/com/duy/ccppcompiler/diagnostic/DiagnosticFragment.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,19 @@ public class DiagnosticFragment extends Fragment implements DiagnosticContract.V
4242
private DiagnosticContract.Presenter mPresenter;
4343
private DiagnosticAdapter mAdapter;
4444

45-
private void init() {
45+
public static DiagnosticFragment newInstance() {
4646

47+
Bundle args = new Bundle();
48+
49+
DiagnosticFragment fragment = new DiagnosticFragment();
50+
fragment.setArguments(args);
51+
return fragment;
4752
}
4853

4954
@Nullable
5055
@Override
5156
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
52-
return super.onCreateView(inflater, container, savedInstanceState);
57+
return inflater.inflate(R.layout.fragment_diagnostic, container, false);
5358

5459
}
5560

@@ -68,7 +73,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
6873
mAdapter = new DiagnosticAdapter(diagnostics, getContext());
6974
mAdapter.setDiagnosticClickListener(this);
7075
mRecyclerView.setAdapter(mAdapter);
71-
init();
7276
}
7377

7478
@Override

app/src/main/java/com/jecelyin/editor/v2/ui/activities/EditorActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.support.annotation.IdRes;
2828
import android.support.annotation.NonNull;
2929
import android.support.annotation.Nullable;
30+
import android.support.v4.app.FragmentManager;
3031
import android.support.v4.view.GravityCompat;
3132
import android.support.v4.view.ViewPager;
3233
import android.support.v4.widget.DrawerLayout;
@@ -45,6 +46,7 @@
4546
import com.duy.ccppcompiler.R;
4647
import com.duy.ccppcompiler.compiler.CompileManager;
4748
import com.duy.ccppcompiler.compiler.CompilerFactory;
49+
import com.duy.ccppcompiler.diagnostic.DiagnosticFragment;
4850
import com.duy.ccppcompiler.diagnostic.DiagnosticPresenter;
4951
import com.duy.ide.compiler.CompileTask;
5052
import com.duy.ide.compiler.INativeCompiler;
@@ -227,9 +229,16 @@ public void onPanelSlide(View panel, float slideOffset) {
227229
}
228230
});
229231

230-
RecyclerView recyclerView = findViewById(R.id.diagnostic_list_view);
231-
DiagnosticView diagnosticView = new DiagnosticView(recyclerView, this);
232-
mDiagnosticPresenter = new DiagnosticPresenter(diagnosticView, this, mTabManager);
232+
FragmentManager fm = getSupportFragmentManager();
233+
String tag = DiagnosticFragment.class.getSimpleName();
234+
DiagnosticFragment diagnosticFragment = (DiagnosticFragment)
235+
fm.findFragmentByTag(tag);
236+
if (diagnosticFragment == null) {
237+
diagnosticFragment = DiagnosticFragment.newInstance();
238+
}
239+
fm.beginTransaction().replace(R.id.container_diagnostic_list_view, diagnosticFragment, tag)
240+
.commit();
241+
mDiagnosticPresenter = new DiagnosticPresenter(diagnosticFragment, this, mTabManager);
233242
}
234243

235244
private void initToolbar() {

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@
7474

7575
</LinearLayout>
7676

77-
<android.support.v7.widget.RecyclerView
78-
android:id="@+id/diagnostic_list_view"
77+
<FrameLayout
78+
android:id="@+id/container_diagnostic_list_view"
7979
android:layout_width="match_parent"
8080
android:layout_height="200dp">
8181

82-
</android.support.v7.widget.RecyclerView>
82+
</FrameLayout>
8383
</LinearLayout>
8484

8585
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Copyright 2018 Mr Duy
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:id="@+id/diagnostic_list_view"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
</android.support.v7.widget.RecyclerView>

0 commit comments

Comments
 (0)