Skip to content

Commit

Permalink
Merge pull request #37 from caseydavenport/instruction-details
Browse files Browse the repository at this point in the history
Add subtitles to certain instructions
  • Loading branch information
Casey Davenport committed Feb 8, 2016
2 parents fa1356f + 9e7a341 commit 3d01444
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 23 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<manifest
package="com.biermacht.brews"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="21"
android:versionName="1.1.2">
android:versionCode="22"
android:versionName="1.1.3">

<uses-sdk
android:minSdkVersion="15"
Expand Down
51 changes: 39 additions & 12 deletions res/layout/row_layout_instruction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,55 @@
android:layout_width="72dp"
android:layout_height="72dp"
android:gravity="center"
android:layout_gravity="center"
android:textColor="@color/subtitle"
android:textSize="14sp"
android:layout_alignParentLeft="true"
android:background="@color/transparent"/>

<TextView
android:id="@+id/label"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="72dp"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="16dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="16sp"
android:textColor="@color/title_color"
android:text="Ingredient Name"
android:layout_toRightOf="@id/tag"
android:layout_toLeftOf="@+id/duration_view"
android:background="@color/transparent"/>
android:orientation="vertical">

<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:layout_gravity="bottom"
android:paddingLeft="8sp"
android:paddingRight="16sp"
android:paddingTop="8dp"
android:paddingBottom="0dp"
android:textSize="16sp"
android:textColor="@color/title_color"
android:text="Acid Rest"
android:background="@color/transparent"/>

<TextView
android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:layout_gravity="top"
android:paddingLeft="8sp"
android:paddingRight="16sp"
android:visibility="visible"
android:paddingTop="0dp"
android:paddingBottom="5dp"
android:textSize="14sp"
android:textColor="@color/subtitle"
android:text="Some text"
android:layout_toRightOf="@id/tag"
android:layout_toLeftOf="@+id/duration_view"
android:background="@color/transparent"/>

</LinearLayout>

<TextView
android:id="@id/duration_view"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.biermacht.brews.frontend.adapters;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.biermacht.brews.R;
Expand All @@ -22,9 +24,11 @@ public class InstructionArrayAdapter extends ArrayAdapter<Instruction> {
private View row;
private LayoutInflater inflater;
private ViewStorage vs;
private Context c;

public InstructionArrayAdapter(Context c, List<Instruction> 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);
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
14 changes: 8 additions & 6 deletions src/com/biermacht/brews/ingredient/Ingredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
29 changes: 27 additions & 2 deletions src/com/biermacht/brews/recipe/Instruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
34 changes: 33 additions & 1 deletion src/com/biermacht/brews/utils/InstructionGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private ArrayList<Instruction> 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);
}
Expand All @@ -161,6 +162,7 @@ private ArrayList<Instruction> 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);

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 3d01444

Please sign in to comment.