Fix switching to playlist on resume

Remove a bunch of unecessary code
This commit is contained in:
Andrew Rabert 2020-03-15 17:06:43 -04:00
parent 76efc2c62c
commit ecdae8c6e3
1 changed files with 3 additions and 52 deletions

View File

@ -65,8 +65,6 @@ import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static net.nullsum.audinaut.domain.MusicDirectory.Entry; import static net.nullsum.audinaut.domain.MusicDirectory.Entry;
@ -105,11 +103,9 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
private ImageButton repeatButton; private ImageButton repeatButton;
private View toggleListButton; private View toggleListButton;
private ScheduledExecutorService executorService;
private DownloadFile currentPlaying; private DownloadFile currentPlaying;
private int swipeDistance; private int swipeDistance;
private int swipeVelocity; private int swipeVelocity;
private ScheduledFuture<?> hideControlsFuture;
private List<DownloadFile> songList; private List<DownloadFile> songList;
private DownloadFileAdapter songListAdapter; private DownloadFileAdapter songListAdapter;
private boolean seekInProgress = false; private boolean seekInProgress = false;
@ -201,7 +197,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
return null; return null;
} }
}.execute(); }.execute();
setControlsVisible(true);
}); });
previousButton.setOnRepeatListener(() -> changeProgress(true)); previousButton.setOnRepeatListener(() -> changeProgress(true));
@ -214,7 +209,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
return true; return true;
} }
}.execute(); }.execute();
setControlsVisible(true);
}); });
nextButton.setOnRepeatListener(() -> changeProgress(false)); nextButton.setOnRepeatListener(() -> changeProgress(false));
@ -269,12 +263,10 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
break; break;
} }
updateRepeatButton(); updateRepeatButton();
setControlsVisible(true);
}); });
toggleListButton.setOnClickListener(view -> { toggleListButton.setOnClickListener(view -> {
toggleFullscreenAlbumArt(); toggleFullscreenAlbumArt();
setControlsVisible(true);
}); });
View overlay = rootView.findViewById(R.id.download_overlay_buttons); View overlay = rootView.findViewById(R.id.download_overlay_buttons);
@ -308,7 +300,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) { public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) {
if (fromUser) { if (fromUser) {
positionTextView.setText(Util.formatDuration(position / 1000)); positionTextView.setText(Util.formatDuration(position / 1000));
setControlsVisible(true);
} }
} }
}); });
@ -473,7 +464,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if (controller != null) { if (controller != null) {
SubsonicFragment fragment = new EqualizerFragment(); SubsonicFragment fragment = new EqualizerFragment();
replaceFragment(fragment); replaceFragment(fragment);
setControlsVisible(true);
return true; return true;
} }
@ -510,19 +500,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
} }
private void onResumeHandlers() { private void onResumeHandlers() {
executorService = Executors.newSingleThreadScheduledExecutor();
setControlsVisible(true);
final DownloadService downloadService = getDownloadService();
if (downloadService == null || downloadService.getCurrentPlaying() == null || startFlipped) {
playlistFlipper.setDisplayedChild(1);
startFlipped = false;
}
if (currentPlaying == null && downloadService != null && null == downloadService.getCurrentPlaying()) {
setAlbumArt(null, false);
}
context.runWhenServiceAvailable(() -> { context.runWhenServiceAvailable(() -> {
if (primaryFragment) { if (primaryFragment) {
DownloadService downloadService1 = getDownloadService(); DownloadService downloadService1 = getDownloadService();
@ -540,13 +517,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
} }
private void onPauseHandlers() { private void onPauseHandlers() {
if (executorService != null) {
DownloadService downloadService = getDownloadService(); DownloadService downloadService = getDownloadService();
if (downloadService != null) { if (downloadService != null) {
downloadService.removeOnSongChangeListener(this); downloadService.removeOnSongChangeListener(this);
} }
} }
}
@Override @Override
public void setPrimaryFragment(boolean primary) { public void setPrimaryFragment(boolean primary) {
@ -581,29 +556,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
return songListAdapter; return songListAdapter;
} }
private void scheduleHideControls() {
if (hideControlsFuture != null) {
hideControlsFuture.cancel(false);
}
final Handler handler = new Handler();
Runnable runnable = () -> handler.post(() -> setControlsVisible(false));
hideControlsFuture = executorService.schedule(runnable, 3000L, TimeUnit.MILLISECONDS);
}
private void setControlsVisible(boolean visible) {
try {
long duration = 1700L;
FadeOutAnimation.createAndStart(rootView.findViewById(R.id.download_overlay_buttons), !visible, duration);
if (visible) {
scheduleHideControls();
}
} catch (Exception ignored) {
}
}
// Scroll to current playing/downloading. // Scroll to current playing/downloading.
private void scrollToCurrent() { private void scrollToCurrent() {
if (getDownloadService() == null || songListAdapter == null) { if (getDownloadService() == null || songListAdapter == null) {
@ -693,7 +645,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
@Override @Override
public boolean onDown(MotionEvent me) { public boolean onDown(MotionEvent me) {
setControlsVisible(true);
return false; return false;
} }