Skip to content

Commit

Permalink
Add real number of records in RecordListAdapter.java+Diffrent limit i…
Browse files Browse the repository at this point in the history
…n attackrecords.
  • Loading branch information
irinil committed Jul 15, 2020
1 parent 69e792f commit 8d60016
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Expand Up @@ -451,9 +451,9 @@ public synchronized ArrayList<RecordAll> getRecordsForFilterMutliStage(LogFilter
return allRecords;
}

public synchronized ArrayList<RecordAll> getRecordsForFilter(LogFilter filter,int offset,int limit) {
public synchronized ArrayList<RecordAll> getRecordsForFilter(LogFilter filter,int offset,int limit,int attackRecordOffset,int attackRecordLimit) {
MessageRecordDAO messageRecordDAO = new MessageRecordDAO(this.daoSession);
ArrayList<AttackRecord> attackRecords = this.selectionQueryFromFilter(filter);
ArrayList<AttackRecord> attackRecords = this.selectionQueryFromFilter(filter,attackRecordOffset,attackRecordLimit);
ArrayList<MessageRecord> records = messageRecordDAO.selectionQueryFromFilter(filter,offset,limit);
ArrayList<MessageRecord> messageRecords =new ArrayList<>();

Expand Down
Expand Up @@ -58,9 +58,10 @@ public class TracingSyncService extends IntentService {
private DaoSession dbSession;
private DAOHelper daoHelper;
private ArrayList<RecordAll> records = new ArrayList<>();
private static int offset=0;
private int offset=0;
private int limit=50;

private int attackRecordOffset=0;
private int attackRecordLimit=50;
SharedPreferences pref;
Editor editor;

Expand Down Expand Up @@ -99,6 +100,7 @@ protected void onHandleIntent(Intent intent) {
/**
* Uploads all new Records to a server, specified in the settings.
*/
//TODO Add limits when the Service is working again.
@Deprecated
private void syncNewRecords() {
long lastSyncTime = pref.getLong("LAST_SYNC_TIME", 0);
Expand All @@ -110,7 +112,7 @@ private void syncNewRecords() {
LogFilter filter = new LogFilter();
filter.setAboveTimestamp(lastSyncTime);
//int recordsSize = daoHelper.getMessageRecordDAO().getRecordCount();
records = daoHelper.getAttackRecordDAO().getRecordsForFilter(filter, offset,limit);
records = daoHelper.getAttackRecordDAO().getRecordsForFilter(filter);

StringWriter writer = new StringWriter();

Expand Down
Expand Up @@ -8,10 +8,15 @@
import java.util.HashMap;
import java.util.List;

import de.tudarmstadt.informatik.hostage.HostageApplication;
import de.tudarmstadt.informatik.hostage.R;
import de.tudarmstadt.informatik.hostage.logging.DaoSession;
import de.tudarmstadt.informatik.hostage.persistence.DAO.DAOHelper;
import de.tudarmstadt.informatik.hostage.ui.model.ExpandableListItem;

public class RecordListAdapter extends ExpandableListAdapter {
private DaoSession dbSession = HostageApplication.getInstances().getDaoSession();
private DAOHelper daoHelper = new DAOHelper(dbSession);

/**
* Constructor
Expand Down Expand Up @@ -47,7 +52,8 @@ public void configureSectionHeaderView(View sectionHeader, int section) {
int valueLabelID = R.id.sectionHeaderValue;
TextView tView = sectionHeader.findViewById(headerLabelID);
TextView vView = sectionHeader.findViewById(valueLabelID);
int value = this.getChildrenCount(section);
//int value = this.getChildrenCount(section);
int value = daoHelper.getMessageRecordDAO().getRecordCount(); //shows the real number of records, not the ones that they are in section.
tView.setText(this._sectionHeader.get(section));
vView.setText("" + value);
}
Expand Down
Expand Up @@ -115,6 +115,8 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che

private int offset=0;
private int limit=20;
private int attackRecordOffset=0;
private int attackRecordLimit=999;//needs Different limit because the attackRecords are smaller than messageRecords.
private final int realLimit=20;
private String sectionToOpen = "";
private ArrayList<Integer> openSections;
Expand Down Expand Up @@ -600,7 +602,7 @@ private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
adapter.setData(sectionData);
adapter.setSectionHeader(groupTitle);
} else {
adapter = new RecordListAdapter( RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
adapter = new RecordListAdapter(RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
}

return adapter;
Expand All @@ -617,19 +619,39 @@ private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
*/
private void populateListGradually(){
int recordsSize = daoHelper.getMessageRecordDAO().getRecordCount();
long attackRecordSize = daoHelper.getAttackRecordDAO().getRecordsCount();
setattackRecordLimits(attackRecordSize);
changeLimitOffset(recordsSize);
}

private void setattackRecordLimits(long attackRecordSize){
changeAttackLimitOffset(attackRecordSize);
}

private void changeLimitOffset(long recordsSize){
if(offset+limit<recordsSize-1) {
limit+=realLimit;
offset+=realLimit;
}
}

private void changeAttackLimitOffset(long recordsSize){
if(recordsSize>1000) {
if (attackRecordOffset + attackRecordLimit < recordsSize - 1) {
attackRecordLimit += realLimit;
attackRecordOffset += realLimit;
}
}
}


private HashMap<String, ArrayList<ExpandableListItem>> fetchDataForFilter(LogFilter filter, ArrayList<String> groupTitle){
HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
// 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)};
int[] ids = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };

data = daoHelper.getAttackRecordDAO().getRecordsForFilter(filter == null ? this.filter : filter,offset,limit);
data = daoHelper.getAttackRecordDAO().getRecordsForFilter(filter == null ? this.filter : filter,offset,limit,attackRecordOffset,attackRecordLimit);

HashMap<String, Integer> mapping = new HashMap<String, Integer>();
int i = 0;
Expand Down Expand Up @@ -674,9 +696,9 @@ private HashMap<String, ArrayList<ExpandableListItem>> fetchDataForFilter(LogFil


if (this.groupingKey.equals(this.groupingTitles().get(DEFAULT_GROUPING_KEY_INDEX))){
Collections.sort(groupTitle, Collections.reverseOrder(new DateStringComparator()));
Collections.sort(groupTitle, new DateStringComparator());
} else {
Collections.sort(groupTitle, Collections.reverseOrder(String::compareToIgnoreCase));
Collections.sort(groupTitle, String::compareToIgnoreCase);
}

return sectionData;
Expand Down

0 comments on commit 8d60016

Please sign in to comment.