|
@@ -24,9 +24,8 @@ import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.AdapterView;
|
|
|
+import android.widget.ExpandableListView;
|
|
|
import android.widget.ImageButton;
|
|
|
-import android.widget.ListAdapter;
|
|
|
-import android.widget.ListView;
|
|
|
import android.widget.PopupMenu;
|
|
|
import android.widget.PopupMenu.OnMenuItemClickListener;
|
|
|
import android.widget.Toast;
|
|
@@ -39,6 +38,7 @@ import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
|
|
|
|
|
|
public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
|
|
|
static final String SELECTED_KEY = "Selected";
|
|
@@ -55,10 +55,13 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
private boolean wasBelowTimePicker;
|
|
|
|
|
|
private LogFilter filter;
|
|
|
- private ListView listView;
|
|
|
private boolean showFilterButton;
|
|
|
DatabaseHandler dbh;
|
|
|
-
|
|
|
+
|
|
|
+ public String groupingKey;
|
|
|
+
|
|
|
+ private ExpandableListView expListView;
|
|
|
+
|
|
|
|
|
|
public RecordOverviewFragment(){}
|
|
|
|
|
@@ -74,22 +77,29 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
|
|
|
dbh = new DatabaseHandler(this.getActivity().getBaseContext());
|
|
|
// Get the message from the intent
|
|
|
- Intent intent = this.getActivity().getIntent();
|
|
|
- LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
|
|
|
|
|
|
- if(filter == null){
|
|
|
- this.clearFilter();
|
|
|
- } else {
|
|
|
- this.filter = filter;
|
|
|
- }
|
|
|
+ if (this.filter == null){
|
|
|
+ Intent intent = this.getActivity().getIntent();
|
|
|
+ LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
|
|
|
+
|
|
|
+ if(filter == null){
|
|
|
+ this.clearFilter();
|
|
|
+ } else {
|
|
|
+ this.filter = filter;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
|
|
|
|
|
|
this.setShowFilterButton(!this.filter.isNotEditable());
|
|
|
|
|
|
this.addRecordToDB();
|
|
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_record_list, container, false);
|
|
|
- ListView mylist = (ListView) rootView.findViewById(R.id.loglistview);
|
|
|
- this.listView = mylist;
|
|
|
+ ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
|
|
|
+ this.expListView = mylist;
|
|
|
populateListViewFromDB(mylist);
|
|
|
|
|
|
registerListClickCallback(mylist);
|
|
@@ -154,30 +164,49 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
*
|
|
|
* ***************************/
|
|
|
|
|
|
- private void populateListViewFromDB(ListView mylist) {
|
|
|
+ private void populateListViewFromDB(ExpandableListView mylist) {
|
|
|
|
|
|
- ArrayList<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
|
|
|
+ HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
|
|
|
|
|
|
- ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
|
|
|
-
|
|
|
+ ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
|
|
|
+
|
|
|
+ // 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)};
|
|
|
+ int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
|
|
|
+
|
|
|
+ HashMap<String, Integer> mapping = new HashMap<String, Integer>();
|
|
|
+ int i = 0;
|
|
|
+ for(String key : keys){
|
|
|
+ mapping.put(key, ids[i]);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
|
|
|
for (Record val : data) {
|
|
|
+ // 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()));
|
|
|
- items.add(map);
|
|
|
+
|
|
|
+ ExpandableListItem item = new ExpandableListItem();
|
|
|
+ item.setData(map);
|
|
|
+ item.setId_Mapping(mapping);
|
|
|
+
|
|
|
+ String groupID = this.getGroupValue(val);
|
|
|
+
|
|
|
+ ArrayList<ExpandableListItem> items = sectionData.get(groupID);
|
|
|
+ if (items == null) {
|
|
|
+ items = new ArrayList<ExpandableListItem>();
|
|
|
+ sectionData.put(groupID, items);
|
|
|
+ }
|
|
|
+ items.add(item);
|
|
|
}
|
|
|
-
|
|
|
- // 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)};
|
|
|
- int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
|
|
|
-
|
|
|
- ListAdapter adapter = new RecordListAdapter(this.getActivity(), items, R.layout.loglist_row, keys, ids);
|
|
|
-
|
|
|
- mylist.setAdapter(adapter);
|
|
|
+
|
|
|
+ RecordListAdapter adapter = new RecordListAdapter(this.getApplicationContext(),this.getGroupTitle(), sectionData);
|
|
|
+
|
|
|
+ mylist.setAdapter(adapter);
|
|
|
}
|
|
|
|
|
|
private Context getBaseContext(){
|
|
@@ -188,7 +217,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
return this.getActivity().getApplicationContext();
|
|
|
}
|
|
|
|
|
|
- private void registerListClickCallback(ListView mylist) {
|
|
|
+ private void registerListClickCallback(ExpandableListView mylist) {
|
|
|
|
|
|
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
public void onItemClick(AdapterView<?> parent, View viewClicked,
|
|
@@ -285,19 +314,54 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
this.wasBelowTimePicker = false;
|
|
|
DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
|
|
|
newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
|
|
|
+ if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
|
|
|
}
|
|
|
|
|
|
private void openTimestampToFilterDialog(){
|
|
|
this.wasBelowTimePicker = true;
|
|
|
DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
|
|
|
newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
|
|
|
- }
|
|
|
+ if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
|
|
|
+ }
|
|
|
|
|
|
private void openSortingDialog(){
|
|
|
ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTtiles(), this.selectedSorttype(), false , this);
|
|
|
newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /*****************************
|
|
|
+ *
|
|
|
+ * Grouping Stuff
|
|
|
+ *
|
|
|
+ * ***************************/
|
|
|
+
|
|
|
+ public String getGroupValue(Record rec){
|
|
|
+ int index = this.groupingTitles().indexOf(this.groupingKey);
|
|
|
+ switch (index){
|
|
|
+ case 0:
|
|
|
+ return rec.getProtocol();
|
|
|
+ case 1:
|
|
|
+ return rec.getBSSID();
|
|
|
+ case 2:
|
|
|
+ return rec.getSSID();
|
|
|
+ default:
|
|
|
+ return rec.getProtocol();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> getGroupTitle(){
|
|
|
+ int index = this.groupingTitles().indexOf(this.groupingKey);
|
|
|
+ switch (index){
|
|
|
+ case 0:
|
|
|
+ return this.protocolTitles();
|
|
|
+ case 1:
|
|
|
+ return this.bssids();
|
|
|
+ case 2:
|
|
|
+ return this.essids();
|
|
|
+ default:
|
|
|
+ return this.protocolTitles();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/*****************************
|
|
|
*
|
|
@@ -325,12 +389,18 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
|
|
|
|
|
|
private void clearFilter(){
|
|
|
- this.filter = new LogFilter();
|
|
|
- this.filter.setProtocols(this.protocolTitles());
|
|
|
- this.filter.setBSSIDs(this.bssids());
|
|
|
- this.filter.setESSIDs(this.essids());
|
|
|
+ if(filter == null) this.filter = new LogFilter();
|
|
|
+ this.filter.clear();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public ArrayList<String> groupingTitles(){
|
|
|
+ ArrayList<String> titles = new ArrayList<String>();
|
|
|
+ for (String groupTitle : this.getResources().getStringArray(
|
|
|
+ R.array.Grouping)) {
|
|
|
+ titles.add(groupTitle);
|
|
|
+ }
|
|
|
+ return titles;
|
|
|
+ }
|
|
|
|
|
|
public ArrayList<String> protocolTitles(){
|
|
|
ArrayList<String> titles = new ArrayList<String>();
|
|
@@ -416,7 +486,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
titles.add(FILTER_MENU_TITLE_PROTOCOLS);
|
|
|
titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
|
|
|
titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
|
|
|
- titles.add(FILTER_MENU_TITLE_REMOVE);
|
|
|
+ if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
|
|
|
return titles;
|
|
|
}
|
|
|
|
|
@@ -433,7 +503,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
} else {
|
|
|
this.filter.setAboveTimestamp(dialog.getDate());
|
|
|
}
|
|
|
- this.populateListViewFromDB(listView);
|
|
|
+ this.populateListViewFromDB(this.expListView);
|
|
|
}
|
|
|
|
|
|
public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
|
|
@@ -447,13 +517,28 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
public void onDialogPositiveClick(ChecklistDialog dialog) {
|
|
|
String title = dialog.getTitle();
|
|
|
if(title.equals(FILTER_MENU_TITLE_BSSID)){
|
|
|
- this.filter.setBSSIDs(dialog.getSelectedItemTitles());
|
|
|
+ ArrayList<String> titles =dialog.getSelectedItemTitles();
|
|
|
+ if (titles.size() == this.bssids().size()){
|
|
|
+ this.filter.setBSSIDs(new ArrayList<String>());
|
|
|
+ } else {
|
|
|
+ this.filter.setBSSIDs(titles);
|
|
|
+ }
|
|
|
}
|
|
|
if(title.equals(FILTER_MENU_TITLE_ESSID)){
|
|
|
- this.filter.setESSIDs(dialog.getSelectedItemTitles());
|
|
|
+ ArrayList<String> titles =dialog.getSelectedItemTitles();
|
|
|
+ if (titles.size() == this.essids().size()){
|
|
|
+ this.filter.setESSIDs(new ArrayList<String>());
|
|
|
+ } else {
|
|
|
+ this.filter.setESSIDs(titles);
|
|
|
+ }
|
|
|
}
|
|
|
if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
|
|
|
- this.filter.setProtocols(dialog.getSelectedItemTitles());
|
|
|
+ ArrayList<String> protocols = dialog.getSelectedItemTitles();
|
|
|
+ if (protocols.size() == this.protocolTitles().size()){
|
|
|
+ this.filter.setProtocols(new ArrayList<String>());
|
|
|
+ } else {
|
|
|
+ this.filter.setProtocols(dialog.getSelectedItemTitles());
|
|
|
+ }
|
|
|
}
|
|
|
if(title.equals(FILTER_MENU_TITLE_SORTING)){
|
|
|
ArrayList<String> titles = dialog.getSelectedItemTitles();
|
|
@@ -461,7 +546,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
int sortType = this.sortTypeTtiles().indexOf(t);
|
|
|
this.filter.setSorttype(SortType.values()[sortType]);
|
|
|
}
|
|
|
- this.populateListViewFromDB(this.listView);
|
|
|
+ this.populateListViewFromDB(this.expListView);
|
|
|
}
|
|
|
|
|
|
public void onDialogNegativeClick(ChecklistDialog dialog) {
|
|
@@ -476,6 +561,9 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
|
|
|
* ***************************/
|
|
|
|
|
|
private void addRecordToDB() {
|
|
|
+
|
|
|
+ if (dbh.getAllRecords().size() > 0) return;
|
|
|
+
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
|
int maxProtocolsIndex = this.getResources().getStringArray(
|