2 * Copyright (C) 2013 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 androidx.appcompat.app.AppCompatActivity;
21 import android.view.MenuItem;
23 import org.strongswan.android.R;
24 import org.strongswan.android.logic.imc.RemediationInstruction;
25 import org.strongswan.android.ui.RemediationInstructionsFragment.OnRemediationInstructionSelectedListener;
27 import java.util.ArrayList;
29 public class RemediationInstructionsActivity extends AppCompatActivity implements OnRemediationInstructionSelectedListener
32 protected void onCreate(Bundle savedInstanceState)
34 super.onCreate(savedInstanceState);
35 setContentView(R.layout.remediation_instructions);
36 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
38 if (savedInstanceState != null)
39 { /* only update if we're not restoring */
42 RemediationInstructionsFragment frag = (RemediationInstructionsFragment)getSupportFragmentManager().findFragmentById(R.id.remediation_instructions_fragment);
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)
49 list = RemediationInstructionsFragment.getInstructionsCompat(extras);
53 list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS,
54 RemediationInstruction.class);
56 frag.updateView(list);
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();
67 public boolean onOptionsItemSelected(MenuItem item)
69 switch (item.getItemId())
71 case android.R.id.home:
72 /* one-pane layout, pop possible fragment from stack, finish otherwise */
73 if (!getSupportFragmentManager().popBackStackImmediate())
77 getSupportActionBar().setTitle(getTitle());
80 return super.onOptionsItemSelected(item);
85 public void onRemediationInstructionSelected(RemediationInstruction instruction)
87 RemediationInstructionFragment frag = (RemediationInstructionFragment)getSupportFragmentManager().findFragmentById(R.id.remediation_instruction_fragment);
90 { /* two-pane layout, update directly */
91 frag.updateView(instruction);
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);
100 getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, frag).addToBackStack(null).commit();
101 getSupportActionBar().setTitle(instruction.getTitle());