2 * Copyright (C) 2013-2016 Tobias Brunner
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 package org.strongswan.android.ui;
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.ArrayAdapter;
24 import android.widget.FrameLayout;
25 import android.widget.TextView;
27 import org.strongswan.android.R;
28 import org.strongswan.android.logic.imc.RemediationInstruction;
30 import androidx.annotation.NonNull;
31 import androidx.annotation.Nullable;
32 import androidx.fragment.app.ListFragment;
34 public class RemediationInstructionFragment extends ListFragment
36 public static final String ARG_REMEDIATION_INSTRUCTION = "instruction";
37 private RemediationInstruction mInstruction = null;
38 private TextView mTitle;
39 private TextView mDescription;
40 private TextView mHeader;
43 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
45 /* while the documentation recommends to include "@android:layout/list_content" to retain
46 * the default functionality, this does not actually work with the ListFragment provided by
47 * the support library as it builds the view manually and uses different IDs */
48 View layout = inflater.inflate(R.layout.remediation_instruction, container, false);
49 FrameLayout list = (FrameLayout)layout.findViewById(R.id.list_container);
50 list.addView(super.onCreateView(inflater, list, savedInstanceState));
55 public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
57 super.onViewCreated(view, savedInstanceState);
59 if (savedInstanceState != null)
61 mInstruction = savedInstanceState.getParcelable(ARG_REMEDIATION_INSTRUCTION);
63 /* show dividers only between list items */
64 getListView().setHeaderDividersEnabled(false);
65 getListView().setFooterDividersEnabled(false);
66 /* don't show loader while adapter is not set */
68 mTitle = (TextView)getView().findViewById(R.id.title);
69 mDescription = (TextView)getView().findViewById(R.id.description);
70 mHeader = (TextView)getView().findViewById(R.id.list_header);
74 public void onSaveInstanceState(Bundle outState)
76 super.onSaveInstanceState(outState);
77 outState.putParcelable(ARG_REMEDIATION_INSTRUCTION, mInstruction);
85 Bundle args = getArguments();
88 mInstruction = args.getParcelable(ARG_REMEDIATION_INSTRUCTION);
90 updateView(mInstruction);
93 public void updateView(RemediationInstruction instruction)
95 mInstruction = instruction;
96 if (mInstruction != null)
98 mTitle.setText(mInstruction.getTitle());
99 mDescription.setText(mInstruction.getDescription());
100 if (mInstruction.getHeader() != null)
102 mHeader.setText(mInstruction.getHeader());
103 setListAdapter(new ArrayAdapter<String>(getActivity(),
104 android.R.layout.simple_list_item_1, mInstruction.getItems()));
109 setListAdapter(null);
115 mDescription.setText("");
117 setListAdapter(null);