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