Explorar el Código

filter indicator in record overview

Julien Clauter hace 10 años
padre
commit
a63564bf53

+ 22 - 5
src/de/tudarmstadt/informatik/hostage/ui/LogFilter.java

@@ -181,15 +181,32 @@ public class LogFilter implements Parcelable{
 	}
 
     public boolean isSet(){
-        boolean hasTime = this.belowTimestamp != Long.MAX_VALUE|| this.aboveTimestamp != Long.MIN_VALUE;
-        boolean hasBSSIDs = this.getBSSIDs().size() > 0;
-        boolean hasESSIDs = this.getESSIDs().size() > 0;
-        boolean hasProtocols = this.getProtocols().size() > 0;
+        boolean hasTime = this.hasATimestamp();
+        boolean hasBSSIDs = this.hasBSSIDs();
+        boolean hasESSIDs =this.hasESSIDs();
+        boolean hasProtocols = this.hasProtocols();
 
         return hasBSSIDs || hasESSIDs || hasProtocols | hasTime;
     }
 
-	
+    public boolean hasBSSIDs(){
+        return  this.getBSSIDs().size() > 0;
+    }
+    public boolean hasESSIDs(){
+        return  this.getESSIDs().size() > 0;
+    }
+    public boolean hasProtocols(){
+        return  this.getProtocols().size() > 0;
+    }
+    public boolean hasAboveTimestamp(){
+        return this.aboveTimestamp != Long.MIN_VALUE;
+    }
+    public boolean hasBelowTimestamp(){
+        return this.belowTimestamp != Long.MAX_VALUE;
+    }
+    public boolean hasATimestamp(){
+        return this.hasBelowTimestamp()|| this.hasAboveTimestamp();
+    }
 	public String convertArrayListToQueryString(ArrayList<String> list, String table,  String key){
 		String statement = "";
 		if (list == null) return statement;

+ 31 - 9
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -48,9 +48,9 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	static final String SELECTED_KEY = "Selected";
 	static final String OTHERS_KEY = "Other";
 
-	static final String FILTER_MENU_TITLE_BSSID = "BSSID";
-	static final String FILTER_MENU_TITLE_ESSID = "ESSID";
-	static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocols";
+	static final String FILTER_MENU_TITLE_BSSID = "Filter by BSSID";
+	static final String FILTER_MENU_TITLE_ESSID = "Filter by ESSID";
+	static final String FILTER_MENU_TITLE_PROTOCOLS = "Filter by Protocol";
 	static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "To Date";
 	static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "From Date";
 	static final String FILTER_MENU_TITLE_SORTING = "Sort by";
@@ -351,7 +351,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
     }
 
 	private void openSortingDialog(){
-		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTtiles(), this.selectedSorttype(), false , this);
+		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTiles(), this.selectedSorttype(), false , this);
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
 	}
 
@@ -399,11 +399,15 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	private void openFilterPopupMenuOnView(View v){
         // Open FilterMenu
         PopupMenu filterMenu = new PopupMenu(getBaseContext(), v);
+
 		for(String title : RecordOverviewFragment.this.filterMenuTitles()){
 			// Set a white Title
 			SpannableString styledMenuTitle = new SpannableString(title);
-				styledMenuTitle.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFFFF")), 0, title.length(), 0);
-				filterMenu.getMenu().add(styledMenuTitle);
+			styledMenuTitle.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFFFF")), 0, title.length(), 0);
+
+            MenuItem item = filterMenu.getMenu().add(styledMenuTitle);
+            item.setCheckable(this.isFilterSetForTitle(title));
+            if (item.isCheckable()) item.setChecked(true);
 		}
 		filterMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
             public boolean onMenuItemClick(MenuItem item) {
@@ -414,6 +418,24 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 			filterMenu.show();
 	}
 
+    private boolean isFilterSetForTitle(String title){
+        if (title.equals(FILTER_MENU_TITLE_BSSID)){
+            return this.filter.hasBSSIDs();
+        }
+        if (title.equals(FILTER_MENU_TITLE_ESSID)){
+            return this.filter.hasESSIDs();
+        }
+        if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+            return this.filter.hasProtocols();
+        }
+        if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
+            return this.filter.hasBelowTimestamp();
+        }
+        if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
+            return this.filter.hasAboveTimestamp();
+        }
+        return false;
+    }
 
 	private void clearFilter(){
     	if(filter == null) this.filter = new LogFilter();
@@ -459,7 +481,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		return selected;
 	}
 
-	public ArrayList<String> sortTypeTtiles(){
+	public ArrayList<String> sortTypeTiles(){
 		ArrayList<String> titles = new ArrayList<String>();
 		titles.add("Time");
 		titles.add("Protocol");
@@ -472,7 +494,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		return titles;
 	}
 	public boolean[] selectedSorttype(){
-		ArrayList<String> types = this.sortTypeTtiles();
+		ArrayList<String> types = this.sortTypeTiles();
 		boolean[] selected = new boolean[types.size()];
 		int i = 0;
 		for(String sorttype : types){
@@ -581,7 +603,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 			ArrayList<String> titles = dialog.getSelectedItemTitles();
             if (titles.size() == 0) return;
 			String t = titles.get(0);
-			int sortType = this.sortTypeTtiles().indexOf(t);
+			int sortType = this.sortTypeTiles().indexOf(t);
 			this.filter.setSorttype(SortType.values()[sortType]);
 		}
         if (title.equals(FILTER_MENU_TITLE_GROUP)){