Commits

littledot5566 committed b69e0af

*Fixed inconsistent shared preferences.

Comments (0)

Files changed (8)

 * 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.
+* 

res/layout/treasure_act.xml

         android:id="@+id/chest_gv_frame"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
+        
         android:columnWidth="90dp"
         android:gravity="center"
         android:horizontalSpacing="10dp"

src/nctuw/littledot/localtreasure/Const.java

 package nctuw.littledot.localtreasure;
 
 public class Const {
+	public static final String PACKAGE = "nctuw.littledot.localtreasure";
 	public static final int THEME = R.style.Theme_Sherlock;
 
 	public static final String BUNDLE_SOURCE = "source";

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

 import android.location.LocationManager;
 import android.os.Bundle;
 import android.view.View;
-import android.widget.TextView;
 
 import com.actionbarsherlock.app.SherlockMapActivity;
 import com.actionbarsherlock.view.Menu;
 		mLM = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 		mSM = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
 		mDB = new Database(this).open(Database.MODE_WRITE);
-		mSP = new SPManager(getBaseContext());
+		mSP = new SPManager(this);
 
 		// initialize map widgets
 		map = (MapView) findViewById(R.id.mapview);

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

 import nctuw.littledot.localtreasure.database.Database;
 import nctuw.littledot.localtreasure.database.Expedition;
 import nctuw.littledot.localtreasure.database.Profile;
+import nctuw.littledot.localtreasure.database.SPManager;
 import nctuw.littledot.util.Leg;
 import android.content.ContentValues;
 import android.content.Context;
 public class HistoryActivityAdapter extends BaseAdapter {
 	private Context mCtx;
 	private Database mDB;
+	private SPManager mSP;
 
 	private ArrayList<ContentValues> mData = new ArrayList<ContentValues>();
 
 	public HistoryActivityAdapter(Context ctx) {
 		mCtx = ctx;
 		mDB = new Database(ctx).open(Database.MODE_READ);
+		mSP = new SPManager(ctx);
 
 		Cursor cur = mDB.rawQuery(String.format(
 				"SELECT * FROM %s, %s WHERE %s.%s=%s.%s ORDER BY %s",
 	}
 
 	public void deleteExpedition(int pos) {
+		long id = getItemId(pos);
+
 		mDB.open(Database.MODE_WRITE);
 
-		if (mDB.deleteExpedition(getItemId(pos)) == 1)
+		if (mDB.deleteExpedition(id) == 1) {
 			mData.remove(pos);
 
+			if (mSP.getActiveExpeditionID() == id)
+				mSP.setActiveExpeditionID(0);
+		}
+
 		notifyDataSetChanged();
 
 		mDB.close();

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

 import nctuw.littledot.util.Leg;
 
 import org.holoeverywhere.app.Activity;
-import org.holoeverywhere.app.AlertDialog;
 
 import android.app.Dialog;
 import android.content.Intent;
 		mSPManager = new SPManager(this);
 		mDB = new Database(this).open(Database.MODE_WRITE);
 
-		AlertDialog.Builder b = new AlertDialog.Builder(this);
-		b.setMessage("message");
-		b.setTitle("titties");
-		b.setPositiveButton("hello", null);
-		b.create().show();
 	}
 
 	@Override

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

 
 	public SPManager(Context ctx) {
 		mCtx = ctx;
+		// mPrefs = ctx.getSharedPreferences(Const.PACKAGE, Context.MODE_PRIVATE);
 		mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
-		// mPrefs.registerOnSharedPreferenceChangeListener(this);
 		mEditor = mPrefs.edit();
 	}
 
 		mEditor.commit();
 	}
 
-	// public float getDistanceTraveled() {
-	// return mPrefs.getFloat(KEY_STATS_DIST_TRAV, 0);
-	// }
-	//
-	// public void incDistanceTraveled(float inc) {
-	// float value = getDistanceTraveled() + inc;
-	// mEditor.putFloat(KEY_STATS_DIST_TRAV, value);
-	// mEditor.commit();
-	// }
-	//
-	// public int getTotalExpeditions() {
-	// return mPrefs.getInt(KEY_STATS_EXP_TOTAL, 0);
-	// }
-	//
-	// public void incTotalExpeditions(int inc) {
-	// int value = getTotalExpeditions() + inc;
-	// mEditor.putInt(KEY_STATS_EXP_TOTAL, value);
-	// mEditor.commit();
-	// }
-	//
-	// public int getSuccessExpeditions() {
-	// return mPrefs.getInt(KEY_STATS_EXP_SUCC, 0);
-	// }
-	//
-	// public void incSuccessExpeditions(int inc) {
-	// int value = getSuccessExpeditions() + inc;
-	// mEditor.putInt(KEY_STATS_EXP_SUCC, value);
-	// mEditor.commit();
-	// }
 }

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

 	}
 
 	public String toString() {
-		return String.format("name=%s", mName);
+		return mName;
 	}
 
 	/**