Make food working, adopt category selection slightly
This commit is contained in:
parent
a78652f737
commit
7d669fbeb8
3 changed files with 13 additions and 26 deletions
|
@ -16,7 +16,7 @@ import info.nightscout.utils.JsonHelper;
|
||||||
* Created by mike on 20.09.2017.
|
* Created by mike on 20.09.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@DatabaseTable(tableName = Food.TABLE_FOODS)
|
@DatabaseTable(tableName = Food.TABLE_FOODS, daoClass=FoodDao.class)
|
||||||
public class Food {
|
public class Food {
|
||||||
private static Logger log = LoggerFactory.getLogger(Food.class);
|
private static Logger log = LoggerFactory.getLogger(Food.class);
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,10 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static ScheduledFuture<?> scheduledFoodEventPost = null;
|
private static ScheduledFuture<?> scheduledFoodEventPost = null;
|
||||||
|
|
||||||
|
public FoodService() {
|
||||||
|
this.onCreate();
|
||||||
|
}
|
||||||
|
|
||||||
public FoodDao getDao() {
|
public FoodDao getDao() {
|
||||||
return FoodDao.with(this.getConnectionSource());
|
return FoodDao.with(this.getConnectionSource());
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -59,27 +60,10 @@ public class FoodFragment extends SubscriberFragment {
|
||||||
|
|
||||||
final String EMPTY = MainApp.sResources.getString(R.string.none);
|
final String EMPTY = MainApp.sResources.getString(R.string.none);
|
||||||
|
|
||||||
private static final String json = " {\n" +
|
|
||||||
" \"_id\": \"551ee3ad368e06e80856e6a9\",\n" +
|
|
||||||
" \"type\": \"food\",\n" +
|
|
||||||
" \"category\": \"Category\",\n" +
|
|
||||||
" \"subcategory\": \"Subcatgory\",\n" +
|
|
||||||
" \"name\": \"Name\",\n" +
|
|
||||||
" \"portion\": 250,\n" +
|
|
||||||
" \"carbs\": 12,\n" +
|
|
||||||
" \"gi\": 1,\n" +
|
|
||||||
" \"created_at\": \"2015-04-14T06:59:16.500Z\",\n" +
|
|
||||||
" \"unit\": \"ml\"\n" +
|
|
||||||
" }";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
try {
|
||||||
log.info("Strartup...");
|
|
||||||
JSONObject food = new JSONObject(json);
|
|
||||||
DataServiceManager.getInstance().getFoodService().createFoodFromJsonIfNotExists(food);
|
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.food_fragment, container, false);
|
View view = inflater.inflate(R.layout.food_fragment, container, false);
|
||||||
filter = (EditText) view.findViewById(R.id.food_filter);
|
filter = (EditText) view.findViewById(R.id.food_filter);
|
||||||
clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter);
|
clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter);
|
||||||
|
@ -168,16 +152,15 @@ public class FoodFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillCategories() {
|
void fillCategories() {
|
||||||
categories = new ArrayList<>();
|
Set<CharSequence> catSet = new HashSet<>();
|
||||||
|
|
||||||
for (Food f : unfiltered) {
|
for (Food f : unfiltered) {
|
||||||
if (f.category != null && !f.category.equals(""))
|
if (f.category != null && !f.category.equals(""))
|
||||||
categories.add(f.category);
|
catSet.add(f.category);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make it unique
|
// make it unique
|
||||||
categories = new ArrayList<>(new HashSet<>(categories));
|
categories = new ArrayList<>(catSet);
|
||||||
|
|
||||||
categories.add(0, MainApp.sResources.getString(R.string.none));
|
categories.add(0, MainApp.sResources.getString(R.string.none));
|
||||||
|
|
||||||
ArrayAdapter<CharSequence> adapterCategories = new ArrayAdapter<>(getContext(),
|
ArrayAdapter<CharSequence> adapterCategories = new ArrayAdapter<>(getContext(),
|
||||||
|
@ -187,19 +170,19 @@ public class FoodFragment extends SubscriberFragment {
|
||||||
|
|
||||||
void fillSubcategories() {
|
void fillSubcategories() {
|
||||||
String categoryFilter = category.getSelectedItem().toString();
|
String categoryFilter = category.getSelectedItem().toString();
|
||||||
subcategories = new ArrayList<>();
|
|
||||||
|
Set<CharSequence> subCatSet = new HashSet<>();
|
||||||
|
|
||||||
if (!categoryFilter.equals(EMPTY)) {
|
if (!categoryFilter.equals(EMPTY)) {
|
||||||
for (Food f : unfiltered) {
|
for (Food f : unfiltered) {
|
||||||
if (f.category != null && f.category.equals(categoryFilter))
|
if (f.category != null && f.category.equals(categoryFilter))
|
||||||
if (f.subcategory != null && !f.subcategory.equals(""))
|
if (f.subcategory != null && !f.subcategory.equals(""))
|
||||||
subcategories.add(f.subcategory);
|
subCatSet.add(f.subcategory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// make it unique
|
// make it unique
|
||||||
subcategories = new ArrayList<>(new HashSet<>(subcategories));
|
subcategories = new ArrayList<>(subCatSet);
|
||||||
|
|
||||||
subcategories.add(0, MainApp.sResources.getString(R.string.none));
|
subcategories.add(0, MainApp.sResources.getString(R.string.none));
|
||||||
|
|
||||||
ArrayAdapter<CharSequence> adapterSubcategories = new ArrayAdapter<>(getContext(),
|
ArrayAdapter<CharSequence> adapterSubcategories = new ArrayAdapter<>(getContext(),
|
||||||
|
|
Loading…
Reference in a new issue