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

Commit b4a5071

Browse files
committed
Add annotations (2/n)
Signed-off-by: Fung <fython@163.com>
1 parent 6273820 commit b4a5071

3 files changed

Lines changed: 63 additions & 14 deletions

File tree

library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsAdapter.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package moe.feng.common.view.breadcrumbs;
22

33
import android.content.Context;
4+
import android.support.annotation.IdRes;
5+
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
47
import android.support.v7.widget.ListPopupWindow;
58
import android.support.v7.widget.RecyclerView;
69
import android.view.*;
@@ -33,23 +36,23 @@ public BreadcrumbsAdapter(BreadcrumbsView parent, ArrayList<BreadcrumbItem> item
3336
DROPDOWN_OFFSET_Y_FIX = parent.getResources().getDimensionPixelOffset(R.dimen.dropdown_offset_y_fix_value);
3437
}
3538

36-
public ArrayList<BreadcrumbItem> getItems() {
39+
public @NonNull ArrayList<BreadcrumbItem> getItems() {
3740
return this.items;
3841
}
3942

40-
public void setItems(ArrayList<BreadcrumbItem> items) {
43+
public void setItems(@NonNull ArrayList<BreadcrumbItem> items) {
4144
this.items = items;
4245
}
4346

44-
public void setCallback(BreadcrumbsCallback callback) {
47+
public void setCallback(@Nullable BreadcrumbsCallback callback) {
4548
this.callback = callback;
4649
}
4750

48-
public BreadcrumbsCallback getCallback() {
51+
public @Nullable BreadcrumbsCallback getCallback() {
4952
return this.callback;
5053
}
5154

52-
public void setPopupThemeId(int popupThemeId) {
55+
public void setPopupThemeId(@IdRes int popupThemeId) {
5356
this.mPopupThemeId = popupThemeId;
5457
}
5558

@@ -100,7 +103,7 @@ public void onClick(View view) {
100103
}
101104

102105
@Override
103-
public void setItem(BreadcrumbItem item) {
106+
public void setItem(@NonNull BreadcrumbItem item) {
104107
super.setItem(item);
105108
button.setText(item.getSelectedItem());
106109
button.setTextColor(
@@ -136,7 +139,7 @@ public void onClick(View view) {
136139
}
137140

138141
@Override
139-
public void setItem(BreadcrumbItem item) {
142+
public void setItem(@NonNull BreadcrumbItem item) {
140143
super.setItem(item);
141144
imageButton.setClickable(item.hasMoreSelect());
142145
if (item.hasMoreSelect()) {
@@ -187,7 +190,7 @@ class ItemHolder<T> extends RecyclerView.ViewHolder {
187190
super(itemView);
188191
}
189192

190-
public void setItem(T item) {
193+
public void setItem(@NonNull T item) {
191194
this.item = item;
192195
}
193196

library/src/main/java/moe/feng/common/view/breadcrumbs/BreadcrumbsView.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ private void init() {
9292
*
9393
* @return Current item
9494
*/
95-
public BreadcrumbItem getCurrentItem() {
95+
public @Nullable BreadcrumbItem getCurrentItem() {
96+
if (mAdapter.getItems().size() <= 0) {
97+
return null;
98+
}
9699
return mAdapter.getItems().get(mAdapter.getItems().size() - 1);
97100
}
98101

@@ -177,7 +180,7 @@ public void removeLastItem() {
177180
* @see BreadcrumbsCallback
178181
* @see DefaultBreadcrumbsCallback
179182
*/
180-
public void setCallback(BreadcrumbsCallback callback) {
183+
public void setCallback(@Nullable BreadcrumbsCallback callback) {
181184
mAdapter.setCallback(callback);
182185
}
183186

@@ -187,7 +190,7 @@ public void setCallback(BreadcrumbsCallback callback) {
187190
* @return Callback
188191
* @see BreadcrumbsCallback
189192
*/
190-
public BreadcrumbsCallback getCallback() {
193+
public @Nullable BreadcrumbsCallback getCallback() {
191194
return mAdapter.getCallback();
192195
}
193196

library/src/main/java/moe/feng/common/view/breadcrumbs/model/BreadcrumbItem.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,64 @@ public BreadcrumbItem(@NonNull List<String> items, int selectedIndex) {
2323
}
2424
}
2525

26-
public void setSelectedItem(String selectedItem) {
26+
public void setSelectedItem(@NonNull String selectedItem) {
2727
this.mSelectedIndex = mItems.indexOf(selectedItem);
2828
if (mSelectedIndex == -1) {
2929
throw new IllegalArgumentException("This item does not exist in items.");
3030
}
3131
}
3232

33+
/**
34+
* Select a item by index
35+
*
36+
* @param selectedIndex The index of the item should be selected
37+
*/
3338
public void setSelectedIndex(int selectedIndex) {
3439
this.mSelectedIndex = selectedIndex;
3540
}
3641

42+
/**
43+
* Get selected item index
44+
*
45+
* @return The index of selected item
46+
*/
3747
public int getSelectedIndex() {
3848
return this.mSelectedIndex;
3949
}
4050

51+
/**
52+
* Get selected item
53+
*
54+
* @return The selected item
55+
*/
4156
public @NonNull String getSelectedItem() {
4257
return this.mItems.get(getSelectedIndex());
4358
}
4459

60+
/**
61+
* Check if there are other items
62+
*
63+
* @return Result
64+
*/
4565
public boolean hasMoreSelect() {
4666
return this.mItems.size() > 1;
4767
}
4868

69+
/**
70+
* Set a new items list
71+
*
72+
* @param items Items list
73+
*/
4974
public void setItems(@NonNull List<String> items) {
5075
this.setItems(items, 0);
5176
}
5277

78+
/**
79+
* Set a new items list with selecting a item
80+
*
81+
* @param items Items list
82+
* @param selectedIndex The selected item index
83+
*/
5384
public void setItems(@NonNull List<String> items, int selectedIndex) {
5485
if (items != null && !items.isEmpty()) {
5586
this.mItems = items;
@@ -59,11 +90,23 @@ public void setItems(@NonNull List<String> items, int selectedIndex) {
5990
}
6091
}
6192

62-
public List<String> getItems() {
93+
/**
94+
* Get items list
95+
*
96+
* @return Items List
97+
*/
98+
public @NonNull List<String> getItems() {
6399
return mItems;
64100
}
65101

66-
public static BreadcrumbItem createSimpleItem(String title) {
102+
/**
103+
* Create a simple BreadcrumbItem with single item
104+
*
105+
* @param title Item title
106+
* @return Simple BreadcrumbItem
107+
* @see BreadcrumbItem
108+
*/
109+
public static BreadcrumbItem createSimpleItem(@NonNull String title) {
67110
return new BreadcrumbItem(Collections.singletonList(title));
68111
}
69112

0 commit comments

Comments
 (0)