3737 */
3838
3939public class DiagnosticFragment extends Fragment implements DiagnosticContract .View , DiagnosticClickListener {
40+ private static final String KEY_DATA = "data" ;
4041 private RecyclerView mRecyclerView ;
4142 private DiagnosticContract .Presenter mPresenter ;
4243 private DiagnosticAdapter mAdapter ;
4344
44-
4545 private void init () {
4646
4747 }
@@ -56,9 +56,16 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
5656 @ Override
5757 public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
5858 super .onViewCreated (view , savedInstanceState );
59+ ArrayList <Diagnostic > diagnostics ;
60+ if (savedInstanceState != null ) {
61+ diagnostics = savedInstanceState .getParcelableArrayList (KEY_DATA );
62+ } else {
63+ diagnostics = new ArrayList <>();
64+ }
65+
5966 mRecyclerView = view .findViewById (R .id .diagnostic_list_view );
6067 mRecyclerView .setLayoutManager (new LinearLayoutManager (getContext ()));
61- mAdapter = new DiagnosticAdapter (new ArrayList < Diagnostic >() , getContext ());
68+ mAdapter = new DiagnosticAdapter (diagnostics , getContext ());
6269 mAdapter .setDiagnosticClickListener (this );
6370 mRecyclerView .setAdapter (mAdapter );
6471 init ();
@@ -67,6 +74,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
6774 @ Override
6875 public void onSaveInstanceState (@ NonNull Bundle outState ) {
6976 super .onSaveInstanceState (outState );
77+ ArrayList <Diagnostic > diagnostics = new ArrayList <>(mAdapter .getDiagnostics ());
78+ outState .putParcelableArrayList (KEY_DATA , diagnostics );
7079 }
7180
7281 @ Override
0 commit comments