|
@@ -1,6 +1,7 @@
|
|
package de.tudarmstadt.informatik.hostage.ui2.fragment;
|
|
package de.tudarmstadt.informatik.hostage.ui2.fragment;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.annotation.SuppressLint;
|
|
|
|
+import android.app.Activity;
|
|
import android.app.FragmentManager;
|
|
import android.app.FragmentManager;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
@@ -25,8 +26,8 @@ import java.util.HashMap;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
-import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
|
import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
|
|
import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
@@ -77,6 +78,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
this.filter = filter;
|
|
this.filter = filter;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Thread loader;
|
|
|
|
|
|
public RecordOverviewFragment(){}
|
|
public RecordOverviewFragment(){}
|
|
|
|
|
|
@@ -116,30 +118,13 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
|
|
if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
|
|
|
|
|
|
this.setShowFilterButton(!this.filter.isNotEditable());
|
|
this.setShowFilterButton(!this.filter.isNotEditable());
|
|
- //this.addRecordToDB();
|
|
|
|
|
|
|
|
View rootView = inflater.inflate(this.getLayoutId(), container, false);
|
|
View rootView = inflater.inflate(this.getLayoutId(), container, false);
|
|
ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
|
|
ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
|
|
|
|
|
|
this.expListView = mylist;
|
|
this.expListView = mylist;
|
|
- populateListViewFromDB(mylist);
|
|
|
|
-
|
|
|
|
- if (this.openSections != null && this.openSections.size() != 0){
|
|
|
|
- for (int i = 0; i < this.openSections.size(); i++){
|
|
|
|
- int index = this.openSections.get(i);
|
|
|
|
- this.expListView.expandGroup(index);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- this.openSections = new ArrayList<Integer>();
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if (mListPosition != -1 && mItemPosition != -1)
|
|
|
|
- this.expListView.setSelectedChild(mListPosition, mItemPosition, true);
|
|
|
|
-
|
|
|
|
- mListPosition = -1;
|
|
|
|
- mItemPosition = -1;
|
|
|
|
-
|
|
|
|
- registerListClickCallback(mylist);
|
|
|
|
|
|
+ this.initialiseListView();
|
|
|
|
|
|
ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
|
|
ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
|
|
filterButton.setOnClickListener(new View.OnClickListener() {
|
|
filterButton.setOnClickListener(new View.OnClickListener() {
|
|
@@ -168,6 +153,75 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
return rootView;
|
|
return rootView;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /*Initialises the expandable list view in a backgorund thread*/
|
|
|
|
+ private void initialiseListView(){
|
|
|
|
+ if (loader != null) loader.interrupt();
|
|
|
|
+
|
|
|
|
+ loader = new Thread(new Runnable(){
|
|
|
|
+
|
|
|
|
+ private void updateUI(final RecordListAdapter currentAdapter)
|
|
|
|
+ {
|
|
|
|
+ if(loader.isInterrupted()){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Activity activity = RecordOverviewFragment.this.getActivity();
|
|
|
|
+
|
|
|
|
+ if (activity != null){
|
|
|
|
+ activity.runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ RecordOverviewFragment.this.expListView.setAdapter(currentAdapter);
|
|
|
|
+ // Update view and remove loading spinner etc...
|
|
|
|
+ RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
|
|
|
|
+
|
|
|
|
+ if (adapter != null){
|
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
|
+
|
|
|
|
+ if (adapter.getGroupCount() == 1){
|
|
|
|
+ RecordOverviewFragment.this.expListView.expandGroup(0);
|
|
|
|
+ } else {
|
|
|
|
+ RecordOverviewFragment.this.setSectionToOpen(RecordOverviewFragment.this.sectionToOpen);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (RecordOverviewFragment.this.openSections != null && RecordOverviewFragment.this.openSections.size() != 0){
|
|
|
|
+ for (int i = 0; i < RecordOverviewFragment.this.openSections.size(); i++){
|
|
|
|
+ int index = RecordOverviewFragment.this.openSections.get(i);
|
|
|
|
+ RecordOverviewFragment.this.expListView.expandGroup(index);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ RecordOverviewFragment.this.openSections = new ArrayList<Integer>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (mListPosition != -1 && mItemPosition != -1)
|
|
|
|
+ RecordOverviewFragment.this.expListView.setSelectedChild(mListPosition, mItemPosition, true);
|
|
|
|
+
|
|
|
|
+ mListPosition = -1;
|
|
|
|
+ mItemPosition = -1;
|
|
|
|
+ registerListClickCallback(RecordOverviewFragment.this.expListView);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private RecordListAdapter doInBackground()
|
|
|
|
+ {
|
|
|
|
+ return populateListViewFromDB(RecordOverviewFragment.this.expListView);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void run()
|
|
|
|
+ {
|
|
|
|
+ updateUI(doInBackground());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ loader.start();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Returns the Fragment layout ID
|
|
* Returns the Fragment layout ID
|
|
* @return int The fragment layout ID
|
|
* @return int The fragment layout ID
|
|
@@ -209,7 +263,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
}
|
|
}
|
|
if(title.equals(FILTER_MENU_TITLE_REMOVE)){
|
|
if(title.equals(FILTER_MENU_TITLE_REMOVE)){
|
|
this.clearFilter();
|
|
this.clearFilter();
|
|
- this.populateListViewFromDB(this.expListView);
|
|
|
|
|
|
+ this.actualiseListViewInBackground();
|
|
}
|
|
}
|
|
if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
|
|
if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
|
|
this.openTimestampToFilterDialog();
|
|
this.openTimestampToFilterDialog();
|
|
@@ -226,12 +280,14 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
public void onStart() {
|
|
public void onStart() {
|
|
super.onStart();
|
|
super.onStart();
|
|
- //this.populateListViewFromDB(this.expListView);
|
|
|
|
- if (this.expListView.getExpandableListAdapter().getGroupCount() == 1){
|
|
|
|
- this.expListView.expandGroup(0);
|
|
|
|
- } else {
|
|
|
|
- this.setSectionToOpen(this.sectionToOpen);
|
|
|
|
|
|
+ if (this.expListView.getExpandableListAdapter() != null){
|
|
|
|
+ if (this.expListView.getExpandableListAdapter().getGroupCount() == 1){
|
|
|
|
+ this.expListView.expandGroup(0);
|
|
|
|
+ } else {
|
|
|
|
+ this.setSectionToOpen(this.sectionToOpen);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/*****************************
|
|
/*****************************
|
|
@@ -265,14 +321,14 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
* Reloads the data in the ExpandableListView for the given filter object.
|
|
* Reloads the data in the ExpandableListView for the given filter object.
|
|
* @param ExpandableListView listview
|
|
* @param ExpandableListView listview
|
|
* */
|
|
* */
|
|
- private void populateListViewFromDB(ExpandableListView mylist) {
|
|
|
|
|
|
+ private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
|
|
|
|
|
|
- HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
|
|
|
|
|
|
+ HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
|
|
|
|
|
|
- ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
|
|
|
|
|
|
+ ArrayList<Record> data = dbh.getRecordsForFilter(RecordOverviewFragment.this.filter);
|
|
|
|
|
|
// Adding Items to ListView
|
|
// Adding Items to ListView
|
|
- String keys[] = new String[] { this.getString(R.string.RecordBSSID), this.getString(R.string.RecordSSID), this.getString(R.string.RecordProtocol), this.getString(R.string.RecordTimestamp)};
|
|
|
|
|
|
+ String keys[] = new String[] { RecordOverviewFragment.this.getString(R.string.RecordBSSID), RecordOverviewFragment.this.getString(R.string.RecordSSID), RecordOverviewFragment.this.getString(R.string.RecordProtocol), RecordOverviewFragment.this.getString(R.string.RecordTimestamp)};
|
|
int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
|
|
int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
|
|
|
|
|
|
HashMap<String, Integer> mapping = new HashMap<String, Integer>();
|
|
HashMap<String, Integer> mapping = new HashMap<String, Integer>();
|
|
@@ -284,14 +340,14 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
ArrayList<String>groupTitle = new ArrayList<String>();
|
|
ArrayList<String>groupTitle = new ArrayList<String>();
|
|
|
|
|
|
- for (Record val : data) {
|
|
|
|
|
|
+ for (Record val : data) {
|
|
// DO GROUPING IN HERE
|
|
// DO GROUPING IN HERE
|
|
- HashMap<String, String> map = new HashMap<String, String>();
|
|
|
|
- map.put(this.getString(R.string.RecordBSSID), val.getBssid());
|
|
|
|
- map.put(this.getString(R.string.RecordSSID), val.getSsid());
|
|
|
|
- map.put(this.getString(R.string.RecordProtocol), val.getProtocol());
|
|
|
|
- map.put(this.getString(R.string.RecordTimestamp),
|
|
|
|
- this.getDateAsString(val.getTimestamp()));
|
|
|
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
|
+ map.put(RecordOverviewFragment.this.getString(R.string.RecordBSSID), val.getBssid());
|
|
|
|
+ map.put(RecordOverviewFragment.this.getString(R.string.RecordSSID), val.getSsid());
|
|
|
|
+ map.put(RecordOverviewFragment.this.getString(R.string.RecordProtocol), val.getProtocol());
|
|
|
|
+ map.put(RecordOverviewFragment.this.getString(R.string.RecordTimestamp),
|
|
|
|
+ RecordOverviewFragment.this.getDateAsString(val.getTimestamp()));
|
|
|
|
|
|
ExpandableListItem item = new ExpandableListItem();
|
|
ExpandableListItem item = new ExpandableListItem();
|
|
item.setData(map);
|
|
item.setData(map);
|
|
@@ -300,7 +356,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
item.setTag(val.getAttack_id());
|
|
item.setTag(val.getAttack_id());
|
|
|
|
|
|
- String groupID = this.getGroupValue(val);
|
|
|
|
|
|
+ String groupID = RecordOverviewFragment.this.getGroupValue(val);
|
|
|
|
|
|
ArrayList<ExpandableListItem> items = sectionData.get(groupID);
|
|
ArrayList<ExpandableListItem> items = sectionData.get(groupID);
|
|
if (items == null) {
|
|
if (items == null) {
|
|
@@ -310,8 +366,8 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- items.add(item);
|
|
|
|
- }
|
|
|
|
|
|
+ items.add(item);
|
|
|
|
+ }
|
|
|
|
|
|
Collections.sort(groupTitle, new Comparator<String>() {
|
|
Collections.sort(groupTitle, new Comparator<String>() {
|
|
@Override
|
|
@Override
|
|
@@ -320,11 +376,56 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- RecordListAdapter adapter = new RecordListAdapter(this.getApplicationContext(), groupTitle, sectionData);
|
|
|
|
|
|
|
|
- mylist.setAdapter(adapter);
|
|
|
|
|
|
+ RecordListAdapter adapter = null;
|
|
|
|
+ if (mylist.getAdapter() != null && mylist.getAdapter() instanceof RecordListAdapter){
|
|
|
|
+ adapter = (RecordListAdapter) mylist.getAdapter();
|
|
|
|
+ adapter.setData(sectionData);
|
|
|
|
+ adapter.setSectionHeader(groupTitle);
|
|
|
|
+ } else {
|
|
|
|
+ adapter = new RecordListAdapter( RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return adapter;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private void actualiseListViewInBackground(){
|
|
|
|
+ if (loader != null && loader.isAlive()) loader.interrupt();
|
|
|
|
+
|
|
|
|
+ loader = null;
|
|
|
|
+
|
|
|
|
+ loader = new Thread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ this.runOnUiThread(this.doInBackground());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private RecordListAdapter doInBackground(){
|
|
|
|
+ return RecordOverviewFragment.this.populateListViewFromDB(RecordOverviewFragment.this.expListView);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void runOnUiThread(final RecordListAdapter adapter){
|
|
|
|
+ Activity actv = RecordOverviewFragment.this.getActivity();
|
|
|
|
+ if (actv != null){
|
|
|
|
+ actv.runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ this.actualiseUI();
|
|
|
|
+ }
|
|
|
|
+ private void actualiseUI(){
|
|
|
|
+ if (adapter != null){
|
|
|
|
+ RecordOverviewFragment.this.expListView.setAdapter(adapter);
|
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ loader.start();
|
|
|
|
+ }
|
|
|
|
+
|
|
/*Thsi will open a section in the ExpandableListView with the same title as the parameter s.
|
|
/*Thsi will open a section in the ExpandableListView with the same title as the parameter s.
|
|
*
|
|
*
|
|
* @param String s (the section title to open)
|
|
* @param String s (the section title to open)
|
|
@@ -764,7 +865,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
} else {
|
|
} else {
|
|
this.filter.setAboveTimestamp(dialog.getDate());
|
|
this.filter.setAboveTimestamp(dialog.getDate());
|
|
}
|
|
}
|
|
- this.populateListViewFromDB(this.expListView);
|
|
|
|
|
|
+ this.actualiseListViewInBackground();
|
|
}
|
|
}
|
|
|
|
|
|
public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
|
|
public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
|
|
@@ -813,7 +914,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
if (titles.size() == 0) return;
|
|
if (titles.size() == 0) return;
|
|
this.groupingKey = titles.get(0);
|
|
this.groupingKey = titles.get(0);
|
|
}
|
|
}
|
|
- this.populateListViewFromDB(this.expListView);
|
|
|
|
|
|
+ this.actualiseListViewInBackground();
|
|
}
|
|
}
|
|
|
|
|
|
public void onDialogNegativeClick(ChecklistDialog dialog) {}
|
|
public void onDialogNegativeClick(ChecklistDialog dialog) {}
|