|
@@ -35,6 +35,8 @@ import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Random;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
@@ -48,13 +50,13 @@ import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
|
|
|
import de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSync;
|
|
|
import de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync;
|
|
|
import de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity;
|
|
|
-import de.tudarmstadt.informatik.hostage.ui2.model.LogFilter;
|
|
|
-import de.tudarmstadt.informatik.hostage.ui2.model.LogFilter.SortType;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
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;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.model.LogFilter;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.model.LogFilter.SortType;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
|
|
@@ -251,7 +253,7 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
@Override
|
|
|
public void run()
|
|
|
{
|
|
|
- //RecordOverviewFragment.this.addRecordToDB(5, 10, 1);
|
|
|
+ RecordOverviewFragment.this.addRecordToDB(5, 10, 2);
|
|
|
updateUI(doInBackground());
|
|
|
}
|
|
|
|
|
@@ -460,10 +462,26 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
* @param mylist {@link ExpandableListView ExpandableListView}
|
|
|
* */
|
|
|
private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
|
|
|
+ ArrayList<String> groupTitle = new ArrayList<String>();
|
|
|
+
|
|
|
+ HashMap<String, ArrayList<ExpandableListItem>> sectionData = this.fetchDataForFilter(this.filter, groupTitle);
|
|
|
+
|
|
|
+ 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 HashMap<String, ArrayList<ExpandableListItem>> fetchDataForFilter(LogFilter filter, ArrayList<String> groupTitle){
|
|
|
HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
|
|
|
|
|
|
- ArrayList<Record> data = dbh.getRecordsForFilter(RecordOverviewFragment.this.filter);
|
|
|
+ ArrayList<Record> data = dbh.getRecordsForFilter(filter == null ? this.filter : filter);
|
|
|
|
|
|
// Adding Items to ListView
|
|
|
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)};
|
|
@@ -476,7 +494,12 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
i++;
|
|
|
}
|
|
|
|
|
|
- ArrayList<String>groupTitle = new ArrayList<String>();
|
|
|
+ if (groupTitle == null){
|
|
|
+ groupTitle = new ArrayList<String>();
|
|
|
+ } else {
|
|
|
+ groupTitle.clear();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
for (Record val : data) {
|
|
|
// DO GROUPING IN HERE
|
|
@@ -507,25 +530,41 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
items.add(item);
|
|
|
}
|
|
|
|
|
|
- Collections.sort(groupTitle, new Comparator<String>() {
|
|
|
- @Override
|
|
|
- public int compare(String s1, String s2) {
|
|
|
- return s1.compareToIgnoreCase(s2);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- RecordListAdapter adapter = null;
|
|
|
- if (mylist.getAdapter() != null && mylist.getAdapter() instanceof RecordListAdapter){
|
|
|
- adapter = (RecordListAdapter) mylist.getAdapter();
|
|
|
- adapter.setData(sectionData);
|
|
|
- adapter.setSectionHeader(groupTitle);
|
|
|
+ if (this.groupingKey.equals(this.groupingTitles().get(0))){
|
|
|
+ Collections.sort(groupTitle,new StringDateComparator());
|
|
|
} else {
|
|
|
- adapter = new RecordListAdapter( RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
|
|
|
+ Collections.sort(groupTitle, new Comparator<String>() {
|
|
|
+ @Override
|
|
|
+ public int compare(String s1, String s2) {
|
|
|
+ return s1.compareToIgnoreCase(s2);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- return adapter;
|
|
|
- }
|
|
|
+ return sectionData;
|
|
|
+ }
|
|
|
+
|
|
|
+ class StringDateComparator implements Comparator<String>
|
|
|
+ {
|
|
|
+ DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
|
|
|
+ //String pattern = ((SimpleDateFormat)formatter).toPattern();
|
|
|
+ String localPattern = ((SimpleDateFormat)formatter).toLocalizedPattern();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat(localPattern);
|
|
|
+
|
|
|
+ public int compare(String lhs, String rhs)
|
|
|
+ {
|
|
|
+ Date date1;
|
|
|
+ Date date2;
|
|
|
+ try {
|
|
|
+ date1 = dateFormat.parse(lhs);
|
|
|
+ date2 = dateFormat.parse(rhs);
|
|
|
+ } catch (java.text.ParseException e ) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return date2.compareTo(date1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Actualises the list in a background thread
|
|
@@ -678,6 +717,41 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the timestamp in a localised format.
|
|
|
+ * if the date is today, it returns today,
|
|
|
+ * if the date was yesterday it returns yesterday, otherwise the format is localised.
|
|
|
+ * @param timestamp long
|
|
|
+ * @return formatted date String
|
|
|
+ */
|
|
|
+ public String getFormattedDate(long timestamp) {
|
|
|
+ Calendar smsTime = Calendar.getInstance();
|
|
|
+ smsTime.setTimeInMillis(timestamp);
|
|
|
+
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+
|
|
|
+ if(now.get(Calendar.DATE) == smsTime.get(Calendar.DATE) ){
|
|
|
+ return this.getDateAsDayString(timestamp) + " - " + this.getResources().getString( R.string.TODAY);
|
|
|
+ }else if(now.get(Calendar.DATE) - smsTime.get(Calendar.DATE) == 1 ){
|
|
|
+ return this.getDateAsDayString(timestamp) + " - " + this.getResources().getString( R.string.YESTERDAY);
|
|
|
+ }
|
|
|
+ return this.getDateAsDayString(timestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**Returns a date as a formated string
|
|
|
+ * @param timeStamp date
|
|
|
+ * @return String date format is localised*/
|
|
|
+ @SuppressLint("SimpleDateFormat")
|
|
|
+ private String getDateAsDayString(long timeStamp) {
|
|
|
+ try {
|
|
|
+ Date netDate = (new Date(timeStamp));
|
|
|
+ DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(this.getActivity());
|
|
|
+ return dateFormat.format(netDate);
|
|
|
+ //return dateFormat.format(netDate);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return "xx";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/*****************************
|
|
|
*
|
|
@@ -760,12 +834,14 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
public String getGroupValue(Record rec){
|
|
|
int index = this.groupingTitles().indexOf(this.groupingKey);
|
|
|
switch (index){
|
|
|
- case 0:
|
|
|
- return rec.getProtocol();
|
|
|
case 1:
|
|
|
- return rec.getBssid();
|
|
|
+ return rec.getProtocol();
|
|
|
case 2:
|
|
|
+ return rec.getBssid();
|
|
|
+ case 3:
|
|
|
return rec.getSsid();
|
|
|
+ case 0:
|
|
|
+ return this.getFormattedDate(rec.getTimestamp());
|
|
|
default:
|
|
|
return rec.getProtocol();
|
|
|
}
|
|
@@ -773,18 +849,30 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
|
|
|
|
|
|
/**Returns the Group titles for the specified grouping key. e.g. groupingKey is "ESSID" it returns all available essids.
|
|
|
* @return ArrayList<String> grouptitles*/
|
|
|
- public ArrayList<String> getGroupTitles(){
|
|
|
+ public List<String> getGroupTitles(){
|
|
|
int index = this.groupingTitles().indexOf(this.groupingKey);
|
|
|
switch (index){
|
|
|
- case 0:
|
|
|
- return this.protocolTitles();
|
|
|
case 1:
|
|
|
- return this.bssids();
|
|
|
+ return this.protocolTitles();
|
|
|
case 2:
|
|
|
+ return this.bssids();
|
|
|
+ case 3:
|
|
|
return this.essids();
|
|
|
- default:
|
|
|
- return this.protocolTitles();
|
|
|
- }
|
|
|
+ case 0:{
|
|
|
+ RecordListAdapter adapter = (RecordListAdapter) this.expListView.getExpandableListAdapter();
|
|
|
+ if (adapter != null){
|
|
|
+ return adapter.getSectionHeaders();
|
|
|
+ }
|
|
|
+ return new ArrayList<String>();
|
|
|
+ }
|
|
|
+ default:{
|
|
|
+ RecordListAdapter adapter = (RecordListAdapter) this.expListView.getExpandableListAdapter();
|
|
|
+ if (adapter != null){
|
|
|
+ return adapter.getSectionHeaders();
|
|
|
+ }
|
|
|
+ return new ArrayList<String>();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|