]> git.ipfire.org Git - thirdparty/strongswan.git/blob
ea33a14e66676e6574fdabd0090c382c3ce66345
[thirdparty/strongswan.git] /
1 /*
2 * Copyright (C) 2013-2016 Tobias Brunner
3 *
4 * Copyright (C) secunet Security Networks AG
5 *
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>.
10 *
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
14 * for more details.
15 */
16
17 package org.strongswan.android.ui;
18
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;
26
27 import org.strongswan.android.R;
28 import org.strongswan.android.logic.imc.RemediationInstruction;
29
30 import androidx.annotation.NonNull;
31 import androidx.annotation.Nullable;
32 import androidx.fragment.app.ListFragment;
33
34 public class RemediationInstructionFragment extends ListFragment
35 {
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;
41
42 @Override
43 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
44 {
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));
51 return layout;
52 }
53
54 @Override
55 public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
56 {
57 super.onViewCreated(view, savedInstanceState);
58
59 if (savedInstanceState != null)
60 {
61 mInstruction = savedInstanceState.getParcelable(ARG_REMEDIATION_INSTRUCTION);
62 }
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 */
67 setListShown(true);
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);
71 }
72
73 @Override
74 public void onSaveInstanceState(Bundle outState)
75 {
76 super.onSaveInstanceState(outState);
77 outState.putParcelable(ARG_REMEDIATION_INSTRUCTION, mInstruction);
78 }
79
80 @Override
81 public void onStart()
82 {
83 super.onStart();
84
85 Bundle args = getArguments();
86 if (args != null)
87 {
88 mInstruction = args.getParcelable(ARG_REMEDIATION_INSTRUCTION);
89 }
90 updateView(mInstruction);
91 }
92
93 public void updateView(RemediationInstruction instruction)
94 {
95 mInstruction = instruction;
96 if (mInstruction != null)
97 {
98 mTitle.setText(mInstruction.getTitle());
99 mDescription.setText(mInstruction.getDescription());
100 if (mInstruction.getHeader() != null)
101 {
102 mHeader.setText(mInstruction.getHeader());
103 setListAdapter(new ArrayAdapter<String>(getActivity(),
104 android.R.layout.simple_list_item_1, mInstruction.getItems()));
105 }
106 else
107 {
108 mHeader.setText("");
109 setListAdapter(null);
110 }
111 }
112 else
113 {
114 mTitle.setText("");
115 mDescription.setText("");
116 mHeader.setText("");
117 setListAdapter(null);
118 }
119 }
120 }