diff --git a/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsAdapter.java b/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsAdapter.java index 547e2dc..8831fdf 100644 --- a/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsAdapter.java +++ b/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsAdapter.java @@ -1,6 +1,9 @@ package moe.feng.common.view.breadcrumbs; import android.content.Context; +import android.support.annotation.IdRes; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.widget.ListPopupWindow; import android.support.v7.widget.RecyclerView; import android.view.*; @@ -33,23 +36,23 @@ public BreadcrumbsAdapter(BreadcrumbsView parent, ArrayList item DROPDOWN_OFFSET_Y_FIX = parent.getResources().getDimensionPixelOffset(R.dimen.dropdown_offset_y_fix_value); } - public ArrayList getItems() { + public @NonNull ArrayList getItems() { return this.items; } - public void setItems(ArrayList items) { + public void setItems(@NonNull ArrayList items) { this.items = items; } - public void setCallback(BreadcrumbsCallback callback) { + public void setCallback(@Nullable BreadcrumbsCallback callback) { this.callback = callback; } - public BreadcrumbsCallback getCallback() { + public @Nullable BreadcrumbsCallback getCallback() { return this.callback; } - public void setPopupThemeId(int popupThemeId) { + public void setPopupThemeId(@IdRes int popupThemeId) { this.mPopupThemeId = popupThemeId; } @@ -100,7 +103,7 @@ public void onClick(View view) { } @Override - public void setItem(BreadcrumbItem item) { + public void setItem(@NonNull BreadcrumbItem item) { super.setItem(item); button.setText(item.getSelectedItem()); button.setTextColor( @@ -136,7 +139,7 @@ public void onClick(View view) { } @Override - public void setItem(BreadcrumbItem item) { + public void setItem(@NonNull BreadcrumbItem item) { super.setItem(item); imageButton.setClickable(item.hasMoreSelect()); if (item.hasMoreSelect()) { @@ -187,7 +190,7 @@ class ItemHolder extends RecyclerView.ViewHolder { super(itemView); } - public void setItem(T item) { + public void setItem(@NonNull T item) { this.item = item; } diff --git a/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsView.java b/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsView.java index 8729245..df087f4 100644 --- a/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsView.java +++ b/library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsView.java @@ -92,7 +92,10 @@ private void init() { * * @return Current item */ - public BreadcrumbItem getCurrentItem() { + public @Nullable BreadcrumbItem getCurrentItem() { + if (mAdapter.getItems().size() <= 0) { + return null; + } return mAdapter.getItems().get(mAdapter.getItems().size() - 1); } @@ -177,7 +180,7 @@ public void removeLastItem() { * @see BreadcrumbsCallback * @see DefaultBreadcrumbsCallback */ - public void setCallback(BreadcrumbsCallback callback) { + public void setCallback(@Nullable BreadcrumbsCallback callback) { mAdapter.setCallback(callback); } @@ -187,7 +190,7 @@ public void setCallback(BreadcrumbsCallback callback) { * @return Callback * @see BreadcrumbsCallback */ - public BreadcrumbsCallback getCallback() { + public @Nullable BreadcrumbsCallback getCallback() { return mAdapter.getCallback(); } diff --git a/library/src/main/java/moe/feng/common/view/breadcrumbs/model/BreadcrumbItem.java b/library/src/main/java/moe/feng/common/view/breadcrumbs/model/BreadcrumbItem.java index d7f042f..9c8fde2 100644 --- a/library/src/main/java/moe/feng/common/view/breadcrumbs/model/BreadcrumbItem.java +++ b/library/src/main/java/moe/feng/common/view/breadcrumbs/model/BreadcrumbItem.java @@ -23,33 +23,64 @@ public BreadcrumbItem(@NonNull List items, int selectedIndex) { } } - public void setSelectedItem(String selectedItem) { + public void setSelectedItem(@NonNull String selectedItem) { this.mSelectedIndex = mItems.indexOf(selectedItem); if (mSelectedIndex == -1) { throw new IllegalArgumentException("This item does not exist in items."); } } + /** + * Select a item by index + * + * @param selectedIndex The index of the item should be selected + */ public void setSelectedIndex(int selectedIndex) { this.mSelectedIndex = selectedIndex; } + /** + * Get selected item index + * + * @return The index of selected item + */ public int getSelectedIndex() { return this.mSelectedIndex; } + /** + * Get selected item + * + * @return The selected item + */ public @NonNull String getSelectedItem() { return this.mItems.get(getSelectedIndex()); } + /** + * Check if there are other items + * + * @return Result + */ public boolean hasMoreSelect() { return this.mItems.size() > 1; } + /** + * Set a new items list + * + * @param items Items list + */ public void setItems(@NonNull List items) { this.setItems(items, 0); } + /** + * Set a new items list with selecting a item + * + * @param items Items list + * @param selectedIndex The selected item index + */ public void setItems(@NonNull List items, int selectedIndex) { if (items != null && !items.isEmpty()) { this.mItems = items; @@ -59,11 +90,23 @@ public void setItems(@NonNull List items, int selectedIndex) { } } - public List getItems() { + /** + * Get items list + * + * @return Items List + */ + public @NonNull List getItems() { return mItems; } - public static BreadcrumbItem createSimpleItem(String title) { + /** + * Create a simple BreadcrumbItem with single item + * + * @param title Item title + * @return Simple BreadcrumbItem + * @see BreadcrumbItem + */ + public static BreadcrumbItem createSimpleItem(@NonNull String title) { return new BreadcrumbItem(Collections.singletonList(title)); }