Skip to content

Commit

Permalink
Fixes Issue openfoodfacts#2069: downloaded offline_product_data zip f…
Browse files Browse the repository at this point in the history
…ile and stored in the database.
  • Loading branch information
prashantkh19 committed Feb 22, 2019
1 parent d5dbe07 commit 5b2d6a1
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package openfoodfacts.github.scrachx.openfood.models;

import com.opencsv.bean.CsvBindByName;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;

@Entity(indexes = {
@Index(value = "barcode", unique = true)
})
public class OfflineProduct {

@Id
private Long id;
@CsvBindByName(column = "product_name")
private String title;
@CsvBindByName(column = "brands")
private String brands;
@CsvBindByName(column = "code")
private String barcode;
@CsvBindByName(column = "quantity")
private String quantity;
@CsvBindByName(column = "nutrition_grade_fr")
private String nutritionGrade;

public OfflineProduct(String title, String brands, String barcode, String quantity, String nutritionGrade) {
this.title = title;
this.brands = brands;
this.barcode = barcode;
this.quantity = quantity;
this.nutritionGrade = nutritionGrade;
}

@Generated(hash = 524339296)
public OfflineProduct(Long id, String title, String brands, String barcode, String quantity,
String nutritionGrade) {
this.id = id;
this.title = title;
this.brands = brands;
this.barcode = barcode;
this.quantity = quantity;
this.nutritionGrade = nutritionGrade;
}

@Generated(hash = 1425505421)
public OfflineProduct() {
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getBrands() {
return brands;
}

public void setBrands(String brands) {
this.brands = brands;
}

public String getBarcode() {
return barcode;
}

public void setBarcode(String barcode) {
this.barcode = barcode;
}

public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

public String getQuantity() {
return quantity;
}

public void setQuantity(String quantity) {
this.quantity = quantity;
}

public String getNutritionGrade() {
return nutritionGrade;
}

public void setNutritionGrade(String nutritionGrade) {
this.nutritionGrade = nutritionGrade;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,13 @@ Single<JsonNode> getIngredients(@Query("code") String code,
Call<String> editImages(@Query("code") String code,
@QueryMap Map<String, String> fields);


/**
* This method downloads the file with a dynamic downloadable url
*
* @param fileUrl
* @return
*/
@GET
Call<ResponseBody> downloadFileWithDynamicUrlSync(@Url String fileUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class Utils {
public static final int MY_PERMISSIONS_REQUEST_CAMERA = 1;
public static final int MY_PERMISSIONS_REQUEST_STORAGE = 2;
public static final String UPLOAD_JOB_TAG = "upload_saved_product_job";
private static final String TAG = "Utils";
public static boolean isUploadJobInitialised;
public static boolean DISABLE_IMAGE_LOAD = false;

Expand Down Expand Up @@ -558,6 +559,24 @@ public static boolean isExternalStorageWritable() {
return Environment.MEDIA_MOUNTED.equals(state);
}

public static boolean isStoragePermissionGranted(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG, "Permission is granted");
return true;
} else {

Log.v(TAG, "Permission is revoked");
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return false;
}
} else { //permission is automatically granted on sdk<23 upon installation
Log.v(TAG, "Permission is granted");
return true;
}
}

public static Uri getOutputPicUri(Context context) {
return (Uri.fromFile(new File(Utils.makeOrGetPictureDirectory(context), "/" + Utils.timeStamp() + ".jpg")));
}
Expand Down
Loading

0 comments on commit 5b2d6a1

Please sign in to comment.