Search in sources :

Example 6 with RecipeList

use of com.se491.chef_ly.model.RecipeList 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()) {
        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());
}
Also used : Paint(android.graphics.Paint) RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Example 7 with RecipeList

use of com.se491.chef_ly.model.RecipeList 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);
    }
}
Also used : RecipeList(com.se491.chef_ly.model.RecipeList) BaseAdapter(android.widget.BaseAdapter) RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Example 8 with RecipeList

use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.

the class ListViewFragment method onSaveInstanceState.

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    RecipeList r = ((RecipeAdapter) listView.getAdapter()).getRecipes();
    outState.putString("title", title);
    outState.putString("pageNum", pageNum);
    outState.putParcelable(title, r);
}
Also used : RecipeList(com.se491.chef_ly.model.RecipeList)

Example 9 with RecipeList

use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.

the class ListViewFragment method setList.

public void setList(RecipeList newList, boolean goToTop) {
    list.clear();
    for (RecipeInformation r : newList) {
        list.add(r);
    }
    ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
    if (goToTop) {
        listView.setSelectionAfterHeaderView();
    }
}
Also used : BaseAdapter(android.widget.BaseAdapter) RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Example 10 with RecipeList

use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.

the class RecipeListActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String user = extras.getString("name");
    RecipeList list = extras.getParcelable("recipeList");
    boolean isSearch = extras.getBoolean("isSearch");
    if (isSearch) {
        String search = extras.getString("search");
        queryString = search;
        server.updateSearch(search);
        server.updateListAdapter(list);
    } else if (list != null) {
        serverRecipes = list;
        server.updateListAdapter(serverRecipes);
    } else {
        Log.d(TAG, "Error - No recipes loaded from server");
        Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
    //TODO handle case where no recipes are retrieved from server
    }
}
Also used : Bundle(android.os.Bundle) RecipeList(com.se491.chef_ly.model.RecipeList) Intent(android.content.Intent)

Aggregations

RecipeList (com.se491.chef_ly.model.RecipeList)8 RecipeInformation (com.se491.chef_ly.model.RecipeInformation)4 Intent (android.content.Intent)3 BaseAdapter (android.widget.BaseAdapter)3 Paint (android.graphics.Paint)2 Bundle (android.os.Bundle)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RequestMethod (com.se491.chef_ly.http.RequestMethod)2 IOException (java.io.IOException)2 Type (java.lang.reflect.Type)2 SharedPreferences (android.content.SharedPreferences)1 Parcel (android.os.Parcel)1 Parcelable (android.os.Parcelable)1 NavigationView (android.support.design.widget.NavigationView)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 ViewPager (android.support.v4.view.ViewPager)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 SearchView (android.support.v7.widget.SearchView)1