Skip to content

Commit

Permalink
Merge branch 'develop' into release/3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
VaiTon committed Nov 14, 2020
2 parents 531d9d6 + 661760b commit c2069a3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 78 deletions.
Expand Up @@ -106,8 +106,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mUrlImage = product.getImagePackagingUrl(langCode);
}

if (nutriments.contains(Nutriments.CARBON_FOOTPRINT)) {
Nutriments.Nutriment carbonFootprintNutriment = nutriments.get(Nutriments.CARBON_FOOTPRINT);
Nutriments.Nutriment carbonFootprintNutriment = nutriments.get(Nutriments.CARBON_FOOTPRINT);
if (carbonFootprintNutriment != null) {
binding.textCarbonFootprint.setText(bold(getString(R.string.textCarbonFootprint)));
binding.textCarbonFootprint.append(carbonFootprintNutriment.getFor100gInUnits());
binding.textCarbonFootprint.append(carbonFootprintNutriment.getUnit());
Expand Down
Expand Up @@ -32,10 +32,7 @@
import android.view.View;
import android.view.ViewGroup;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabsIntent;
Expand Down Expand Up @@ -92,47 +89,49 @@

public class IngredientsProductFragment extends BaseFragment implements IIngredientsProductPresenter.View {
public static final Pattern INGREDIENT_PATTERN = Pattern.compile("[\\p{L}\\p{Nd}(),.-]+");
private FragmentIngredientsProductBinding binding;
private AllergenNameDao mAllergenNameDao;
private OpenFoodAPIClient client;
private String mUrlImage;
private ProductState activityProductState;
private String barcode;
private SendProduct mSendProduct;
private WikiDataApiClient wikidataClient;
private FragmentIngredientsProductBinding binding;
private OpenFoodAPIClient client;
private CustomTabActivityHelper customTabActivityHelper;
private CustomTabsIntent customTabsIntent;
private IIngredientsProductPresenter.Actions presenter;
private boolean extractIngredients = false;
private boolean sendUpdatedIngredientsImage = false;
private final CompositeDisposable disp = new CompositeDisposable();
private boolean ingredientExtracted = false;
/**
* boolean to determine if image should be loaded or not
**/
private boolean isLowBatteryMode = false;
private AllergenNameDao mAllergenNameDao;
private SendProduct mSendProduct;
private String mUrlImage;
private final ActivityResultLauncher<Product> performOCRLauncher = registerForActivityResult(new ProductEditActivity.EditProductPerformOCR(), result -> {
if (result) {
onRefresh();
}
});
private PhotoReceiverHandler photoReceiverHandler;
ActivityResultLauncher<Product> productActivityResultLauncher = registerForActivityResult(
private IIngredientsProductPresenter.Actions presenter;
private boolean sendUpdatedIngredientsImage = false;
private final ActivityResultLauncher<Void> loginLauncher = registerForActivityResult(
new LoginActivity.LoginContract(),
result -> ProductEditActivity.start(getContext(),
activityProductState,
sendUpdatedIngredientsImage,
ingredientExtracted));
private final ActivityResultLauncher<Product> updateImagesLauncher = registerForActivityResult(
new ProductEditActivity.EditProductSendUpdatedImg(),
(ActivityResultCallback<Boolean>) result -> {
result -> {
if (result) {
onRefresh();
}
});
ActivityResultLauncher<Void> loginActivityResultLauncher = registerForActivityResult(
new LoginActivity.LoginContract(),
(ActivityResultCallback<Boolean>) result -> {
ProductEditActivity.start(getContext(),
activityProductState,
sendUpdatedIngredientsImage,
extractIngredients);
});

private WikiDataApiClient wikidataClient;

@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
customTabActivityHelper = new CustomTabActivityHelper();
customTabsIntent = CustomTabsHelper.getCustomTabsIntent(getContext(), customTabActivityHelper.getSession());
customTabsIntent = CustomTabsHelper.getCustomTabsIntent(requireContext(), customTabActivityHelper.getSession());

activityProductState = FragmentUtils.requireStateFromArguments(this);
}
Expand Down Expand Up @@ -445,7 +444,7 @@ public void changeIngImage() {
} else {
activityProductState = FragmentUtils.getStateFromArguments(this);
if (activityProductState != null) {
productActivityResultLauncher.launch(activityProductState.getProduct());
updateImagesLauncher.launch(activityProductState.getProduct());
}
}
}
Expand Down Expand Up @@ -494,18 +493,14 @@ void novaMethodLinkDisplay() {
}

public void extractIngredients() {
extractIngredients = true;
ingredientExtracted = true;
final SharedPreferences settings = requireActivity().getSharedPreferences("login", 0);
final String login = settings.getString("user", "");
if (login.isEmpty()) {
showSignInDialog();
} else {
activityProductState = FragmentUtils.requireStateFromArguments(this);
registerForActivityResult(new ProductEditActivity.EditProductPerformOCR(), result -> {
if (result) {
onRefresh();
}
}).launch(activityProductState.getProduct());
performOCRLauncher.launch(activityProductState.getProduct());
}
}

Expand All @@ -515,7 +510,7 @@ private void showSignInDialog() {
.positiveText(R.string.txtSignIn)
.negativeText(R.string.dialog_cancel)
.onPositive((dialog, which) -> {
loginActivityResultLauncher.launch(null);
loginLauncher.launch(null);
dialog.dismiss();
})
.onNegative((dialog, which) -> dialog.dismiss())
Expand Down
Expand Up @@ -34,7 +34,6 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -121,23 +120,38 @@ public class SummaryProductFragment extends BaseFragment implements CustomTabAct
private static final int EDIT_PRODUCT_AFTER_LOGIN = 1;
private static final int EDIT_PRODUCT_NUTRITION_AFTER_LOGIN = 3;
private static final int EDIT_REQUEST_CODE = 2;
private OpenFoodAPIClient client;
private WikiDataApiClient wikidataCLient;
private AnnotationAnswer annotation;
private String barcode;
private FragmentSummaryProductBinding binding;
private OpenFoodAPIClient client;
private CustomTabActivityHelper customTabActivityHelper;
private CustomTabsIntent customTabsIntent;
private CompositeDisposable disp;
private boolean hasCategoryInsightQuestion = false;
private String insightId;
private AnnotationAnswer annotation;
ActivityResultLauncher<Void> loginActivityResultLauncher = registerForActivityResult(
//boolean to determine if image should be loaded or not
private boolean isLowBatteryMode = false;
private TagDao mTagDao;
private String mUrlImage;
private Uri nutritionScoreUri;
private PhotoReceiverHandler photoReceiverHandler;
private ISummaryProductPresenter.Actions presenter;
private Product product;
private Question productQuestion = null;
private final ActivityResultLauncher<Void> loginLauncher = registerForActivityResult(
new LoginActivity.LoginContract(),
(ActivityResultCallback<Boolean>) isLoggedIn -> {
isLoggedIn -> {
if (isLoggedIn) {
processInsight(insightId, annotation);
}
});
private ProductState productState;
private boolean sendOther = false;
//boolean to determine if category prompt should be shown
private boolean showCategoryPrompt = false;
//boolean to determine if nutrient prompt should be shown
private boolean showNutrientPrompt = false;
private WikiDataApiClient wikidataCLient;

private void onImageListenerComplete() {
binding.uploadingImageProgress.setVisibility(GONE);
Expand All @@ -160,22 +174,6 @@ private void onImageListenerError(Throwable error) {
Toast.makeText(context, error.getMessage(), Toast.LENGTH_SHORT).show();
}

//boolean to determine if image should be loaded or not
private boolean isLowBatteryMode = false;
private TagDao mTagDao;
private String mUrlImage;
private Uri nutritionScoreUri;
private PhotoReceiverHandler photoReceiverHandler;
private ISummaryProductPresenter.Actions presenter;
private Product product;
private Question productQuestion = null;
private boolean sendOther = false;
//boolean to determine if category prompt should be shown
private boolean showCategoryPrompt = false;
//boolean to determine if nutrient prompt should be shown
private boolean showNutrientPrompt = false;
private ProductState productState;

@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
Expand Down Expand Up @@ -471,6 +469,7 @@ private void refreshScoresLayout() {
if (binding.novaGroup.getVisibility() == GONE &&
binding.co2Icon.getVisibility() == GONE &&
binding.imageGrade.getVisibility() == GONE &&
binding.ecoscoreIcon.getVisibility() == GONE &&
binding.addNutriscorePrompt.getVisibility() == GONE) {
binding.scoresLayout.setVisibility(GONE);
} else {
Expand Down Expand Up @@ -690,7 +689,7 @@ public void sendProductInsights(String insightId, AnnotationAnswer annotation) {
.title(getString(R.string.sign_in_to_answer))
.positiveText(getString(R.string.sign_in_or_register))
.onPositive((dialog, which) -> {
loginActivityResultLauncher.launch(null);
loginLauncher.launch(null);
dialog.dismiss();
})
.neutralText(R.string.dialog_cancel)
Expand Down
Expand Up @@ -23,6 +23,7 @@
import android.provider.Settings;
import android.view.View;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -54,6 +55,28 @@ public abstract class BaseFragment extends Fragment implements SwipeRefreshLayou
* an image width can't be less than 640. See https://github.com/openfoodfacts/openfoodfacts-server/blob/5bee6b8d3cad19bedd7e4194848682805b90728c/lib/ProductOpener/Images.pm#L577
*/
public static final int MIN_CROP_RESULT_WIDTH_ACCEPTED_BY_OFF = 640;
private final ActivityResultLauncher<String[]> cameraPermissionRequestLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(),
results -> {
if (!Utils.isAllGranted(results)) {
// Tell the user how to give permission
new MaterialDialog.Builder(requireActivity())
.title(R.string.permission_title)
.content(R.string.permission_denied)
.negativeText(R.string.txtNo)
.positiveText(R.string.txtYes)
.onPositive((dialog, which) -> {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", requireActivity().getPackageName(), null);
intent.setData(uri);
startActivity(intent);
})
.show();
} else {
// Callback
doOnPhotosPermissionGranted();
}
});
private OnRefreshListener refreshListener;
private SwipeRefreshLayout swipeRefreshLayout;

Expand Down Expand Up @@ -106,27 +129,7 @@ protected void doChooseOrTakePhotos(String title) {
return;
}
// Ask for permissions
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), results -> {
if (!Utils.isAllGranted(results)) {
// Tell the user how to give permission
new MaterialDialog.Builder(requireActivity())
.title(R.string.permission_title)
.content(R.string.permission_denied)
.negativeText(R.string.txtNo)
.positiveText(R.string.txtYes)
.onPositive((dialog, which) -> {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", requireActivity().getPackageName(), null);
intent.setData(uri);
startActivity(intent);
})
.show();
} else {
// Callback
doOnPhotosPermissionGranted();
}
}).launch(new String[]{CAMERA});
cameraPermissionRequestLauncher.launch(new String[]{CAMERA});
}

protected void doOnPhotosPermissionGranted() {
Expand Down

0 comments on commit c2069a3

Please sign in to comment.