-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from yuyakaido/issue/153
Fix crash when recreating holder activity
- Loading branch information
Showing
2 changed files
with
68 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...iew/src/main/java/com/yuyakaido/android/cardstackview/internal/CardStackDataObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.yuyakaido.android.cardstackview.internal; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.yuyakaido.android.cardstackview.CardStackLayoutManager; | ||
|
||
public class CardStackDataObserver extends RecyclerView.AdapterDataObserver { | ||
|
||
public boolean isRegistered = false; | ||
|
||
private final RecyclerView recyclerView; | ||
|
||
public CardStackDataObserver(RecyclerView recyclerView) { | ||
this.recyclerView = recyclerView; | ||
} | ||
|
||
@Override | ||
public void onChanged() { | ||
CardStackLayoutManager manager = getCardStackLayoutManager(); | ||
manager.setTopPosition(0); | ||
} | ||
|
||
@Override | ||
public void onItemRangeChanged(int positionStart, int itemCount) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onItemRangeInserted(int positionStart, int itemCount) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onItemRangeRemoved(int positionStart, int itemCount) { | ||
CardStackLayoutManager manager = getCardStackLayoutManager(); | ||
if (positionStart == 0) { | ||
manager.setTopPosition(0); | ||
} | ||
manager.removeAllViews(); | ||
} | ||
|
||
@Override | ||
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { | ||
// Do nothing | ||
} | ||
|
||
private CardStackLayoutManager getCardStackLayoutManager() { | ||
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); | ||
if (manager instanceof CardStackLayoutManager) { | ||
return (CardStackLayoutManager) manager; | ||
} | ||
throw new IllegalStateException("CardStackView must be set CardStackLayoutManager."); | ||
} | ||
|
||
} |