Skip to content

Commit

Permalink
barcode details added, barcode info saves to parse. fixed bug with ol…
Browse files Browse the repository at this point in the history
…d description null crashing description edit page
  • Loading branch information
JBreece committed Apr 6, 2016
1 parent 7f4ae20 commit 78cc3ed
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 40 deletions.
91 changes: 66 additions & 25 deletions app/src/main/java/edu/sc/snacktrack/NewEntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class NewEntryActivity extends AppCompatActivity implements OnClickListen
private static final int PREVIEW_HEIGHT = 100;

private static final String STATE_DESCRIPTION_STRING = "descriptionString";
private static final String STATE_SCAN_CONTENT_STRING = "scanContentString";
private static final String STATE_SCAN_DETAILS_STRING = "scanDetailsString";
private static final String STATE_SAVING = "saving";

public static final String PHOTO_FILE_KEY = "photo";
Expand All @@ -78,12 +80,23 @@ public class NewEntryActivity extends AppCompatActivity implements OnClickListen

private boolean saving = false;

private Button scanBtn;
//private TextView formatTxt, contentTxt;
private TextView contentText;
private TextView detailsText;

//private TextView detailsTxt;
private String barcodeContent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_entry);


contentText = (TextView) findViewById(R.id.scan_content);
detailsText = (TextView) findViewById(R.id.scan_details);

mealTypeSpinner = (Spinner) findViewById(R.id.meal_type_spinner);
// mealLocationSpinner = (Spinner) findViewById(R.id.meal_location_spinner);

Expand Down Expand Up @@ -123,6 +136,8 @@ public void onClick(View v) {
// String currentPhotoPath, newPhotoPath;

descriptionTextView.setText(savedInstanceState.getString(STATE_DESCRIPTION_STRING, ""));
contentText.setText(savedInstanceState.getString(STATE_SCAN_CONTENT_STRING, ""));
detailsText.setText(savedInstanceState.getString(STATE_SCAN_DETAILS_STRING, ""));

this.saving = savedInstanceState.getBoolean(STATE_SAVING, false);

Expand Down Expand Up @@ -155,7 +170,7 @@ public void onClick(View v) {

scanBtn = (Button)findViewById(R.id.scan_button);
// formatTxt = (TextView)findViewById(R.id.scan_format);
contentTxt = (TextView)findViewById(R.id.scan_content);
// contentTxt = (TextView)findViewById(R.id.scan_content);
scanBtn.setOnClickListener(this);
}

Expand Down Expand Up @@ -198,17 +213,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
descriptionTextView.setText(newText);
}
}
} else if(requestCode == IntentIntegrator.REQUEST_CODE){
} else if(requestCode == IntentIntegrator.REQUEST_CODE) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
String scanContent = null;
String scanFormat = null;
if(scanningResult != null){
scanContent = scanningResult.getContents();
scanFormat = scanningResult.getFormatName();
}
if (scanContent != null) {
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
// formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
// contentTxt.setText("CONTENT: " + scanContent);
//detailsTxt.setText("DETAILS");
Log.d("scanContent", scanContent);
/*
try {
Expand All @@ -219,26 +231,38 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
barcodeContent = scanContent;
*/
try {
int commaIndex = 3;
String brand = "Brand";
String scannerInfo = new RetrieveFeedTask().execute(scanContent).get();
Integer nameBegin = scannerInfo.lastIndexOf("name") + 7;
Integer nameEnd = scannerInfo.indexOf("attributes") - 8;
String productName = scannerInfo.substring(nameBegin, nameEnd);
int nameBegin = scannerInfo.lastIndexOf("name") + 7;
int nameEnd = scannerInfo.indexOf("attributes") - 8;
final String productName = scannerInfo.substring(nameBegin, nameEnd);
Log.d("productName", productName);
//brand name if statement currently causes an exception, not sure why
/*
/*
if(scannerInfo.toLowerCase().contains(brand.toLowerCase())) {
commaIndex++;
Integer brandBegin = scannerInfo.lastIndexOf("Brand") + 7;
Integer brandEnd = scannerInfo.indexOf(",") - 2;
productName = productName.concat(scannerInfo.substring(brandBegin, brandEnd));
int brandEnd = scannerInfo.indexOf(",", 0);
while (commaIndex-- > 0 && brandEnd != -1)
brandEnd = scannerInfo.indexOf(",", brandEnd+1);
brandEnd = brandEnd - 3;
productName = productName.concat("\r\n" + scannerInfo.substring(brandBegin, brandEnd));
}
*/
contentTxt.setText(productName);
}catch(Exception e) {
*/
nameBegin = scannerInfo.lastIndexOf("attributes") + 16;
nameEnd = scannerInfo.indexOf("images") - 8;
String productDetails = scannerInfo.substring(nameBegin, nameEnd);
Log.d("productDetails", productDetails);
//detailsTxt.setText(productDetails);
// contentTxt.setText(productName);
contentText.setText(productName);
detailsText.setText(productDetails);
} catch (Exception e) {
Log.e("httpget", scanContent);
}
barcodeContent = scanContent;
}
else{
} else {
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
Expand Down Expand Up @@ -314,12 +338,17 @@ private void loadPhotoPreview(File imageFile){
private void saveEntry(){
String description;
String mealType;
String scanDetails;
String scanContent;

final SnackEntry entry = new SnackEntry();
final ParseFile parseFile = new ParseFile(currentImageFile);

description = descriptionTextView.getText().toString();
mealType = mealTypeSpinner.getSelectedItem().toString();
//scanDetails = detailsTxt.getText().toString();
scanContent = contentText.getText().toString();
scanDetails = detailsText.getText().toString();

saving = true;
setWidgetsEnabled(false);
Expand All @@ -329,6 +358,20 @@ private void saveEntry(){
entry.setDescription(descriptionTextView.getText().toString());
}

//if(scanDetails != null && !scanDetails.trim().equals("")){
// entry.setScanDetails(detailsTxt.getText().toString());
//}

if(scanContent != null && !scanContent.trim().equals("")){
entry.setScanContent(contentText.getText().toString());
Log.d("contentText1", contentText.getText().toString());
}
if(scanDetails != null && !scanDetails.trim().equals("")){
entry.setScanDetails(detailsText.getText().toString());
Log.d("detailsText1", detailsText.getText().toString());
}
// Log.d("scanContent", scanContent);

// if(mealType != null && !mealType.trim().equals(getResources().getString(R.string.default_spinner_item))){
if(mealType != null){
entry.setTypeOfMeal(mealTypeSpinner.getSelectedItem().toString());
Expand Down Expand Up @@ -397,6 +440,8 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

outState.putString(STATE_DESCRIPTION_STRING, descriptionTextView.getText().toString());
outState.putString(STATE_SCAN_CONTENT_STRING, contentText.getText().toString());
outState.putString(STATE_SCAN_DETAILS_STRING, detailsText.getText().toString());
// if(currentImageFile != null){
// outState.putString(STATE_CURRENT_PHOTO_PATH, currentImageFile.getAbsolutePath());
// }
Expand Down Expand Up @@ -520,10 +565,6 @@ protected void onCancelled(){
super.onCancelled();
}
}
private Button scanBtn;
//private TextView formatTxt, contentTxt;
private TextView contentTxt;
private String barcodeContent;

//old way of httpGet
/*
Expand Down
22 changes: 15 additions & 7 deletions app/src/main/java/edu/sc/snacktrack/SnackDetailsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class SnackDetailsFragment extends Fragment {
private ImageView imageView;
// private TextView descriptionTextView;
private EditText descriptionEditText;
private TextView contentText;
private TextView detailsText;
private String oldMealType;
private String oldDescription;
//private TextView mealTypeTextView;
Expand Down Expand Up @@ -82,6 +84,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
imageView = (ImageView) view.findViewById(R.id.imageView);
//descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);
descriptionEditText = (EditText) view.findViewById(R.id.descriptionEditTextView);
contentText = (TextView) view.findViewById(R.id.scan_content);
detailsText = (TextView) view.findViewById(R.id.scan_details);
//descriptionEditText.setTextColor();
saveButton = (Button) view.findViewById(R.id.save_button);
saveButton.setVisibility(View.GONE);
Expand All @@ -91,13 +95,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onClick(View v) {
final ParseObject snackEntry = ParseObject.createWithoutData("SnackEntry", objectId);

if (!(oldMealType.equals(mealTypeSpinner.getSelectedItem().toString()))) ;
{
snackEntry.put("mealType", mealTypeSpinner.getSelectedItem().toString());
}
if (!(oldDescription.equals(descriptionEditText.getText().toString()))) {
snackEntry.put("description", descriptionEditText.getText().toString());
}
snackEntry.put("mealType", mealTypeSpinner.getSelectedItem().toString());
snackEntry.put("description", descriptionEditText.getText().toString());
//snackEntry.put("scanDetails", detailsText.getText().toString());
//snackEntry.put("scanContent", contentText.getText().toString());

snackEntry.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
progressOverlay.setVisibility(View.GONE);
Expand Down Expand Up @@ -163,9 +165,15 @@ public void done(SnackEntry snackEntry, ParseException e) {
String photoURL = snackEntry.getPhoto().getUrl();
String description = snackEntry.getDescription();
String mealType = snackEntry.getMealType();
String scanDetails = snackEntry.getScanDetails();
String scanContent = snackEntry.getScanContent();

ImageLoader.getInstance(getContext()).displayImage(photoURL, imageView);
descriptionEditText.setText(description != null ? description : "No description");
Log.d("descriptionEditText", descriptionEditText.getText().toString());
detailsText.setText(scanDetails);
contentText.setText(scanContent);

// mealTypeTextView.setText(mealType != null ? mealType : "No meal type");
if (mealType != null) {
mealTypeSpinner.setSelection(((ArrayAdapter) mealTypeSpinner.getAdapter()).getPosition(mealType));
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/edu/sc/snacktrack/SnackEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class SnackEntry extends ParseObject{
private static final String MEAL_TYPE_KEY = "mealType";
private static final String DESCRIPTION_KEY = "description";
private static final String PHOTO_KEY = "photo";
private static final String SCAN_DETAILS_KEY = "scanDetails";
private static final String SCAN_CONTENT_KEY = "scanContent";

public void setOwner(ParseUser owner){
put(OWNER_KEY, owner);
Expand All @@ -41,6 +43,22 @@ public String getDescription(){
return getString(DESCRIPTION_KEY);
}

public void setScanDetails(String description){
put(SCAN_DETAILS_KEY, description);
}

public String getScanDetails(){
return getString(SCAN_DETAILS_KEY);
}

public void setScanContent(String description){
put(SCAN_CONTENT_KEY, description);
}

public String getScanContent(){
return getString(SCAN_CONTENT_KEY);
}

public void setPhoto(final ParseFile imageFile){
put(PHOTO_KEY, imageFile);
}
Expand Down
42 changes: 36 additions & 6 deletions app/src/main/res/layout/activity_new_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,43 @@
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/scan_button" />
<TextView
android:id="@+id/scan_content"
android:layout_width="wrap_content"


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/scan_format" />
android:background="#55ffffff"
android:orientation="vertical"
android:layout_below="@id/descriptionWrapper"
android:layout_marginTop="20dp"
android:padding="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/scan_data_hint"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/barcode_label"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/scan_content"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/scan_details"
/>

</LinearLayout>
</RelativeLayout>

</ScrollView>
Expand Down
38 changes: 36 additions & 2 deletions app/src/main/res/layout/fragment_snack_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
android:layout_height="match_parent"
android:orientation="vertical">

//"match_parent"
//"wrap_content"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -111,6 +109,42 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cdffffff"
android:orientation="vertical"
android:layout_below="@id/descriptionWrapper"
android:layout_marginTop="20dp"
android:padding="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/scan_data_hint"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/barcode_label"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/scan_content"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/scan_details"
/>

</LinearLayout>

</RelativeLayout>

</ScrollView>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<string name="new_email_text">Enter new email:</string>
<string name="email_edittext">Click here</string>
<string name="email_submit">SUBMIT</string>
<string name="scan_data_hint">Barcode Data</string>

<string name="search_text">Search dietitians:</string>
<string name="search_edittext">Dietitian\'s username</string>
Expand Down

0 comments on commit 78cc3ed

Please sign in to comment.