@Test public void testRestoreInstanceState() { final SelectionModule module = new SelectionModule(); final SelectionModule.SavedState savedState = new SelectionModule.SavedState(SelectionModule.SavedState.EMPTY_STATE); savedState.mode = SelectionModule.MULTIPLE; savedState.selection = SELECTION_ARRAY; module.restoreInstanceState(savedState); assertThat(module.getMode(), is(SelectionModule.MULTIPLE)); assertThat(module.getSelectionSize(), is(SELECTION_ARRAY.length)); assertThat(module.getSelection(), is(SELECTION_LIST)); for (final long aSSelectionArray : SELECTION_ARRAY) { assertThat(module.isSelected(aSSelectionArray), is(true)); } }
@Override @CallSuper public void restoreInstanceState(@NonNull final Parcelable savedState) { if (!(savedState instanceof SavedState)) { super.restoreInstanceState(savedState); return; } final SavedState state = (SavedState) savedState; super.restoreInstanceState(state.getSuperState()); this.mode = state.mode; if (state.selection != null) { if (selection == null) { this.selection = new ArrayList<>(state.selection.length); } for (final long id : state.selection) { this.selection.add(id); } } }
SelectionModule extends AdapterModule { @Override @CallSuper public void restoreInstanceState(@NonNull final Parcelable savedState) { if (!(savedState instanceof SavedState)) { super.restoreInstanceState(savedState); return; } final SavedState state = (SavedState) savedState; super.restoreInstanceState(state.getSuperState()); this.mode = state.mode; if (state.selection != null) { if (selection == null) { this.selection = new ArrayList<>(state.selection.length); } for (final long id : state.selection) { this.selection.add(id); } } } }
SelectionModule extends AdapterModule { @Override @CallSuper public void restoreInstanceState(@NonNull final Parcelable savedState) { if (!(savedState instanceof SavedState)) { super.restoreInstanceState(savedState); return; } final SavedState state = (SavedState) savedState; super.restoreInstanceState(state.getSuperState()); this.mode = state.mode; if (state.selection != null) { if (selection == null) { this.selection = new ArrayList<>(state.selection.length); } for (final long id : state.selection) { this.selection.add(id); } } }  }
SelectionModule extends AdapterModule { @Override @CallSuper public void restoreInstanceState(@NonNull final Parcelable savedState) { if (!(savedState instanceof SavedState)) { super.restoreInstanceState(savedState); return; } final SavedState state = (SavedState) savedState; super.restoreInstanceState(state.getSuperState()); this.mode = state.mode; if (state.selection != null) { if (selection == null) { this.selection = new ArrayList<>(state.selection.length); } for (final long id : state.selection) { this.selection.add(id); } } }  void setMode(@SelectionMode final int mode); @SelectionMode int getMode(); int toggleSelection(final long id); void setSelected(final long id, final boolean selected); void selectAll(); void selectRange(final int startPosition, final int count); void setSelection(@Nullable final List<Long> selection); boolean isSelected(final long id); @NonNull List<Long> getSelection(); int getSelectionSize(); void clearSelection(); void clearSelectionInRange(final int startPosition, final int count); @Override boolean requiresStateSaving(); @Override @CallSuper @NonNull Parcelable saveInstanceState(); @Override @CallSuper void restoreInstanceState(@NonNull final Parcelable savedState); }
SelectionModule extends AdapterModule { @Override @CallSuper public void restoreInstanceState(@NonNull final Parcelable savedState) { if (!(savedState instanceof SavedState)) { super.restoreInstanceState(savedState); return; } final SavedState state = (SavedState) savedState; super.restoreInstanceState(state.getSuperState()); this.mode = state.mode; if (state.selection != null) { if (selection == null) { this.selection = new ArrayList<>(state.selection.length); } for (final long id : state.selection) { this.selection.add(id); } } }  void setMode(@SelectionMode final int mode); @SelectionMode int getMode(); int toggleSelection(final long id); void setSelected(final long id, final boolean selected); void selectAll(); void selectRange(final int startPosition, final int count); void setSelection(@Nullable final List<Long> selection); boolean isSelected(final long id); @NonNull List<Long> getSelection(); int getSelectionSize(); void clearSelection(); void clearSelectionInRange(final int startPosition, final int count); @Override boolean requiresStateSaving(); @Override @CallSuper @NonNull Parcelable saveInstanceState(); @Override @CallSuper void restoreInstanceState(@NonNull final Parcelable savedState); static final int SINGLE; static final int MULTIPLE; }