Skip to content

Commit

Permalink
-Added save on exit to local playlist fragment.
Browse files Browse the repository at this point in the history
-Improved drag reordering experience by setting minimum velocity.
-Increased save debounce to 10 seconds.
  • Loading branch information
karyogamy committed Jan 31, 2018
1 parent 326a5c4 commit 35e7b10
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistStreamEntry>, Void> {

private static final long SAVE_DEBOUNCE_MILLIS = 2000;
// Save the list 10 seconds after the last change occurred
private static final long SAVE_DEBOUNCE_MILLIS = 10000;
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 15;

private View headerRootLayout;
private TextView headerTitleView;
Expand Down Expand Up @@ -205,6 +207,7 @@ public void startLoading(boolean forceLoad) {
public void onPause() {
super.onPause();
itemsListState = itemsList.getLayoutManager().onSaveInstanceState();
saveImmediate(); // Save on exit
}

@Override
Expand Down Expand Up @@ -371,10 +374,10 @@ private Disposable getDebouncedSaver() {
return debouncedSaveSignal
.debounce(SAVE_DEBOUNCE_MILLIS, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> saveJoin());
.subscribe(ignored -> saveImmediate());
}

private void saveJoin() {
private void saveImmediate() {
final List<LocalItem> items = itemListAdapter.getItemsList();
List<Long> streamIds = new ArrayList<>(items.size());
for (final LocalItem item : items) {
Expand Down Expand Up @@ -449,6 +452,17 @@ protected void showStreamDialog(final PlaylistStreamEntry item) {
private ItemTouchHelper.SimpleCallback getItemTouchCallback() {
return new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,
ItemTouchHelper.ACTION_STATE_IDLE) {
@Override
public int interpolateOutOfBoundsScroll(RecyclerView recyclerView, int viewSize,
int viewSizeOutOfBounds, int totalSize,
long msSinceStartScroll) {
final int standardSpeed = super.interpolateOutOfBoundsScroll(recyclerView, viewSize,
viewSizeOutOfBounds, totalSize, msSinceStartScroll);
final int minimumAbsVelocity = Math.max(MINIMUM_INITIAL_DRAG_VELOCITY,
Math.abs(standardSpeed));
return minimumAbsVelocity * (int) Math.signum(viewSizeOutOfBounds);
}

@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source,
RecyclerView.ViewHolder target) {
Expand Down

0 comments on commit 35e7b10

Please sign in to comment.