Search in sources :

Example 1 with RecipeList

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();
    }
}
Also used : Type(java.lang.reflect.Type) JsonSyntaxException(com.google.gson.JsonSyntaxException) HttpConnection(com.se491.chef_ly.http.HttpConnection) GsonBuilder(com.google.gson.GsonBuilder) RecipeList(com.se491.chef_ly.model.RecipeList) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Example 2 with 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);
}
Also used : RequestMethod(com.se491.chef_ly.http.RequestMethod) GetRecipesFromServer(com.se491.chef_ly.utils.GetRecipesFromServer)

Example 3 with RecipeList

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);
        ////////////////////////////////////////////////////////////////////////////////////////////
        */
}
Also used : SharedPreferences(android.content.SharedPreferences) RecipeList(com.se491.chef_ly.model.RecipeList) Intent(android.content.Intent)

Example 4 with RecipeList

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);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Parcel(android.os.Parcel) Gson(com.google.gson.Gson) Intent(android.content.Intent) Parcelable(android.os.Parcelable) IOException(java.io.IOException) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Type(java.lang.reflect.Type) RecipeList(com.se491.chef_ly.model.RecipeList)

Example 5 with RecipeList

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);
}
Also used : NavigationView(android.support.design.widget.NavigationView) RequestMethod(com.se491.chef_ly.http.RequestMethod) Bundle(android.os.Bundle) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ViewPager(android.support.v4.view.ViewPager) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) RecipeList(com.se491.chef_ly.model.RecipeList) DrawerLayout(android.support.v4.widget.DrawerLayout) Credentials(com.auth0.android.result.Credentials) Toolbar(android.support.v7.widget.Toolbar)

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