Skip to content

Commit

Permalink
Merge pull request #33 from caseydavenport/auto-decoction
Browse files Browse the repository at this point in the history
Auto calculate decoction amount
  • Loading branch information
Casey Davenport committed Dec 29, 2015
2 parents 52bd905 + dd7c5a9 commit bbb66e6
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 18 deletions.
1 change: 1 addition & 0 deletions res/layout-large/fragment_abv_attenuation_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
Expand Down
1 change: 1 addition & 0 deletions res/layout-large/fragment_hydrometer_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
Expand Down
1 change: 1 addition & 0 deletions res/layout-xlarge/fragment_abv_attenuation_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
Expand Down
1 change: 1 addition & 0 deletions res/layout-xlarge/fragment_hydrometer_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
Expand Down
1 change: 1 addition & 0 deletions res/layout/fragment_abv_attenuation_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
Expand Down
1 change: 1 addition & 0 deletions res/layout/fragment_hydrometer_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
Expand Down
3 changes: 0 additions & 3 deletions res/layout/fragment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:listSelector="@drawable/selector"
android:background="#fff"
android:visibility="gone">
</ListView>

Expand Down
17 changes: 14 additions & 3 deletions src/com/biermacht/brews/database/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
public static final int DATABASE_ALPHA = 1; // Database used in development stages
public static final int DATABASE_BETA = 2; // Database in first release.
public static final int DATABASE_GAMMA = 3; // Add measured batch size to the Recipe class.
public static final int DATABASE_DELTA = 4; // Add auto-calc decoct amount to mash steps.

// Current database version
public static final int DATABASE_VERSION = DATABASE_GAMMA;
public static final int DATABASE_VERSION = DATABASE_DELTA;

// Tables
public static final String TABLE_RECIPES = "RecipeTable";
Expand Down Expand Up @@ -175,6 +176,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
public static final String STE_COL_DECOCT_AMT = "decoctionAmount";
public static final String STE_COL_CALC_INFUSE_TEMP = "stepCalcInfuseTemp";
public static final String STE_COL_CALC_INFUSE_AMT = "stepCalcInfuseAmt";
public static final String STE_COL_CALC_DECOCT_AMT = "stepCalcDecoctAmt";

// Create table strings
private static final String CREATE_RECIPE_TABLE = "create table " +
Expand Down Expand Up @@ -338,7 +340,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
+ STE_COL_INFUSE_TEMP + " float, "
+ STE_COL_DECOCT_AMT + " float, "
+ STE_COL_CALC_INFUSE_TEMP + " int, "
+ STE_COL_CALC_INFUSE_AMT + " int"
+ STE_COL_CALC_INFUSE_AMT + " int, "
+ STE_COL_CALC_DECOCT_AMT + " int"
+ ");";

// Public Constructor
Expand Down Expand Up @@ -378,13 +381,21 @@ public void onUpgrade(SQLiteDatabase db, int currentVersion, int newVersion) {
db.execSQL(sql);
break;
case DATABASE_GAMMA:
// Upgrade from BETA to ALPHA. Adds column to recipe table in order to store
// Upgrade from BETA to GAMMA. Adds column to recipe table in order to store
// measured batch size in beer XML format (Liters).
Log.d("DatabaseHelper", "Upgrading database from BETA to GAMMA");
sql = "ALTER TABLE " + TABLE_RECIPES + " ADD COLUMN " +
DatabaseHelper.REC_COL_MEAS_BATCH_SIZE + " float";
db.execSQL(sql);
break;
case DATABASE_DELTA:
// Upgrade from GAMMA to DELTA. Adds column to mash step table to store whether or
// not to auto-calculate decoction amount.
Log.d("DatabaseHelper", "Upgrading database from GAMMA to DELTA");
sql = "ALTER TABLE " + TABLE_STEPS + " ADD COLUMN " +
DatabaseHelper.STE_COL_CALC_DECOCT_AMT + " int";
db.execSQL(sql);
break;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/com/biermacht/brews/database/DatabaseInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public class DatabaseInterface {
DatabaseHelper.STE_COL_DECOCT_AMT,
DatabaseHelper.STE_COL_CALC_INFUSE_TEMP,
DatabaseHelper.STE_COL_CALC_INFUSE_AMT,
DatabaseHelper.STE_COL_CALC_DECOCT_AMT,
};

// Constructor
Expand Down Expand Up @@ -538,6 +539,7 @@ public ContentValues getMashStepValues(MashStep s, long ownerId) {
values.put(DatabaseHelper.STE_COL_DECOCT_AMT, s.getBeerXmlDecoctAmount());
values.put(DatabaseHelper.STE_COL_CALC_INFUSE_TEMP, s.getAutoCalcInfuseTemp() ? 1 : 0);
values.put(DatabaseHelper.STE_COL_CALC_INFUSE_AMT, s.getAutoCalcInfuseAmt() ? 1 : 0);
values.put(DatabaseHelper.STE_COL_CALC_DECOCT_AMT, s.getAutoCalcDecoctAmt() ? 1 : 0);
return values;
}

Expand Down Expand Up @@ -1121,6 +1123,8 @@ private MashStep cursorToMashStep(Cursor cursor) {
cid++;
int calcInfuseAmt = cursor.getInt(cid);
cid++;
int calcDecoctAmt = cursor.getInt(cid);
cid++;

MashStep s = new MashStep();
s.setId(id);
Expand All @@ -1140,6 +1144,7 @@ private MashStep cursorToMashStep(Cursor cursor) {
s.setBeerXmlDecoctAmount(decoctAmt);
s.setAutoCalcInfuseTemp(calcInfuseTemp == 1 ? true : false);
s.setAutoCalcInfuseAmt(calcInfuseAmt == 1 ? true : false);
s.setAutoCalcDecoctAmt(calcDecoctAmt == 1 ? true : false);

return s;
}
Expand Down
17 changes: 16 additions & 1 deletion src/com/biermacht/brews/frontend/AddMashStepActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class AddMashStepActivity extends AddEditActivity {
// Callbacks for auto-calculation fields.
public BooleanCallback infuseTempCallback;
public BooleanCallback infuseAmountCallback;
public BooleanCallback decoctAmountCallback;

// Stores potential MashStep types - Temperature, Infusion, Decoction.
ArrayList<String> stepTypeArray;
Expand Down Expand Up @@ -156,7 +157,10 @@ else if (v.equals(waterToGrainRatioView)) {
}
else if (v.equals(stepAmountView)) {
if (step.getType().equals(MashStep.DECOCTION)) {
alert = alertBuilder.editTextFloatAlert(stepAmountViewText, stepAmountViewTitle).create();
alert = alertBuilder.editTextFloatCheckBoxAlert(stepAmountViewText,
stepAmountViewTitle,
step.getAutoCalcDecoctAmt(),
decoctAmountCallback).create();
}
else {
alert = alertBuilder.editTextFloatCheckBoxAlert(stepAmountViewText,
Expand Down Expand Up @@ -219,6 +223,17 @@ public void call(boolean b) {
waterToGrainRatioViewText.setText(String.format("%2.2f", step.getDisplayWaterToGrainRatio()));
}
};

// Called when the "auto-calculate" checkbox is pressed for decoction amount.
decoctAmountCallback = new BooleanCallback() {
@Override
public void call(boolean b) {
Log.d("AddMashStepActivity", "Decoct amount autocalc checkbox pressed, set to: " + b);
step.setAutoCalcDecoctAmt(b);
stepAmountViewText.setText(String.format("%2.2f", step.getDisplayAmount()));
waterToGrainRatioViewText.setText(String.format("%2.2f", step.getDisplayWaterToGrainRatio()));
}
};
}

public void setValues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;

import com.biermacht.brews.R;
Expand All @@ -24,6 +25,7 @@ public class AlcoholAttenuationCalculatorFragment extends Fragment implements Bi
EditText finalGravEditText;
TextView abvTextView;
TextView attnTextView;
ScrollView scrollView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
Expand All @@ -40,6 +42,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
abvTextView = (TextView) pageView.findViewById(R.id.calculated_abv_text_view);
attnTextView = (TextView) pageView.findViewById(R.id.attenuation_text_view);

scrollView = (ScrollView) pageView.findViewById(R.id.scrollview);

return pageView;
}

Expand Down Expand Up @@ -88,6 +92,15 @@ public String name() {
public void handleClick(View v) {
if (v.getId() == R.id.calculate_button) {
this.calculate();

// The page is a bit long - scroll to the bottom so the user can see the
// calculation output.
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;

import com.biermacht.brews.R;
Expand All @@ -28,6 +29,7 @@ public class HydrometerTempCalculatorFragment extends Fragment implements Bierma
TextView calcGravityTitle;
TextView calibTempTitle;
EditText calibTempEditText;
ScrollView scrollView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
Expand All @@ -47,6 +49,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
calibTempEditText = (EditText) pageView.findViewById(R.id.calibrate_temperature_edit_text);
calcGravityTitle = (TextView) pageView.findViewById(R.id.calculated_gravity_title);

scrollView = (ScrollView) pageView.findViewById(R.id.scrollview);

// Set the correct temperature titles / hints based on unit settings.
measTempTitle.setText("Temperature of Wort (" + Units.getTemperatureUnits() + ")");
calibTempTitle.setText("Calibration Temperature (" + Units.getTemperatureUnits() + ")");
Expand Down Expand Up @@ -116,6 +120,15 @@ public String name() {
public void handleClick(View v) {
if (v.getId() == R.id.calculate_button) {
this.calculate();

// The page is a bit long - scroll to the bottom so the user can see the
// calculation output.
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
}
}
7 changes: 4 additions & 3 deletions src/com/biermacht/brews/recipe/Instruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public String getBrewTimerText() {
Units.getTemperatureUnits());
}

if (mashStep.getDisplayDecoctAmount() != 0) {
if (mashStep.getDisplayDecoctAmount() != 0 && mashStep.getType().equals(MashStep.DECOCTION)) {
// This is a decoction step.
String fmt = "Remove %2.2f %s of mash and boil it. Then, add it back to the mash.";
s += String.format(fmt, mashStep.getDisplayDecoctAmount(), Units.getVolumeUnits());
double quarts = Units.litersToQuarts(mashStep.getBeerXmlDecoctAmount());
String fmt = "Remove %2.2f %s (%2.2fqt) of mash and boil it. Then, add it back to the mash tun.\n\n";
s += String.format(fmt, mashStep.getDisplayDecoctAmount(), Units.getVolumeUnits(), quarts);
}

if (mashStep.getType().equals(MashStep.TEMPERATURE)) {
Expand Down
Loading

0 comments on commit bbb66e6

Please sign in to comment.