Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: brand autosuggest added #3883

Merged
merged 3 commits into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Expand Up @@ -370,7 +370,7 @@ kapt {
}
}

greendao { schemaVersion(21) }
greendao { schemaVersion(22) }



Expand Down
Expand Up @@ -58,6 +58,8 @@ import openfoodfacts.github.scrachx.openfood.images.ProductImage
import openfoodfacts.github.scrachx.openfood.models.Product
import openfoodfacts.github.scrachx.openfood.models.ProductImageField
import openfoodfacts.github.scrachx.openfood.models.entities.OfflineSavedProduct
import openfoodfacts.github.scrachx.openfood.models.entities.brand.BrandName
import openfoodfacts.github.scrachx.openfood.models.entities.brand.BrandNameDao
import openfoodfacts.github.scrachx.openfood.models.entities.category.CategoryName
import openfoodfacts.github.scrachx.openfood.models.entities.category.CategoryNameDao
import openfoodfacts.github.scrachx.openfood.models.entities.country.CountryName
Expand Down Expand Up @@ -96,6 +98,7 @@ class ProductEditOverviewFragment : ProductEditFragment() {
private val countries = mutableListOf<String>()
private val labels = mutableListOf<String>()
private val stores = mutableListOf<String>()
private val brands = mutableListOf<String>()

private var barcode: String? = null
private var editionMode = false
Expand Down Expand Up @@ -480,6 +483,7 @@ class ProductEditOverviewFragment : ProductEditFragment() {
val asyncSessionLabels = OFFApplication.daoSession.startAsyncSession()
val asyncSessionCategories = OFFApplication.daoSession.startAsyncSession()
val asyncSessionStores = OFFApplication.daoSession.startAsyncSession()
val asyncSessionBrands = OFFApplication.daoSession.startAsyncSession()

asyncSessionCountries.queryList(OFFApplication.daoSession.countryNameDao.queryBuilder()
.where(CountryNameDao.Properties.LanguageCode.eq(appLanguageCode))
Expand All @@ -497,6 +501,10 @@ class ProductEditOverviewFragment : ProductEditFragment() {
.where(StoreNameDao.Properties.LanguageCode.eq(appLanguageCode))
.orderDesc(StoreNameDao.Properties.Name).build())

asyncSessionBrands.queryList(OFFApplication.daoSession.brandNameDao.queryBuilder()
.where(BrandNameDao.Properties.LanguageCode.eq(appLanguageCode))
.orderDesc(BrandNameDao.Properties.Name).build())

asyncSessionCountries.listenerMainThread = AsyncOperationListener { operation ->
countries.clear()
(operation.result as List<CountryName>).mapTo(countries) { it.name }
Expand Down Expand Up @@ -536,6 +544,15 @@ class ProductEditOverviewFragment : ProductEditFragment() {
stores
))
}
asyncSessionBrands.listenerMainThread = AsyncOperationListener { operation ->
brands.clear()
(operation.result as List<BrandName>).mapTo(brands) { it.name }
binding.brand.setAdapter(ArrayAdapter(
requireContext(),
android.R.layout.simple_dropdown_item_1line,
brands
))
}

if (isFlavors(OBF)) {
binding.periodOfTimeAfterOpeningTil.visibility = View.VISIBLE
Expand Down
Expand Up @@ -65,6 +65,7 @@ class SplashController internal constructor(
activateDownload(ANALYSIS_TAG_CONFIG, OFF, OBF, OPFF)
activateDownload(STATES, OFF, OBF, OPFF)
activateDownload(STORES, OFF, OBF, OPFF)
activateDownload(BRANDS, OFF, OBF)

//first run ever off this application, whatever the version
val firstRun = settings.getBoolean("firstRun", true)
Expand Down
Expand Up @@ -47,7 +47,8 @@ class LoadTaxonomiesWorker(appContext: Context, workerParams: WorkerParameters)
ProductRepository.reloadAdditivesFromServer().ignoreElement(),
ProductRepository.reloadCategoriesFromServer().ignoreElement(),
ProductRepository.reloadStatesFromServer().ignoreElement(),
ProductRepository.reloadStoresFromServer().ignoreElement()
ProductRepository.reloadStoresFromServer().ignoreElement(),
ProductRepository.reloadBrandsFromServer().ignoreElement()
)
return Completable.merge(syncObservables)
.toSingle {
Expand Down
@@ -0,0 +1,184 @@
package openfoodfacts.github.scrachx.openfood.models.entities.brand;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.JoinProperty;
import org.greenrobot.greendao.annotation.Keep;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Unique;

import java.util.List;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import openfoodfacts.github.scrachx.openfood.models.DaoSession;


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

@Id(autoincrement = true)
private Long id;

@Unique
private String tag;

@Unique
private String wikiDataId;

private Boolean isWikiDataIdPresent;

@ToMany(joinProperties = {
@JoinProperty(name = "tag", referencedName = "brandTag")
})
private List<BrandName> names;

/** Used to resolve relations */
@Generated(hash = 2040040024)
private transient DaoSession daoSession;

/** Used for active entity operations. */
@Generated(hash = 1427825859)
private transient BrandDao myDao;

public Brand(){
}

@Keep
public Brand(String tag, List<BrandName> names, String wikiDataId) {
this.tag = tag;
this.names = names;
this.wikiDataId = wikiDataId;
this.isWikiDataIdPresent = true;
}

@Keep
public Brand(String tag, List<BrandName> names) {
this.tag = tag;
this.names = names;
this.isWikiDataIdPresent = false;
}

@Generated(hash = 435873667)
public Brand(Long id, String tag, String wikiDataId,
Boolean isWikiDataIdPresent) {
this.id = id;
this.tag = tag;
this.wikiDataId = wikiDataId;
this.isWikiDataIdPresent = isWikiDataIdPresent;
}

public Long getId() {
return id;
}

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

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

public String getWikiDataId() {
return wikiDataId;
}

public void setWikiDataId(String wikiDataId) {
this.wikiDataId = wikiDataId;
}

public Boolean getWikiDataIdPresent() {
return isWikiDataIdPresent;
}

public void setWikiDataIdPresent(Boolean wikiDataIdPresent) {
isWikiDataIdPresent = wikiDataIdPresent;
}

public Boolean getIsWikiDataIdPresent() {
return this.isWikiDataIdPresent;
}

public void setIsWikiDataIdPresent(Boolean isWikiDataIdPresent) {
this.isWikiDataIdPresent = isWikiDataIdPresent;
}

/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1714612506)
public List<BrandName> getNames() {
if (names == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
BrandNameDao targetDao = daoSession.getBrandNameDao();
List<BrandName> namesNew = targetDao._queryBrand_Names(tag);
synchronized (this) {
if (names == null) {
names = namesNew;
}
}
}
return names;
}

/** Resets a to-many relationship, making the next get call to query for a fresh result. */
@Generated(hash = 1832659617)
public synchronized void resetNames() {
names = null;
}

/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 128553479)
public void delete() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.delete(this);
}

/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 1942392019)
public void refresh() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.refresh(this);
}

/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 713229351)
public void update() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.update(this);
}

/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 538692092)
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
myDao = daoSession != null ? daoSession.getBrandDao() : null;
}

}