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;
}
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);
}
}
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;
}
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");
}
}
Aggregations