Commits

littledot5566  committed 91809c8

*Changed TreasureActivity layout to use ListView instead of GridView. *Fixed logic to retrieve Treasure depending on TID.

  • Participants
  • Parent commits 41424f7

Comments (0)

Files changed (9)

File release/TIL.txt

 O: db.rawQuery(String.format("select * from %s where %s=%d", "profile", "pID", 1));
 
 > How to find the limits for Floats and Doubles?
-O: Use $(Type).MAX_VALUE to check (eg: Float.MAX_VALUE, Double.MAX_VALUE)
+O: Use $(Type).MAX_VALUE to check (eg: Float.MAX_VALUE, Double.MAX_VALUE)
+
+O: ABS and HE can share HE's SharedPreferences, but not compatible with Android's SharedPreferences.

File release/TODO.txt

 * Display treasure in a trophy case.
 * Distance from destination, distance travelled in MapAct.
 * "Displayable" column for Expeditions. Don't delete data. (do last)
-* After completing an Expedition, remove from Active Expedition.
+v After completing an Expedition, remove from Active Expedition.
 * Completed Expeditions should not display "Continue Expedition" option.

File res/layout/treasure_act.xml

     android:layout_height="fill_parent"
     android:orientation="vertical" >
 
-    <GridView
-        android:id="@+id/chest_gv_frame"
+    <ListView
+        android:id="@+id/chest_lv_frame"
         android:layout_width="fill_parent"
-        android:layout_height="fill_parent"
-        
-        android:columnWidth="90dp"
-        android:gravity="center"
-        android:horizontalSpacing="10dp"
-        android:numColumns="auto_fit"
-        android:stretchMode="columnWidth"
-        android:verticalSpacing="10dp" />
+        android:layout_height="0dp"
+        android:layout_weight="1" />
 
 </LinearLayout>

File res/layout/treasure_item.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:orientation="vertical" >
+    android:layout_height="wrap_content"
+    android:orientation="horizontal" >
 
     <ImageView
         android:id="@+id/tItem_iv_image"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent" />
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+    <TextView
+        android:id="@+id/tItem_tv_name"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1" />
+
+    <TextView
+        android:id="@+id/tItem_tv_amount"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
 
 </LinearLayout>

File src/nctuw/littledot/localtreasure/components/HistoryActivity.java

 import org.holoeverywhere.app.Dialog;
 import org.holoeverywhere.widget.ListView;
 
-import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;

File src/nctuw/littledot/localtreasure/components/TreasureActivity.java

 import nctuw.littledot.localtreasure.R;
 
 import org.holoeverywhere.app.Activity;
+import org.holoeverywhere.widget.ListView;
 
 import android.os.Bundle;
-import android.widget.GridView;
 
 public class TreasureActivity extends Activity {
 
-	private GridView gvTreasure;
+	private ListView gvTreasure;
 
 	private TreasureActivityAdapter mAdapter;
 
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.treasure_act);
-		gvTreasure = (GridView) findViewById(R.id.chest_gv_frame);
+		gvTreasure = (ListView) findViewById(R.id.chest_lv_frame);
 
 		mAdapter = new TreasureActivityAdapter(this);
 		gvTreasure.setAdapter(mAdapter);

File src/nctuw/littledot/localtreasure/components/TreasureActivityAdapter.java

 import nctuw.littledot.localtreasure.R;
 import nctuw.littledot.localtreasure.database.Database;
 import nctuw.littledot.localtreasure.database.Expedition;
+import nctuw.littledot.localtreasure.database.Treasure;
+import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.ImageView;
+import android.widget.TextView;
 
 public class TreasureActivityAdapter extends BaseAdapter {
 	private Context mCtx;
 	private Database mDB;
-	private ArrayList<Expedition> mData = new ArrayList<Expedition>();
+	private ArrayList<ContentValues> mData = new ArrayList<ContentValues>();
 
 	public TreasureActivityAdapter(Context ctx) {
 		mCtx = ctx;
 		mDB = new Database(ctx).open(Database.MODE_READ);
 
-		Cursor cur = mDB.rawQuery(String.format("SELECT * FROM %s WHERE %s>0",
-				Expedition.TABLE_NAME, Expedition.KEY_TREASURE));
+		Cursor cur = mDB.rawQuery(String
+				.format("SELECT %s, COUNT(*) FROM %s WHERE %s>0 GROUP BY %s",
+						Expedition.KEY_TREASURE_ID,
+						Expedition.TABLE_NAME,
+						Expedition.KEY_TREASURE_ID,
+						Expedition.KEY_TREASURE_ID));
 
 		if (cur.moveToFirst()) {
 			while (!cur.isAfterLast()) {
-				mData.add(new Expedition(cur));
+				ContentValues kv = new ContentValues();
+				kv.put(Expedition.KEY_TREASURE_ID,
+						cur.getInt(cur.getColumnIndex(Expedition.KEY_TREASURE_ID)));
+				kv.put("COUNT(*)", cur.getInt(cur.getColumnIndex("COUNT(*)")));
+				mData.add(kv);
 				cur.moveToNext();
 			}
 		}
 	}
 
 	@Override
-	public Object getItem(int arg0) {
+	public ContentValues getItem(int arg0) {
 		return mData.get(arg0);
 	}
 
 	@Override
 	public long getItemId(int position) {
-		return mData.get(position).getEID();
+		return position;
 	}
 
 	@Override
 		}
 
 		ImageView ivTreasure = (ImageView) view.findViewById(R.id.tItem_iv_image);
+		TextView tvName = (TextView) view.findViewById(R.id.tItem_tv_name);
+		TextView tvNum = (TextView) view.findViewById(R.id.tItem_tv_amount);
 
-		ivTreasure.setImageResource(mData.get(position).getPrize().getDrawableID());
+		ContentValues kv = mData.get(position);
+		Treasure t = Treasure.getTreasure(kv
+				.getAsInteger(Expedition.KEY_TREASURE_ID));
+		ivTreasure.setImageResource(t.getDrawableID());
+		tvName.setText(t.getName());
+		tvNum.setText("" + kv.getAsInteger("COUNT(*)"));
 
 		return view;
 	}

File src/nctuw/littledot/localtreasure/database/Expedition.java

 	public static final String KEY_START_TIMESTAMP = "eStartTimestamp";
 	public static final String KEY_END_TIMESTAMP = "eEndTimestamp";
 	public static final String KEY_TIME = "eTime";
-	public static final String KEY_TREASURE = "eTreasure";
+	public static final String KEY_TREASURE_ID = "eTreasure";
 
 	public static final String COUNT_ID = "count(" + KEY_ID + ")";
 	public static final String SUM_TRAVELED = "sum(" + KEY_TRAVELED + ")";
 			+ " integer,"
 			+ KEY_TIME // long
 			+ " integer,"
-			+ KEY_TREASURE // int
+			+ KEY_TREASURE_ID // int
 			+ " integer"
 			+ ");";
 
 		if ((i = Database.getIndex(cur, Expedition.KEY_END_TIMESTAMP)) > -1)
 			setEndTS(cur.getLong(i));
 
-		if ((i = Database.getIndex(cur, Expedition.KEY_TREASURE)) > -1)
+		if ((i = Database.getIndex(cur, Expedition.KEY_TREASURE_ID)) > -1)
 			setPrize(Treasure.getTreasure(cur.getInt(i)));
 	}
 
 			vals.add(mEndTS - mStartTS);
 		}
 		if (mPrize != null) {
-			keys.add(KEY_TREASURE);
+			keys.add(KEY_TREASURE_ID);
 			vals.add(mPrize.getTID());
 		}
 
 		kv.put(KEY_END_TIMESTAMP,
 				c.getLong(c.getColumnIndex(KEY_END_TIMESTAMP)));
 		kv.put(KEY_TIME, c.getLong(c.getColumnIndex(KEY_TIME)));
-		kv.put(KEY_TREASURE, c.getInt(c.getColumnIndex(KEY_TREASURE)));
+		kv.put(KEY_TREASURE_ID, c.getInt(c.getColumnIndex(KEY_TREASURE_ID)));
 
 		return kv;
 	}

File src/nctuw/littledot/localtreasure/database/Treasure.java

 	}
 
 	public static Treasure getTreasure(int id) {
-		return values()[id - 1];
+
+		for (Treasure t : values()) {
+			if (t.mID == id)
+				return t;
+		}
+		throw new IllegalArgumentException("Treasure ID does not exist.");
 	}
 
 	/**************************/
 	}
 
 	public void writeToParcel(Parcel dest, int flags) {
-		dest.writeInt(ordinal());
+		dest.writeInt(mID);
 	}
 
 	public static final Parcelable.Creator<Treasure> CREATOR = new Parcelable.Creator<Treasure>() {
-		public Treasure createFromParcel(
-				Parcel in) {
-			return values()[in
-					.readInt()];
+		public Treasure createFromParcel(Parcel in) {
+			return getTreasure(in.readInt());
 		}
 
 		public Treasure[] newArray(