From 9e7a3417d70f2d13aa1fde59dd9be1e535ec32c3 Mon Sep 17 00:00:00 2001 From: Casey Davenport Date: Fri, 5 Feb 2016 23:30:18 -0800 Subject: [PATCH] Add subtitles to certain instructions --- AndroidManifest.xml | 4 +- res/layout/row_layout_instruction.xml | 51 ++++++++++++++----- .../adapters/InstructionArrayAdapter.java | 32 ++++++++++++ .../brews/ingredient/Ingredient.java | 14 ++--- .../biermacht/brews/recipe/Instruction.java | 29 ++++++++++- .../brews/utils/InstructionGenerator.java | 34 ++++++++++++- 6 files changed, 141 insertions(+), 23 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b55e59e..f34d4b4 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="22" + android:versionName="1.1.3"> - + android:orientation="vertical"> + + + + + + { private View row; private LayoutInflater inflater; private ViewStorage vs; + private Context c; public InstructionArrayAdapter(Context c, List list) { super(c, android.R.layout.simple_list_item_1, list); + this.c = c; this.list = list; this.inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @@ -42,6 +46,7 @@ public View getView(int position, View convertView, ViewGroup parent) { // Store component views. vs = new ViewStorage(); vs.labelView = (TextView) this.row.findViewById(R.id.label); + vs.subtitleView = (TextView) (this.row.findViewById(R.id.subtitle)); vs.tagView = (TextView) this.row.findViewById(R.id.tag); vs.durationView = (TextView) this.row.findViewById(R.id.duration_view); row.setTag(vs); @@ -67,11 +72,38 @@ public View getView(int position, View convertView, ViewGroup parent) { // Set the instruction text view. vs.labelView.setText(list.get(position).getInstructionText()); + if (! list.get(position).getSubtitle().isEmpty()) { + // If there is a subtitle, display it and make sure formatting is correct. + vs.subtitleView.setText(list.get(position).getSubtitle()); + + // Ensure correct formatting. + vs.subtitleView.setVisibility(View.VISIBLE); + vs.labelView.setGravity(Gravity.BOTTOM); + + // Set padding - we need to scale values into dp. + float scale = c.getResources().getDisplayMetrics().density; + int eight = (int) (8 * scale + 0.5f); + int sixteen = (int) (16 * scale + 0.5f); + vs.labelView.setPadding(eight, eight, sixteen, 0); + } + else { + // Don't display subtitle and ensure formatting is correct. + vs.subtitleView.setVisibility(View.GONE); + vs.labelView.setGravity(Gravity.CENTER_VERTICAL); + + // Set padding - we need to scale values into dp. + float scale = c.getResources().getDisplayMetrics().density; + int eight = (int) (8 * scale + 0.5f); + int sixteen = (int) (16 * scale + 0.5f); + vs.labelView.setPadding(eight, eight, sixteen, eight); + } + return row; } private class ViewStorage { TextView labelView; + TextView subtitleView; TextView tagView; TextView durationView; } diff --git a/src/com/biermacht/brews/ingredient/Ingredient.java b/src/com/biermacht/brews/ingredient/Ingredient.java index a12fadc..dd00c39 100644 --- a/src/com/biermacht/brews/ingredient/Ingredient.java +++ b/src/com/biermacht/brews/ingredient/Ingredient.java @@ -211,11 +211,13 @@ public void setVersion(int version) { */ public int compareTo(Ingredient other) { // If they are not the same type, sort based on type. - if (! this.getType().equals(other.getType())) { - return this.getType().compareTo(other.getType()); + int typeResult = this.getType().compareTo(other.getType()); + if (typeResult != 0) { + return typeResult; + } + else { + // Otherwise, sort based on name. + return this.getName().compareTo(other.getName()); } - - // Otherwise, sort based on name. - return this.name.compareTo(other.getName()); } -} +} \ No newline at end of file diff --git a/src/com/biermacht/brews/recipe/Instruction.java b/src/com/biermacht/brews/recipe/Instruction.java index 938a385..e46c12b 100644 --- a/src/com/biermacht/brews/recipe/Instruction.java +++ b/src/com/biermacht/brews/recipe/Instruction.java @@ -14,6 +14,7 @@ public class Instruction implements Parcelable { private String instructionText; private String instructionType; + private String subtitle; private int order; private double duration; private String durationUnits; @@ -43,6 +44,7 @@ public class Instruction implements Parcelable { public Instruction(Recipe r) { this.r = r; this.setInstructionText("Blank Instruction"); + this.setSubtitle(""); this.duration = 0; this.durationUnits = Units.MINUTES; this.order = - 1; @@ -111,6 +113,14 @@ public String getInstructionText() { return instructionText; } + public void setSubtitle(String s) { + this.subtitle = s; + } + + public String getSubtitle() { + return this.subtitle; + } + public void setMashStep(MashStep s) { this.mashStep = s; } @@ -279,15 +289,30 @@ public void setInstructionTextFromIngredients() { String s = ""; for (Ingredient i : this.getRelevantIngredients()) { if (s.isEmpty()) { - s += i.getName(); + s += i.getName() + " (" + String.format("%2.1f ", i.getDisplayAmount()) + i.getDisplayUnits() + ")"; } else { - s += "\n" + i.getName(); + s += "\n" + i.getName() + " (" + String.format("%2.1f ", i.getDisplayAmount()) + i.getDisplayUnits() + ")"; } } this.instructionText = s; } + public void setSubtitleFromIngredients() { + String s = ""; + for (Ingredient i : this.getRelevantIngredients()) { + if (s.isEmpty()) { + s += i.getName() + + " - " + String.format("%2.1f", i.getDisplayAmount()) + i.getDisplayUnits(); + } + else { + s += "\n" + i.getName() + + " - " + String.format("%2.1f", i.getDisplayAmount()) + i.getDisplayUnits(); + } + } + this.subtitle = s; + } + public String getInstructionType() { return instructionType; } diff --git a/src/com/biermacht/brews/utils/InstructionGenerator.java b/src/com/biermacht/brews/utils/InstructionGenerator.java index 75a5169..e89e94e 100644 --- a/src/com/biermacht/brews/utils/InstructionGenerator.java +++ b/src/com/biermacht/brews/utils/InstructionGenerator.java @@ -150,6 +150,7 @@ private ArrayList getSpargeInstructions() { i.setDurationUnits(Units.HOURS); i.setLastInType(false); i.setInstructionText("Add First Wort Hops"); + i.setSubtitleFromIngredients(); i.setDuration(0); // Set duration to 0 so we don't show timer. list.add(i); } @@ -161,6 +162,7 @@ private ArrayList getSpargeInstructions() { i.setDurationUnits(Units.HOURS); i.setLastInType(true); i.setInstructionText(r.getMashProfile().getSpargeType() + " sparge"); + i.setSubtitle("Until " + String.format("%2.1f", r.getDisplayBoilSize()) + Units.getVolumeUnits()); i.setDuration(0); // Set duration to 0 so we don't show timer. list.add(i); @@ -204,6 +206,7 @@ private void steeps() { inst.setDurationUnits(Units.MINUTES); inst.setOrder(- 1 * time); // Inversely proportional to time inst.setInstructionTextFromIngredients(); + inst.setSubtitle("@" + String.format("%2.0f", r.getDisplaySteepTemp()) + Units.getTemperatureUnits()); steepsList.add(inst); } } @@ -478,7 +481,36 @@ private void mashSteps() { if (mashSteps.size() > 0) { for (MashStep s : mashSteps) { inst = new Instruction(r); - inst.setInstructionText(s.getName()); + + // Determine the correct text for this instruction. + String text = s.getName(); + + // Determine subtitle. + String subtitle = ""; + + // If an infuse step, add the infusion amount. + if (s.getType().equals(MashStep.INFUSION)) { + subtitle += "Infuse " + + String.format("%2.1f", s.getDisplayInfuseAmount()) + Units.getVolumeUnits() + + " @ " + + String.format("%2.0f", s.getDisplayInfuseTemp()) + Units.getTemperatureUnits(); + } + else if (s.getType().equals(MashStep.DECOCTION)) { + subtitle += "Decoct " + String.format("%2.1f", s.getDisplayDecoctAmount()) + Units.getVolumeUnits(); + } + else if (s.getType().equals(MashStep.TEMPERATURE)) { + subtitle += "Ramp over " + String.format("%2.0f", s.getRampTime()) + "m"; + } + + // Add the hold time and temperature. + subtitle += "\nHold " + + String.format("%2.0f", s.getStepTime()) + + "m @ " + + String.format("%2.0f", s.getDisplayStepTemp()) + + Units.getTemperatureUnits(); + + inst.setInstructionText(text); + inst.setSubtitle(subtitle); inst.setInstructionType(Instruction.TYPE_MASH); inst.setDuration(s.getStepTime()); inst.setOrder(s.getOrder());