Skip to content

Commit

Permalink
minor sonarqube fixes (#2742)
Browse files Browse the repository at this point in the history
* minor sonarqube fixes

* remove jsoup dependencies

* + remove fab dependency
+ refactor barcode validator method

* + add code style settings in Version Control to be sure everyone is using it.
+ add comments about code formatting in CONTRIBUTING.md

* rename method name
  • Loading branch information
deniger authored and teolemon committed Jun 18, 2019
1 parent aaea578 commit 32c130f
Show file tree
Hide file tree
Showing 22 changed files with 483 additions and 310 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.gradle
/local.properties
/.idea
/.idea/*
!/.idea/codeStyles
.DS_Store
/build
*.iml
/captures
/captures
179 changes: 179 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Join the development
* Before you join development, please set up the project on your local machine, run it and go through the application completely. Press on any button you can find and see where it leads to. Explore.You'll be more familiar with what is where and might even get some cool ideas on how to improve various aspects of the app.
* If you would like to work on an issue, drop in a comment at the issue. If it is already assigned to someone, but there is no sign of any work being done, please free to drop in a comment so that the issue can be assigned to you if the previous assignee has dropped it entirely.
* Ensure you use OpenFoodFact code style defined in [.idea folder](.idea). It should be automatically used by your IDE ( Android Studio, IntelliJ)
* **Review your code formatting, check classes imports and remove commented code lines and before creating a Pull Request**

# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, or the official [slack channel](https://slack-ssl-openfoodfacts.herokuapp.com/).

## Pull Request Process

1. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
2. Check that there are no conflicts and your request passes [Travis](https://travis-ci.org/openfoodfacts/openfoodfacts-androidapp) build. Check the log of the pass test if it fails the build.
3. Give the description of the issue that you want to resolve in the pull request message. The format of the commit message to be fixed - **Fixes #[issue number] [Description of the issue]** Example: **Fixes #529: Add toast warning in `MainActivity.java`**
4. Wait for the maintainers to review your pull request and do the changes if requested.
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ We use the following libraries, and we're not closed to changes where relevant :
[code-mc/loadtoast](https://github.com/code-mc/loadtoast),
[dm77/barcodescanner](https://github.com/dm77/barcodescanner),
[koush/ion](https://github.com/koush/ion),
[jsoup](https://jsoup.org/),
[satyan/sugar](https://github.com/satyan/sugar),
[afollestad/material-dialogs](https://github.com/afollestad/material-dialogs),
[jjhesk/LoyalNativeSlider](https://github.com/jjhesk/LoyalNativeSlider),
Expand Down
5 changes: 0 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-databind:$rootProject.jacksonVersion"
implementation "com.fasterxml.jackson.core:jackson-annotations:$rootProject.jacksonVersion"

// compile 'io.rest-assured:json-path:3.0.7'

//CSV Serialization/Deserialization
implementation "com.opencsv:opencsv:$rootProject.openCsvVersion"
Expand All @@ -217,8 +216,6 @@ dependencies {
}
implementation "com.google.zxing:core:$rootProject.zxingCoreVersion"

//HTML Dom
implementation "org.jsoup:jsoup:$rootProject.htmlDomVersion"

//Apache
implementation "org.apache.commons:commons-collections4:$rootProject.apacheCollectionsVersion"
Expand Down Expand Up @@ -246,8 +243,6 @@ dependencies {
implementation "com.mikepenz:fastadapter-commons:$rootProject.fastAdapterCommons"
implementation "com.squareup.retrofit2:converter-scalars:$rootProject.converterScalars"

//UI Component : Fab
implementation "com.github.clans:fab:$rootProject.fabVersion"

//UI Component : Font Icons
implementation "com.mikepenz:iconics-core:$rootProject.fontIconCoreVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import openfoodfacts.github.scrachx.openfood.utils.Utils;
import openfoodfacts.github.scrachx.openfood.views.AddProductActivity;
import openfoodfacts.github.scrachx.openfood.views.OFFApplication;
import org.apache.commons.lang3.StringUtils;
import org.greenrobot.greendao.async.AsyncSession;
import org.jsoup.helper.StringUtil;

import java.io.File;
import java.net.URI;
Expand Down Expand Up @@ -384,7 +384,7 @@ public void getAllDetails(Map<String, String> targetMap) {
String lc = (!languageCode.isEmpty()) ? languageCode : "en";
targetMap.put(PARAM_INGREDIENTS + "_" + lc, ingredients.getText().toString());
List<String> list = traces.getChipValues();
String string = StringUtil.join(list, ",");
String string = StringUtils.join(list, ",");
targetMap.put(PARAM_TRACES.substring(4), string);
}
}
Expand All @@ -402,7 +402,7 @@ public void getDetails() {
}
if (!traces.getChipValues().isEmpty()) {
List<String> list = traces.getChipValues();
String string = StringUtil.join(list, ",");
String string = StringUtils.join(list, ",");
((AddProductActivity) activity).addToMap(PARAM_TRACES, string);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import io.reactivex.schedulers.Schedulers;
import openfoodfacts.github.scrachx.openfood.BuildConfig;
import openfoodfacts.github.scrachx.openfood.R;
import openfoodfacts.github.scrachx.openfood.images.PhotoReceiver;
import openfoodfacts.github.scrachx.openfood.images.ProductImage;
import openfoodfacts.github.scrachx.openfood.jobs.FileDownloader;
import openfoodfacts.github.scrachx.openfood.images.PhotoReceiver;
import openfoodfacts.github.scrachx.openfood.jobs.PhotoReceiverHandler;
import openfoodfacts.github.scrachx.openfood.models.*;
import openfoodfacts.github.scrachx.openfood.network.CommonApiManager;
Expand All @@ -51,7 +51,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
import org.greenrobot.greendao.async.AsyncSession;
import org.jsoup.helper.StringUtil;

import java.io.File;
import java.net.URI;
Expand Down Expand Up @@ -786,7 +785,7 @@ private void chipifyAllUnterminatedTokens() {

private String getValues(NachoTextView nachoTextView) {
List<String> list = nachoTextView.getChipValues();
return StringUtil.join(list, ",");
return StringUtils.join(list, ",");
}

@OnClick(R.id.section_manufacturing_details)
Expand Down Expand Up @@ -841,7 +840,7 @@ void searchProductLink() {
String url = "https://www.google.com/search?q=" + code;
if (!brand.getChipAndTokenValues().isEmpty()) {
List<String> brandNames = brand.getChipAndTokenValues();
url = url + " " + StringUtil.join(brandNames, " ");
url = url + " " + StringUtils.join(brandNames, " ");
}
if (!name.getText().toString().isEmpty()) {
url = url + " " + name.getText().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstan
mRvAllergens.setHasFixedSize(true);
mAdapter.registerAdapterDataObserver(mDataObserver);
mDataObserver.onChanged();
}, Throwable::printStackTrace);
}, e->Log.e(AllergensAlertFragment.class.getSimpleName(),"getAllergensByEnabledAndLanguageCode",e));

productRepository.getAllergensByLanguageCode(language)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(allergens -> {
mAllergensFromDao = allergens;
}, Throwable::printStackTrace);
}, e->Log.e(AllergensAlertFragment.class.getSimpleName(),"getAllergensByLanguageCode",e));


currentView = view;
Expand Down Expand Up @@ -190,14 +190,14 @@ private void updateAllergenDao() {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(allergens -> {
mAllergensEnabled = allergens;
}, Throwable::printStackTrace);
}, e->Log.e(AllergensAlertFragment.class.getSimpleName(),"getAllergensByEnabledAndLanguageCode",e));

productRepository.getAllergensByLanguageCode(language)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(allergens -> {
mAllergensFromDao = allergens;
}, Throwable::printStackTrace);
}, e->Log.e(AllergensAlertFragment.class.getSimpleName(),"getAllergensByLanguageCode",e));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import openfoodfacts.github.scrachx.openfood.R;
import openfoodfacts.github.scrachx.openfood.network.OpenFoodAPIClient;
import openfoodfacts.github.scrachx.openfood.utils.NavigationDrawerListener.NavigationDrawerType;
import openfoodfacts.github.scrachx.openfood.utils.ProductUtils;
import openfoodfacts.github.scrachx.openfood.utils.Utils;
import openfoodfacts.github.scrachx.openfood.views.listeners.BottomNavigationListenerInstaller;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.checkdigit.EAN13CheckDigit;

import static openfoodfacts.github.scrachx.openfood.utils.NavigationDrawerListener.ITEM_SEARCH_BY_CODE;

Expand Down Expand Up @@ -65,8 +65,7 @@ protected void onSearchBarcodeProduct() {
if (barcodeText.length() <= 2) {
displayToast(getResources().getString(R.string.txtBarcodeNotValid));
} else {
if (EAN13CheckDigit.EAN13_CHECK_DIGIT.isValid(barcodeText) && (!barcodeText.substring(0, 3).contains("977") || !barcodeText.substring(0, 3)
.contains("978") || !barcodeText.substring(0, 3).contains("979"))) {
if (ProductUtils.isBarcodeValid(barcodeText)) {
api.getProduct(mBarCodeText.getText().toString(), getActivity());
} else {
displayToast(getResources().getString(R.string.txtBarcodeNotValid));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package openfoodfacts.github.scrachx.openfood.utils;

import android.support.annotation.Nullable;
import openfoodfacts.github.scrachx.openfood.models.Product;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.checkdigit.EAN13CheckDigit;

public class ProductUtils {
public static final String DEFAULT_NUTRITION_SIZE = "100g";
Expand All @@ -13,4 +15,14 @@ private ProductUtils(){
public static boolean isPerServingInLiter(Product product) {
return StringUtils.containsIgnoreCase(product.getServingSize(), UnitUtils.UNIT_LITER);
}

/**
*
* @param barcode
* @return true if valid according to {@link EAN13CheckDigit#EAN13_CHECK_DIGIT} and if the barecode doesn't start will 977/978/979 (Book barcode)
*/
public static boolean isBarcodeValid(@Nullable String barcode){
return barcode!=null && (EAN13CheckDigit.EAN13_CHECK_DIGIT.isValid(barcode) && (!barcode.substring(0, 3).contains("977") || !barcode.substring(0, 3)
.contains("978") || !barcode.substring(0, 3).contains("979")));
}
}
Loading

0 comments on commit 32c130f

Please sign in to comment.