forked from h6ah4i/android-advancedrecyclerview
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
2,657 additions
and
394 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
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
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
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
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
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
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
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
206 changes: 206 additions & 0 deletions
206
...c/main/java/com/h6ah4i/android/example/advrecyclerview/common/data/DebugDataProvider.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,206 @@ | ||
/* | ||
* Copyright (C) 2015 Haruki Hasegawa | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.h6ah4i.android.example.advrecyclerview.common.data; | ||
|
||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class DebugDataProvider extends AbstractDataProvider { | ||
private List<ConcreteData> mData; | ||
private ConcreteData mLastRemovedData; | ||
private int mLastRemovedPosition = -1; | ||
|
||
public DebugDataProvider() { | ||
final String atoz = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
|
||
mData = new LinkedList<>(); | ||
@SuppressWarnings("PointlessBitwiseExpression") | ||
final int[] swipeReactionTable = { | ||
RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT, | ||
RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT, | ||
RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_SWIPE_RIGHT, | ||
RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT_WITH_RUBBER_BAND_EFFECT | RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT, | ||
RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT_WITH_RUBBER_BAND_EFFECT | RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT, | ||
RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT_WITH_RUBBER_BAND_EFFECT | RecyclerViewSwipeManager.REACTION_CAN_SWIPE_RIGHT, | ||
RecyclerViewSwipeManager.REACTION_CAN_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT, | ||
RecyclerViewSwipeManager.REACTION_CAN_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT, | ||
RecyclerViewSwipeManager.REACTION_CAN_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_SWIPE_RIGHT, | ||
}; | ||
|
||
for (int i = 0; i < 2; i++) { | ||
for (int j = 0; j < atoz.length(); j++) { | ||
final long id = mData.size(); | ||
final int viewType = j % 2; | ||
final String text = Character.toString(atoz.charAt(j)); | ||
final int swipeReaction = swipeReactionTable[j % swipeReactionTable.length]; | ||
mData.add(new ConcreteData(id, viewType, text, swipeReaction)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mData.size(); | ||
} | ||
|
||
@Override | ||
public Data getItem(int index) { | ||
if (index < 0 || index >= getCount()) { | ||
throw new IndexOutOfBoundsException("index = " + index); | ||
} | ||
|
||
return mData.get(index); | ||
} | ||
|
||
@Override | ||
public int undoLastRemoval() { | ||
if (mLastRemovedData != null) { | ||
int insertedPosition; | ||
if (mLastRemovedPosition >= 0 && mLastRemovedPosition < mData.size()) { | ||
insertedPosition = mLastRemovedPosition; | ||
} else { | ||
insertedPosition = mData.size(); | ||
} | ||
|
||
mData.add(insertedPosition, mLastRemovedData); | ||
|
||
mLastRemovedData = null; | ||
mLastRemovedPosition = -1; | ||
|
||
return insertedPosition; | ||
} else { | ||
return -1; | ||
} | ||
} | ||
|
||
@Override | ||
public void moveItem(int fromPosition, int toPosition) { | ||
if (fromPosition == toPosition) { | ||
return; | ||
} | ||
|
||
final ConcreteData item = mData.remove(fromPosition); | ||
|
||
mData.add(toPosition, item); | ||
mLastRemovedPosition = -1; | ||
} | ||
|
||
@Override | ||
public void removeItem(int position) { | ||
//noinspection UnnecessaryLocalVariable | ||
final ConcreteData removedItem = mData.remove(position); | ||
|
||
mLastRemovedData = removedItem; | ||
mLastRemovedPosition = position; | ||
} | ||
|
||
public static final class ConcreteData extends Data { | ||
|
||
private final long mId; | ||
private final String mText; | ||
private final int mViewType; | ||
private final int mSwipeReaction; | ||
private boolean mPinnedToSwipeLeft; | ||
|
||
ConcreteData(long id, int viewType, String text, int swipeReaction) { | ||
mId = id; | ||
mViewType = viewType; | ||
mText = makeText(id, text, swipeReaction); | ||
mSwipeReaction = swipeReaction; | ||
} | ||
|
||
private static String makeText(long id, String text, int swipeReaction) { | ||
final StringBuilder sb = new StringBuilder(); | ||
|
||
sb.append(id); | ||
sb.append(" - "); | ||
sb.append(text); | ||
|
||
sb.append("\n"); | ||
|
||
sb.append("(LEFT: "); | ||
switch (swipeReaction & 0x03) { | ||
case RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT: | ||
sb.append("disabled"); | ||
break; | ||
case RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_LEFT_WITH_RUBBER_BAND_EFFECT: | ||
sb.append("rubber band effect"); | ||
break; | ||
case RecyclerViewSwipeManager.REACTION_CAN_SWIPE_LEFT: | ||
sb.append("enabled"); | ||
break; | ||
} | ||
sb.append(", RIGHT: "); | ||
switch (swipeReaction & (0x03 << 16)) { | ||
case RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT: | ||
sb.append("disabled"); | ||
break; | ||
case RecyclerViewSwipeManager.REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT: | ||
sb.append("rubber band effect"); | ||
break; | ||
case RecyclerViewSwipeManager.REACTION_CAN_SWIPE_RIGHT: | ||
sb.append("enabled"); | ||
break; | ||
} | ||
sb.append(")"); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public boolean isSectionHeader() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getViewType() { | ||
return mViewType; | ||
} | ||
|
||
@Override | ||
public long getId() { | ||
return mId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return mText; | ||
} | ||
|
||
@Override | ||
public int getSwipeReactionType() { | ||
return mSwipeReaction; | ||
} | ||
|
||
@Override | ||
public String getText() { | ||
return mText; | ||
} | ||
|
||
@Override | ||
public boolean isPinnedToSwipeLeft() { | ||
return mPinnedToSwipeLeft; | ||
} | ||
|
||
@Override | ||
public void setPinnedToSwipeLeft(boolean pinedToSwipeLeft) { | ||
mPinnedToSwipeLeft = pinedToSwipeLeft; | ||
} | ||
} | ||
} |
Oops, something went wrong.