Search in sources :

Example 11 with RequestMethod

use of com.se491.chef_ly.http.RequestMethod in project chefly_android by chef-ly.

the class RegisterActivity method emailExists.

private boolean emailExists() throws InterruptedException, ExecutionException {
    Log.d(TAG, "Checking if email exists in user database...");
    String userEmailExists = null;
    //call Chefly server
    userEmailExists = new UserCheck(userEmail).execute(new RequestMethod()).get();
    if (userEmailExists.equals("true")) {
        Log.d(TAG, "user email exists returns true");
        return true;
    } else if (userEmailExists.equals("false")) {
        Log.d(TAG, "user email exists returns false");
        return false;
    }
    Log.d(TAG, "user email exists DID NOT RETURN TRUE OR FALSE");
    return false;
}
Also used : RequestMethod(com.se491.chef_ly.http.RequestMethod)

Example 12 with RequestMethod

use of com.se491.chef_ly.http.RequestMethod in project chefly_android by chef-ly.

the class RecipeListActivity method onDestroy.

@Override
protected void onDestroy() {
    super.onDestroy();
    //  Update favorites list for user on server
    if (favListAdd.size() > 0 || favListRemove.size() > 0) {
        new AsyncTask<String, Integer, Integer>() {

            @Override
            protected Integer doInBackground(String... params) {
                GsonBuilder builder = new GsonBuilder();
                Gson gson = builder.create();
                Type type = new TypeToken<ArrayList<Integer>>() {
                }.getType();
                String bodyAdd = gson.toJson(favListAdd, type);
                String bodyRemove = gson.toJson(favListRemove, type);
                String token = CredentialsManager.getCredentials(getApplicationContext()).getAccessToken();
                if (token == null) {
                    token = "test";
                }
                Log.d(TAG, bodyAdd + " " + bodyRemove);
                RequestMethod rm = new RequestMethod();
                rm.setEndPoint(urlFavsString);
                rm.setMethod("POST");
                rm.setHeader("Authorization", "Bearer " + token);
                rm.setParam("add", bodyAdd);
                rm.setParam("remove", bodyRemove);
                try {
                    HttpConnection http = new HttpConnection();
                    http.downloadFromFeed(rm);
                } catch (IOException e) {
                    return 0;
                }
                return 200;
            }

            @Override
            protected void onPostExecute(Integer integer) {
                super.onPostExecute(integer);
            }
        }.execute();
    }
    if (BuildConfig.DEBUG) {
        RefWatcher refWatcher = CheflyApplication.getRefWatcher(this);
        refWatcher.watch(this);
    }
}
Also used : Type(java.lang.reflect.Type) GsonBuilder(com.google.gson.GsonBuilder) HttpConnection(com.se491.chef_ly.http.HttpConnection) TypeToken(com.google.gson.reflect.TypeToken) RequestMethod(com.se491.chef_ly.http.RequestMethod) Gson(com.google.gson.Gson) RefWatcher(com.squareup.leakcanary.RefWatcher) IOException(java.io.IOException)

Example 13 with RequestMethod

use of com.se491.chef_ly.http.RequestMethod 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 14 with RequestMethod

use of com.se491.chef_ly.http.RequestMethod in project chefly_android by chef-ly.

the class SearchIngredients method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.findRecipes:
            //take the text as ingredient1, ingredient2,..
            selectedIngredient = ingredients.getText().toString();
            // Get recipes from server
            if (//returns true if internet available
            NetworkHelper.hasNetworkAccess(SearchIngredients.this)) {
                //Start AsyncTaskLoader to get recipes from server
                RequestMethod requestPackage = new RequestMethod();
                //find the url
                requestPackage.setEndPoint(urlString + selectedIngredient);
                //  or requestPackage.setMethod("POST");
                requestPackage.setMethod("GET");
                //  serverConnection();
                Bundle searchIngredients = new Bundle();
                searchIngredients.putParcelable("requestPackage", requestPackage);
                getSupportLoaderManager().initLoader(selectedIngredient.hashCode(), searchIngredients, this).forceLoad();
            } else {
                //Toast.makeText(RecipeListActivity.this,"No Internet Connection",Toast.LENGTH_LONG).show();
                Log.d(TAG, "No Internet Connection");
            }
            break;
        default:
            Log.d(TAG, "Unknown click received");
    }
}
Also used : RequestMethod(com.se491.chef_ly.http.RequestMethod) Bundle(android.os.Bundle)

Aggregations

RequestMethod (com.se491.chef_ly.http.RequestMethod)13 Bundle (android.os.Bundle)6 Intent (android.content.Intent)4 IOException (java.io.IOException)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 Type (java.lang.reflect.Type)3 Handler (android.os.Handler)2 TypeToken (com.google.gson.reflect.TypeToken)2 HttpConnection (com.se491.chef_ly.http.HttpConnection)2 RecipeInformation (com.se491.chef_ly.model.RecipeInformation)2 RecipeList (com.se491.chef_ly.model.RecipeList)2 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 AsyncTask (android.os.AsyncTask)1 Parcel (android.os.Parcel)1