View refresh improvements, revert stream proxy changes
This commit is contained in:
parent
47d23aa474
commit
f841b26023
|
@ -2,8 +2,8 @@
|
|||
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
package="com.thejoshwa.ultrasonic.androidapp"
|
||||
a:installLocation="auto"
|
||||
a:versionCode="33"
|
||||
a:versionName="1.2.0.6" >
|
||||
a:versionCode="34"
|
||||
a:versionName="1.2.0.7" >
|
||||
|
||||
<uses-permission a:name="android.permission.INTERNET" />
|
||||
<uses-permission a:name="android.permission.READ_PHONE_STATE" />
|
||||
|
|
|
@ -325,8 +325,19 @@
|
|||
<string name="settings.use_id3_summary">Utiliser ID3 tag à la place du système de fichier basique</string>
|
||||
<string name="settings.use_stream_proxy">Utiliser un proxy</string>
|
||||
<string name="settings.use_stream_proxy_summary">Support de lecture de flux à travers un proxy (peut provoquer des fritures)</string>
|
||||
<string name="settings.video_title">Video</string>
|
||||
<string name="settings.video_player">Video player</string>
|
||||
<string name="settings.video_title">Vidéo</string>
|
||||
<string name="settings.video_player">Lecteur vidéo</string>
|
||||
<string name="settings.view_refresh">Actualisation de la vue</string>
|
||||
<string name="settings.view_refresh_500">0,5 secondes</string>
|
||||
<string name="settings.view_refresh_1000">1 seconde</string>
|
||||
<string name="settings.view_refresh_1500">1,5 secondes</string>
|
||||
<string name="settings.view_refresh_2000">2 secondes</string>
|
||||
<string name="settings.view_refresh_2500">2,5 secondes</string>
|
||||
<string name="settings.view_refresh_3000">3 secondes</string>
|
||||
<string name="settings.view_refresh_3500">3,5 secondes</string>
|
||||
<string name="settings.view_refresh_4000">4 secondes</string>
|
||||
<string name="settings.view_refresh_4500">4,5 secondes</string>
|
||||
<string name="settings.view_refresh_5000">5 secondes</string>
|
||||
<string name="settings.wifi_required_summary">Lire uniquement les flux médias si connecté au réseau Wi-Fi</string>
|
||||
<string name="settings.wifi_required_title">Wi-Fi en streaming uniquement</string>
|
||||
<string name="shuffle.endYear">Année de fin:</string>
|
||||
|
|
|
@ -327,6 +327,17 @@
|
|||
<string name="settings.use_stream_proxy_summary">Média lejátszása stream proxy-n keresztül (akadozások elkerülése érdekében).</string>
|
||||
<string name="settings.video_title">Videó</string>
|
||||
<string name="settings.video_player">Videólejátszó</string>
|
||||
<string name="settings.view_refresh">Megtekinté Frissítési</string>
|
||||
<string name="settings.view_refresh_500">0,5 másodperc</string>
|
||||
<string name="settings.view_refresh_1000">1 másodperc</string>
|
||||
<string name="settings.view_refresh_1500">1,5 másodperc</string>
|
||||
<string name="settings.view_refresh_2000">2 másodperc</string>
|
||||
<string name="settings.view_refresh_2500">2,5 másodperc</string>
|
||||
<string name="settings.view_refresh_3000">3 másodperc</string>
|
||||
<string name="settings.view_refresh_3500">3,5 másodperc</string>
|
||||
<string name="settings.view_refresh_4000">4 másodperc</string>
|
||||
<string name="settings.view_refresh_4500">4,5 másodperc</string>
|
||||
<string name="settings.view_refresh_5000">5 másodperc</string>
|
||||
<string name="settings.wifi_required_summary">Streaming, csak ha rendelkezésre áll Wi-Fi kapcsolat.</string>
|
||||
<string name="settings.wifi_required_title">Csak Wi-Fi streaming</string>
|
||||
<string name="shuffle.endYear">Utolsó év:</string>
|
||||
|
|
|
@ -214,5 +214,31 @@
|
|||
<item>Default</item>
|
||||
<item>Flash</item>
|
||||
</string-array>
|
||||
<string-array name="viewRefreshNames">
|
||||
<item>@string/settings.view_refresh_500</item>
|
||||
<item>@string/settings.view_refresh_1000</item>
|
||||
<item>@string/settings.view_refresh_1500</item>
|
||||
<item>@string/settings.view_refresh_2000</item>
|
||||
<item>@string/settings.view_refresh_2500</item>
|
||||
<item>@string/settings.view_refresh_3000</item>
|
||||
<item>@string/settings.view_refresh_3500</item>
|
||||
<item>@string/settings.view_refresh_4000</item>
|
||||
<item>@string/settings.view_refresh_4500</item>
|
||||
<item>@string/settings.view_refresh_5000</item>
|
||||
</string-array>
|
||||
<string-array name="viewRefreshValues">
|
||||
<item>500</item>
|
||||
<item>1000</item>
|
||||
<item>1500</item>
|
||||
<item>2000</item>
|
||||
<item>2500</item>
|
||||
<item>3000</item>
|
||||
<item>3500</item>
|
||||
<item>4000</item>
|
||||
<item>4500</item>
|
||||
<item>5000</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
|
||||
</resources>
|
|
@ -327,6 +327,17 @@
|
|||
<string name="settings.use_stream_proxy_summary">Stream media playback through a proxy (may help stutter)</string>
|
||||
<string name="settings.video_title">Video</string>
|
||||
<string name="settings.video_player">Video player</string>
|
||||
<string name="settings.view_refresh">View Refresh</string>
|
||||
<string name="settings.view_refresh_500">.5 seconds</string>
|
||||
<string name="settings.view_refresh_1000">1 second</string>
|
||||
<string name="settings.view_refresh_1500">1.5 seconds</string>
|
||||
<string name="settings.view_refresh_2000">2 seconds</string>
|
||||
<string name="settings.view_refresh_2500">2.5 seconds</string>
|
||||
<string name="settings.view_refresh_3000">3 seconds</string>
|
||||
<string name="settings.view_refresh_3500">3.5 seconds</string>
|
||||
<string name="settings.view_refresh_4000">4 seconds</string>
|
||||
<string name="settings.view_refresh_4500">4.5 seconds</string>
|
||||
<string name="settings.view_refresh_5000">5 seconds</string>
|
||||
<string name="settings.wifi_required_summary">Only stream media if connected to Wi-Fi</string>
|
||||
<string name="settings.wifi_required_title">Wi-Fi Streaming Only</string>
|
||||
<string name="shuffle.endYear">End Year:</string>
|
||||
|
|
|
@ -39,6 +39,12 @@
|
|||
a:key="discAndTrackSort"
|
||||
a:summary="@string/settings.disc_sort_summary"
|
||||
a:title="@string/settings.disc_sort" />
|
||||
<ListPreference
|
||||
a:defaultValue="1000"
|
||||
a:entries="@array/viewRefreshNames"
|
||||
a:entryValues="@array/viewRefreshValues"
|
||||
a:key="viewRefresh"
|
||||
a:title="@string/settings.view_refresh" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory a:title="@string/settings.playback_control_title" >
|
||||
<CheckBoxPreference
|
||||
|
|
|
@ -86,6 +86,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
private CheckBoxPreference lockScreenEnabled;
|
||||
private CheckBoxPreference sendBluetoothNotifications;
|
||||
private CheckBoxPreference sendBluetoothAlbumArt;
|
||||
private ListPreference viewRefresh;
|
||||
private int maxServerCount = 10;
|
||||
private int minServerCount = 0;
|
||||
|
||||
|
@ -169,6 +170,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
CheckBoxPreference gaplessPlaybackEnabled = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_GAPLESS_PLAYBACK);
|
||||
sendBluetoothAlbumArt = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART);
|
||||
sendBluetoothNotifications = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_NOTIFICATIONS);
|
||||
viewRefresh = (ListPreference) findPreference(Constants.PREFERENCES_KEY_VIEW_REFRESH);
|
||||
|
||||
findPreference(Constants.PREFERENCES_KEY_CLEAR_SEARCH_HISTORY).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
|
@ -442,6 +444,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
defaultSongs.setSummary(defaultSongs.getEntry());
|
||||
chatRefreshInterval.setSummary(chatRefreshInterval.getEntry());
|
||||
directoryCacheTime.setSummary(directoryCacheTime.getEntry());
|
||||
viewRefresh.setSummary(viewRefresh.getEntry());
|
||||
|
||||
if (!mediaButtonsEnabled.isChecked()) {
|
||||
lockScreenEnabled.setChecked(false);
|
||||
|
|
|
@ -241,7 +241,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
lifecycleSupport.onDestroy();
|
||||
mediaPlayer.release();
|
||||
|
||||
if(nextMediaPlayer != null) {
|
||||
if (nextMediaPlayer != null) {
|
||||
nextMediaPlayer.release();
|
||||
}
|
||||
|
||||
|
@ -631,11 +631,12 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
}
|
||||
|
||||
nextSetup = false;
|
||||
if(nextPlayingTask != null) {
|
||||
if (nextPlayingTask != null) {
|
||||
nextPlayingTask.cancel();
|
||||
nextPlayingTask = null;
|
||||
}
|
||||
if(index < size() && index != -1) {
|
||||
|
||||
if (index < size() && index != -1) {
|
||||
nextPlaying = downloadList.get(index);
|
||||
nextPlayingTask = new CheckCompletionTask(nextPlaying);
|
||||
nextPlayingTask.start();
|
||||
|
@ -749,7 +750,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
private synchronized void playNext(boolean start) {
|
||||
// Swap the media players since nextMediaPlayer is ready to play
|
||||
if (start) {
|
||||
nextMediaPlayer.start();
|
||||
//nextMediaPlayer.start();
|
||||
} else {
|
||||
Log.i(TAG, "nextMediaPlayer already playing");
|
||||
}
|
||||
|
@ -1362,6 +1363,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
});
|
||||
|
||||
final int duration = downloadFile.getSong().getDuration() == null ? 0 : downloadFile.getSong().getDuration() * 1000;
|
||||
|
||||
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
|
@ -1411,7 +1413,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
|
||||
@Override
|
||||
public void setVolume(float volume) {
|
||||
if(mediaPlayer != null) {
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.setVolume(volume, volume);
|
||||
}
|
||||
}
|
||||
|
@ -1420,17 +1422,17 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
public synchronized void swap(boolean mainList, int from, int to) {
|
||||
List<DownloadFile> list = mainList ? downloadList : backgroundDownloadList;
|
||||
int max = list.size();
|
||||
if(to >= max) {
|
||||
if (to >= max) {
|
||||
to = max - 1;
|
||||
}
|
||||
else if(to < 0) {
|
||||
} else if(to < 0) {
|
||||
to = 0;
|
||||
}
|
||||
|
||||
int currentPlayingIndex = getCurrentPlayingIndex();
|
||||
DownloadFile movedSong = list.remove(from);
|
||||
list.add(to, movedSong);
|
||||
if(jukeboxEnabled && mainList) {
|
||||
|
||||
if (jukeboxEnabled && mainList) {
|
||||
updateJukeboxPlaylist();
|
||||
} else if(mainList && (movedSong == nextPlaying || (currentPlayingIndex + 1) == to)) {
|
||||
// Moving next playing or moving a song to be next playing
|
||||
|
@ -1499,7 +1501,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
currentDownloading = downloadFile;
|
||||
currentDownloading.download();
|
||||
cleanupCandidates.add(currentDownloading);
|
||||
if(i == (start + 1)) {
|
||||
if (i == (start + 1)) {
|
||||
setNextPlayerState(DOWNLOADING);
|
||||
}
|
||||
break;
|
||||
|
@ -1675,8 +1677,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
|
||||
public CheckCompletionTask(DownloadFile downloadFile) {
|
||||
setNextPlayerState(PlayerState.IDLE);
|
||||
|
||||
this.downloadFile = downloadFile;
|
||||
if(downloadFile != null) {
|
||||
|
||||
if (downloadFile != null) {
|
||||
partialFile = downloadFile.getPartialFile();
|
||||
} else {
|
||||
partialFile = null;
|
||||
|
@ -1691,8 +1695,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
|
||||
// Do an initial sleep so this prepare can't compete with main prepare
|
||||
Util.sleepQuietly(5000L);
|
||||
|
||||
while (!bufferComplete()) {
|
||||
Util.sleepQuietly(5000L);
|
||||
|
||||
if (isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ public final class Constants {
|
|||
public static final String PREFERENCES_KEY_VIDEO_PLAYER = "videoPlayer";
|
||||
public static final String PREFERENCES_KEY_SEND_BLUETOOTH_NOTIFICATIONS = "sendBluetoothNotifications";
|
||||
public static final String PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART = "sendBluetoothAlbumArt";
|
||||
public static final String PREFERENCES_KEY_VIEW_REFRESH = "viewRefresh";
|
||||
|
||||
// Name of the preferences file.
|
||||
public static final String PREFERENCES_FILE_NAME = "com.thejoshwa.ultrasonic.androidapp_preferences";
|
||||
|
|
|
@ -157,22 +157,12 @@ public class StreamProxy implements Runnable {
|
|||
Log.i(TAG, "Streaming song in background");
|
||||
DownloadFile downloadFile = downloadService.getCurrentPlaying();
|
||||
MusicDirectory.Entry song = downloadFile.getSong();
|
||||
long fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8;
|
||||
Log.i(TAG, "Streaming fileSize: " + fileSize);
|
||||
|
||||
// Create HTTP header
|
||||
String headers = "HTTP/1.0 200 OK\r\n";
|
||||
headers += "Content-Type: " + "application/octet-stream" + "\r\n";
|
||||
|
||||
Integer contentLength = downloadFile.getContentLength();
|
||||
long fileSize;
|
||||
|
||||
if (contentLength == null) {
|
||||
fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8;
|
||||
} else {
|
||||
fileSize = contentLength;
|
||||
headers += "Content-Length: " + fileSize + "\r\n";
|
||||
}
|
||||
|
||||
Log.i(TAG, "Streaming fileSize: " + fileSize);
|
||||
|
||||
headers += "Connection: close\r\n";
|
||||
headers += "\r\n";
|
||||
|
|
|
@ -1338,4 +1338,10 @@ public class Util extends DownloadActivity {
|
|||
SharedPreferences preferences = getPreferences(context);
|
||||
return preferences.getBoolean(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART, true);
|
||||
}
|
||||
|
||||
public static int getViewRefreshInterval(Context context) {
|
||||
SharedPreferences preferences = getPreferences(context);
|
||||
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_VIEW_REFRESH, "1000"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package com.thejoshwa.ultrasonic.androidapp.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -39,15 +40,34 @@ import com.thejoshwa.ultrasonic.androidapp.util.Util;
|
|||
public class AlbumView extends UpdateView {
|
||||
|
||||
private static final String TAG = AlbumView.class.getSimpleName();
|
||||
private static Drawable starDrawable;
|
||||
private static Drawable starHollowDrawable;
|
||||
private static String theme;
|
||||
|
||||
private TextView titleView;
|
||||
private TextView artistView;
|
||||
private View coverArtView;
|
||||
private ImageView starImageView;
|
||||
private Context context;
|
||||
|
||||
public AlbumView(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.album_list_item, this, true);
|
||||
|
||||
String theme = Util.getTheme(context);
|
||||
boolean themesMatch = theme.equals(this.theme);
|
||||
this.theme = theme;
|
||||
|
||||
if (starHollowDrawable == null || !themesMatch) {
|
||||
starHollowDrawable = Util.getDrawableFromAttribute(context, R.attr.star_hollow);
|
||||
}
|
||||
|
||||
if (starDrawable == null || !themesMatch) {
|
||||
starDrawable = Util.getDrawableFromAttribute(context, R.attr.star_full);
|
||||
}
|
||||
|
||||
titleView = (TextView) findViewById(R.id.album_title);
|
||||
artistView = (TextView) findViewById(R.id.album_artist);
|
||||
coverArtView = findViewById(R.id.album_coverart);
|
||||
|
@ -55,47 +75,51 @@ public class AlbumView extends UpdateView {
|
|||
}
|
||||
|
||||
public void setAlbum(final MusicDirectory.Entry album, ImageLoader imageLoader) {
|
||||
titleView.setText(album.getTitle());
|
||||
artistView.setText(album.getArtist());
|
||||
artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE);
|
||||
starImageView.setImageDrawable(album.getStarred() ? Util.getDrawableFromAttribute(getContext(), R.attr.star_full) : Util.getDrawableFromAttribute(getContext(), R.attr.star_hollow));
|
||||
imageLoader.loadImage(coverArtView, album, false, 0, false, true);
|
||||
String title = album.getTitle();
|
||||
String artist = album.getArtist();
|
||||
boolean starred = album.getStarred();
|
||||
|
||||
titleView.setText(title);
|
||||
artistView.setText(artist);
|
||||
artistView.setVisibility(artist == null ? View.GONE : View.VISIBLE);
|
||||
starImageView.setImageDrawable(starred ? starDrawable : starHollowDrawable);
|
||||
imageLoader.loadImage(this.coverArtView, album, false, 0, false, true);
|
||||
|
||||
if (Util.isOffline(getContext())) {
|
||||
if (Util.isOffline(this.context)) {
|
||||
starImageView.setVisibility(View.GONE);
|
||||
} else {
|
||||
starImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final boolean isStarred = album.getStarred();
|
||||
final String id = album.getId();
|
||||
|
||||
if (!isStarred) {
|
||||
starImageView.setImageDrawable(starDrawable);
|
||||
album.setStarred(true);
|
||||
} else {
|
||||
starImageView.setImageDrawable(starHollowDrawable);
|
||||
album.setStarred(false);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(null);
|
||||
boolean useId3 = Util.getShouldUseId3Tags(getContext());
|
||||
|
||||
try {
|
||||
if (!isStarred) {
|
||||
musicService.star(!useId3 ? id : null, useId3 ? id : null, null, getContext(), null);
|
||||
} else {
|
||||
musicService.unstar(!useId3 ? id : null, useId3 ? id : null, null, getContext(), null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
starImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final boolean isStarred = album.getStarred();
|
||||
final String id = album.getId();
|
||||
|
||||
if (!isStarred) {
|
||||
starImageView.setImageDrawable(Util.getDrawableFromAttribute(getContext(), R.attr.star_full));
|
||||
album.setStarred(true);
|
||||
} else {
|
||||
starImageView.setImageDrawable(Util.getDrawableFromAttribute(getContext(), R.attr.star_hollow));
|
||||
album.setStarred(false);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(null);
|
||||
boolean useId3 = Util.getShouldUseId3Tags(getContext());
|
||||
|
||||
try {
|
||||
if (!isStarred) {
|
||||
musicService.star(!useId3 ? id : null, useId3 ? id : null, null, getContext(), null);
|
||||
} else {
|
||||
musicService.unstar(!useId3 ? id : null, useId3 ? id : null, null, getContext(), null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ import com.thejoshwa.ultrasonic.androidapp.R;
|
|||
import com.thejoshwa.ultrasonic.androidapp.domain.Playlist;
|
||||
|
||||
/**
|
||||
* Used to display albums in a {@code ListView}.
|
||||
* Used to display playlists in a {@code ListView}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
|
|
|
@ -47,23 +47,70 @@ import java.io.File;
|
|||
public class SongView extends UpdateView implements Checkable {
|
||||
|
||||
private static final String TAG = SongView.class.getSimpleName();
|
||||
private static Drawable starHollowDrawable;
|
||||
private static Drawable starDrawable;
|
||||
private static Drawable unpinImage;
|
||||
private static Drawable downloadedImage;
|
||||
private static Drawable downloadingImage;
|
||||
private static Drawable playingImage;
|
||||
private static String theme;
|
||||
|
||||
private CheckedTextView checkedTextView;
|
||||
private ImageView starImageView;
|
||||
private TextView titleTextView;
|
||||
private TextView statusTextView;
|
||||
private Entry song;
|
||||
private Context context;
|
||||
|
||||
private Drawable leftImage;
|
||||
private ImageType previousLeftImageType;
|
||||
private ImageType previousRightImageType;
|
||||
private ImageType leftImageType;
|
||||
private ImageType rightImageType;
|
||||
private Drawable rightImage;
|
||||
private DownloadService downloadService;
|
||||
private DownloadFile downloadFile;
|
||||
private boolean playing = false;
|
||||
|
||||
public SongView(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
|
||||
String theme = Util.getTheme(context);
|
||||
boolean themesMatch = theme.equals(this.theme);
|
||||
|
||||
this.theme = theme;
|
||||
|
||||
if (starHollowDrawable == null || !themesMatch) {
|
||||
starHollowDrawable = Util.getDrawableFromAttribute(context, R.attr.star_hollow);
|
||||
}
|
||||
|
||||
if (starDrawable == null || !themesMatch) {
|
||||
starDrawable = Util.getDrawableFromAttribute(context, R.attr.star_full);
|
||||
}
|
||||
|
||||
if (unpinImage == null || !themesMatch) {
|
||||
unpinImage = Util.getDrawableFromAttribute(context, R.attr.unpin);
|
||||
}
|
||||
|
||||
if (downloadedImage == null || !themesMatch) {
|
||||
downloadedImage = Util.getDrawableFromAttribute(context, R.attr.downloaded);
|
||||
}
|
||||
|
||||
if (downloadingImage == null || !themesMatch) {
|
||||
downloadingImage = Util.getDrawableFromAttribute(context, R.attr.downloading);
|
||||
}
|
||||
|
||||
if (playingImage == null || !themesMatch) {
|
||||
playingImage = Util.getDrawableFromAttribute(context, R.attr.media_play_small);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSong(final Entry song, boolean checkable) {
|
||||
protected void setSong(final Entry song, boolean checkable) {
|
||||
updateBackground();
|
||||
|
||||
this.song = song;
|
||||
|
||||
this.downloadFile = downloadService.forSong(song);
|
||||
|
||||
if (song.isVideo()) {
|
||||
LayoutInflater.from(this.context).inflate(R.layout.video_list_item, this, true);
|
||||
} else {
|
||||
|
@ -78,30 +125,32 @@ public class SongView extends UpdateView implements Checkable {
|
|||
TextView durationTextView = (TextView) findViewById(R.id.song_duration);
|
||||
statusTextView = (TextView) findViewById(R.id.song_status);
|
||||
|
||||
|
||||
StringBuilder artist = new StringBuilder(60);
|
||||
|
||||
String bitRate = null;
|
||||
|
||||
if (song.getBitRate() != null) {
|
||||
bitRate = String.format(getContext().getString(R.string.song_details_kbps), song.getBitRate());
|
||||
bitRate = String.format(this.context.getString(R.string.song_details_kbps), song.getBitRate());
|
||||
}
|
||||
|
||||
VideoPlayerType videoPlayer = Util.getVideoPlayerType(getContext());
|
||||
VideoPlayerType videoPlayer = Util.getVideoPlayerType(this.context);
|
||||
|
||||
String fileFormat;
|
||||
String suffix = song.getSuffix();
|
||||
String transcodedSuffix = song.getTranscodedSuffix();
|
||||
|
||||
if (song.getTranscodedSuffix() == null || song.getTranscodedSuffix().equals(song.getSuffix()) || (song.isVideo() && videoPlayer != VideoPlayerType.FLASH)) {
|
||||
fileFormat = song.getSuffix();
|
||||
if (transcodedSuffix == null || transcodedSuffix.equals(suffix) || (song.isVideo() && videoPlayer != VideoPlayerType.FLASH)) {
|
||||
fileFormat = suffix;
|
||||
} else {
|
||||
fileFormat = String.format("%s > %s", song.getSuffix(), song.getTranscodedSuffix());
|
||||
fileFormat = String.format("%s > %s", suffix, transcodedSuffix);
|
||||
}
|
||||
|
||||
String artistName = song.getArtist();
|
||||
|
||||
if (artistName != null) {
|
||||
if (Util.shouldDisplayBitrateWithArtist(getContext())) {
|
||||
if (Util.shouldDisplayBitrateWithArtist(this.context)) {
|
||||
artist.append(artistName).append(" (")
|
||||
.append(String.format(getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate + " ", fileFormat))
|
||||
.append(String.format(this.context.getString(R.string.song_details_all), bitRate == null ? "" : bitRate + " ", fileFormat))
|
||||
.append(")");
|
||||
} else {
|
||||
artist.append(artistName);
|
||||
|
@ -111,7 +160,7 @@ public class SongView extends UpdateView implements Checkable {
|
|||
int trackNumber = song.getTrack();
|
||||
|
||||
if (trackTextView != null) {
|
||||
if (Util.shouldShowTrackNumber(getContext()) && trackNumber != 0) {
|
||||
if (Util.shouldShowTrackNumber(this.context) && trackNumber != 0) {
|
||||
trackTextView.setText(String.format("%02d.", trackNumber));
|
||||
} else {
|
||||
trackTextView.setVisibility(View.GONE);
|
||||
|
@ -130,61 +179,58 @@ public class SongView extends UpdateView implements Checkable {
|
|||
durationTextView.setText(Util.formatTotalDuration(duration));
|
||||
}
|
||||
|
||||
starImageView.setImageDrawable(song.getStarred() ? Util.getDrawableFromAttribute(getContext(), R.attr.star_full) : Util.getDrawableFromAttribute(getContext(), R.attr.star_hollow));
|
||||
checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (Util.isOffline(getContext())) {
|
||||
if (Util.isOffline(this.context)) {
|
||||
starImageView.setVisibility(View.GONE);
|
||||
} else {
|
||||
starImageView.setImageDrawable(song.getStarred() ? starDrawable : starHollowDrawable);
|
||||
|
||||
starImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final boolean isStarred = song.getStarred();
|
||||
final String id = song.getId();
|
||||
|
||||
if (!isStarred) {
|
||||
starImageView.setImageDrawable(starDrawable);
|
||||
song.setStarred(true);
|
||||
} else {
|
||||
starImageView.setImageDrawable(starHollowDrawable);
|
||||
song.setStarred(false);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(SongView.this.context);
|
||||
|
||||
try {
|
||||
if (!isStarred) {
|
||||
musicService.star(id, null, null, SongView.this.context, null);
|
||||
} else {
|
||||
musicService.unstar(id, null, null, SongView.this.context, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
starImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final boolean isStarred = song.getStarred();
|
||||
final String id = song.getId();
|
||||
|
||||
if (!isStarred) {
|
||||
starImageView.setImageDrawable(Util.getDrawableFromAttribute(getContext(), R.attr.star_full));
|
||||
song.setStarred(true);
|
||||
} else {
|
||||
starImageView.setImageDrawable(Util.getDrawableFromAttribute(getContext(), R.attr.star_hollow));
|
||||
song.setStarred(false);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(null);
|
||||
|
||||
try {
|
||||
if (!isStarred) {
|
||||
musicService.star(id, null, null, getContext(), null);
|
||||
} else {
|
||||
musicService.unstar(id, null, null, getContext(), null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
|
||||
updateBackground();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateBackground() {
|
||||
if (downloadService == null) {
|
||||
|
||||
downloadService = DownloadServiceImpl.getInstance();
|
||||
|
||||
if(downloadService == null) {
|
||||
if (downloadService == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
downloadService.forSong(song);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,39 +239,62 @@ public class SongView extends UpdateView implements Checkable {
|
|||
return;
|
||||
}
|
||||
|
||||
DownloadFile downloadFile = downloadService.forSong(song);
|
||||
downloadFile.getCompleteFile();
|
||||
downloadFile = downloadService.forSong(this.song);
|
||||
File partialFile = downloadFile.getPartialFile();
|
||||
|
||||
Drawable leftImage = null;
|
||||
Drawable rightImage = null;
|
||||
|
||||
if (downloadFile.isWorkDone()) {
|
||||
leftImage = downloadFile.isSaved() ? Util.getDrawableFromAttribute(getContext(), R.attr.unpin) : Util.getDrawableFromAttribute(getContext(), R.attr.downloaded);
|
||||
ImageType newLeftImageType = downloadFile.isSaved() ? ImageType.unpin : ImageType.downloaded;
|
||||
|
||||
if (this.leftImageType != newLeftImageType) {
|
||||
this.leftImage = downloadFile.isSaved() ? unpinImage : downloadedImage;
|
||||
this.leftImageType = newLeftImageType;
|
||||
}
|
||||
} else {
|
||||
this.leftImageType = ImageType.none;
|
||||
this.leftImage = null;
|
||||
}
|
||||
|
||||
if (statusTextView != null) {
|
||||
if (downloadFile.isDownloading() && !downloadFile.isDownloadCancelled() && partialFile.exists()) {
|
||||
statusTextView.setText(Util.formatLocalizedBytes(partialFile.length(), getContext()));
|
||||
rightImage = Util.getDrawableFromAttribute(getContext(), R.attr.downloading);
|
||||
} else {
|
||||
statusTextView.setText(null);
|
||||
}
|
||||
|
||||
statusTextView.setCompoundDrawablesWithIntrinsicBounds(leftImage, null, rightImage, null);
|
||||
if (downloadFile.isDownloading() && !downloadFile.isDownloadCancelled() && partialFile.exists()) {
|
||||
this.statusTextView.setText(Util.formatLocalizedBytes(partialFile.length(), this.context));
|
||||
this.rightImageType = ImageType.downloading;
|
||||
this.rightImage = downloadingImage;
|
||||
} else {
|
||||
this.rightImageType = ImageType.none;
|
||||
this.rightImage = null;
|
||||
|
||||
if (this.statusTextView.getText() != null) {
|
||||
this.statusTextView.setText(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this.previousLeftImageType != leftImageType || this.previousRightImageType != rightImageType) {
|
||||
this.previousLeftImageType = leftImageType;
|
||||
this.previousRightImageType = rightImageType;
|
||||
this.statusTextView.setCompoundDrawablesWithIntrinsicBounds(leftImage, null, rightImage, null);
|
||||
}
|
||||
|
||||
if (!song.getStarred()) {
|
||||
starImageView.setImageDrawable(Util.getDrawableFromAttribute(getContext(), R.attr.star_hollow));
|
||||
if (starImageView.getDrawable() != starHollowDrawable) {
|
||||
starImageView.setImageDrawable(starHollowDrawable);
|
||||
}
|
||||
} else {
|
||||
starImageView.setImageDrawable(Util.getDrawableFromAttribute(getContext(), R.attr.star_full));
|
||||
if (starImageView.getDrawable() != starDrawable) {
|
||||
starImageView.setImageDrawable(starDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
boolean playing = downloadService.getCurrentPlaying() == downloadFile;
|
||||
|
||||
if (playing) {
|
||||
titleTextView.setCompoundDrawablesWithIntrinsicBounds(Util.getDrawableFromAttribute(getContext(), R.attr.media_play_small), null, null, null);
|
||||
if (!this.playing) {
|
||||
this.playing = true;
|
||||
titleTextView.setCompoundDrawablesWithIntrinsicBounds(playingImage, null, null, null);
|
||||
}
|
||||
} else {
|
||||
titleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
if (this.playing) {
|
||||
this.playing = false;
|
||||
titleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,4 +312,11 @@ public class SongView extends UpdateView implements Checkable {
|
|||
public void toggle() {
|
||||
checkedTextView.toggle();
|
||||
}
|
||||
|
||||
public enum ImageType {
|
||||
none,
|
||||
unpin,
|
||||
downloaded,
|
||||
downloading
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import android.util.Log;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.thejoshwa.ultrasonic.androidapp.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
@ -18,19 +21,14 @@ public class UpdateView extends LinearLayout {
|
|||
private static Handler backgroundHandler;
|
||||
private static Handler uiHandler;
|
||||
private static Runnable updateRunnable;
|
||||
private static Context context;
|
||||
|
||||
public UpdateView(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
|
||||
setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
INSTANCES.put(this, null);
|
||||
int instanceCount = INSTANCES.size();
|
||||
|
||||
if (instanceCount > 50) {
|
||||
Log.w(TAG, instanceCount + " live UpdateView instances");
|
||||
}
|
||||
|
||||
startUpdater();
|
||||
}
|
||||
|
||||
|
@ -77,6 +75,7 @@ public class UpdateView extends LinearLayout {
|
|||
Log.w(TAG, "Error when updating song views.", x);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateAllLive(final List<UpdateView> views) {
|
||||
final Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
|
@ -88,7 +87,7 @@ public class UpdateView extends LinearLayout {
|
|||
} catch (Throwable x) {
|
||||
Log.w(TAG, "Error when updating song views.", x);
|
||||
}
|
||||
uiHandler.postDelayed(updateRunnable, 1000L);
|
||||
uiHandler.postDelayed(updateRunnable, Util.getViewRefreshInterval(context));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue