Created
May 21, 2014 19:09
-
-
Save RynanBear/622fb448048ec3851906 to your computer and use it in GitHub Desktop.
Gist for Dan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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