Search in sources :

Example 6 with RecipeInformation

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

the class DatabaseHandler method getRecipes.

public ArrayList<RecipeInformation> getRecipes() {
    SQLiteDatabase db = null;
    Cursor cursor = null;
    ArrayList<RecipeInformation> list = new ArrayList<>();
    String[] columns = { RecipeDetailTable.COLUMN_RECIPE_DETAIL_ID, RecipeDetailTable.COLUMN_RECIPE_DETAIL_NAME, RecipeDetailTable.COLUMN_RECIPE_DETAIL_AUTHOR, RecipeDetailTable.COLUMN_RECIPE_DETAIL_CATEGORIES, RecipeDetailTable.COLUMN_RECIPE_DETAIL_LEVEL, RecipeDetailTable.COLUMN_RECIPE_DETAIL_TIME, RecipeDetailTable.COLUMN_RECIPE_DETAIL_RATING, RecipeDetailTable.COLUMN_RECIPE_DETAIL_IMAGE };
    try {
        db = this.getWritableDatabase();
        cursor = db.query(RecipeDetailTable.RECIPE_DETAIL_TABLE_ITEMS, columns, null, null, null, null, RecipeDetailTable.COLUMN_RECIPE_DETAIL_NAME);
        if (cursor.moveToFirst()) {
            do {
                String id = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_ID));
                String name = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_NAME));
                String author = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_AUTHOR));
                String cats = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_CATEGORIES));
                String level = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_LEVEL));
                int time = cursor.getInt(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_TIME));
                int rating = cursor.getInt(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_RATING));
                String image = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_IMAGE));
                Gson gson = new Gson();
                String[] categories = gson.fromJson(cats, String[].class);
            // list.add(new RecipeInformation(id,name,author,image, rating, time, categories, level));
            } while (cursor.moveToNext());
        }
    } finally {
        if (cursor != null)
            cursor.close();
        if (db != null)
            db.close();
    }
    return list;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Cursor(android.database.Cursor) RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Example 7 with RecipeInformation

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

the class RecipeListActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == CREATE_RECIPE_CODE) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            Log.d(TAG, "Result from CreateRecipe");
            RecipeInformation r = data.getParcelableExtra("recipe");
            favoriteRecipes.add(r);
            favs.updateListAdapter(favoriteRecipes);
        }
    }
}
Also used : RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Example 8 with RecipeInformation

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

the class ListViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_list_view, container, false);
    listView = (ListView) v.findViewById(R.id.list);
    emptyView = v.findViewById(R.id.emptyList);
    if (title.equals("Favorites")) {
        emptyView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.emptylist));
    } else {
        emptyView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.emptylistwelcome));
    }
    listView.setAdapter(new ListViewFragment.RecipeAdapter(getContext(), list, mListener));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView l, View v, int position, long id) {
            Intent intent = new Intent(getContext(), RecipeDetailActivity.class);
            RecipeInformation recipe = ((RecipeInformation) l.getAdapter().getItem(position));
            // intent.putExtra("recipe", String.valueOf(recipeID));
            intent.putExtra("recipeDetail", recipe);
            Log.d(TAG + "/" + title, "Recipe Clicked: id -> " + recipe.getId());
            startActivity(intent);
        }
    });
    final LoaderManager.LoaderCallbacks callbacks = this;
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (title.equals(RECIPES)) {
                // TODO remove limit and or wait for user to scroll past end of list to load more
                if (firstVisibleItem + visibleItemCount + 2 == totalItemCount && totalItemCount != 0 && totalItemCount < 25) {
                    if (!isLoading.get()) {
                        Log.d(TAG + "/" + title, "Getting more recipes from server");
                        isLoading.set(true);
                        RequestMethod requestPackage = new RequestMethod();
                        if (searchText.length() == 0) {
                            // requestPackage.setEndPoint(urlString + qMark + urlRequestNumber + requestNumRandom);
                            requestPackage.setEndPoint(urlString + urlQ + urlPageNum + requestNumRandom);
                            requestNumRandom++;
                        } else {
                            // requestPackage.setEndPoint(urlStringSearch + searchText + urlRequestNumber + requestNumSearch);
                            requestPackage.setEndPoint(urlStringSearch + searchText + urlA + urlPageNum + requestNumSearch);
                            requestNumSearch++;
                        }
                        requestPackage.setMethod("GET");
                        Log.d(TAG, "Get more recipes from -> " + requestPackage.getEndpoint());
                        Bundle bundle = new Bundle();
                        bundle.putParcelable("requestPackage", requestPackage);
                        // Log.d(TAG, "onScroll: SearchQuery -> " + searchText);
                        getLoaderManager().initLoader((new Date()).hashCode(), bundle, callbacks).forceLoad();
                    }
                }
            }
        }
    });
    final Handler h = new Handler();
    h.postDelayed(new Runnable() {

        @Override
        public void run() {
            listView.setEmptyView(emptyView);
        }
    }, 500);
    // Inflate the layout for this fragment
    return v;
}
Also used : RequestMethod(com.se491.chef_ly.http.RequestMethod) Bundle(android.os.Bundle) AbsListView(android.widget.AbsListView) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) RecipeInformation(com.se491.chef_ly.model.RecipeInformation) Date(java.util.Date) LoaderManager(android.support.v4.app.LoaderManager) AdapterView(android.widget.AdapterView)

Example 9 with RecipeInformation

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

the class ListViewFragment method onLoadFinished.

// LoaderManager callback method
@Override
public void onLoadFinished(Loader<RecipeList> loader, RecipeList data) {
    Log.d(TAG + "/" + title, "Loader - OnLoadFinish");
    for (RecipeInformation recipe : data) {
        list.add(recipe);
    }
    ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
    isLoading.set(false);
    Log.d(TAG, "Getting more recipes from server --- Done");
}
Also used : BaseAdapter(android.widget.BaseAdapter) RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Aggregations

RecipeInformation (com.se491.chef_ly.model.RecipeInformation)9 BaseAdapter (android.widget.BaseAdapter)4 Intent (android.content.Intent)2 Handler (android.os.Handler)2 Gson (com.google.gson.Gson)2 RequestMethod (com.se491.chef_ly.http.RequestMethod)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Paint (android.graphics.Paint)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1 LoaderManager (android.support.v4.app.LoaderManager)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1