]> git.ipfire.org Git - thirdparty/strongswan.git/blob
d1de552145ce2437d15a6e0e8b5657bc01458d27
[thirdparty/strongswan.git] /
1 /*
2 * Copyright (C) 2013 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 androidx.appcompat.app.AppCompatActivity;
21 import android.view.MenuItem;
22
23 import org.strongswan.android.R;
24 import org.strongswan.android.logic.imc.RemediationInstruction;
25 import org.strongswan.android.ui.RemediationInstructionsFragment.OnRemediationInstructionSelectedListener;
26
27 import java.util.ArrayList;
28
29 public class RemediationInstructionsActivity extends AppCompatActivity implements OnRemediationInstructionSelectedListener
30 {
31 @Override
32 protected void onCreate(Bundle savedInstanceState)
33 {
34 super.onCreate(savedInstanceState);
35 setContentView(R.layout.remediation_instructions);
36 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
37
38 if (savedInstanceState != null)
39 { /* only update if we're not restoring */
40 return;
41 }
42 RemediationInstructionsFragment frag = (RemediationInstructionsFragment)getSupportFragmentManager().findFragmentById(R.id.remediation_instructions_fragment);
43 if (frag != null)
44 { /* two-pane layout, update fragment */
45 Bundle extras = getIntent().getExtras();
46 ArrayList<RemediationInstruction> list = null;
47 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU)
48 {
49 list = RemediationInstructionsFragment.getInstructionsCompat(extras);
50 }
51 else
52 {
53 list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS,
54 RemediationInstruction.class);
55 }
56 frag.updateView(list);
57 }
58 else
59 { /* one-pane layout, create fragment */
60 frag = new RemediationInstructionsFragment();
61 frag.setArguments(getIntent().getExtras());
62 getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, frag).commit();
63 }
64 }
65
66 @Override
67 public boolean onOptionsItemSelected(MenuItem item)
68 {
69 switch (item.getItemId())
70 {
71 case android.R.id.home:
72 /* one-pane layout, pop possible fragment from stack, finish otherwise */
73 if (!getSupportFragmentManager().popBackStackImmediate())
74 {
75 finish();
76 }
77 getSupportActionBar().setTitle(getTitle());
78 return true;
79 default:
80 return super.onOptionsItemSelected(item);
81 }
82 }
83
84 @Override
85 public void onRemediationInstructionSelected(RemediationInstruction instruction)
86 {
87 RemediationInstructionFragment frag = (RemediationInstructionFragment)getSupportFragmentManager().findFragmentById(R.id.remediation_instruction_fragment);
88
89 if (frag != null)
90 { /* two-pane layout, update directly */
91 frag.updateView(instruction);
92 }
93 else
94 { /* one-pane layout, replace fragment */
95 frag = new RemediationInstructionFragment();
96 Bundle args = new Bundle();
97 args.putParcelable(RemediationInstructionFragment.ARG_REMEDIATION_INSTRUCTION, instruction);
98 frag.setArguments(args);
99
100 getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, frag).addToBackStack(null).commit();
101 getSupportActionBar().setTitle(instruction.getTitle());
102 }
103 }
104 }