Skip to content

Commit

Permalink
Add spinner unit for products to send to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
itchix committed Jul 1, 2015
1 parent 44a45d5 commit 630e2fa
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/app.iml
Expand Up @@ -98,6 +98,7 @@
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="commons-validator-1.4.0" level="project" />
<orderEntry type="library" exported="" name="1_commons-validator-1.4.0" level="project" />
<orderEntry type="library" exported="" name="commons-beanutils-1.8.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "openfoodfacts.github.scrachx.openfood"
minSdkVersion 15
targetSdkVersion 21
versionCode 5
versionName "0.1.4"
versionCode 6
versionName "0.1.5"
}
buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -26,7 +26,7 @@
<activity android:name=".views.SaveProductOfflineActivity" android:screenOrientation="portrait"></activity>

<meta-data android:name="DATABASE" android:value="offacts.db" />
<meta-data android:name="VERSION" android:value="1" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="openfoodfacts.github.scrachx.openfood.models" />

Expand Down
Expand Up @@ -134,7 +134,7 @@ public void onPositive(MaterialDialog dialog) {
params.put("user_id", loginS);
params.put("password", passS);
params.put("product_name", sp.getName());
params.put("quantity", sp.getWeight());
params.put("quantity", sp.getWeight() + " " + sp.getWeight_unit());
params.put("stores", sp.getStores());
params.put("nutriment_energy", sp.getEnergy());
params.put("nutriment_energy_unit", sp.getEnergy_unit());
Expand Down
Expand Up @@ -13,23 +13,33 @@ public class SendProduct extends SugarRecord<SendProduct> {
String energy;
String energy_unit;
String weight;
String weight_unit;
String imgupload_front;
String stores;

public SendProduct() {

}

public SendProduct(String barcode, String name, String energy, String energy_unit, String weight, String imgupload_front, String stores) {
public SendProduct(String barcode, String name, String energy, String energy_unit, String weight, String weight_unit, String imgupload_front, String stores) {
this.barcode = barcode;
this.name = name;
this.energy = energy;
this.energy_unit = energy_unit;
this.weight = weight;
this.weight_unit = weight_unit;
this.imgupload_front = imgupload_front;
this.stores = stores;
}

public String getWeight_unit() {
return weight_unit;
}

public void setWeight_unit(String weight_unit) {
this.weight_unit = weight_unit;
}

public String getBarcode() {
return barcode;
}
Expand Down
Expand Up @@ -10,9 +10,12 @@
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -46,6 +49,8 @@ protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
final String barcode = intent.getStringExtra("barcode");

final String[] unit = new String[1];

imgSave = (ImageView) findViewById(R.id.imageSave);
name = (EditText) findViewById(R.id.editTextName);
store = (EditText) findViewById(R.id.editTextStores);
Expand All @@ -57,6 +62,20 @@ protected void onCreate(Bundle savedInstanceState) {
store.setSelected(false);
weight.setSelected(false);

Spinner spinner = (Spinner) findViewById(R.id.spinnerUnitWeight);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.units_array, R.layout.custom_spinner_item);
adapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
unit[0] = parent.getItemAtPosition(pos).toString();
}

public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
});

List<SendProduct> sp = SendProduct.find(SendProduct.class,"barcode = ?", barcode);
if(sp.size() > 0){
SendProduct product = sp.get(0);
Expand All @@ -65,6 +84,9 @@ protected void onCreate(Bundle savedInstanceState) {
name.setText(product.getName());
store.setText(product.getStores());
weight.setText(product.getWeight());
ArrayAdapter unitAdapter = (ArrayAdapter) spinner.getAdapter(); //cast to an ArrayAdapter
int spinnerPosition = unitAdapter.getPosition(product.getWeight_unit());
spinner.setSelection(spinnerPosition);
}

takePic.setOnClickListener(new View.OnClickListener() {
Expand All @@ -78,18 +100,19 @@ public void onClick(View v) {
@Override
public void onClick(View v) {

if(!settings.getString("imgUrl", "").isEmpty() && !name.getText().toString().isEmpty() && !store.getText().toString().isEmpty()){
if(!settings.getString("imgUrl", "").isEmpty() && !name.getText().toString().isEmpty()){
List<SendProduct> sp = SendProduct.find(SendProduct.class,"barcode = ?", barcode);
if(sp.size() > 0){
SendProduct product = sp.get(0);
product.setName(name.getText().toString());
product.setImgupload_front(settings.getString("imgUrl", ""));
product.setStores(store.getText().toString());
product.setWeight(weight.getText().toString());
product.setWeight_unit(unit[0]);
product.save();
}else{
SendProduct product = new SendProduct(barcode, name.getText().toString(), "",
"", weight.getText().toString(), settings.getString("imgUrl", ""), store.getText().toString());
"", weight.getText().toString(), unit[0], settings.getString("imgUrl", ""), store.getText().toString());
product.save();
}
Toast.makeText(getApplicationContext(), R.string.txtDialogsContentInfoSave, Toast.LENGTH_LONG).show();
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_arrow_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_arrow_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_arrow_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions app/src/main/res/drawable/spinner_default.xml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="@color/indigo_600" />
<stroke
android:width="1dp"
android:color="#d2d2d2" />
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<shape>
<solid
android:color="@color/indigo_400" />
<stroke
android:width="1dp"
android:color="@color/indigo_300" />
<corners android:radius="5dp"/>
</shape>
</item>
</selector>
53 changes: 36 additions & 17 deletions app/src/main/res/layout/activity_save_product_offline.xml
Expand Up @@ -40,28 +40,47 @@
android:id="@+id/editTextName"
android:hint="@string/hintNameProduct"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/spacing_tiny"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_normal"
android:background="@drawable/edittext_top"
android:background="@drawable/edittext_full"
android:paddingLeft="50dp"
android:singleLine="true"
/>

<EditText
android:layout_width="match_parent"
android:layout_height="70dp"
android:inputType="number"
android:ems="10"
android:id="@+id/editTextWeight"
android:numeric="signed"
android:hint="@string/hintWeight"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_normal"
android:background="@drawable/edittext_middle"
android:paddingLeft="50dp"
android:singleLine="true"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<EditText
android:layout_width="match_parent"
android:layout_height="70dp"
android:inputType="number"
android:ems="10"
android:id="@+id/editTextWeight"
android:numeric="signed"
android:hint="@string/hintWeight"
android:layout_marginBottom="@dimen/spacing_tiny"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_tiny"
android:background="@drawable/edittext_full"
android:paddingLeft="50dp"
android:singleLine="true"
/>

<Spinner
android:id="@+id/spinnerUnitWeight"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/spinner_default"
android:spinnerMode="dropdown"
android:layout_marginBottom="@dimen/spacing_tiny"
android:layout_marginLeft="@dimen/spacing_tiny"
android:layout_marginRight="@dimen/spacing_normal"
/>

</LinearLayout>


<EditText
android:layout_width="match_parent"
Expand All @@ -73,7 +92,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_normal"
android:background="@drawable/edittext_bottom"
android:background="@drawable/edittext_full"
android:paddingLeft="50dp"
android:singleLine="true"
/>
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/custom_spinner_dropdown_item.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="@color/indigo_400"
android:textSize="@dimen/font_large"
android:gravity="center"
android:drawablePadding="@dimen/spacing_normal"
android:ellipsize="marquee"
android:textStyle="bold"
/>
13 changes: 13 additions & 0 deletions app/src/main/res/layout/custom_spinner_item.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="marquee"
android:gravity="center"
android:drawableRight="@drawable/ic_arrow_down"
android:textSize="20sp"
android:textColor="#fff"
android:textStyle="bold"
/>
1 change: 1 addition & 0 deletions app/src/main/res/sugar_upgrades/2.sql
@@ -0,0 +1 @@
alter table SENDPRODUCT add COLUMN weight_unit TEXT;
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -44,6 +44,15 @@
<item>@drawable/ic_home</item>
</array>

<!-- Text units -->
<string-array name="units_array">
<item>g</item>
<item>mg</item>
<item>kg</item>
<item>l</item>
<item>ml</item>
</string-array>

<!-- Content Description -->
<string name="desc_list_item_icon">Item Icon</string>
<string name="alert_dialog_product_error_msg">Product not found, please try again</string>
Expand Down

0 comments on commit 630e2fa

Please sign in to comment.