|
@@ -4,12 +4,15 @@ import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.app.AlertDialog;
|
|
|
import android.app.FragmentManager;
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.IntentFilter;
|
|
|
import android.content.SharedPreferences;
|
|
|
import android.os.Bundle;
|
|
|
import android.preference.PreferenceManager;
|
|
|
+import android.support.v4.content.LocalBroadcastManager;
|
|
|
import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
@@ -36,6 +39,7 @@ import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Random;
|
|
|
|
|
|
+import de.tudarmstadt.informatik.hostage.Handler;
|
|
|
import de.tudarmstadt.informatik.hostage.Hostage;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
|
|
@@ -58,6 +62,7 @@ import de.tudarmstadt.informatik.hostage.ui.dialog.DateTimeDialogFragment;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.model.ExpandableListItem;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.model.LogFilter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.model.LogFilter.SortType;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.model.ServicesListItem;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.popup.AbstractPopup;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.popup.AbstractPopupItem;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.popup.SimplePopupItem;
|
|
@@ -109,6 +114,10 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
Thread loader;
|
|
|
|
|
|
+ private boolean mReceiverRegistered = false;
|
|
|
+ private BroadcastReceiver mReceiver;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
static final DateFormat localisedDateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
|
|
@@ -188,6 +197,14 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
this.initialiseListView();
|
|
|
|
|
|
+ ImageButton deleteButton = (ImageButton) rootView.findViewById(R.id.DeleteButton);
|
|
|
+ deleteButton.setOnClickListener(new View.OnClickListener() {
|
|
|
+ public void onClick(View v) {
|
|
|
+ RecordOverviewFragment.this.openDeleteFilteredAttacksDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ deleteButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
|
|
|
+
|
|
|
ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
|
|
|
filterButton.setOnClickListener(new View.OnClickListener() {
|
|
|
public void onClick(View v) {
|
|
@@ -196,6 +213,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
});
|
|
|
filterButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
|
|
|
|
|
|
+
|
|
|
ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
|
|
|
sortButton.setOnClickListener(new View.OnClickListener() {
|
|
|
public void onClick(View v) {
|
|
@@ -212,6 +230,8 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ this.registerBroadcastReceiver();
|
|
|
+
|
|
|
return rootView;
|
|
|
}
|
|
|
|
|
@@ -219,6 +239,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
private void initialiseListView(){
|
|
|
if (loader != null) loader.interrupt();
|
|
|
+ if (this.openSections == null) this.openSections = new ArrayList<Integer>();
|
|
|
|
|
|
this.spinner.setVisibility(View.VISIBLE);
|
|
|
|
|
@@ -244,6 +265,9 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
if (adapter.getGroupCount() >= 1){
|
|
|
RecordOverviewFragment.this.expListView.expandGroup(DEFAULT_GROUPING_KEY_INDEX);
|
|
|
+ if (!RecordOverviewFragment.this.openSections.contains(DEFAULT_GROUPING_KEY_INDEX)){
|
|
|
+ RecordOverviewFragment.this.openSections.add(DEFAULT_GROUPING_KEY_INDEX);
|
|
|
+ }
|
|
|
} else {
|
|
|
RecordOverviewFragment.this.setSectionToOpen(RecordOverviewFragment.this.sectionToOpen);
|
|
|
}
|
|
@@ -346,7 +370,6 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void onStart() {
|
|
|
super.onStart();
|
|
@@ -360,7 +383,15 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
+ public void onDestroy(){
|
|
|
+ if (mReceiver != null){
|
|
|
+ }
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
|
|
inflater.inflate(R.menu.records_overview_actions, menu);
|
|
@@ -431,11 +462,15 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
|
|
- String deleteAttacksTitle = MainActivity.getInstance().getString(R.string.deleteAttacksTitle);
|
|
|
+ String deleteFILTEREDAttacksTitle = MainActivity.getInstance().getString(R.string.deleteFILTEREDAttacksTitle);
|
|
|
+ String deleteALLAttacksTitle = MainActivity.getInstance().getString(R.string.deleteALLAttacksTitle);
|
|
|
+
|
|
|
String cancelTitle = MainActivity.getInstance().getString(R.string.cancel);
|
|
|
String deleteTitle = MainActivity.getInstance().getString(R.string.delete);
|
|
|
|
|
|
- builder.setMessage(deleteAttacksTitle)
|
|
|
+ String text = this.filter.isSet()? deleteFILTEREDAttacksTitle : deleteALLAttacksTitle;
|
|
|
+
|
|
|
+ builder.setMessage(text)
|
|
|
.setPositiveButton(deleteTitle, new DialogInterface.OnClickListener() {
|
|
|
private RecordOverviewFragment recordOverviewFragment = null;
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
@@ -595,6 +630,24 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * register a broadcast receiver if not already registered
|
|
|
+ * and also update the number of attacks per protocol
|
|
|
+ */
|
|
|
+ private void registerBroadcastReceiver() {
|
|
|
+ if (!mReceiverRegistered) {
|
|
|
+ mReceiver = new BroadcastReceiver() {
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ RecordOverviewFragment.this.actualiseListViewInBackground();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
|
|
|
+ this.mReceiverRegistered = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* Actualises the list in a background thread
|
|
|
*/
|
|
@@ -625,12 +678,19 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
this.actualiseUI();
|
|
|
}
|
|
|
private void actualiseUI(){
|
|
|
+ RecordOverviewFragment self = RecordOverviewFragment.this;
|
|
|
if (adapter != null){
|
|
|
- RecordOverviewFragment.this.expListView.setAdapter(adapter);
|
|
|
+ self.expListView.setAdapter(adapter);
|
|
|
adapter.notifyDataSetChanged();
|
|
|
- RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
|
|
|
+ self.spinner.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ self.showEmptyDataNotification();
|
|
|
+ if (self.openSections != null && self.expListView != null){
|
|
|
+ for (int i = 0; i < self.openSections.size(); i++){
|
|
|
+ int index = self.openSections.get(i);
|
|
|
+ self.expListView.expandGroup(index);
|
|
|
+ }
|
|
|
}
|
|
|
- RecordOverviewFragment.this.showEmptyDataNotification();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -670,6 +730,9 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
int section = this.getGroupTitles().indexOf(this.sectionToOpen);
|
|
|
this.expListView.expandGroup(section);
|
|
|
this.sectionToOpen = "";
|
|
|
+ if (!this.openSections.contains(section)){
|
|
|
+ RecordOverviewFragment.this.openSections.add(section);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -712,13 +775,15 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
mylist.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
|
|
|
@Override
|
|
|
public void onGroupExpand(int i) {
|
|
|
- RecordOverviewFragment.this.openSections.add(new Integer(i));
|
|
|
+ if (!RecordOverviewFragment.this.openSections.contains(i)){
|
|
|
+ RecordOverviewFragment.this.openSections.add(i);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
mylist.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
|
|
|
@Override
|
|
|
public void onGroupCollapse(int i) {
|
|
|
- RecordOverviewFragment.this.openSections.remove(new Integer(i));
|
|
|
+ RecordOverviewFragment.this.openSections.remove(i);
|
|
|
}
|
|
|
});
|
|
|
}
|