Skip to content
This repository has been archived by the owner on Aug 22, 2020. It is now read-only.

Commit

Permalink
Add annotations (2/n)
Browse files Browse the repository at this point in the history
Signed-off-by: Fung <[email protected]>
  • Loading branch information
fython committed Jul 25, 2017
1 parent 6273820 commit b4a5071
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -33,23 +36,23 @@ public BreadcrumbsAdapter(BreadcrumbsView parent, ArrayList<BreadcrumbItem> item
DROPDOWN_OFFSET_Y_FIX = parent.getResources().getDimensionPixelOffset(R.dimen.dropdown_offset_y_fix_value);
}

public ArrayList<BreadcrumbItem> getItems() {
public @NonNull ArrayList<BreadcrumbItem> getItems() {
return this.items;
}

public void setItems(ArrayList<BreadcrumbItem> items) {
public void setItems(@NonNull ArrayList<BreadcrumbItem> 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;
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -187,7 +190,7 @@ class ItemHolder<T> extends RecyclerView.ViewHolder {
super(itemView);
}

public void setItem(T item) {
public void setItem(@NonNull T item) {
this.item = item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -187,7 +190,7 @@ public void setCallback(BreadcrumbsCallback callback) {
* @return Callback
* @see BreadcrumbsCallback
*/
public BreadcrumbsCallback getCallback() {
public @Nullable BreadcrumbsCallback getCallback() {
return mAdapter.getCallback();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,64 @@ public BreadcrumbItem(@NonNull List<String> 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<String> 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<String> items, int selectedIndex) {
if (items != null && !items.isEmpty()) {
this.mItems = items;
Expand All @@ -59,11 +90,23 @@ public void setItems(@NonNull List<String> items, int selectedIndex) {
}
}

public List<String> getItems() {
/**
* Get items list
*
* @return Items List
*/
public @NonNull List<String> 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));
}

Expand Down

0 comments on commit b4a5071

Please sign in to comment.