Skip to content

Commit

Permalink
Write javadoc for rest of the menus package.
Browse files Browse the repository at this point in the history
  • Loading branch information
vilikin committed May 3, 2017
1 parent c110c67 commit 7310690
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 50 additions & 8 deletions app/src/main/java/in/vilik/tamkapp/menus/Campusravita.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,25 @@
import okhttp3.Request;

/**
* Created by vili on 10/04/2017.
* Implements a MenuList for Campusravita.
*
* @author Vili Kinnunen vili.kinnunen@cs.tamk.fi
* @version 2017.0503
* @since 1.7
*/

public class Campusravita extends MenuList {

/**
* Preferences of the app.
*/
private AppPreferences preferences;

/**
* Initializes MenuList to interact with Campusravita API.
*
* @param context Context
* @param language Language for the MenuList
*/
public Campusravita(Context context, final String language) {
super(context, new API() {
@Override
Expand All @@ -49,6 +62,12 @@ public String getCacheKey() {
this.preferences = new AppPreferences(context);
}

/**
* Parses received response and converts it to a list of menus.
*
* @param response Response body
* @return If parsing succeeded or not
*/
boolean handleSuccessfulResponse(String response) {
ArrayList<Menu> menus = getMenus();

Expand All @@ -75,6 +94,14 @@ boolean handleSuccessfulResponse(String response) {
}
}

/**
* Parses JSON representation of a Menu.
*
* @param json JSON representation of a Menu
* @return Menu object
* @throws JSONException Thrown when parsing of JSON fails
* @throws ParseException Thrown when parsing of a date fails
*/
private Menu parseMenu(JSONObject json) throws JSONException, ParseException {
Menu menu = new Menu(this);

Expand Down Expand Up @@ -103,6 +130,13 @@ private Menu parseMenu(JSONObject json) throws JSONException, ParseException {
return menu;
}

/**
* Parses JSON representation of a Meal.
*
* @param json JSON representation of a meal
* @return Meal object
* @throws JSONException Thrown when parsing of JSON fails
*/
private Meal parseMeal(JSONObject json) throws JSONException {
Meal meal = new Meal();

Expand Down Expand Up @@ -130,6 +164,13 @@ private Meal parseMeal(JSONObject json) throws JSONException {
return meal;
}

/**
* Parses JSON representation of a MealOption.
*
* @param json JSON representation of a MealOption
* @return MealOption object
* @throws JSONException Thrown when parsing of JSON fails
*/
private MealOption parseOption(JSONObject json) throws JSONException {
MealOption option = new MealOption(json.getString("name"));

Expand All @@ -145,19 +186,20 @@ private MealOption parseOption(JSONObject json) throws JSONException {

option.setDietsShown(preferences.areDietsShown());

/*
option.setPriceForStudent(json.getDouble("priceForStudent"));
option.setPriceForStaff(json.getDouble("priceForStaff"));
option.setPriceForOther(json.getDouble("priceForOthers"));
*/

if (json.has("details")) {
option.setDetails(json.getString("details"));
}

return option;
}

/**
* Parses JSON representation of a Diet.
*
* @param json JSON representation of a Diet
* @return Diet object
* @throws JSONException Thrown when parsing of JSON fails
*/
private Diet parseDiet(JSONObject json) throws JSONException {
Diet diet = new Diet();
diet.setName(json.getString("name"));
Expand Down
97 changes: 95 additions & 2 deletions app/src/main/java/in/vilik/tamkapp/menus/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,44 @@


/**
* Created by vili on 10/04/2017.
* Implements a class representing a menu of a single date.
*
* @author Vili Kinnunen vili.kinnunen@cs.tamk.fi
* @version 2017.0503
* @since 1.7
*/

public class Menu implements MenuListItem, Parent<MenuListItem> {

/**
* Date of the menu.
*/
private Date date;

/**
* List of meals associated with the menu.
*/
private ArrayList<Meal> meals;

/**
* Flag: if menu is empty or not.
*/
private boolean empty;

/**
* Parent MenuList of the menu.
*/
private MenuList parentMenuList;

/**
* Set of meals that should be shown in the menu.
*/
private Set<String> includedMeals;

/**
* Initializes menu with parent MenuList.
*
* @param parentMenuList Parent MenuList
*/
public Menu(MenuList parentMenuList) {
this.parentMenuList = parentMenuList;

Expand All @@ -40,22 +68,49 @@ public Menu(MenuList parentMenuList) {
this.meals = new ArrayList<>();
}

/**
* Gets parent MenuList.
*
* @return Parent MenuList
*/
public MenuList getParentMenuList() {
return parentMenuList;
}

/**
* Gets date of the menu.
*
* @return Date of the menu
*/
public Date getDate() {
return date;
}

/**
* Sets date for the menu.
*
* @param date Date for the menu
*/
public void setDate(Date date) {
this.date = date;
}

/**
* Gets all meals associated with the menu.
*
* @return All meals associated with the menu
*/
public ArrayList<Meal> getMeals() {
return meals;
}

/**
* Sets meals associated with the menu.
*
* Removes meals that are not part of included meals that are selected in preferences.
*
* @param meals Meals associated with the menu
*/
public void setMeals(ArrayList<Meal> meals) {
Iterator<Meal> iterator = meals.iterator();

Expand All @@ -75,6 +130,12 @@ public void setMeals(ArrayList<Meal> meals) {
this.meals = meals;
}

/**
* Checks if certain meal type should be visible in the menu.
*
* @param type Type for visibility check
* @return If it should be visible
*/
private boolean showMealType(String type) {
if (includedMeals != null) {
return includedMeals.contains(type);
Expand All @@ -83,25 +144,50 @@ private boolean showMealType(String type) {
}
}

/**
* Checks if menu is empty.
*
* @return If menu is empty or not
*/
public boolean isEmpty() {
return empty;
}

/**
* Gets primary text of menu item.
*
* @return Formatted date of the menu
*/
@Override
public String getPrimaryText() {
return DateUtil.formatDate(parentMenuList.getContext(), date, DateUtil.DateFormat.ON_DAY);
}

/**
* Gets secondary text of menu item.
*
* @return Null, as there is no secondary text for menus
*/
@Override
public String getSecondaryText() {
return null;
}

/**
* Gets item type of menu item.
*
* @return MENU_HEADER item type
*/
@Override
public ItemType getItemType() {
return ItemType.MENU_HEADER;
}

/**
* Gets child list associated with the menu in RecyclerView.
*
* @return List of MenuListItems associated with the menu
*/
@Override
public List<MenuListItem> getChildList() {
ArrayList<MenuListItem> menuListItems = new ArrayList<>();
Expand All @@ -119,6 +205,13 @@ public List<MenuListItem> getChildList() {
return menuListItems;
}

/**
* Determines if the menu is initially expanded in the RecyclerView.
*
* Only first menu of the parent MenuList is expanded initially.
*
* @return If menu is initially expanded in the RecyclerView
*/
@Override
public boolean isInitiallyExpanded() {
return getParentMenuList().getMenus().get(0) == this;
Expand Down
Loading

0 comments on commit 7310690

Please sign in to comment.