Fixed java.lang.IllegalStateException thrown by

RollHistortDatabaseAdapter

RollHistortDatabaseAdapter only updates the roll count in
notifyDataSetChanged()

re-added roll thread

added boolean isRolling to prevent multiple rolls at the same time
Change-Id: I47fea7af989d0b2239ad8c5082649022836a2263
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-02-10 00:42:54 -05:00
parent 73b6ff3319
commit c2ef86ea54
2 changed files with 45 additions and 26 deletions

View File

@@ -53,6 +53,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
private NumberPicker mModPicker;
private ProgressBar mRollProgress;
private View mRollButton;
private boolean isRolling = false;
/**
* Applies the presets from the provided roll
@@ -382,28 +383,32 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
* @author ricky barrette
*/
public void rollDice() {
mListAdapter.notifyDataSetInvalidated();
mRollButton.setEnabled(false);
mRollProgress.setVisibility(View.VISIBLE);
// new Thread( new Runnable() {
// @Override
// public void run(){
// vibrate for 50 milliseconds
vibrate(50);
int rollId = mDb.getGameRollCount(mGameId) +1;
ContentValues roll = new ContentValues();
roll.put(Database.KEY_D_TYPE, mDiceValues[mDPicker.getValue()]);
roll.put(Database.KEY_NUMBER, mNumberPicker.getValue());
roll.putAll(results(mNumberPicker.getValue()));
roll.put(Database.KEY_MOD, DatabaseUtils.sqlEscapeString(mModValues[mModPicker.getValue()]));
mDb.updateGame(mGameId, mGameName, roll, rollId);
// }
// }).start();
if(!isRolling){
isRolling = true;
mListAdapter.notifyDataSetInvalidated();
mRollButton.setEnabled(false);
mRollProgress.setVisibility(View.VISIBLE);
new Thread( new Runnable() {
@Override
public void run(){
// vibrate for 50 milliseconds
vibrate(50);
int rollId = mDb.getGameRollCount(mGameId) +1;
ContentValues roll = new ContentValues();
roll.put(Database.KEY_D_TYPE, mDiceValues[mDPicker.getValue()]);
roll.put(Database.KEY_NUMBER, mNumberPicker.getValue());
roll.putAll(results(mNumberPicker.getValue()));
roll.put(Database.KEY_MOD, DatabaseUtils.sqlEscapeString(mModValues[mModPicker.getValue()]));
mDb.updateGame(mGameId, mGameName, roll, rollId);
}
}).start();
}
}
/**
@@ -494,6 +499,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
@Override
public void onDatabaseInsertComplete() {
isRolling = false;
this.runOnUiThread(new Runnable(){
@Override
public void run(){

View File

@@ -8,7 +8,6 @@ package com.TwentyCode.android.ExaltedDice;
import android.content.ContentValues;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -21,11 +20,11 @@ import android.widget.TextView;
*/
public class RollHistoryDatabaseAdapter extends BaseAdapter {
private static final String TAG = "RollHistoryDatabaseAdapter";
private long mGameId;
private Database mDb;
private String mGameName;
private LayoutInflater mInflater;
private int mCount;
/**
* Creates a new RollHistoryDatabaseAdapter
@@ -36,6 +35,7 @@ public class RollHistoryDatabaseAdapter extends BaseAdapter {
mGameName = db.getGameName(gameId);
mDb = db;
mInflater = LayoutInflater.from(context);
mCount = mDb.getGameRollCount(mGameId);
}
/**
@@ -44,8 +44,7 @@ public class RollHistoryDatabaseAdapter extends BaseAdapter {
*/
@Override
public int getCount() {
Log.v(TAG, "getCount() "+mDb.getGameRollCount(mGameId));
return mDb.getGameRollCount(mGameId);
return mCount;
}
/**
@@ -95,6 +94,20 @@ public class RollHistoryDatabaseAdapter extends BaseAdapter {
return convertView;
}
/**
* (non-Javadoc)
* @see android.widget.BaseAdapter#notifyDataSetChanged()
*/
@Override
public void notifyDataSetChanged() {
mCount = mDb.getGameRollCount(mGameId);
super.notifyDataSetChanged();
}
/**
* A simple holder class
* @author ricky barrette
*/
private class ViewHolder {
TextView mRoll;
TextView mStats;