diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 803e6f728..9e760bdf9 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -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(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(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) { @@ -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(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(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; } }); } @@ -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(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(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; diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index f1b2b9c8e..af6d4a2ac 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -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; @@ -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; @@ -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); @@ -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); @@ -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(context) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().previous(); - return null; - } - }.execute(); - setControlsVisible(true); + changeSong(true); } }); previousButton.setOnRepeatListener(new Runnable() { @@ -258,15 +251,7 @@ public void run() { nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - warnIfStorageUnavailable(); - new SilentBackgroundTask(context) { - @Override - protected Boolean doInBackground() throws Throwable { - getDownloadService().next(); - return true; - } - }.execute(); - setControlsVisible(true); + changeSong(false); } }); nextButton.setOnRepeatListener(new Runnable() { @@ -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; } }); @@ -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; } }); @@ -1013,6 +1002,27 @@ private void start() { } } + private void changeSong(final boolean previous) { + final DownloadService downloadService = getDownloadService(); + if(downloadService == null) { + return; + } + + warnIfStorageUnavailable(); + new SilentBackgroundTask(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) { diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index e90969007..dce5a9606 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -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; } @@ -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; } diff --git a/app/src/main/res/layout/abstract_fragment_activity.xml b/app/src/main/res/layout/abstract_fragment_activity.xml index ae6647c44..e4bc5611b 100644 --- a/app/src/main/res/layout/abstract_fragment_activity.xml +++ b/app/src/main/res/layout/abstract_fragment_activity.xml @@ -108,6 +108,7 @@ android:id="@+id/download_rewind" android:src="?attr/actionbar_rewind" android:padding="2dp" + android:longClickable="true" android:visibility="gone"/> diff --git a/app/src/main/res/layout/download_media_buttons.xml b/app/src/main/res/layout/download_media_buttons.xml index 0610c5f90..2b4115ee9 100644 --- a/app/src/main/res/layout/download_media_buttons.xml +++ b/app/src/main/res/layout/download_media_buttons.xml @@ -21,7 +21,7 @@ android:layout_centerVertical="true" /> - -