Commits

littledot5566 committed 522ee92

*Added eDisplay column to Expedition table. *Implemented DataSetObservers in Activities that use ListViews. *Increased Location update frequency to 3s/0m.

Comments (0)

Files changed (9)

res/layout/history_act_layout.xml

         android:id="@+id/history_tv_empty"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:text="No Expeditions yet."
+        android:text="No expeditions yet."
         android:visibility="gone" />
 
     <ListView

res/layout/treasure_act.xml

     android:layout_height="fill_parent"
     android:orientation="vertical" >
 
+    <TextView
+        android:id="@+id/chest_tv_empty"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:text="No treasure yet."
+        android:visibility="gone" />
+
     <ListView
         android:id="@+id/chest_lv_frame"
         android:layout_width="fill_parent"

src/nctuw/littledot/localtreasure/components/CreditsActivity.java

 
 import org.holoeverywhere.app.Activity;
 
+import com.actionbarsherlock.app.ActionBar;
+
 import android.os.Bundle;
 
 public class CreditsActivity extends Activity {
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
-		
+
 		setContentView(R.layout.credits_act);
 
+		ActionBar ab = getSupportActionBar();
+		ab.setDisplayHomeAsUpEnabled(true);
+		ab.setDisplayShowHomeEnabled(false);
+		ab.setTitle("Credits");
+
 	}
 }

src/nctuw/littledot/localtreasure/components/ExpeditionActivity.java

 		for (String provider : mLM.getAllProviders()) {
 			Leg.a("provider=" + provider);
 
-			mLM.requestLocationUpdates(provider, 0, (float) (mExpedition
-					.getDistance() * 0.05 < 10 ? 10
-					: mExpedition.getDistance() * 0.05),
-					this);
+			mLM.requestLocationUpdates(provider, 3000, 0, this);
 		}
 
 		// register sensor updates

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

 import android.content.DialogInterface;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
+import android.database.DataSetObserver;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
+import android.widget.TextView;
 
 public class HistoryActivity extends Activity {
 
+	private TextView tvExcuse;
 	private ListView lvHistory;
 	private HistoryActivityAdapter mAdapter;
 
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.history_act_layout);
+		tvExcuse = (TextView) findViewById(R.id.history_tv_empty);
 		lvHistory = (ListView) findViewById(R.id.history_lv_expeditions);
 
 		ActionBar ab = getSupportActionBar();
 		ab.setTitle("Journal");
 
 		mAdapter = new HistoryActivityAdapter(this);
+		mAdapter.registerDataSetObserver(new DataSetObserver() {
+			@Override
+			public void onChanged() {
+				super.onChanged();
+				checkEmpty();
+			}
+		});
 		lvHistory.setAdapter(mAdapter);
 		lvHistory.setOnItemClickListener(new OnItemClickListener() {
 			@Override
 			}
 		});
 
+		checkEmpty();
+	}
+
+	private void checkEmpty() {
+		if (mAdapter.getCount() == 0)
+			tvExcuse.setVisibility(View.VISIBLE);
+		else
+			tvExcuse.setVisibility(View.GONE);
 	}
 
 	@Override

src/nctuw/littledot/localtreasure/components/HistoryActivityAdapter.java

 		mSP = new SPManager(ctx);
 
 		Cursor cur = mDB.rawQuery(String.format(
-				"SELECT * FROM %s, %s WHERE %s.%s=%s.%s ORDER BY %s",
-				Expedition.TABLE_NAME, Profile.TABLE_NAME,
-				Expedition.TABLE_NAME, Expedition.KEY_PID,
-				Profile.TABLE_NAME, Profile.KEY_ID,
-				Expedition.KEY_START_TIMESTAMP));
+				"SELECT * FROM %s, %s WHERE %s.%s=%s.%s AND %s=1 ORDER BY %s",
+				Expedition.TABLE_NAME, Profile.TABLE_NAME, // tables
+				Expedition.TABLE_NAME, Expedition.KEY_PID, // join
+				Profile.TABLE_NAME, Profile.KEY_ID, // on
+				Expedition.KEY_DISPLAY, // where
+				Expedition.KEY_START_TIMESTAMP // order by
+				));
 
 		if (cur.moveToFirst()) {
 			while (!cur.isAfterLast()) {

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

 import org.holoeverywhere.app.Activity;
 import org.holoeverywhere.widget.ListView;
 
+import android.database.DataSetObserver;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+
 import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.view.MenuItem;
 
-import android.os.Bundle;
-
 public class TreasureActivity extends Activity {
 
-	private ListView gvTreasure;
+	private TextView tvExcuse;
+	private ListView lvTreasure;
 
 	private TreasureActivityAdapter mAdapter;
 
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.treasure_act);
-		gvTreasure = (ListView) findViewById(R.id.chest_lv_frame);
+		tvExcuse = (TextView) findViewById(R.id.chest_tv_empty);
+		lvTreasure = (ListView) findViewById(R.id.chest_lv_frame);
 
 		ActionBar ab = getSupportActionBar();
 		ab.setDisplayHomeAsUpEnabled(true);
 		ab.setTitle("Treasure Chest");
 
 		mAdapter = new TreasureActivityAdapter(this);
-		gvTreasure.setAdapter(mAdapter);
+		mAdapter.registerDataSetObserver(new DataSetObserver() {
+			@Override
+			public void onChanged() {
+				super.onChanged();
+				checkEmpty();
+			}
+		});
+		lvTreasure.setAdapter(mAdapter);
+
+		checkEmpty();
+	}
+
+	private void checkEmpty() {
+		if (mAdapter.getCount() == 0)
+			tvExcuse.setVisibility(View.VISIBLE);
+		else
+			tvExcuse.setVisibility(View.GONE);
 	}
 
 	@Override

src/nctuw/littledot/localtreasure/database/Database.java

 import android.database.sqlite.SQLiteOpenHelper;
 
 public class Database {
-	private static final int DB_VERSION = 5;
+	private static final int DB_VERSION = 6;
 	public static final String DBNAME = "nctuw.littledot.localtreasure";
 
 	public static final String DBTABLE_TREASURE = "treasure";
 	}
 
 	public Profile queryProfile(long profileID) {
-		Cursor cur = rawQuery(String
-				.format(
+		Cursor cur = rawQuery(String.format(
 						"SELECT *, %s, %s FROM %s LEFT JOIN %s ON %s.%s=%s.%s WHERE %s=%d GROUP BY %s",
 						Expedition.SUM_TRAVELED, Expedition.COUNT_ID,
 						Profile.TABLE_NAME, Expedition.TABLE_NAME,
 						Expedition.TABLE_NAME,
 						Expedition.KEY_PID,
 						Profile.KEY_ID, profileID,
-						Profile.KEY_ID));
+						Profile.KEY_ID
+				));
 
 		Leg.dumpCursor(cur);
 
 	}
 
 	public int deleteExpedition(long id) {
-		return delete(Expedition.TABLE_NAME, Expedition.KEY_ID + "=" + id);
+		// return delete(Expedition.TABLE_NAME, Expedition.KEY_ID + "=" + id);
+		return update(Expedition.TABLE_NAME, Expedition.KEY_DISPLAY, 0,
+				Expedition.KEY_ID + "=" + id);
 	}
 
 	/***************/

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

 	public static final String KEY_END_TIMESTAMP = "eEndTimestamp";
 	public static final String KEY_TIME = "eTime";
 	public static final String KEY_TREASURE_ID = "eTreasure";
+	public static final String KEY_DISPLAY = "eDisplay";
 
 	public static final String COUNT_ID = "count(" + KEY_ID + ")";
 	public static final String SUM_TRAVELED = "sum(" + KEY_TRAVELED + ")";
 			+ KEY_TIME // long
 			+ " integer,"
 			+ KEY_TREASURE_ID // int
-			+ " integer"
+			+ " integer,"
+			+ KEY_DISPLAY // int 0:hide 1:show
+			+ " integer default 1"
 			+ ");";
 
 	/**