diff --git a/app/src/main/java/info/nightscout/androidaps/db/Food.java b/app/src/main/java/info/nightscout/androidaps/db/Food.java index f3f7071cb5..9824d1964b 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Food.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Food.java @@ -16,7 +16,7 @@ import info.nightscout.utils.JsonHelper; * Created by mike on 20.09.2017. */ -@DatabaseTable(tableName = Food.TABLE_FOODS) +@DatabaseTable(tableName = Food.TABLE_FOODS, daoClass=FoodDao.class) public class Food { private static Logger log = LoggerFactory.getLogger(Food.class); diff --git a/app/src/main/java/info/nightscout/androidaps/db/FoodService.java b/app/src/main/java/info/nightscout/androidaps/db/FoodService.java index b753764341..56fd4b3a4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/FoodService.java +++ b/app/src/main/java/info/nightscout/androidaps/db/FoodService.java @@ -32,6 +32,10 @@ public class FoodService extends OrmLiteBaseService { private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor(); private static ScheduledFuture scheduledFoodEventPost = null; + public FoodService() { + this.onCreate(); + } + public FoodDao getDao() { return FoodDao.with(this.getConnectionSource()); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java index f8042f3de5..bd3cb9fe6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Set; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -59,27 +60,10 @@ public class FoodFragment extends SubscriberFragment { 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 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { - log.info("Strartup..."); - JSONObject food = new JSONObject(json); - DataServiceManager.getInstance().getFoodService().createFoodFromJsonIfNotExists(food); - View view = inflater.inflate(R.layout.food_fragment, container, false); filter = (EditText) view.findViewById(R.id.food_filter); clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter); @@ -168,16 +152,15 @@ public class FoodFragment extends SubscriberFragment { } void fillCategories() { - categories = new ArrayList<>(); + Set catSet = new HashSet<>(); for (Food f : unfiltered) { if (f.category != null && !f.category.equals("")) - categories.add(f.category); + catSet.add(f.category); } // make it unique - categories = new ArrayList<>(new HashSet<>(categories)); - + categories = new ArrayList<>(catSet); categories.add(0, MainApp.sResources.getString(R.string.none)); ArrayAdapter adapterCategories = new ArrayAdapter<>(getContext(), @@ -187,19 +170,19 @@ public class FoodFragment extends SubscriberFragment { void fillSubcategories() { String categoryFilter = category.getSelectedItem().toString(); - subcategories = new ArrayList<>(); + + Set subCatSet = new HashSet<>(); if (!categoryFilter.equals(EMPTY)) { for (Food f : unfiltered) { if (f.category != null && f.category.equals(categoryFilter)) if (f.subcategory != null && !f.subcategory.equals("")) - subcategories.add(f.subcategory); + subCatSet.add(f.subcategory); } } // make it unique - subcategories = new ArrayList<>(new HashSet<>(subcategories)); - + subcategories = new ArrayList<>(subCatSet); subcategories.add(0, MainApp.sResources.getString(R.string.none)); ArrayAdapter adapterSubcategories = new ArrayAdapter<>(getContext(),