Skip to content

Commit f1ee43b

Browse files
committed
Version 12.3.4
- Fixes #87.
1 parent 0d0c7aa commit f1ee43b

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apply plugin: 'com.android.library'
22

3-
def libVersion = '12.3.3'
3+
def libVersion = '12.3.4'
44

55
android {
66
compileSdkVersion 25

lib/src/main/java/com/turingtechnologies/materialscrollbar/AlphabetIndicator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class AlphabetIndicator extends Indicator<INameableAdapter, AlphabetIndicator>{
2727

2828
public AlphabetIndicator (Context c){
29-
super(c);
29+
super(c, INameableAdapter.class);
3030
}
3131

3232
@Override

lib/src/main/java/com/turingtechnologies/materialscrollbar/CustomIndicator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class CustomIndicator extends Indicator<ICustomAdapter, CustomIndicator>
2929
private int textSize = 25;
3030

3131
public CustomIndicator(Context context){
32-
super(context);
32+
super(context, ICustomAdapter.class);
3333
}
3434

3535
@Override

lib/src/main/java/com/turingtechnologies/materialscrollbar/DateAndTimeIndicator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class DateAndTimeIndicator extends Indicator<IDateableAdapter, DateAndTim
3939
private Context context;
4040

4141
public DateAndTimeIndicator(Context c, boolean includeYear, boolean includeMonth, boolean includeDay, boolean includeTime){
42-
super(c);
42+
super(c, IDateableAdapter.class);
4343
context = c;
4444
this.includeYear = includeYear;
4545
this.includeMonth = includeMonth;

lib/src/main/java/com/turingtechnologies/materialscrollbar/Indicator.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*
3636
* T is the interface needed in the corresponding {@link RecyclerView.Adapter}.
3737
* U is the sub-class of indicator.
38+
* The second parameter for the constructor is the class of T.
3839
*/
3940
@SuppressWarnings("unchecked")
4041
public abstract class Indicator<T, U extends Indicator> extends RelativeLayout{
@@ -45,12 +46,15 @@ public abstract class Indicator<T, U extends Indicator> extends RelativeLayout{
4546
private MaterialScrollBar materialScrollBar;
4647
private boolean rtl;
4748
private int size;
49+
private Class<T> adapterClass;
4850

49-
public Indicator(Context context) {
51+
public Indicator(Context context, Class<T> adapter) {
5052
super(context);
5153
this.context = context;
5254
textView = new TextView(context);
5355
setVisibility(INVISIBLE);
56+
57+
adapterClass = adapter;
5458
}
5559

5660
void setSizeCustom(int size){
@@ -146,19 +150,17 @@ void setText(int section){
146150
}
147151

148152
/**
149-
* This method should test the adapter to make sure that it implements the needed interface(s).
153+
* This method tests the adapter to make sure that it implements the needed interface.
150154
*
151155
* @param adapter The adapter of the attached {@link RecyclerView}.
152156
*/
153-
void testAdapter(RecyclerView.Adapter adapter){
154-
try{
155-
if (adapter == null) {
156-
Log.e("MaterialScrollBarLib", "The adapter for your recyclerView has not been set; " +
157-
"skipping indicator layout.");
158-
return;
159-
}
160-
getTextElement(0, (T)adapter);
161-
} catch (ClassCastException e){
157+
void testAdapter(RecyclerView.Adapter adapter) {
158+
if (adapter == null) {
159+
Log.e("MaterialScrollBarLib", "The adapter for your recyclerView has not been set; " +
160+
"skipping indicator layout.");
161+
return;
162+
}
163+
if(!adapterClass.isInstance(adapter)){
162164
throw new IllegalArgumentException(
163165
"In order to add this indicator, the adapter for your recyclerView, "
164166
+ adapter.getClass().getName()

0 commit comments

Comments
 (0)