2013-02-10 09:13:20 +01:00
|
|
|
/*
|
|
|
|
This file is part of Subsonic.
|
|
|
|
|
|
|
|
Subsonic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Subsonic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2009 (C) Sindre Mehus
|
|
|
|
*/
|
2013-04-06 21:47:24 +02:00
|
|
|
package com.thejoshwa.ultrasonic.androidapp.activity;
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2013-04-28 01:01:34 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2013-02-10 09:13:20 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2013-04-09 08:01:45 +02:00
|
|
|
import android.util.Log;
|
2013-05-17 09:00:20 +02:00
|
|
|
import android.view.*;
|
2013-02-10 09:13:20 +01:00
|
|
|
import android.view.GestureDetector.OnGestureListener;
|
|
|
|
import android.view.animation.AnimationUtils;
|
2013-05-17 09:00:20 +02:00
|
|
|
import android.widget.*;
|
2013-05-26 07:19:28 +02:00
|
|
|
|
2013-04-06 21:47:24 +02:00
|
|
|
import com.thejoshwa.ultrasonic.androidapp.R;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.domain.MusicDirectory;
|
2013-04-09 08:01:45 +02:00
|
|
|
import com.thejoshwa.ultrasonic.androidapp.domain.MusicDirectory.Entry;
|
2013-04-06 21:47:24 +02:00
|
|
|
import com.thejoshwa.ultrasonic.androidapp.domain.PlayerState;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.domain.RepeatMode;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.service.DownloadFile;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.service.DownloadService;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.service.MusicService;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.service.MusicServiceFactory;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.util.Constants;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.util.SilentBackgroundTask;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.util.Util;
|
2013-05-16 09:59:55 +02:00
|
|
|
import com.thejoshwa.ultrasonic.androidapp.view.AutoRepeatButton;
|
|
|
|
import com.thejoshwa.ultrasonic.androidapp.view.SongView;
|
2013-04-06 21:47:24 +02:00
|
|
|
import com.thejoshwa.ultrasonic.androidapp.view.VisualizerView;
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2013-04-06 21:47:24 +02:00
|
|
|
import static com.thejoshwa.ultrasonic.androidapp.domain.PlayerState.*;
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
public class DownloadActivity extends SubsonicTabActivity implements OnGestureListener {
|
2013-04-09 08:01:45 +02:00
|
|
|
private static final String TAG = DownloadActivity.class.getSimpleName();
|
2013-02-10 09:13:20 +01:00
|
|
|
private static final int DIALOG_SAVE_PLAYLIST = 100;
|
|
|
|
private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 5;
|
|
|
|
|
|
|
|
private ViewFlipper playlistFlipper;
|
|
|
|
private TextView emptyTextView;
|
|
|
|
private TextView songTitleTextView;
|
|
|
|
private TextView albumTextView;
|
|
|
|
private TextView artistTextView;
|
|
|
|
private ImageView albumArtImageView;
|
|
|
|
private ListView playlistView;
|
|
|
|
private TextView positionTextView;
|
2013-05-26 07:19:28 +02:00
|
|
|
private TextView downloadTrackTextView;
|
|
|
|
private TextView downloadTotalDurationTextView;
|
2013-02-10 09:13:20 +01:00
|
|
|
private TextView durationTextView;
|
|
|
|
private static SeekBar progressBar;
|
|
|
|
private View pauseButton;
|
|
|
|
private View stopButton;
|
|
|
|
private View startButton;
|
2013-04-28 01:01:34 +02:00
|
|
|
private ImageView repeatButton;
|
2013-05-29 10:21:09 +02:00
|
|
|
private ImageButton starImageButton;
|
|
|
|
private ImageButton bookmarkImageButton;
|
|
|
|
private ImageButton removeAllImageButton;
|
|
|
|
private ImageButton saveImageButton;
|
2013-02-10 09:13:20 +01:00
|
|
|
private ScheduledExecutorService executorService;
|
|
|
|
private DownloadFile currentPlaying;
|
2013-04-09 08:01:45 +02:00
|
|
|
private Entry currentSong;
|
2013-02-10 09:13:20 +01:00
|
|
|
private long currentRevision;
|
|
|
|
private EditText playlistNameView;
|
|
|
|
private GestureDetector gestureScanner;
|
|
|
|
private int swipeDistance;
|
|
|
|
private int swipeVelocity;
|
|
|
|
private VisualizerView visualizerView;
|
|
|
|
private boolean visualizerAvailable;
|
|
|
|
private boolean equalizerAvailable;
|
2013-05-16 09:59:55 +02:00
|
|
|
private SilentBackgroundTask<Void> onProgressChangedTask;
|
2013-05-29 10:21:09 +02:00
|
|
|
LinearLayout visualizerViewLayout;
|
2013-05-16 09:59:55 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
/**
|
|
|
|
* Called when the activity is first created.
|
|
|
|
*/
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
2013-02-10 09:13:20 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.download);
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final WindowManager windowManager = getWindowManager();
|
|
|
|
final Display display = windowManager.getDefaultDisplay();
|
|
|
|
swipeDistance = (display.getWidth() + display.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
|
|
|
|
swipeVelocity = (display.getWidth() + display.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
|
2013-02-10 09:13:20 +01:00
|
|
|
gestureScanner = new GestureDetector(this);
|
|
|
|
|
|
|
|
playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper);
|
|
|
|
emptyTextView = (TextView) findViewById(R.id.download_empty);
|
|
|
|
songTitleTextView = (TextView) findViewById(R.id.download_song_title);
|
|
|
|
albumTextView = (TextView) findViewById(R.id.download_album);
|
|
|
|
artistTextView = (TextView) findViewById(R.id.download_artist);
|
|
|
|
albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image);
|
|
|
|
positionTextView = (TextView) findViewById(R.id.download_position);
|
2013-05-26 07:19:28 +02:00
|
|
|
downloadTrackTextView = (TextView) findViewById(R.id.download_track);
|
|
|
|
downloadTotalDurationTextView = (TextView) findViewById(R.id.download_total_duration);
|
2013-02-10 09:13:20 +01:00
|
|
|
durationTextView = (TextView) findViewById(R.id.download_duration);
|
|
|
|
progressBar = (SeekBar) findViewById(R.id.download_progress_bar);
|
|
|
|
playlistView = (ListView) findViewById(R.id.download_list);
|
2013-05-17 09:00:20 +02:00
|
|
|
final AutoRepeatButton previousButton = (AutoRepeatButton) findViewById(R.id.download_previous);
|
|
|
|
final AutoRepeatButton nextButton = (AutoRepeatButton) findViewById(R.id.download_next);
|
2013-02-10 09:13:20 +01:00
|
|
|
pauseButton = findViewById(R.id.download_pause);
|
|
|
|
stopButton = findViewById(R.id.download_stop);
|
|
|
|
startButton = findViewById(R.id.download_start);
|
2013-05-17 09:00:20 +02:00
|
|
|
final View shuffleButton = findViewById(R.id.download_shuffle);
|
2013-04-28 01:01:34 +02:00
|
|
|
repeatButton = (ImageView) findViewById(R.id.download_repeat);
|
2013-05-29 10:21:09 +02:00
|
|
|
starImageButton = (ImageButton) findViewById(R.id.download_star);
|
|
|
|
bookmarkImageButton = (ImageButton) findViewById(R.id.download_bookmark);
|
|
|
|
removeAllImageButton = (ImageButton) findViewById(R.id.download_remove_all);
|
|
|
|
saveImageButton = (ImageButton) findViewById(R.id.download_save_playlist);
|
|
|
|
visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout);
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-29 10:21:09 +02:00
|
|
|
final ImageButton toggleListButton = (ImageButton) findViewById(R.id.download_toggle_list);
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
albumArtImageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
|
|
|
toggleFullScreenAlbumArt();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
previousButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
|
|
|
warnIfNetworkOrStorageUnavailable();
|
2013-05-16 09:59:55 +02:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
new SilentBackgroundTask<Void>(DownloadActivity.this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
getDownloadService().previous();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void done(final Void result) {
|
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
2013-05-16 09:59:55 +02:00
|
|
|
|
|
|
|
previousButton.setOnRepeatListener(new Runnable() {
|
2013-05-17 09:00:20 +02:00
|
|
|
public void run() {
|
2013-05-17 09:26:06 +02:00
|
|
|
int incrementTime = Util.getIncrementTime(DownloadActivity.this);
|
|
|
|
changeProgress(-incrementTime);
|
2013-05-17 09:00:20 +02:00
|
|
|
}
|
|
|
|
});
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
nextButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
2013-02-10 09:13:20 +01:00
|
|
|
warnIfNetworkOrStorageUnavailable();
|
2013-05-17 09:00:20 +02:00
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
new SilentBackgroundTask<Boolean>(DownloadActivity.this) {
|
2013-05-17 09:00:20 +02:00
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground() throws Throwable {
|
|
|
|
if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
|
|
|
|
getDownloadService().next();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 09:59:55 +02:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
@Override
|
|
|
|
protected void done(final Boolean result) {
|
|
|
|
if (result) {
|
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
2013-05-16 09:59:55 +02:00
|
|
|
|
|
|
|
nextButton.setOnRepeatListener(new Runnable() {
|
2013-05-17 09:00:20 +02:00
|
|
|
public void run() {
|
2013-05-17 09:26:06 +02:00
|
|
|
int incrementTime = Util.getIncrementTime(DownloadActivity.this);
|
|
|
|
changeProgress(incrementTime);
|
2013-05-17 09:00:20 +02:00
|
|
|
}
|
|
|
|
});
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
pauseButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
2013-05-16 09:59:55 +02:00
|
|
|
new SilentBackgroundTask<Void>(DownloadActivity.this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
getDownloadService().pause();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
stopButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
2013-05-16 09:59:55 +02:00
|
|
|
new SilentBackgroundTask<Void>(DownloadActivity.this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
getDownloadService().reset();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
startButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
2013-02-10 09:13:20 +01:00
|
|
|
warnIfNetworkOrStorageUnavailable();
|
2013-05-16 09:59:55 +02:00
|
|
|
|
|
|
|
new SilentBackgroundTask<Void>(DownloadActivity.this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
start();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
shuffleButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
2013-02-10 09:13:20 +01:00
|
|
|
getDownloadService().shuffle();
|
|
|
|
Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
repeatButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
|
|
|
final RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
getDownloadService().setRepeatMode(repeatMode);
|
|
|
|
onDownloadListChanged();
|
2013-05-17 09:00:20 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
switch (repeatMode) {
|
|
|
|
case OFF:
|
|
|
|
Util.toast(DownloadActivity.this, R.string.download_repeat_off);
|
|
|
|
break;
|
|
|
|
case ALL:
|
|
|
|
Util.toast(DownloadActivity.this, R.string.download_repeat_all);
|
|
|
|
break;
|
|
|
|
case SINGLE:
|
|
|
|
Util.toast(DownloadActivity.this, R.string.download_repeat_single);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
toggleListButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
|
|
|
toggleFullScreenAlbumArt();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onStopTrackingTouch(final SeekBar seekBar) {
|
2013-05-16 09:59:55 +02:00
|
|
|
new SilentBackgroundTask<Void>(DownloadActivity.this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
getDownloadService().seekTo(getProgressBar().getProgress());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onStartTrackingTouch(final SeekBar seekBar) {
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
|
2013-02-10 09:13:20 +01:00
|
|
|
warnIfNetworkOrStorageUnavailable();
|
2013-05-16 09:59:55 +02:00
|
|
|
|
|
|
|
new SilentBackgroundTask<Void>(DownloadActivity.this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
getDownloadService().play(position);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
registerForContextMenu(playlistView);
|
2013-04-09 08:01:45 +02:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final DownloadService downloadService = getDownloadService();
|
2013-02-10 09:13:20 +01:00
|
|
|
if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
|
|
|
|
warnIfNetworkOrStorageUnavailable();
|
|
|
|
downloadService.setShufflePlayEnabled(true);
|
|
|
|
}
|
2013-04-09 08:01:45 +02:00
|
|
|
|
|
|
|
if (Util.isOffline(this)) {
|
2013-05-29 10:21:09 +02:00
|
|
|
starImageButton.setVisibility(View.GONE);
|
|
|
|
bookmarkImageButton.setVisibility(View.GONE);
|
2013-04-09 08:01:45 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 10:21:09 +02:00
|
|
|
starImageButton.setOnClickListener(new View.OnClickListener() {
|
2013-04-09 08:01:45 +02:00
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final View view) {
|
2013-04-09 08:01:45 +02:00
|
|
|
if (currentSong == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean isStarred = currentSong.getStarred();
|
|
|
|
final String id = currentSong.getId();
|
2013-05-17 09:00:20 +02:00
|
|
|
|
|
|
|
if (isStarred) {
|
2013-05-29 10:21:09 +02:00
|
|
|
starImageButton.setImageDrawable(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow));
|
2013-05-17 09:00:20 +02:00
|
|
|
currentSong.setStarred(false);
|
|
|
|
} else {
|
2013-05-29 10:21:09 +02:00
|
|
|
starImageButton.setImageDrawable(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full));
|
2013-05-17 09:00:20 +02:00
|
|
|
currentSong.setStarred(true);
|
|
|
|
}
|
2013-04-09 08:01:45 +02:00
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
2013-05-26 07:19:28 +02:00
|
|
|
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
|
2013-04-09 08:01:45 +02:00
|
|
|
|
|
|
|
try {
|
2013-05-17 09:00:20 +02:00
|
|
|
if (isStarred) {
|
2013-05-26 07:19:28 +02:00
|
|
|
musicService.unstar(id, null, null, DownloadActivity.this, null);
|
2013-05-17 09:00:20 +02:00
|
|
|
} else {
|
2013-05-26 07:19:28 +02:00
|
|
|
musicService.star(id, null, null, DownloadActivity.this, null);
|
2013-05-17 09:00:20 +02:00
|
|
|
}
|
2013-04-09 08:01:45 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(TAG, e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
});
|
2013-05-29 10:21:09 +02:00
|
|
|
|
|
|
|
bookmarkImageButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View view) {
|
|
|
|
if (currentSong == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-29 10:21:09 +02:00
|
|
|
final String id = currentSong.getId();
|
|
|
|
final int playerPosition = getDownloadService()
|
|
|
|
.getPlayerPosition();
|
|
|
|
|
|
|
|
currentSong.setBookmarkPosition(playerPosition);
|
|
|
|
|
|
|
|
String bookmarkTime = Util.formatTotalDuration(playerPosition, true);
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
|
|
|
|
|
|
|
|
try {
|
|
|
|
musicService.createBookmark(id, playerPosition, DownloadActivity.this, null);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(TAG, e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
String msg = getResources().getString(R.string.download_bookmark_set_at_position, bookmarkTime);
|
|
|
|
|
|
|
|
Util.toast(DownloadActivity.this, msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bookmarkImageButton.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(final View view) {
|
|
|
|
if (currentSong == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String id = currentSong.getId();
|
|
|
|
currentSong.setBookmarkPosition(0);
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
|
|
|
|
|
|
|
|
try {
|
|
|
|
musicService.deleteBookmark(id, DownloadActivity.this, null);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(TAG, e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
Util.toast(DownloadActivity.this, R.string.download_bookmark_removed);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
removeAllImageButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View view) {
|
|
|
|
getDownloadService().setShufflePlayEnabled(false);
|
|
|
|
getDownloadService().clear();
|
|
|
|
onDownloadListChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
saveImageButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View view) {
|
|
|
|
showDialog(DIALOG_SAVE_PLAYLIST);
|
|
|
|
}
|
|
|
|
});
|
2013-05-26 07:19:28 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null;
|
|
|
|
equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null;
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final View nowPlayingMenuItem = findViewById(R.id.menu_now_playing);
|
2013-04-27 11:52:25 +02:00
|
|
|
menuDrawer.setActiveView(nowPlayingMenuItem);
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
if (visualizerAvailable) {
|
|
|
|
visualizerView = new VisualizerView(this);
|
|
|
|
visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
|
|
|
|
|
2013-05-29 10:21:09 +02:00
|
|
|
if (!visualizerView.isActive()) {
|
|
|
|
visualizerViewLayout.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
visualizerViewLayout.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
visualizerView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onTouch(final View view, final MotionEvent motionEvent) {
|
2013-02-10 09:13:20 +01:00
|
|
|
visualizerView.setActive(!visualizerView.isActive());
|
|
|
|
getDownloadService().setShowVisualization(visualizerView.isActive());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2013-05-29 10:21:09 +02:00
|
|
|
} else {
|
|
|
|
visualizerViewLayout.setVisibility(View.GONE);
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2013-05-29 10:21:09 +02:00
|
|
|
final DownloadService downloadService = getDownloadService();
|
|
|
|
|
|
|
|
if (downloadService == null || downloadService.getCurrentPlaying() == null) {
|
|
|
|
playlistFlipper.setDisplayedChild(1);
|
|
|
|
}
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
final Handler handler = new Handler();
|
2013-05-17 09:00:20 +02:00
|
|
|
final Runnable runnable = new Runnable() {
|
2013-02-10 09:13:20 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2013-05-29 10:21:09 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
executorService = Executors.newSingleThreadScheduledExecutor();
|
2013-05-29 10:21:09 +02:00
|
|
|
executorService.scheduleWithFixedDelay(runnable, 0L, 500L, TimeUnit.MILLISECONDS);
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
if (downloadService != null && downloadService.getKeepScreenOn()) {
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
} else {
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visualizerView != null) {
|
|
|
|
visualizerView.setActive(downloadService != null && downloadService.getShowVisualization());
|
|
|
|
}
|
2013-05-29 10:21:09 +02:00
|
|
|
|
|
|
|
if (Util.isOffline(this)) {
|
|
|
|
saveImageButton.setVisibility(View.GONE);
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
2013-05-26 07:19:28 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
// Scroll to current playing/downloading.
|
|
|
|
private void scrollToCurrent() {
|
|
|
|
if (getDownloadService() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-26 07:19:28 +02:00
|
|
|
|
2013-05-29 10:21:09 +02:00
|
|
|
ListAdapter adapter = playlistView.getAdapter();
|
|
|
|
|
|
|
|
if (adapter != null) {
|
|
|
|
int count = adapter.getCount();
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
if (currentPlaying == playlistView.getItemAtPosition(i)) {
|
|
|
|
playlistView.smoothScrollToPositionFromTop(i, 40);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final DownloadFile currentDownloading = getDownloadService().getCurrentDownloading();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
if (currentDownloading == playlistView.getItemAtPosition(i)) {
|
|
|
|
playlistView.smoothScrollToPositionFromTop(i, 40);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
executorService.shutdown();
|
2013-05-29 10:21:09 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
if (visualizerView != null) {
|
|
|
|
visualizerView.setActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected Dialog onCreateDialog(final int id) {
|
2013-02-10 09:13:20 +01:00
|
|
|
if (id == DIALOG_SAVE_PLAYLIST) {
|
2013-05-17 09:00:20 +02:00
|
|
|
final AlertDialog.Builder builder;
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
|
|
|
final View layout = layoutInflater.inflate(R.layout.save_playlist, (ViewGroup) findViewById(R.id.save_playlist_root));
|
2013-02-10 09:13:20 +01:00
|
|
|
playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name);
|
|
|
|
|
|
|
|
builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.download_playlist_title);
|
|
|
|
builder.setMessage(R.string.download_playlist_name);
|
|
|
|
builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final DialogInterface dialog, final int clickId) {
|
2013-02-10 09:13:20 +01:00
|
|
|
savePlaylistInBackground(String.valueOf(playlistNameView.getText()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onClick(final DialogInterface dialog, final int clickId) {
|
2013-02-10 09:13:20 +01:00
|
|
|
dialog.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setView(layout);
|
|
|
|
builder.setCancelable(true);
|
|
|
|
|
|
|
|
return builder.create();
|
|
|
|
} else {
|
|
|
|
return super.onCreateDialog(id);
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 09:59:55 +02:00
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void onPrepareDialog(final int id, final Dialog dialog) {
|
2013-02-10 09:13:20 +01:00
|
|
|
if (id == DIALOG_SAVE_PLAYLIST) {
|
2013-05-17 09:00:20 +02:00
|
|
|
final String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null;
|
2013-02-10 09:13:20 +01:00
|
|
|
if (playlistName != null) {
|
|
|
|
playlistNameView.setText(playlistName);
|
|
|
|
} else {
|
2013-05-17 09:00:20 +02:00
|
|
|
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
2013-02-10 09:13:20 +01:00
|
|
|
playlistNameView.setText(dateFormat.format(new Date()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
|
|
|
final MenuInflater menuInflater = getMenuInflater();
|
|
|
|
menuInflater.inflate(R.menu.nowplaying, menu);
|
2013-02-10 09:13:20 +01:00
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onPrepareOptionsMenu(final Menu menu) {
|
2013-05-29 10:21:09 +02:00
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final MenuItem screenOption = menu.findItem(R.id.menu_screen_on_off);
|
2013-05-29 10:21:09 +02:00
|
|
|
final MenuItem jukeboxOption = menu.findItem(R.id.download_jukebox);
|
2013-05-17 09:00:20 +02:00
|
|
|
final MenuItem equalizerMenuItem = menu.findItem(R.id.download_equalizer);
|
|
|
|
final MenuItem visualizerMenuItem = menu.findItem(R.id.download_visualizer);
|
|
|
|
|
|
|
|
if (equalizerMenuItem != null) {
|
|
|
|
equalizerMenuItem.setEnabled(equalizerAvailable);
|
|
|
|
equalizerMenuItem.setVisible(equalizerAvailable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visualizerMenuItem != null) {
|
|
|
|
visualizerMenuItem.setEnabled(visualizerAvailable);
|
|
|
|
visualizerMenuItem.setVisible(visualizerAvailable);
|
|
|
|
}
|
|
|
|
|
|
|
|
final DownloadService downloadService = getDownloadService();
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
if (downloadService != null) {
|
2013-05-29 10:21:09 +02:00
|
|
|
if (downloadService.getKeepScreenOn()) {
|
2013-05-17 09:00:20 +02:00
|
|
|
if (screenOption != null) {
|
|
|
|
screenOption.setTitle(R.string.download_menu_screen_off);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (screenOption != null) {
|
|
|
|
screenOption.setTitle(R.string.download_menu_screen_on);
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 10:21:09 +02:00
|
|
|
|
|
|
|
if (downloadService.isJukeboxEnabled()) {
|
|
|
|
if (jukeboxOption != null) {
|
|
|
|
jukeboxOption.setTitle(R.string.download_menu_jukebox_off);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (jukeboxOption != null) {
|
|
|
|
jukeboxOption.setTitle(R.string.download_menu_jukebox_on);
|
|
|
|
}
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
2013-05-29 10:21:09 +02:00
|
|
|
|
|
|
|
return true;
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo menuInfo) {
|
2013-02-10 09:13:20 +01:00
|
|
|
super.onCreateContextMenu(menu, view, menuInfo);
|
|
|
|
if (view == playlistView) {
|
2013-05-17 09:00:20 +02:00
|
|
|
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
|
|
|
final DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
|
|
|
|
|
|
|
|
final MenuInflater menuInflater = getMenuInflater();
|
|
|
|
menuInflater.inflate(R.menu.nowplaying_context, menu);
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
Entry song = null;
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
if (downloadFile != null) {
|
|
|
|
song = downloadFile.getSong();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (song != null && song.getParent() == null) {
|
2013-02-10 09:13:20 +01:00
|
|
|
menu.findItem(R.id.menu_show_album).setVisible(false);
|
|
|
|
}
|
|
|
|
if (Util.isOffline(this)) {
|
|
|
|
menu.findItem(R.id.menu_lyrics).setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onContextItemSelected(final MenuItem menuItem) {
|
|
|
|
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
|
|
|
|
|
|
|
|
DownloadFile downloadFile = null;
|
|
|
|
|
|
|
|
if (info != null) {
|
|
|
|
downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
|
|
|
|
}
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
2013-02-10 09:13:20 +01:00
|
|
|
return menuItemSelected(menuItem.getItemId(), null) || super.onOptionsItemSelected(menuItem);
|
|
|
|
}
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
private boolean menuItemSelected(final int menuItemId, final DownloadFile song) {
|
2013-02-10 09:13:20 +01:00
|
|
|
switch (menuItemId) {
|
|
|
|
case R.id.menu_show_album:
|
|
|
|
Intent intent = new Intent(this, SelectAlbumActivity.class);
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, song.getSong().getParent());
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, song.getSong().getAlbum());
|
|
|
|
Util.startActivityWithoutTransition(this, intent);
|
|
|
|
return true;
|
|
|
|
case R.id.menu_lyrics:
|
|
|
|
intent = new Intent(this, LyricsActivity.class);
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, song.getSong().getArtist());
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle());
|
|
|
|
Util.startActivityWithoutTransition(this, intent);
|
|
|
|
return true;
|
|
|
|
case R.id.menu_remove:
|
|
|
|
getDownloadService().remove(song);
|
|
|
|
onDownloadListChanged();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_screen_on_off:
|
|
|
|
if (getDownloadService().getKeepScreenOn()) {
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
getDownloadService().setKeepScreenOn(false);
|
|
|
|
} else {
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
getDownloadService().setKeepScreenOn(true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.menu_shuffle:
|
|
|
|
getDownloadService().shuffle();
|
|
|
|
Util.toast(this, R.string.download_menu_shuffle_notification);
|
|
|
|
return true;
|
|
|
|
case R.id.download_equalizer:
|
|
|
|
startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
|
|
|
|
return true;
|
|
|
|
case R.id.download_visualizer:
|
2013-05-17 09:00:20 +02:00
|
|
|
final boolean active = !visualizerView.isActive();
|
2013-02-10 09:13:20 +01:00
|
|
|
visualizerView.setActive(active);
|
2013-05-29 10:21:09 +02:00
|
|
|
|
|
|
|
if (!visualizerView.isActive()) {
|
|
|
|
visualizerViewLayout.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
visualizerViewLayout.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
getDownloadService().setShowVisualization(visualizerView.isActive());
|
|
|
|
Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
|
|
|
|
return true;
|
|
|
|
case R.id.download_jukebox:
|
2013-05-17 09:00:20 +02:00
|
|
|
final boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
|
2013-02-10 09:13:20 +01:00
|
|
|
getDownloadService().setJukeboxEnabled(jukeboxEnabled);
|
|
|
|
Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void update() {
|
|
|
|
if (getDownloadService() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentRevision != getDownloadService().getDownloadListUpdateRevision()) {
|
|
|
|
onDownloadListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentPlaying != getDownloadService().getCurrentPlaying()) {
|
|
|
|
onCurrentChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void savePlaylistInBackground(final String playlistName) {
|
|
|
|
Util.toast(DownloadActivity.this, getResources().getString(R.string.download_playlist_saving, playlistName));
|
|
|
|
getDownloadService().setSuggestedPlaylistName(playlistName);
|
|
|
|
new SilentBackgroundTask<Void>(this) {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
2013-05-17 09:00:20 +02:00
|
|
|
final List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>();
|
|
|
|
for (final DownloadFile downloadFile : getDownloadService().getSongs()) {
|
2013-02-10 09:13:20 +01:00
|
|
|
entries.add(downloadFile.getSong());
|
|
|
|
}
|
2013-05-17 09:00:20 +02:00
|
|
|
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
|
2013-02-10 09:13:20 +01:00
|
|
|
musicService.createPlaylist(null, playlistName, entries, DownloadActivity.this, null);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-02-10 09:13:20 +01:00
|
|
|
Util.toast(DownloadActivity.this, R.string.download_playlist_done);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void error(final Throwable error) {
|
|
|
|
final String msg = getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error);
|
2013-02-10 09:13:20 +01:00
|
|
|
Util.toast(DownloadActivity.this, msg);
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
private void toggleFullScreenAlbumArt() {
|
2013-02-10 09:13:20 +01:00
|
|
|
if (playlistFlipper.getDisplayedChild() == 1) {
|
|
|
|
playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_in));
|
|
|
|
playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_out));
|
|
|
|
playlistFlipper.setDisplayedChild(0);
|
|
|
|
} else {
|
|
|
|
playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
|
|
|
|
playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));
|
|
|
|
playlistFlipper.setDisplayedChild(1);
|
|
|
|
}
|
2013-05-29 10:21:09 +02:00
|
|
|
|
|
|
|
scrollToCurrent();
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void start() {
|
2013-05-17 09:00:20 +02:00
|
|
|
final DownloadService service = getDownloadService();
|
|
|
|
final PlayerState state = service.getPlayerState();
|
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
if (state == PAUSED || state == COMPLETED || state == STOPPED) {
|
2013-02-10 09:13:20 +01:00
|
|
|
service.start();
|
2013-05-17 09:00:20 +02:00
|
|
|
} else if (state == IDLE) {
|
2013-02-10 09:13:20 +01:00
|
|
|
warnIfNetworkOrStorageUnavailable();
|
2013-05-17 09:00:20 +02:00
|
|
|
|
|
|
|
final int current = service.getCurrentPlayingIndex();
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
if (current == -1) {
|
|
|
|
service.play(0);
|
|
|
|
} else {
|
|
|
|
service.play(current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 09:59:55 +02:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
private void onDownloadListChanged() {
|
|
|
|
final DownloadService downloadService = getDownloadService();
|
2013-02-10 09:13:20 +01:00
|
|
|
if (downloadService == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final List<DownloadFile> list = downloadService.getSongs();
|
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
emptyTextView.setText(R.string.download_empty);
|
|
|
|
playlistView.setAdapter(new SongListAdapter(list));
|
2013-02-10 09:13:20 +01:00
|
|
|
emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
|
|
|
|
currentRevision = downloadService.getDownloadListUpdateRevision();
|
|
|
|
|
|
|
|
switch (downloadService.getRepeatMode()) {
|
2013-05-16 09:59:55 +02:00
|
|
|
case OFF:
|
|
|
|
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_off));
|
|
|
|
break;
|
|
|
|
case ALL:
|
|
|
|
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_all));
|
|
|
|
break;
|
|
|
|
case SINGLE:
|
|
|
|
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_single));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onCurrentChanged() {
|
|
|
|
if (getDownloadService() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentPlaying = getDownloadService().getCurrentPlaying();
|
2013-05-20 08:33:40 +02:00
|
|
|
|
2013-05-26 07:19:28 +02:00
|
|
|
scrollToCurrent();
|
|
|
|
|
|
|
|
long totalDuration = getDownloadService().getDownloadListDuration();
|
|
|
|
long totalSongs = getDownloadService().getSongs().size();
|
|
|
|
int currentSongIndex = getDownloadService().getCurrentPlayingIndex() + 1;
|
|
|
|
|
|
|
|
String duration = Util.formatTotalDuration(totalDuration);
|
|
|
|
|
|
|
|
String trackFormat = String.format("%d / %d",
|
|
|
|
currentSongIndex,
|
|
|
|
totalSongs
|
|
|
|
);
|
|
|
|
|
2013-02-10 09:13:20 +01:00
|
|
|
if (currentPlaying != null) {
|
2013-05-26 07:19:28 +02:00
|
|
|
currentSong = currentPlaying.getSong();
|
2013-05-17 09:00:20 +02:00
|
|
|
final Drawable starDrawable = currentSong.getStarred() ? Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full) : Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow);
|
2013-05-29 10:21:09 +02:00
|
|
|
starImageButton.setImageDrawable(starDrawable);
|
2013-04-09 08:01:45 +02:00
|
|
|
songTitleTextView.setText(currentSong.getTitle());
|
|
|
|
albumTextView.setText(currentSong.getAlbum());
|
|
|
|
artistTextView.setText(currentSong.getArtist());
|
2013-05-26 07:19:28 +02:00
|
|
|
downloadTrackTextView.setText(trackFormat);
|
|
|
|
downloadTotalDurationTextView.setText(duration);
|
2013-05-20 08:33:40 +02:00
|
|
|
getImageLoader().loadImage(albumArtImageView, currentSong, true, 0, false, true);
|
2013-02-10 09:13:20 +01:00
|
|
|
} else {
|
2013-04-09 08:01:45 +02:00
|
|
|
currentSong = null;
|
2013-02-10 09:13:20 +01:00
|
|
|
songTitleTextView.setText(null);
|
|
|
|
albumTextView.setText(null);
|
|
|
|
artistTextView.setText(null);
|
2013-05-26 07:19:28 +02:00
|
|
|
downloadTrackTextView.setText(null);
|
|
|
|
downloadTotalDurationTextView.setText(null);
|
2013-05-20 08:33:40 +02:00
|
|
|
getImageLoader().loadImage(albumArtImageView, null, true, 0, false, false);
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
private void onSliderProgressChanged() {
|
|
|
|
if (getDownloadService() == null || onProgressChangedTask != null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
onProgressChangedTask = new SilentBackgroundTask<Void>(this) {
|
|
|
|
DownloadService downloadService;
|
|
|
|
boolean isJukeboxEnabled;
|
|
|
|
int millisPlayed;
|
|
|
|
Integer duration;
|
|
|
|
PlayerState playerState;
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
downloadService = getDownloadService();
|
|
|
|
isJukeboxEnabled = downloadService.isJukeboxEnabled();
|
|
|
|
millisPlayed = Math.max(0, downloadService.getPlayerPosition());
|
|
|
|
duration = downloadService.getPlayerDuration();
|
|
|
|
playerState = getDownloadService().getPlayerState();
|
|
|
|
return null;
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-16 09:59:55 +02:00
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
if (currentPlaying != null) {
|
2013-05-17 09:00:20 +02:00
|
|
|
final int millisTotal = duration == null ? 0 : duration;
|
2013-05-16 09:59:55 +02:00
|
|
|
|
2013-05-31 10:02:25 +02:00
|
|
|
positionTextView.setText(Util.formatTotalDuration(millisPlayed, true));
|
|
|
|
durationTextView.setText(Util.formatTotalDuration(millisTotal, true));
|
2013-05-16 09:59:55 +02:00
|
|
|
progressBar.setMax(millisTotal == 0 ? 100 : millisTotal); // Work-around for apparent bug.
|
|
|
|
progressBar.setProgress(millisPlayed);
|
|
|
|
progressBar.setEnabled(currentPlaying.isWorkDone() || isJukeboxEnabled);
|
|
|
|
} else {
|
|
|
|
positionTextView.setText(R.string.util_zero_time);
|
|
|
|
durationTextView.setText(R.string.util_no_time);
|
|
|
|
progressBar.setProgress(0);
|
|
|
|
progressBar.setMax(0);
|
|
|
|
progressBar.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
switch (playerState) {
|
|
|
|
case DOWNLOADING:
|
|
|
|
final long bytes = currentPlaying != null ? currentPlaying.getPartialFile().length() : 0;
|
2013-05-29 10:21:09 +02:00
|
|
|
getActionBar().setSubtitle(getResources().getString(
|
2013-05-17 09:00:20 +02:00
|
|
|
R.string.download_playerstate_downloading,
|
|
|
|
Util.formatLocalizedBytes(bytes,
|
|
|
|
DownloadActivity.this)));
|
|
|
|
break;
|
|
|
|
case PREPARING:
|
2013-05-29 10:21:09 +02:00
|
|
|
getActionBar().setSubtitle(R.string.download_playerstate_buffering);
|
2013-05-17 09:00:20 +02:00
|
|
|
break;
|
|
|
|
case STARTED:
|
2013-05-17 09:46:00 +02:00
|
|
|
final DownloadService downloadService = getDownloadService();
|
|
|
|
|
|
|
|
if (downloadService != null && downloadService.isShufflePlayEnabled()) {
|
2013-05-29 10:21:09 +02:00
|
|
|
getActionBar().setSubtitle(R.string.download_playerstate_playing_shuffle);
|
2013-05-17 09:00:20 +02:00
|
|
|
} else {
|
2013-05-29 10:21:09 +02:00
|
|
|
getActionBar().setSubtitle(null);
|
2013-05-17 09:00:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-05-29 10:21:09 +02:00
|
|
|
getActionBar().setSubtitle(null);
|
2013-05-17 09:00:20 +02:00
|
|
|
break;
|
|
|
|
case IDLE:
|
|
|
|
break;
|
|
|
|
case PREPARED:
|
|
|
|
break;
|
|
|
|
case STOPPED:
|
|
|
|
break;
|
|
|
|
case PAUSED:
|
|
|
|
break;
|
|
|
|
case COMPLETED:
|
|
|
|
break;
|
|
|
|
}
|
2013-05-16 09:59:55 +02:00
|
|
|
|
|
|
|
switch (playerState) {
|
|
|
|
case STARTED:
|
|
|
|
pauseButton.setVisibility(View.VISIBLE);
|
|
|
|
stopButton.setVisibility(View.GONE);
|
|
|
|
startButton.setVisibility(View.GONE);
|
|
|
|
break;
|
|
|
|
case DOWNLOADING:
|
|
|
|
case PREPARING:
|
|
|
|
pauseButton.setVisibility(View.GONE);
|
|
|
|
stopButton.setVisibility(View.VISIBLE);
|
|
|
|
startButton.setVisibility(View.GONE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pauseButton.setVisibility(View.GONE);
|
|
|
|
stopButton.setVisibility(View.GONE);
|
|
|
|
startButton.setVisibility(View.VISIBLE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
onProgressChangedTask = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
onProgressChangedTask.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void changeProgress(final int ms) {
|
|
|
|
final DownloadService downloadService = getDownloadService();
|
|
|
|
if(downloadService == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new SilentBackgroundTask<Void>(this) {
|
|
|
|
int msPlayed;
|
|
|
|
Integer duration;
|
|
|
|
int seekTo;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground() throws Throwable {
|
|
|
|
msPlayed = Math.max(0, downloadService.getPlayerPosition());
|
|
|
|
duration = downloadService.getPlayerDuration();
|
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final int msTotal = duration == null ? 0 : duration;
|
|
|
|
seekTo = msPlayed + ms > msTotal ? msTotal : msPlayed + ms;
|
2013-05-16 09:59:55 +02:00
|
|
|
downloadService.seekTo(seekTo);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
protected void done(final Void result) {
|
2013-05-16 09:59:55 +02:00
|
|
|
progressBar.setProgress(seekTo);
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
2013-02-10 09:13:20 +01:00
|
|
|
|
|
|
|
private class SongListAdapter extends ArrayAdapter<DownloadFile> {
|
2013-05-17 09:00:20 +02:00
|
|
|
public SongListAdapter(final List<DownloadFile> entries) {
|
2013-02-10 09:13:20 +01:00
|
|
|
super(DownloadActivity.this, android.R.layout.simple_list_item_1, entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public View getView(final int position, final View convertView, final ViewGroup parent) {
|
|
|
|
final SongView view;
|
|
|
|
view = convertView != null && convertView instanceof SongView ? (SongView) convertView : new SongView(DownloadActivity.this);
|
|
|
|
final DownloadFile downloadFile = getItem(position);
|
2013-02-10 09:13:20 +01:00
|
|
|
view.setSong(downloadFile.getSong(), false);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onTouchEvent(final MotionEvent me) {
|
2013-02-10 09:13:20 +01:00
|
|
|
return gestureScanner.onTouchEvent(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onDown(final MotionEvent me) {
|
2013-02-10 09:13:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onFling(final MotionEvent e1, final MotionEvent e2, final float velocityX, final float velocityY) {
|
2013-02-10 09:13:20 +01:00
|
|
|
|
2013-05-17 09:00:20 +02:00
|
|
|
final DownloadService downloadService = getDownloadService();
|
2013-02-10 09:13:20 +01:00
|
|
|
if (downloadService == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right to Left swipe
|
|
|
|
if (e1.getX() - e2.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) {
|
|
|
|
warnIfNetworkOrStorageUnavailable();
|
|
|
|
if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) {
|
|
|
|
downloadService.next();
|
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Left to Right swipe
|
|
|
|
if (e2.getX() - e1.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) {
|
|
|
|
warnIfNetworkOrStorageUnavailable();
|
|
|
|
downloadService.previous();
|
|
|
|
onCurrentChanged();
|
|
|
|
onSliderProgressChanged();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Top to Bottom swipe
|
|
|
|
if (e2.getY() - e1.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) {
|
|
|
|
warnIfNetworkOrStorageUnavailable();
|
|
|
|
downloadService.seekTo(downloadService.getPlayerPosition() + 30000);
|
|
|
|
onSliderProgressChanged();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom to Top swipe
|
|
|
|
if (e1.getY() - e2.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) {
|
|
|
|
warnIfNetworkOrStorageUnavailable();
|
|
|
|
downloadService.seekTo(downloadService.getPlayerPosition() - 8000);
|
|
|
|
onSliderProgressChanged();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onLongPress(final MotionEvent e) {
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onScroll(final MotionEvent e1, final MotionEvent e2, final float distanceX, final float distanceY) {
|
2013-02-10 09:13:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public void onShowPress(final MotionEvent e) {
|
2013-02-10 09:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-17 09:00:20 +02:00
|
|
|
public boolean onSingleTapUp(final MotionEvent e) {
|
2013-02-10 09:13:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SeekBar getProgressBar() {
|
|
|
|
return progressBar;
|
|
|
|
}
|
|
|
|
}
|