Browse Source

record detail view: deleting records

Fabio Arnold 10 years ago
parent
commit
4999b5c196

+ 23 - 6
res/layout/fragment_record_overview.xml

@@ -7,12 +7,20 @@
             android:fillViewport="true">
 
 	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-	              android:orientation="vertical"
-	              android:layout_width="match_parent"
-	              android:layout_height="wrap_content"
-	              android:measureWithLargestChild="false"
-	              android:baselineAligned="true"
-	              android:id="@+id/record_overview_conversation">
+				  android:orientation="vertical"
+				  android:layout_width="match_parent"
+				  android:layout_height="wrap_content"
+				  android:measureWithLargestChild="false"
+				  android:baselineAligned="true"
+				  android:id="@+id/linearLayout3">
+
+		<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+					  android:orientation="vertical"
+					  android:layout_width="match_parent"
+					  android:layout_height="wrap_content"
+					  android:measureWithLargestChild="false"
+					  android:baselineAligned="true"
+					  android:id="@+id/record_overview_conversation">
 
 		<RelativeLayout
 				android:layout_width="match_parent"
@@ -133,5 +141,14 @@
 				android:layout_marginTop="10dp"
 				android:layout_marginBottom="20dp"/>
 
+	</LinearLayout>
+
+
+		<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
+				android:text="@string/delete" android:id="@+id/record_delete_button"
+				android:layout_gravity="center_horizontal" android:layout_weight="0"
+				android:layout_margin="8dp" android:background="@color/holo_red"
+				android:textColor="@android:color/white"/>
+
 	</LinearLayout>
 </ScrollView>

+ 1 - 0
res/values/strings.xml

@@ -145,6 +145,7 @@
 	<string name="record_details_nocontent">No content</string>
 	<string name="record_details_remote_ip">REMOTE IP</string>
 	<string name="record_details_conversation">Conversation</string>
+	<string name="record_details_confirm_delete">Do you really want to delete this record?</string>
     <string name="profile_vista_desc">This profile will imitate a Windows Vista machine</string>
     <string name="profile_xp_desc">This profile will activate Windows XP typical services</string>
     <string name="profile_webserv_http_desc">This profile will imitate a simple webserver, which just supports the HTTP protocol</string>

+ 13 - 0
src/de/tudarmstadt/informatik/hostage/deprecated/UglyDbHelper.java

@@ -423,6 +423,19 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		db.close();
 	}
 
+	/**
+	 * Deletes all records from {@link #TABLE_RECORDS} with a specific Attack ID.
+	 *
+	 * @param attackID
+	 *            The Attack ID to match against.
+	 */
+	public void deleteByAttackID(long attackID) {
+		SQLiteDatabase db = this.getReadableDatabase();
+		db.delete(TABLE_RECORDS, KEY_ATTACK_ID + " = ?", new String[] { String.valueOf(attackID) });
+		db.delete(TABLE_ATTACK_INFO, KEY_ATTACK_ID + " = ?", new String[] { String.valueOf(attackID) });
+		db.close();
+	}
+
 	/**
 	 * Returns a String array with all BSSIDs stored in the database.
 	 * 

+ 37 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordDetailFragment.java

@@ -3,6 +3,9 @@ package de.tudarmstadt.informatik.hostage.ui2.fragment;
 import java.util.ArrayList;
 import java.util.Date;
 
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
 import android.os.Bundle;
 import android.text.format.DateFormat;
 import android.view.LayoutInflater;
@@ -11,12 +14,15 @@ import android.view.MenuInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Button;
 import android.widget.LinearLayout;
 import android.widget.ScrollView;
 import android.widget.TextView;
 import de.tudarmstadt.informatik.hostage.R;
 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.ui2.activity.MainActivity;
 
 /**
  * Created by Julien on 02.03.14.
@@ -74,6 +80,7 @@ public class RecordDetailFragment extends UpNavigatibleFragment {
 	private TextView mRecordDetailsTextBssid;
 	private TextView mRecordDetailsTextRemoteip;
 	private TextView mRecordDetailsTextProtocol;
+	private Button mRecordDeleteButton;
 
 	public void setRecord(Record rec) {
 		this.record = rec;
@@ -120,6 +127,7 @@ public class RecordDetailFragment extends UpNavigatibleFragment {
 		mRecordDetailsTextBssid = (TextView) view.findViewById(R.id.record_details_text_bssid);
 		mRecordDetailsTextRemoteip = (TextView) view.findViewById(R.id.record_details_text_remoteip);
 		mRecordDetailsTextProtocol = (TextView) view.findViewById(R.id.record_details_text_protocol);
+		mRecordDeleteButton = (Button) view.findViewById(R.id.record_delete_button);
 	}
 
 	private void configurateRootView(View rootView) {
@@ -172,6 +180,35 @@ public class RecordDetailFragment extends UpNavigatibleFragment {
 
 			mRecordOverviewConversation.addView(row);
 		}
+
+		mRecordDeleteButton.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				Activity activity = getActivity();
+				if (activity == null) {
+					return;
+				}
+				new AlertDialog.Builder(getActivity())
+						.setTitle(android.R.string.dialog_alert_title)
+						.setMessage(R.string.record_details_confirm_delete)
+						.setPositiveButton(R.string.yes,
+								new DialogInterface.OnClickListener() {
+									public void onClick(DialogInterface dialog,
+											int which) {
+										dbh.deleteByAttackID(record.getAttack_id());
+
+										// TODO: just navigate back...
+										RecordOverviewFragment recordOverviewFragment = new RecordOverviewFragment();
+										recordOverviewFragment.setFilter(new LogFilter());
+										recordOverviewFragment.setGroupKey("Protocol");
+
+										MainActivity.getInstance().injectFragment(recordOverviewFragment, false);
+									}
+								}
+						).setNegativeButton(R.string.no, null)
+						.setIcon(android.R.drawable.ic_dialog_alert).show();
+			}
+		});
 	}
 
 	/*****************************