Fix DownloadActivity broken with Jukebox changes, improve SongListAdapter

This commit is contained in:
Joshua Bahnsen 2013-12-06 23:13:36 -07:00
parent 887b8877d7
commit ab088f4f86
4 changed files with 52 additions and 26 deletions

View File

@ -2,8 +2,8 @@
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
package="com.thejoshwa.ultrasonic.androidapp"
a:installLocation="auto"
a:versionCode="37"
a:versionName="1.2.0.10" >
a:versionCode="38"
a:versionName="1.2.0.11" >
<uses-permission a:name="android.permission.INTERNET" />
<uses-permission a:name="android.permission.READ_PHONE_STATE" />

View File

@ -370,7 +370,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(final SeekBar seekBar)
{
@ -389,7 +388,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
onSliderProgressChanged();
}
}.execute();
}
@Override
@ -677,7 +675,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
};
executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(runnable, 0L, 500L, TimeUnit.MILLISECONDS);
executorService.scheduleWithFixedDelay(runnable, 0L, 250L, TimeUnit.MILLISECONDS);
if (downloadService != null && downloadService.getKeepScreenOn())
{
@ -864,11 +862,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
jukeboxOption.setEnabled(jukeboxAvailable);
jukeboxOption.setVisible(jukeboxAvailable);
if (!jukeboxAvailable)
{
downloadService.setJukeboxEnabled(false);
}
if (downloadService.isJukeboxEnabled())
{
jukeboxOption.setTitle(R.string.download_menu_jukebox_off);
@ -1140,18 +1133,20 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
private void onCurrentChanged()
{
if (getDownloadService() == null)
DownloadService downloadService = getDownloadService();
if (downloadService == null)
{
return;
}
currentPlaying = getDownloadService().getCurrentPlaying();
currentPlaying = downloadService.getCurrentPlaying();
scrollToCurrent();
long totalDuration = getDownloadService().getDownloadListDuration();
long totalSongs = getDownloadService().getSongs().size();
int currentSongIndex = getDownloadService().getCurrentPlayingIndex() + 1;
long totalDuration = downloadService.getDownloadListDuration();
long totalSongs = downloadService.getSongs().size();
int currentSongIndex = downloadService.getCurrentPlayingIndex() + 1;
String duration = Util.formatTotalDuration(totalDuration);
@ -1183,7 +1178,9 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
private void onSliderProgressChanged()
{
if (getDownloadService() == null || onProgressChangedTask != null)
DownloadService downloadService = getDownloadService();
if (downloadService == null || onProgressChangedTask != null)
{
return;
}

View File

@ -1533,7 +1533,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
{
if (percent == 100)
{
mediaPlayer.setOnBufferingUpdateListener(null);
mp.setOnBufferingUpdateListener(null);
}
SeekBar progressBar = DownloadActivity.getProgressBar();
@ -1705,7 +1705,15 @@ public class DownloadServiceImpl extends Service implements DownloadService
{
if (nextPlaying != null && nextPlayerState == PlayerState.PREPARED)
{
playNext();
if (!nextSetup)
{
playNext();
}
else
{
nextSetup = false;
playNext();
}
}
else
{
@ -1720,7 +1728,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
if (downloadFile.isWorkDone())
{
// Complete was called early even though file is fully buffered
Log.i(TAG, "Requesting restart from " + pos + " of " + duration);
Log.i(TAG, String.format("Requesting restart from %d of %d", pos, duration));
reset();
downloadFile.setPlaying(false);
doPlay(downloadFile, pos, true);
@ -1728,7 +1736,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
}
else
{
Log.i(TAG, "Requesting restart from " + pos + " of " + duration);
Log.i(TAG, String.format("Requesting restart from %d of %d", pos, duration));
reset();
bufferTask = new BufferTask(downloadFile, pos);
bufferTask.start();
@ -2002,7 +2010,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
long byteCount = Math.max(100000, bitRate * 1024L / 8L * bufferLength);
// Find out how large the file should grow before resuming playback.
Log.i(TAG, "Buffering from position " + position + " and bitrate " + bitRate);
Log.i(TAG, String.format("Buffering from position %d and bitrate %d", position, bitRate));
expectedFileSize = (position * bitRate / 8) + byteCount;
}

View File

@ -5,6 +5,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.thejoshwa.ultrasonic.androidapp.domain.MusicDirectory;
import com.thejoshwa.ultrasonic.androidapp.service.DownloadFile;
import java.util.List;
@ -22,10 +23,30 @@ public class SongListAdapter extends ArrayAdapter<DownloadFile>
@Override
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(this.context);
final DownloadFile downloadFile = getItem(position);
view.setSong(downloadFile.getSong(), false);
DownloadFile downloadFile = getItem(position);
MusicDirectory.Entry entry = downloadFile.getSong();
SongView view;
if (convertView != null && convertView instanceof SongView)
{
SongView currentView = (SongView) convertView;
if (currentView.getEntry().equals(entry))
{
currentView.update();
return currentView;
}
else
{
view = new SongView(this.context);
}
}
else
{
view = new SongView(this.context);
}
view.setSong(entry, false);
return view;
}
}
}