Browse Source

Fixed: ViewLog doesn't crash when database is empty
Scrolling in ViewLog works correctly

lp-tu 10 years ago
parent
commit
2dfe0767cf

+ 8 - 8
res/layout/activity_viewlog.xml

@@ -1,17 +1,17 @@
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:paddingBottom="@dimen/activity_vertical_margin"
-    android:paddingLeft="@dimen/activity_horizontal_margin"
-    android:paddingRight="@dimen/activity_horizontal_margin"
-    android:paddingTop="@dimen/activity_vertical_margin"
-    android:scrollbars="none" >
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+	android:scrollbars="none">
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="vertical" >
+        android:orientation="vertical"
+        android:paddingBottom="@dimen/activity_vertical_margin"
+    	android:paddingLeft="@dimen/activity_horizontal_margin"
+    	android:paddingRight="@dimen/activity_horizontal_margin"
+    	android:paddingTop="@dimen/activity_vertical_margin" >
 
         <TextView
             android:id="@+id/textStatistics"

+ 6 - 5
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -9,6 +9,7 @@ import java.util.HashMap;
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
+import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
 import android.annotation.SuppressLint;
 import android.app.Activity;
@@ -283,14 +284,14 @@ public class ViewLog extends Activity {
 	}
 
 	private void setFirstAndLastAttack() {
-		int firstAttackId = dbh.getSmallestAttackId();
-		int lastAttackId = dbh.getHighestAttackId();
-		if (firstAttackId != -1) {
-			Date resultdate = new Date(dbh.getRecordOfAttackId(firstAttackId).getTimestamp());
+		Record firstAttack = dbh.getRecordOfAttackId(dbh.getSmallestAttackId());
+		Record lastAttack = dbh.getRecordOfAttackId(dbh.getHighestAttackId());
+		if (firstAttack != null) {
+			Date resultdate = new Date(firstAttack.getTimestamp());
 			TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
 			text.setText(sdf.format(resultdate));
 			text = (TextView) findViewById(R.id.textLastAttackValue);
-			resultdate = new Date(dbh.getRecordOfAttackId(lastAttackId).getTimestamp());
+			resultdate = new Date(lastAttack.getTimestamp());
 			text.setText(sdf.format(resultdate));
 		} else {
 			TextView text = (TextView) findViewById(R.id.textFirstAttackValue);