Commit 0f78ddca authored by CaoRX's avatar CaoRX

fix: use random shuffle for unSort

parent 834751c0
...@@ -141,16 +141,9 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -141,16 +141,9 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
public void unSort() { public void unSort() {
if (mMainCount == 0) return; if (mMainCount == 0) return;
for (int i = 0; i < Constants.UNSORT_TIMES; i++) { for (int i = 0; i < mMainCount; i++) {
int index1 = mRandom.nextInt(mMainCount); int index = mRandom.nextInt(mMainCount - i);
int index2 = mRandom.nextInt(mMainCount); Collections.swap(mItems, DeckItem.MainStart + i, DeckItem.MainStart + i + index);
if (index1 != index2) {
int sp = (mMainCount - Math.max(index1, index2));
int count = sp > 1 ? mRandom.nextInt(sp - 1) : 1;
for (int j = 0; j < count; j++) {
Collections.swap(mItems, DeckItem.MainStart + index1 + j, DeckItem.MainStart + index2 + j);
}
}
} }
notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount()); notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment