Skip to content

Commit

Permalink
Changed rewind/fastforward button actions so holding will skip tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
KBerstene committed Mar 29, 2019
1 parent 2b26df3 commit 2709c48
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,42 +275,32 @@ public void run() {
}

rewindButton = (ImageButton) findViewById(R.id.download_rewind);
previousButton = (ImageButton) findViewById(R.id.download_previous);
startButton = (ImageButton) findViewById(R.id.download_start);
nextButton = (ImageButton) findViewById(R.id.download_next);
fastforwardButton = (ImageButton) findViewById(R.id.download_fastforward);

rewindButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
if (getDownloadService() == null) {
return null;
}

getDownloadService().rewind();
return null;
}
}.execute();
changeProgress(true);
}
});
rewindButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
changeSong(true);
return true;
}
});

previousButton = (ImageButton) findViewById(R.id.download_previous);
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
if(getDownloadService() == null) {
return null;
}

getDownloadService().previous();
return null;
}
}.execute();
changeSong(true);
}
});

startButton = (ImageButton) findViewById(R.id.download_start);
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -332,39 +322,24 @@ protected Void doInBackground() throws Throwable {
}
});

nextButton = (ImageButton) findViewById(R.id.download_next);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
if(getDownloadService() == null) {
return null;
}

getDownloadService().next();
return null;
}
}.execute();
changeSong(false);
}
});

fastforwardButton = (ImageButton) findViewById(R.id.download_fastforward);
fastforwardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
if (getDownloadService() == null) {
return null;
}

getDownloadService().fastForward();
return null;
}
}.execute();
changeProgress(false);
}
});
fastforwardButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
changeSong(false);
return true;
}
});
}
Expand Down Expand Up @@ -919,6 +894,47 @@ public Toolbar getActiveToolbar() {
return slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED ? nowPlayingToolbar : mainToolbar;
}

private void changeProgress(final boolean rewind) {
final DownloadService downloadService = getDownloadService();
final Context context = this;

if(downloadService == null) {
return;
}

new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
if(rewind) {
downloadService.rewind();
} else {
downloadService.fastForward();
}
return null;
}
}.execute();
}

private void changeSong(final boolean previous) {
final DownloadService downloadService = getDownloadService();
final Context context = this;
if(downloadService == null) {
return;
}

new SilentBackgroundTask<Void>(this) {
@Override
protected Void doInBackground() throws Throwable {
if(previous) {
downloadService.previous();
} else {
downloadService.next();
}
return null;
}
}.execute();
}

@Override
public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward) {
this.currentPlaying = currentPlaying;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ViewFlipper;
Expand Down Expand Up @@ -109,8 +108,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
private SeekBar progressBar;
private AutoRepeatButton previousButton;
private AutoRepeatButton nextButton;
private AutoRepeatButton rewindButton;
private AutoRepeatButton fastforwardButton;
private ImageButton rewindButton;
private ImageButton fastforwardButton;
private View pauseButton;
private View stopButton;
private View startButton;
Expand Down Expand Up @@ -179,8 +178,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bu
progressBar = (SeekBar)rootView.findViewById(R.id.download_progress_bar);
previousButton = (AutoRepeatButton)rootView.findViewById(R.id.download_previous);
nextButton = (AutoRepeatButton)rootView.findViewById(R.id.download_next);
rewindButton = (AutoRepeatButton) rootView.findViewById(R.id.download_rewind);
fastforwardButton = (AutoRepeatButton) rootView.findViewById(R.id.download_fastforward);
rewindButton = rootView.findViewById(R.id.download_rewind);
fastforwardButton = rootView.findViewById(R.id.download_fastforward);
pauseButton =rootView.findViewById(R.id.download_pause);
stopButton =rootView.findViewById(R.id.download_stop);
startButton =rootView.findViewById(R.id.download_start);
Expand Down Expand Up @@ -220,6 +219,8 @@ public boolean onTouch(View v, MotionEvent me) {
pauseButton.setOnTouchListener(touchListener);
stopButton.setOnTouchListener(touchListener);
startButton.setOnTouchListener(touchListener);
rewindButton.setOnTouchListener(touchListener);
fastforwardButton.setOnTouchListener(touchListener);
bookmarkButton.setOnTouchListener(touchListener);
rateBadButton.setOnTouchListener(touchListener);
rateGoodButton.setOnTouchListener(touchListener);
Expand All @@ -238,15 +239,7 @@ public boolean onTouch(View v, MotionEvent me) {
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
warnIfStorageUnavailable();
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().previous();
return null;
}
}.execute();
setControlsVisible(true);
changeSong(true);
}
});
previousButton.setOnRepeatListener(new Runnable() {
Expand All @@ -258,15 +251,7 @@ public void run() {
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
warnIfStorageUnavailable();
new SilentBackgroundTask<Boolean>(context) {
@Override
protected Boolean doInBackground() throws Throwable {
getDownloadService().next();
return true;
}
}.execute();
setControlsVisible(true);
changeSong(false);
}
});
nextButton.setOnRepeatListener(new Runnable() {
Expand All @@ -281,9 +266,11 @@ public void onClick(View view) {
changeProgress(true);
}
});
rewindButton.setOnRepeatListener(new Runnable() {
public void run() {
changeProgress(true);
rewindButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
changeSong(true);
return true;
}
});

Expand All @@ -293,9 +280,11 @@ public void onClick(View view) {
changeProgress(false);
}
});
fastforwardButton.setOnRepeatListener(new Runnable() {
public void run() {
changeProgress(false);
fastforwardButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
changeSong(false);
return true;
}
});

Expand Down Expand Up @@ -1013,6 +1002,27 @@ private void start() {
}
}

private void changeSong(final boolean previous) {
final DownloadService downloadService = getDownloadService();
if(downloadService == null) {
return;
}

warnIfStorageUnavailable();
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
if(previous) {
downloadService.previous();
} else {
downloadService.next();
}
return null;
}
}.execute();
setControlsVisible(true);
}

private void changeProgress(final boolean rewind) {
final DownloadService downloadService = getDownloadService();
if(downloadService == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,7 @@ public synchronized void previous() {
return;
}

// If only one song, just skip within song
if(shouldFastForward()) {
rewind();
return;
} else if(playerState == PREPARING || playerState == PREPARED) {
if(playerState == PREPARING || playerState == PREPARED) {
return;
}

Expand All @@ -1282,11 +1278,7 @@ public synchronized void next(boolean forceCutoff) {
next(forceCutoff, false);
}
public synchronized void next(boolean forceCutoff, boolean forceStart) {
// If only one song, just skip within song
if(shouldFastForward()) {
fastForward();
return;
} else if(playerState == PREPARING || playerState == PREPARED) {
if(playerState == PREPARING || playerState == PREPARED) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/abstract_fragment_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
android:id="@+id/download_rewind"
android:src="?attr/actionbar_rewind"
android:padding="2dp"
android:longClickable="true"
android:visibility="gone"/>

<ImageButton
Expand All @@ -132,6 +133,7 @@
android:id="@+id/download_fastforward"
android:src="?attr/actionbar_fastforward"
android:padding="2dp"
android:longClickable="true"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
Expand Down

0 comments on commit 2709c48

Please sign in to comment.