Skip to content

Instantly share code, notes, and snippets.

@RynanBear
Created May 21, 2014 19:09
Show Gist options
  • Save RynanBear/622fb448048ec3851906 to your computer and use it in GitHub Desktop.
Save RynanBear/622fb448048ec3851906 to your computer and use it in GitHub Desktop.
Gist for Dan
this.daoSession = GreenDAOSession.getInstance(super.getActivity());
// set the title label for the dialog
DateTimeFormatter fmt = DateTimeFormat.forPattern("E d MMM YYYY");
String label = "Add recipe to " + this.timesOfDate[timeOfDay] + " " + this.date.toString(fmt);
LayoutInflater inflater = getActivity().getLayoutInflater();
layout = inflater.inflate(R.layout.activity_recipe_select_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder
.setTitle(label)
.setView(layout)
.setPositiveButton(R.string.add_ingredient, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
RecipeSelectDialog.this.selectedRecipe =
(Recipe) RecipeSelectDialog.this.recipeSpinner.getSelectedItem();
RecipeSelectDialog.this.mRecipeSelectDialogInteractionListener
.onRecipeSelectDialogPositiveClick(RecipeSelectDialog.this);
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
RecipeSelectDialog.this.getDialog().cancel();
}
});
// get and set the selection of recipes
this.recipeSpinner = (Spinner) layout.findViewById(R.id.recipe_spinner);
this.recipeSpinner.setAdapter(new ArrayAdapter<Recipe>(
getActivity(),
android.R.layout.simple_spinner_dropdown_item,
this.daoSession.getRecipeDao().loadAll()
)
);
this.recipeListView = (ListView) layout.findViewById(R.id.recipe_list_view);
this.recipeListView.setAdapter(new RecipeDayAdapter(
getActivity(),
this.daoSession.getRecipeDao().queryRaw(
" INNER JOIN " + DayRecipeDao.TABLENAME + " DR ON T." + RecipeDao.Properties.Id.columnName + " = DR." + DayRecipeDao.Properties.RecipeId.columnName +
" INNER JOIN " + DayDao.TABLENAME + " D ON DR." + DayRecipeDao.Properties.DateId.columnName + " = D." + DayDao.Properties.Id.columnName +
" WHERE DATE(D.'" + DayDao.Properties.MyDate.columnName + "') = '" + date.toString(DateUsefulness.getDateTimeFormatter()) + "'" +
" AND DR." + DayRecipeDao.Properties.TimeOfDay.columnName + " = " + timeOfDay
)
));
return builder.create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment