use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.
the class GetRecipesFromServer method loadInBackground.
@Override
public RecipeList loadInBackground() {
String response;
Log.d(TAG, requestPackage.getMethod() + " " + requestPackage.getEndpoint());
try {
HttpConnection http = new HttpConnection();
response = http.downloadFromFeed(requestPackage);
} catch (IOException e) {
e.printStackTrace();
return new RecipeList();
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
Type type = new TypeToken<RecipeList>() {
}.getType();
Log.d("AsyncTaskLoader", "Response " + getId() + " -> " + response);
try {
return gson.fromJson(response, type);
} catch (JsonSyntaxException e) {
Log.d(TAG, "Error - RecipeListObject Required: " + e.getMessage());
return new RecipeList();
}
}
use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.
the class ListViewFragment method onCreateLoader.
// LoaderManager callback method
@Override
public Loader<RecipeList> onCreateLoader(int id, Bundle args) {
Log.d(TAG + "/" + title, "Loader Created");
RequestMethod rm = args.getParcelable("requestPackage");
return new GetRecipesFromServer(getContext(), rm);
}
use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
serverRecipes = new RecipeList();
if (!BuildConfig.DEBUG) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Check if we need to display our OnboardingFragment
if (!sharedPreferences.getBoolean("FirstTimeRun", false)) {
Log.d(TAG, "First time run-> True");
// The user hasn't seen the OnboardingFragment yet, so show it
startActivityForResult(new Intent(this, IntroActivity.class), INTROACTIVITYCODE);
} else {
Log.d(TAG, "First time run-> False");
startRecipeLoader();
}
} else {
Log.d(TAG, "First time run-> True");
// The user hasn't seen the OnboardingFragment yet, so show it
startActivityForResult(new Intent(this, IntroActivity.class), INTROACTIVITYCODE);
}
////////////////////////////////////////////////////////////////////////////////////////////
/* Register receiver for Alarm
IntentFilter filter = new IntentFilter();
filter.addAction("alarm");
final CheflyTimer c = CheflyTimer.getInstance(getApplicationContext());
registerReceiver(new AlarmReceiver(c), filter);
// Timer test
c.setTimer("test",60, getApplicationContext());
c.setTimer("test2",10, getApplicationContext());
// simulate checking a timer after 30 seconds
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "time remaining = " + c.getTimerStatus("test"), Toast.LENGTH_SHORT).show();
}
},30*1000);
////////////////////////////////////////////////////////////////////////////////////////////
*/
}
use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.
the class MyService method onHandleIntent.
//called automaticly when server starts, receives data as an argument
@Override
protected void onHandleIntent(Intent intent) {
RequestMethod requestPackage = intent.getParcelableExtra(REQUEST_PACKAGE);
String sender = intent.getStringExtra("Tag");
Log.d(TAG, "Sender -> " + sender);
Log.d(TAG, "Request Package Endpoint-> " + requestPackage.getEndpoint());
String response;
try {
HttpConnection http = new HttpConnection();
response = http.downloadFromFeed(requestPackage);
} catch (IOException e) {
//e.printStackTrace();
return;
}
Log.d(TAG, "Response -> " + response);
GsonBuilder builder = new GsonBuilder();
//builder.registerTypeAdapter(Uri.class, new JsonDeserializer<Uri>() {
// @Override
// public Uri deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
// return Uri.parse(json.toString());
// }
//});
Gson gson = builder.create();
RecipeList dataItems;
Type type = new TypeToken<RecipeList>() {
}.getType();
dataItems = gson.fromJson(response, type);
Intent messageIntent = new Intent(MY_SERVICE_MESSAGE);
messageIntent.putExtra(MY_SERVICE_RESPONSE_STRING, response);
// messageIntent.putExtra(MY_SERVICE_PAYLOAD, "Service all done!"); //pass data back, set key value and message
if (dataItems != null) {
//pass back the data
messageIntent.putExtra(MY_SERVICE_PAYLOAD, dataItems);
} else {
// unidentified sender - send empty parcel back
messageIntent.putExtra(MY_SERVICE_PAYLOAD, new Parcelable() {
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
});
//pass back the data
}
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getApplicationContext());
manager.sendBroadcast(messageIntent);
}
use of com.se491.chef_ly.model.RecipeList in project chefly_android by chef-ly.
the class RecipeListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe_list);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//Initialize recipe lists
serverRecipes = new RecipeList();
favoriteRecipes = new RecipeList();
//Start AsyncTaskLoader to get FavoriteRecipes
Credentials cred = CredentialsManager.getCredentials(getApplicationContext());
String t = cred.getAccessToken();
Log.d(TAG, "Token -> " + t);
if (t != null) {
RequestMethod requestPackageFavs = new RequestMethod();
requestPackageFavs.setEndPoint(urlFavsString);
requestPackageFavs.setMethod("GET");
requestPackageFavs.setHeader("Authorization", "Bearer " + t);
Bundle bundlefavs = new Bundle();
bundlefavs.putParcelable("requestPackage", requestPackageFavs);
getSupportLoaderManager().initLoader(FAVORTIESID, bundlefavs, this).forceLoad();
} else {
Toast.makeText(this, "Could not retrieve favorites, token is null", Toast.LENGTH_SHORT).show();
}
// PageViewer
pager = (ViewPager) findViewById(R.id.viewpager);
Bundle serv = new Bundle();
serv.putString("title", "Recipes");
serv.putString("pageNum", "1");
serv.putString("search", "");
server = new ListViewFragment();
server.setArguments(serv);
Bundle f = new Bundle();
f.putString("title", "Favorites");
f.putString("pageNum", "2");
f.putString("search", "");
favs = new ListViewFragment();
favs.setArguments(f);
ListViewFragment[] frags = { server, favs };
pager.setAdapter(new RecipeListPagerAdapter(getSupportFragmentManager(), frags));
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//Log.d(TAG, "Position -> " + position);
if (position == 1) {
favoritesHeader.setPaintFlags(favoritesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
recipesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
} else {
recipesHeader.setPaintFlags(recipesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
favoritesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
// Header links
// ingredientsHeader = (TextView) findViewById(R.id.ingredientsHeader);
favoritesHeader = (TextView) findViewById(R.id.favortiesHeader);
recipesHeader = (TextView) findViewById(R.id.recipesHeader);
View.OnClickListener headerListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == favoritesHeader.getId()) {
favoritesHeader.setPaintFlags(favoritesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
recipesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
pager.setCurrentItem(1);
} else {
recipesHeader.setPaintFlags(recipesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
favoritesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
pager.setCurrentItem(0);
}
}
};
// ingredientsHeader.setOnClickListener(headerListener);
favoritesHeader.setOnClickListener(headerListener);
recipesHeader.setOnClickListener(headerListener);
//Tool/Appbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Navigation Drawer
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Aggregations