Skip to content

Commit b62f181

Browse files
committed
data improvevents
1 parent 1f23c14 commit b62f181

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

library/multichoicerecyclerview/src/main/java/com/davidecirillo/multichoicerecyclerview/MultiChoiceAdapter.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
161161
mItemList = (Map<Integer, State>) savedInstanceState.getSerializable(EXTRA_ITEM_LIST);
162162

163163
int selectedListSize = getSelectedItemListInternal().size();
164-
updateToolbarIfNeeded(selectedListSize);
165-
updateMultiChoiceMode(selectedListSize);
166-
processNotifyDataSetChanged();
164+
refreshMultiChoiceModeState(selectedListSize);
167165
}
168166
}
169167

@@ -176,6 +174,7 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
176174
*/
177175
public void notifyAdapterDataSetChanged() {
178176
notifyAdapterDataSetChangedInternal();
177+
refreshMultiChoiceModeState(getSelectedItemListInternal().size());
179178
}
180179

181180
//endregion
@@ -251,9 +250,7 @@ private void perform(Action action, int position, boolean withCallback, boolean
251250

252251
int selectedListSize = getSelectedItemListInternal().size();
253252

254-
updateToolbarIfNeeded(selectedListSize);
255-
256-
updateMultiChoiceMode(selectedListSize);
253+
refreshMultiChoiceModeState(selectedListSize);
257254

258255
processNotifyDataSetChanged();
259256

@@ -272,13 +269,11 @@ void processNotifyDataSetChanged() {
272269
}
273270
}
274271

275-
private void updateToolbarIfNeeded(int selectedListSize) {
272+
private void refreshMultiChoiceModeState(int selectedListSize) {
276273
if ((mIsInMultiChoiceMode || mIsInSingleClickMode || selectedListSize > 0) && mMultiChoiceToolbarHelper != null) {
277274
mMultiChoiceToolbarHelper.updateToolbar(selectedListSize);
278275
}
279-
}
280276

281-
private void updateMultiChoiceMode(int selectedListSize) {
282277
boolean somethingSelected = selectedListSize > 0;
283278
if (mIsInMultiChoiceMode != somethingSelected) {
284279
mIsInMultiChoiceMode = somethingSelected;
@@ -303,8 +298,7 @@ private void performAll(Action action) {
303298
mItemList.put(i, state);
304299
}
305300

306-
updateToolbarIfNeeded(selectedItems);
307-
updateMultiChoiceMode(selectedItems);
301+
refreshMultiChoiceModeState(selectedItems);
308302

309303
processNotifyDataSetChanged();
310304

sample/src/main/java/com/davidecirillo/multichoicesample/sampleToolbar/SampleToolbarActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void notifyDataChanged() {
7171

7272
stringList.clear();
7373
Random random = new Random();
74-
for (int i = 0; i < random.nextInt(15); i++) {
74+
for (int i = 0; i < random.nextInt(30); i++) {
7575
stringList.add("New item " + i);
7676
}
7777

sample/src/main/res/layout/activity_sample_toolbar.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
android:textColor="@android:color/white"
3131
android:layout_width="wrap_content"
3232
android:layout_height="wrap_content"
33-
android:text="Change data"/>
33+
android:text="Change data and notify"/>
3434
</LinearLayout>
3535

3636
<android.support.v7.widget.RecyclerView

0 commit comments

Comments
 (0)