CiderCS3398 / CS3398-Cider-S2017

CS3398 Team Github
0 stars 2 forks source link

Understand the Java code in the new source program #52

Closed forrest87 closed 7 years ago

forrest87 commented 7 years ago

The source code we originally wanted to work with did not actually work for us, which we discovered midway through Sprint 1. A different open-source software packet was subsequently found on GitHub that would better suite our needs. This presented a new need, however--the need to understand the new code. Realizing that most of the XML code for the project won't necessarily need to change for this sprint (if at all in the long run), there's no need to try to understand its functioning at the moment. The need, on the other hand, is to understand what the Java code is doing in the program.

forrest87 commented 7 years ago

Some Initial Observations on the Kitchen Helper's Java Code:

///////////////////////////////////////////////////////////////////////// // Recipe, RecipeStep, and RecipeActivity Classes // ////////////////////////////////////////////////////////////////////////

The RecipeActivity class extends the Activity class and makes use of the Recipe class to collect the titles, summaries, associated images, ingredients, and steps of recipes. To represent the steps of a recipe, the Recipe class itself contains a class called RecipeStep, and each RecipeStep object contains text and possibly an associated image. The RecipeStep objects of a recipe are contained in the Recipe class’s member field called recipeSteps, which is an ArrayList of RecipeStep objects.

The Recipe class makes use of JSON files to store and retrieve information about the various recipes and their associated steps.

The RecipeActivity class contains a function called onStart, which overrides its parent’s onStart function. This function finds the name of the recipe to be viewed in the JSON recipe file and then loads the entire recipe using a function called loadRecipe(). When the particular recipe is being loaded, information about the recipe is read from a JSON file. All the JSON file needs is the name of the recipe. It will then retrieve the appropriate Recipe object associated with the object’s name. A call to RecipeActivity’s displayRecipe() member function, which displays the information to the screen.

The RecipeActivity class also contains a function called startCooking(), which activates when the onOptionsItemSelected() is executed. I assume this means that when a user touches a particular item on the screen, on OptionsItemSelected executes, which during the course of its execution, runs startCooking().

forrest87 commented 7 years ago

========================================================================

////////////////////////////////////// // RecipeListAdapter Class //////////////////////////////////////

The RecipeListAdapter class reads an entire json file and places each recipe into a class called Item. All the Items are parsed and placed in an ArrayList called mItems, which is a member variable to RecipleListAdapter. This all happens in the loadRecipes() member function, which is called by RecipeListAdapter’s constructor. loadRecipes() reads the son file and creates a json object, which is then parsed by the parseJson() function. In parseJson, each line (representing a recipe) is broken down in placed in a member variable in the Item class. Finally, each Item is added to an ArrayList of Items that is returned. That returned ArrayList is assigned to “items” in loadRecipesList, which is then added to the RecipeAdapter’s member ArrayList mItems using the appendItemsToList() member function.

========================================================================

////////////////////////////////////// // RecipeService Class //////////////////////////////////////

The RecipeService class seems to act as a class that adds supplemental information to the various recipes in the form of sticky notes, I believe.

========================================================================

////////////////////////////////////// // AssestUtils Class //////////////////////////////////////

The AssetUtils class seems to set up the context (I’m not sure what that is) by loading assets for JSON and Bitmap objects.

========================================================================

////////////////////////////////////// // Constants Class //////////////////////////////////////

The Constants class contains a collection of constant—denoted by the keyword “final”—values that are utilized by the other classes of the program. They are also static, which means (I believe) that only one of each constant variable exists for the entire class so that there is not the overhead in needing to create multiple fields upon instantiation of the class. An example of how these constants are used in the program is the static final String reference called ACTION_START_COOKING, which is used in the onStartCommand function in RecipeService.java.

========================================================================

////////////////////////////////////// // MainActivity Class //////////////////////////////////////

The MainActivity Class seems to be wear the action happens, that is to say that it kicks the main action of the application off when called in the relevant XML code. It does not contain a main function, but Android applications seem not to use main functions in their Java code. The MainActivity class aggregates the RecipeListAdapter class (its variable is called mAdapter) and also contains a member field String object that is used for logging purposes. The function onListItemsClick() first attempts to log the TAG, “recipeAssistant”. Then a String object called itemName is assigned whatever name the mAdapter object finds from the “position” provided to it. Context is set up using an Intent object and then the activity starts using the Intent object. The function onCreate takes a Bundle object as a parameter. That bundle object is then passed to MainActivity’s parent’s onCreate() function. The content view is set up next (for visual purposes, maybe?). The mAdapter private variable is given an actual object to reference, and finally, the ListAdapter is set using mAdapter.