use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class RecipeDetailActivity method onStart.
/*
private void textViewClicked() {
ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.my_switcher);
View currentView = switcher.getCurrentView();
//switcher.showNext(); //or switcher.showPrevious();
TextView viewText = (TextView) switcher.findViewById(R.id.directionView);
EditText editText = (EditText) findViewById(R.id.hidden_edit_view);
if (currentView instanceof EditText) {
//Save steps and prepare next view (Text view)
directionsForCooking = editText.getText().toString().split("\n");
StringBuilder sb = new StringBuilder();
int count = 1;
for (String s : directionsForCooking) {
sb.append(count);
sb.append(": ");
sb.append(s);
sb.append("\n");
directionsForCooking[count - 1] = s;
count++;
}
steps = sb.toString();
viewText.setText(steps);
}
else if (currentView instanceof TextView) {
// Prepare next view (Edit view)
String tmpSteps = implode("\n", directionsForCooking);
editText.setText(tmpSteps);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
switcher.showNext();
}
private static String implode(String separator, String... data) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length - 1; i++) {
//data.length - 1 => to not add separator at the end
if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on
sb.append(data[i]);
sb.append(separator);
}
}
sb.append(data[data.length - 1].trim());
return sb.toString();
}
*/
@Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
final String recipeID = intent.getStringExtra("recipe");
RecipeInformation result = intent.getParcelableExtra("recipeDetail");
if (result != null) {
recipeDetail = result;
setRecipeInfo();
} else if (// returns true if internet available
NetworkHelper.hasNetworkAccess(RecipeDetailActivity.this)) {
// register to listen the data
RequestMethod requestPackage = new RequestMethod();
requestPackage.setEndPoint(urlString + recipeID);
// or requestPackage.setMethod("POST");
requestPackage.setMethod("GET");
new AsyncTask<RequestMethod, Integer, Long>() {
String resp = "";
@Override
protected Long doInBackground(RequestMethod... params) {
for (RequestMethod r : params) {
try {
HttpConnection http = new HttpConnection();
resp = http.downloadFromFeed(r);
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
Type type;
type = new TypeToken<RecipeInformation>() {
}.getType();
recipeDetail = gson.fromJson(resp, type);
Log.d(TAG, recipeDetail.toString());
} catch (Exception e) {
// e.printStackTrace();
return -1L;
}
Log.d(TAG, resp);
}
return 1L;
}
@Override
protected void onPostExecute(Long aLong) {
super.onPostExecute(aLong);
setRecipeInfo();
}
}.execute(requestPackage);
} else {
// Toast.makeText(RecipeListActivity.this,"No Internet Connection",Toast.LENGTH_LONG).show();
Log.d(TAG, "No Internet Connection");
}
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class RecipeListActivity method onLoadFinished.
// LoaderManager callback method
@Override
public void onLoadFinished(Loader<RecipeList> loader, RecipeList data) {
int id = loader.getId();
if (id == FAVORTIESID) {
favoriteRecipes = data;
for (RecipeInformation r : favoriteRecipes) {
// favorites.add(r.getId());
r.setFavorite(true);
}
favs.updateListAdapter(favoriteRecipes);
} else if (id == queryString.hashCode()) {
spinner.setVisibility(View.GONE);
Log.d(TAG, " Recipe Search -> " + data.size());
if (data.size() > 0) {
// Collect all recipes so list can be redisplayed when search is closed
server.setList(data, true);
} else {
Log.d(TAG, "Error - No recipes loaded from server");
Toast.makeText(this, "Sorry we couldn't find any recipes", Toast.LENGTH_SHORT).show();
// TODO handle case where no recipes are retrieved from server
}
}
Log.d(TAG, "OnLoadFinished " + loader.getId());
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class ListViewFragment method setList.
public void setList(RecipeList newList, final boolean goToTop) {
list.clear();
for (RecipeInformation r : newList) {
list.add(r);
}
// If the list view is null just wait 100 ms to give it time to inflate
if (listView == null) {
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
if (goToTop) {
listView.setSelectionAfterHeaderView();
}
}
}, 100);
} else {
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
if (goToTop) {
listView.setSelectionAfterHeaderView();
}
}
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class ListViewFragment method updateListAdapter.
public void updateListAdapter(RecipeList newList) {
if (list == null) {
list = new RecipeList();
}
for (RecipeInformation r : newList) {
list.add(r);
}
if (listView != null) {
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
Log.d(TAG + "/" + title, "ListView updated " + title + " " + listView.getAdapter().getCount() + " list " + list.size());
// listView.setVisibility(View.VISIBLE);
}
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class ListViewFragment method removeFavorite.
public void removeFavorite(RecipeInformation r) {
int index = list.indexOf(r);
if (index > 0) {
list.get(index).setFavorite(false);
} else {
Log.d(TAG + "/" + title, "Remove Favorite index -> " + index);
for (RecipeInformation rec : list) {
Log.d(TAG + "/" + title, "ID -> " + rec.getId());
}
}
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
}
Aggregations