Skip to content

Commit

Permalink
Write javadoc and refactor BottomSheetMenu.
Browse files Browse the repository at this point in the history
  • Loading branch information
vilikin committed May 4, 2017
1 parent 7310690 commit dee07f7
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,30 @@
import in.vilik.tamkapp.utils.UtilCompat;

/**
* Created by vili on 23/04/2017.
* Implements a bottom sheet menu.
*
* @author Vili Kinnunen vili.kinnunen@cs.tamk.fi
* @version 2017.0504
* @since 1.7
*/
public class BottomSheetMenu extends BottomSheetDialog {

public class BottomSheetOptions extends BottomSheetDialog {
/**
* Context.
*/
private Context context;

/**
* Root view.
*/
private LinearLayout rootView;

public BottomSheetOptions(@NonNull Context context) {
/**
* Initializes bottom sheet menu.
*
* @param context Context
*/
public BottomSheetMenu(@NonNull Context context) {
super(context);

this.context = context;
Expand All @@ -42,6 +58,46 @@ public BottomSheetOptions(@NonNull Context context) {
setContentView(rootView);
}

/**
* Sets categories for the bottom sheet menu.
*
* @param categories Categories for the bottom sheet menu
*/
public void setCategories(List<Category> categories) {
LayoutInflater inflater = LayoutInflater.from(context);

for (Category category : categories) {
View categoryView = inflater.inflate(R.layout.bottom_sheet_dialog_category, null);

TextView categoryText = (TextView) categoryView.findViewById(R.id.item_header);

categoryText.setText(category.getName());

rootView.addView(categoryView);

for (Option option : category.getOptions()) {
View optionView = inflater.inflate(R.layout.bottom_sheet_dialog_item, null);
ImageView icon = (ImageView) optionView.findViewById(R.id.item_icon);

icon.setImageDrawable(option.getIcon());

TextView text = (TextView) optionView.findViewById(R.id.item_text);

text.setText(option.getName());

optionView.setOnClickListener(option.getListener());

rootView.addView(optionView);
}
}
}

/**
* Creates option categories for a single day.
*
* @param day Day to generate categories for
* @return Categories for the day
*/
public List<Category> getCategoriesForDate(final Day day) {
List<Category> categories = new ArrayList<>();

Expand All @@ -56,7 +112,7 @@ public List<Category> getCategoriesForDate(final Day day) {
@Override
public void onClick(View v) {
createNewNote(day.getDate(), Note.NoteType.DEADLINE);
BottomSheetOptions.this.dismiss();
BottomSheetMenu.this.dismiss();
}
});

Expand All @@ -70,7 +126,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
createNewNote(day.getDate(), Note.NoteType.EXAM);
BottomSheetOptions.this.dismiss();
BottomSheetMenu.this.dismiss();
}
});

Expand All @@ -84,7 +140,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
createNewNote(day.getDate(), Note.NoteType.EVENT);
BottomSheetOptions.this.dismiss();
BottomSheetMenu.this.dismiss();
}
});

Expand All @@ -98,7 +154,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
createNewNote(day.getDate(), Note.NoteType.NOTE);
BottomSheetOptions.this.dismiss();
BottomSheetMenu.this.dismiss();
}
});

Expand All @@ -111,6 +167,12 @@ public void onClick(View v) {
return categories;
}

/**
* Starts new activity to create a note with specific date and type.
*
* @param date Date for the note
* @param type Type for the note
*/
private void createNewNote(Date date, Note.NoteType type) {
Intent intent = new Intent(context, NoteActivity.class);
Calendar calendar = Calendar.getInstance();
Expand All @@ -122,33 +184,4 @@ private void createNewNote(Date date, Note.NoteType type) {

context.startActivity(intent);
}

public void setCategories(List<Category> categories) {
LayoutInflater inflater = LayoutInflater.from(context);

for (Category category : categories) {
View categoryView = inflater.inflate(R.layout.bottom_sheet_dialog_category, null);

TextView categoryText = (TextView) categoryView.findViewById(R.id.item_header);

categoryText.setText(category.getName());

rootView.addView(categoryView);

for (Option option : category.getOptions()) {
View optionView = inflater.inflate(R.layout.bottom_sheet_dialog_item, null);
ImageView icon = (ImageView) optionView.findViewById(R.id.item_icon);

icon.setImageDrawable(option.getIcon());

TextView text = (TextView) optionView.findViewById(R.id.item_text);

text.setText(option.getName());

optionView.setOnClickListener(option.getListener());

rootView.addView(optionView);
}
}
}
}
35 changes: 33 additions & 2 deletions app/src/main/java/in/vilik/tamkapp/bottomsheet/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,56 @@
import java.util.List;

/**
* Created by vili on 23/04/2017.
* Implements a category of options for a bottom sheet.
*
* @author Vili Kinnunen vili.kinnunen@cs.tamk.fi
* @version 2017.0504
* @since 1.7
*/

public class Category {

/**
* Name of the category.
*/
private String name;

/**
* List of all options in the category.
*/
private List<Option> options;

/**
* Gets name of the category.
*
* @return Name of the category
*/
public String getName() {
return name;
}

/**
* Sets name for the category.
*
* @param name Name for the category
*/
public void setName(String name) {
this.name = name;
}

/**
* Gets list of all options in the category.
*
* @return List of all options in the category
*/
public List<Option> getOptions() {
return options;
}

/**
* Sets list of all options in the category.
*
* @param options List of all options for the category
*/
public void setOptions(List<Option> options) {
this.options = options;
}
Expand Down
49 changes: 47 additions & 2 deletions app/src/main/java/in/vilik/tamkapp/bottomsheet/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,79 @@
import android.view.View;

/**
* Created by vili on 23/04/2017.
* Implements a single option on a bottom sheet.
*
* @author Vili Kinnunen vili.kinnunen@cs.tamk.fi
* @version 2017.0504
* @since 1.7
*/

public class Option {

/**
* Name of the option.
*/
private String name;

/**
* Icon of the option.
*/
private Drawable icon;

/**
* OnClickListener of the option.
*/
private View.OnClickListener listener;

/**
* Gets name of the option.
*
* @return Name of the option
*/
public String getName() {
return name;
}

/**
* Sets name for the option.
*
* @param name Name for the option
*/
public void setName(String name) {
this.name = name;
}

/**
* Gets icon of the option.
*
* @return Icon of the option
*/
public Drawable getIcon() {
return icon;
}

/**
* Sets icon for the option.
*
* @param icon Icon for the option
*/
public void setIcon(Drawable icon) {
this.icon = icon;
}

/**
* Gets OnClickListener of the option.
*
* @return OnClickListener of the option
*/
public View.OnClickListener getListener() {
return listener;
}

/**
* Sets OnClickListener for the option.
*
* @param listener OnClickListener for the option
*/
public void setListener(View.OnClickListener listener) {
this.listener = listener;
}
Expand Down
52 changes: 48 additions & 4 deletions app/src/main/java/in/vilik/tamkapp/fragments/MenuFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,53 @@
import in.vilik.tamkapp.utils.DataLoader;

/**
* Created by vili on 10/04/2017.
* Implements a fragment containing a list of menus.
*
* @author Vili Kinnunen vili.kinnunen@cs.tamk.fi
* @version 2017.0504
* @since 1.7
*/

public class MenuFragment extends Fragment {

/**
* Root view of the fragment.
*/
View rootView;

/**
* MenuList displayed on this fragment.
*/
MenuList menuList;

/**
* Flag: is the fragment and MenuList initialized.
*/
boolean initialized;

/**
* RecyclerView containing the list of menus.
*/
RecyclerView recyclerView;

/**
* Adapter for the RecyclerView containing the list of menus.
*/
MenuListAdapter adapter;

/**
* Overlay for when there are no menu lists available.
*/
LinearLayout noMenuListsOverlay;

/**
* Overlay for when there is no localization of the menu list available.
*/
LinearLayout noLocalizationOverlay;
AppPreferences preferences;
SwipeRefreshLayout swipeRefreshLayout;

/**
* Returns a new instance of this fragment for the given section
* number.
* Returns a new instance of this fragment for the given menu type.
*/
public static Fragment newInstance(API.Type menuType) {
MenuFragment fragment = new MenuFragment();
Expand All @@ -54,6 +84,14 @@ public static Fragment newInstance(API.Type menuType) {
return fragment;
}

/**
* Creates view for the fragment.
*
* @param inflater Inflater
* @param container Container
* @param savedInstanceState Saved instance state
* @return View for the fragment
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down Expand Up @@ -158,6 +196,9 @@ public void onRefresh() {
return rootView;
}

/**
* Resumes fragment.
*/
@Override
public void onResume() {
super.onResume();
Expand All @@ -168,6 +209,9 @@ public void onResume() {
}
}

/**
* Refreshes contents of the RecyclerView.
*/
private void refreshMenuContent() {
initialized = true;

Expand Down
Loading

0 comments on commit dee07f7

Please sign in to comment.