7
7
import android .view .ViewGroup ;
8
8
9
9
import androidx .annotation .NonNull ;
10
+ import androidx .annotation .VisibleForTesting ;
10
11
import androidx .recyclerview .widget .RecyclerView ;
11
12
12
13
import org .smartregister .commonregistry .CommonPersonObject ;
18
19
*/
19
20
public class RecyclerViewPaginatedAdapter <V extends RecyclerView .ViewHolder > extends RecyclerViewCursorAdapter {
20
21
private final RecyclerViewProvider <RecyclerView .ViewHolder > listItemProvider ;
21
- private CommonRepository commonRepository ;
22
-
23
22
public int totalcount = 0 ;
24
23
public int currentlimit = 20 ;
25
24
public int currentoffset = 0 ;
25
+ private CommonRepository commonRepository ;
26
26
27
27
public RecyclerViewPaginatedAdapter (Cursor cursor ,
28
28
RecyclerViewProvider <RecyclerView .ViewHolder >
@@ -47,9 +47,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
47
47
public void onBindViewHolder (RecyclerView .ViewHolder viewHolder , Cursor cursor ) {
48
48
if (listItemProvider .isFooterViewHolder (viewHolder )) {
49
49
// make sure counts are updated before updating the view
50
- (new Handler (getMainLooper ())).post (() -> {
51
- listItemProvider .getFooterView (viewHolder , getCurrentPageCount (), getTotalPageCount (), hasNextPage (), hasPreviousPage ());
52
- });
50
+ updateFooterViewCounts (listItemProvider , viewHolder );
51
+
53
52
} else {
54
53
CommonPersonObject personinlist = commonRepository .readAllcommonforCursorAdapter (cursor );
55
54
CommonPersonObjectClient pClient = new CommonPersonObjectClient (personinlist .getCaseId (),
@@ -59,6 +58,11 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, Cursor cursor)
59
58
}
60
59
}
61
60
61
+ @ VisibleForTesting
62
+ protected void updateFooterViewCounts (RecyclerViewProvider <RecyclerView .ViewHolder > listItemProvider , RecyclerView .ViewHolder viewHolder ) {
63
+ new Handler (getMainLooper ()).post (() -> listItemProvider .getFooterView (viewHolder , getCurrentPageCount (), getTotalPageCount (), hasNextPage (), hasPreviousPage ()));
64
+ }
65
+
62
66
// Pagination
63
67
private int getCurrentPageCount () {
64
68
if (currentoffset != 0 ) {
@@ -97,28 +101,28 @@ public void previousPageOffset() {
97
101
currentoffset = currentoffset - currentlimit ;
98
102
}
99
103
100
- public void setTotalcount (int totalcount ) {
101
- this .totalcount = totalcount ;
102
- }
103
-
104
104
public int getTotalcount () {
105
105
return totalcount ;
106
106
}
107
107
108
- public void setCurrentoffset (int currentoffset ) {
109
- this .currentoffset = currentoffset ;
108
+ public void setTotalcount (int totalcount ) {
109
+ this .totalcount = totalcount ;
110
110
}
111
111
112
112
public int getCurrentoffset () {
113
113
return currentoffset ;
114
114
}
115
115
116
- public void setCurrentlimit (int currentlimit ) {
117
- this .currentlimit = currentlimit ;
116
+ public void setCurrentoffset (int currentoffset ) {
117
+ this .currentoffset = currentoffset ;
118
118
}
119
119
120
120
public int getCurrentlimit () {
121
121
return currentlimit ;
122
122
}
123
123
124
+ public void setCurrentlimit (int currentlimit ) {
125
+ this .currentlimit = currentlimit ;
126
+ }
127
+
124
128
}
0 commit comments