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:
@@ -53,6 +53,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
private NumberPicker mModPicker;
|
private NumberPicker mModPicker;
|
||||||
private ProgressBar mRollProgress;
|
private ProgressBar mRollProgress;
|
||||||
private View mRollButton;
|
private View mRollButton;
|
||||||
|
private boolean isRolling = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the presets from the provided roll
|
* Applies the presets from the provided roll
|
||||||
@@ -382,28 +383,32 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void rollDice() {
|
public void rollDice() {
|
||||||
mListAdapter.notifyDataSetInvalidated();
|
if(!isRolling){
|
||||||
mRollButton.setEnabled(false);
|
isRolling = true;
|
||||||
mRollProgress.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
// new Thread( new Runnable() {
|
mListAdapter.notifyDataSetInvalidated();
|
||||||
// @Override
|
mRollButton.setEnabled(false);
|
||||||
// public void run(){
|
mRollProgress.setVisibility(View.VISIBLE);
|
||||||
// vibrate for 50 milliseconds
|
|
||||||
vibrate(50);
|
|
||||||
|
|
||||||
int rollId = mDb.getGameRollCount(mGameId) +1;
|
new Thread( new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
// vibrate for 50 milliseconds
|
||||||
|
vibrate(50);
|
||||||
|
|
||||||
ContentValues roll = new ContentValues();
|
int rollId = mDb.getGameRollCount(mGameId) +1;
|
||||||
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()]));
|
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()));
|
||||||
|
|
||||||
mDb.updateGame(mGameId, mGameName, roll, rollId);
|
roll.put(Database.KEY_MOD, DatabaseUtils.sqlEscapeString(mModValues[mModPicker.getValue()]));
|
||||||
// }
|
|
||||||
// }).start();
|
mDb.updateGame(mGameId, mGameName, roll, rollId);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,6 +499,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDatabaseInsertComplete() {
|
public void onDatabaseInsertComplete() {
|
||||||
|
isRolling = false;
|
||||||
this.runOnUiThread(new Runnable(){
|
this.runOnUiThread(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package com.TwentyCode.android.ExaltedDice;
|
|||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -21,11 +20,11 @@ import android.widget.TextView;
|
|||||||
*/
|
*/
|
||||||
public class RollHistoryDatabaseAdapter extends BaseAdapter {
|
public class RollHistoryDatabaseAdapter extends BaseAdapter {
|
||||||
|
|
||||||
private static final String TAG = "RollHistoryDatabaseAdapter";
|
|
||||||
private long mGameId;
|
private long mGameId;
|
||||||
private Database mDb;
|
private Database mDb;
|
||||||
private String mGameName;
|
private String mGameName;
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
|
private int mCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new RollHistoryDatabaseAdapter
|
* Creates a new RollHistoryDatabaseAdapter
|
||||||
@@ -36,6 +35,7 @@ public class RollHistoryDatabaseAdapter extends BaseAdapter {
|
|||||||
mGameName = db.getGameName(gameId);
|
mGameName = db.getGameName(gameId);
|
||||||
mDb = db;
|
mDb = db;
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
|
mCount = mDb.getGameRollCount(mGameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,8 +44,7 @@ public class RollHistoryDatabaseAdapter extends BaseAdapter {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
Log.v(TAG, "getCount() "+mDb.getGameRollCount(mGameId));
|
return mCount;
|
||||||
return mDb.getGameRollCount(mGameId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,6 +94,20 @@ public class RollHistoryDatabaseAdapter extends BaseAdapter {
|
|||||||
return convertView;
|
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 {
|
private class ViewHolder {
|
||||||
TextView mRoll;
|
TextView mRoll;
|
||||||
TextView mStats;
|
TextView mStats;
|
||||||
|
|||||||
Reference in New Issue
Block a user