diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-01-19 14:07:44 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-01-19 14:07:44 -0800 |
commit | 5cc2e1596af9edb33e74ee648ccf8fc3755bed96 (patch) | |
tree | 3ce565aa4766b778af55b266e6b5321f11264b3f /src/github/daneren2005 | |
parent | fdda03ceed2b46a4a008dac48e88c4bc5e654aa3 (diff) | |
parent | 7d53ef61b7498a8dd0e5f63bc2e907eb4937b261 (diff) | |
download | dsub-5cc2e1596af9edb33e74ee648ccf8fc3755bed96.tar.gz dsub-5cc2e1596af9edb33e74ee648ccf8fc3755bed96.tar.bz2 dsub-5cc2e1596af9edb33e74ee648ccf8fc3755bed96.zip |
Merge commit
Diffstat (limited to 'src/github/daneren2005')
8 files changed, 231 insertions, 84 deletions
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index 55415725..375e8505 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -83,6 +83,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private EditTextPreference chatRefreshRate; private ListPreference videoPlayer; private ListPreference syncInterval; + private CheckBoxPreference syncEnabled; + private CheckBoxPreference syncWifi; + private CheckBoxPreference syncNotification; + private CheckBoxPreference syncStarred; + private CheckBoxPreference syncMostRecent; + private String internalSSID; private int serverCount = 3; private SharedPreferences settings; @@ -94,6 +100,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); + internalSSID = Util.getSSID(this); + if(internalSSID == null) { + internalSSID = ""; + } + internalSSID = this.getResources().getString(R.string.settings_server_local_network_ssid_hint, internalSSID); + theme = (ListPreference) findPreference(Constants.PREFERENCES_KEY_THEME); maxBitrateWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI); maxBitrateMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE); @@ -113,6 +125,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer chatRefreshRate = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CHAT_REFRESH); videoPlayer = (ListPreference) findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER); syncInterval = (ListPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL); + syncEnabled = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED); + syncWifi = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_WIFI); + syncNotification = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION); + syncStarred = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_STARRED); + syncMostRecent = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT); settings = Util.getPreferences(this); serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 3); @@ -290,6 +307,23 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer chatRefreshRate.setSummary(chatRefreshRate.getText()); videoPlayer.setSummary(videoPlayer.getEntry()); syncInterval.setSummary(syncInterval.getEntry()); + if(syncEnabled.isChecked()) { + if(!syncInterval.isEnabled()) { + syncInterval.setEnabled(true); + syncWifi.setEnabled(true); + syncNotification.setEnabled(true); + syncStarred.setEnabled(true); + syncMostRecent.setEnabled(true); + } + } else { + if(syncInterval.isEnabled()) { + syncInterval.setEnabled(false); + syncWifi.setEnabled(false); + syncNotification.setEnabled(false); + syncStarred.setEnabled(false); + syncMostRecent.setEnabled(false); + } + } for (ServerSettings ss : serverSettings.values()) { ss.update(); } @@ -304,6 +338,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); + serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); @@ -316,6 +351,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); + serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); @@ -323,17 +359,25 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); + + final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(this); + serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); + serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); + serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); + serverLocalNetworkSSIDPreference.setDialogMessage(internalSSID); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(this); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue("http://"); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); + serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(this); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); + serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(this); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); @@ -346,6 +390,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverTagPreference.setChecked(Util.isTagBrowsing(this, instance)); serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary); serverTagPreference.setTitle(R.string.settings_browse_by_tags); + serverPasswordPreference.setDialogTitle(R.string.settings_server_password); final Preference serverOpenBrowser = new Preference(this); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); @@ -410,12 +455,13 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); + screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverTagPreference); - screen.addPreference(serverRemoveServerPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); + screen.addPreference(serverRemoveServerPreference); screen.setOrder(instance); @@ -541,6 +587,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private class ServerSettings { private EditTextPreference serverName; private EditTextPreference serverUrl; + private EditTextPreference serverLocalNetworkSSID; private EditTextPreference serverInternalUrl; private EditTextPreference username; private PreferenceScreen screen; @@ -550,6 +597,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer screen = (PreferenceScreen) findPreference("server" + instance); serverName = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_URL + instance); + serverLocalNetworkSSID = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverInternalUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); username = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_USERNAME + instance); @@ -574,6 +622,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer public boolean onPreferenceChange(Preference preference, Object value) { try { String url = (String) value; + // Allow blank internal IP address + if("".equals(url) || url == null) { + return true; + } + new URL(url); if (url.contains(" ") || url.contains("@") || url.contains("_")) { throw new Exception(); @@ -602,6 +655,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer public void update() { serverName.setSummary(serverName.getText()); serverUrl.setSummary(serverUrl.getText()); + serverLocalNetworkSSID.setSummary(serverLocalNetworkSSID.getText()); serverInternalUrl.setSummary(serverInternalUrl.getText()); username.setSummary(username.getText()); screen.setSummary(serverUrl.getText()); diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index de721f7d..f345334f 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -178,17 +178,21 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe toggleListButton =rootView.findViewById(R.id.download_toggle_list);
starButton = (ImageButton)rootView.findViewById(R.id.download_star);
- starButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
- if (currentDownload != null) {
- MusicDirectory.Entry currentSong = currentDownload.getSong();
- toggleStarred(currentSong);
- starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) {
+ starButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ DownloadFile currentDownload = getDownloadService().getCurrentPlaying();
+ if (currentDownload != null) {
+ MusicDirectory.Entry currentSong = currentDownload.getSong();
+ toggleStarred(currentSong);
+ starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ }
}
- }
- });
+ });
+ } else {
+ starButton.setVisibility(View.GONE);
+ }
View.OnTouchListener touchListener = new View.OnTouchListener() {
@Override
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index a7a61f71..99f21d6e 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -83,7 +83,16 @@ public class CachedMusicService implements MusicService { checkSettingsChanged(context); Boolean result = cachedLicenseValid.get(); if (result == null) { - result = musicService.isLicenseValid(context, progressListener); + result = FileUtil.deserialize(context, getCacheName(context, "license"), Boolean.class); + + if(result == null) { + result = musicService.isLicenseValid(context, progressListener); + + // Only save a copy license is valid + if(result == true) { + FileUtil.serialize(context, (Boolean) result, getCacheName(context, "license")); + } + } cachedLicenseValid.set(result, result ? 30L * 60L : 2L * 60L, TimeUnit.SECONDS); } return result; diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 90713466..600f2d52 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -104,6 +104,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { private final Scrobbler scrobbler = new Scrobbler(); private RemoteController remoteController; private DownloadFile currentPlaying; + private int currentPlayingIndex = -1; private DownloadFile nextPlaying; private DownloadFile currentDownloading; private CancellableTask bufferTask; @@ -329,6 +330,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } else { if (currentPlaying == null) { currentPlaying = downloadList.get(0); + currentPlayingIndex = 0; currentPlaying.setPlaying(true); } checkDownloads(); @@ -498,6 +500,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { currentDownloading = null; } backgroundDownloadList.clear(); + Util.hideDownloadingNotification(this); } @Override @@ -603,6 +606,11 @@ public class DownloadServiceImpl extends Service implements DownloadService { this.currentPlaying.setPlaying(false); } this.currentPlaying = currentPlaying; + if(currentPlaying == null) { + currentPlayingIndex = -1; + } else { + currentPlayingIndex = downloadList.indexOf(currentPlaying); + } if (currentPlaying != null) { Util.broadcastNewTrackInfo(this, currentPlaying.getSong()); @@ -640,8 +648,8 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override - public synchronized int getCurrentPlayingIndex() { - return downloadList.indexOf(currentPlaying); + public int getCurrentPlayingIndex() { + return currentPlayingIndex; } private int getNextPlayingIndex() { int index = getCurrentPlayingIndex(); @@ -951,7 +959,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { boolean show = playerState == PlayerState.STARTED; boolean pause = playerState == PlayerState.PAUSED; boolean hide = playerState == PlayerState.STOPPED; - Util.broadcastPlaybackStatusChange(this, playerState); + Util.broadcastPlaybackStatusChange(this, (currentPlaying != null) ? currentPlaying.getSong() : null, playerState); this.playerState = playerState; @@ -1299,6 +1307,11 @@ public class DownloadServiceImpl extends Service implements DownloadService { Log.i(TAG, "Ending position " + pos + " of " + duration); if (!isPartial || (downloadFile.isWorkDone() && (Math.abs(duration - pos) < 10000))) { playNext(); + + // Finished loading, delete when list is cleared + if(downloadFile.getSong() instanceof PodcastEpisode) { + toDelete.add(downloadFile); + } } else { // If file is not completely downloaded, restart the playback from the current position. synchronized (DownloadServiceImpl.this) { @@ -1317,13 +1330,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { } } } - - // Finished loading, delete when list is cleared - if(downloadFile.getSong() instanceof PodcastEpisode) { - toDelete.add(downloadFile); - } - - wakeLock.release(); } }); } diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index 2196afbb..c5803728 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -37,6 +37,7 @@ import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.Genre; import github.daneren2005.dsub.domain.Indexes; +import github.daneren2005.dsub.domain.PodcastEpisode; import github.daneren2005.dsub.domain.RemoteStatus; import github.daneren2005.dsub.domain.Lyrics; import github.daneren2005.dsub.domain.MusicDirectory; @@ -116,22 +117,25 @@ public class OfflineMusicService extends RESTMusicService { @Override public MusicDirectory getMusicDirectory(String id, String artistName, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - File dir = new File(id); - MusicDirectory result = new MusicDirectory(); - result.setName(dir.getName()); - - Set<String> names = new HashSet<String>(); - - for (File file : FileUtil.listMediaFiles(dir)) { - String name = getName(file); - if (name != null & !names.contains(name)) { - names.add(name); - result.addChild(createEntry(context, file, name)); - } - } - result.sortChildren(); - return result; + return getMusicDirectory(id, artistName, refresh, context, progressListener, false); } + private MusicDirectory getMusicDirectory(String id, String artistName, boolean refresh, Context context, ProgressListener progressListener, boolean isPodcast) throws Exception { + File dir = new File(id); + MusicDirectory result = new MusicDirectory(); + result.setName(dir.getName()); + + Set<String> names = new HashSet<String>(); + + for (File file : FileUtil.listMediaFiles(dir)) { + String name = getName(file); + if (name != null & !names.contains(name)) { + names.add(name); + result.addChild(createEntry(context, file, name, true, isPodcast)); + } + } + result.sortChildren(); + return result; + } @Override public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { @@ -161,18 +165,28 @@ public class OfflineMusicService extends RESTMusicService { return createEntry(context, file, name, true); } private MusicDirectory.Entry createEntry(Context context, File file, String name, boolean load) { - MusicDirectory.Entry entry = new MusicDirectory.Entry(); - entry.setDirectory(file.isDirectory()); - entry.setId(file.getPath()); - entry.setParent(file.getParent()); - entry.setSize(file.length()); - String root = FileUtil.getMusicDirectory(context).getPath(); + return createEntry(context, file, name, load, false); + } + private MusicDirectory.Entry createEntry(Context context, File file, String name, boolean load, boolean isPodcast) { + MusicDirectory.Entry entry; + if(isPodcast) { + PodcastEpisode episode = new PodcastEpisode(); + episode.setStatus("completed"); + entry = episode; + } else { + entry = new MusicDirectory.Entry(); + } + entry.setDirectory(file.isDirectory()); + entry.setId(file.getPath()); + entry.setParent(file.getParent()); + entry.setSize(file.length()); + String root = FileUtil.getMusicDirectory(context).getPath(); if(!file.getParentFile().getParentFile().getPath().equals(root)) { entry.setGrandParent(file.getParentFile().getParent()); } - entry.setPath(file.getPath().replaceFirst("^" + root + "/" , "")); + entry.setPath(file.getPath().replaceFirst("^" + root + "/" , "")); String title = name; - if (file.isFile()) { + if (file.isFile()) { File artistFolder = file.getParentFile().getParentFile(); File albumFolder = file.getParentFile(); if(artistFolder.getPath().equals(root)) { @@ -180,8 +194,8 @@ public class OfflineMusicService extends RESTMusicService { } else { entry.setArtist(artistFolder.getName()); } - entry.setAlbum(albumFolder.getName()); - + entry.setAlbum(albumFolder.getName()); + int index = name.indexOf('-'); if(index != -1) { try { @@ -191,24 +205,24 @@ public class OfflineMusicService extends RESTMusicService { // Failed parseInt, just means track filled out } } - + if(load) { entry.loadMetadata(file); } - } - - entry.setTitle(title); - entry.setSuffix(FileUtil.getExtension(file.getName().replace(".complete", ""))); + } - File albumArt = FileUtil.getAlbumArtFile(context, entry); - if (albumArt.exists()) { - entry.setCoverArt(albumArt.getPath()); - } + entry.setTitle(title); + entry.setSuffix(FileUtil.getExtension(file.getName().replace(".complete", ""))); + + File albumArt = FileUtil.getAlbumArtFile(context, entry); + if (albumArt.exists()) { + entry.setCoverArt(albumArt.getPath()); + } if(FileUtil.isVideoFile(file)) { entry.setVideo(true); } - return entry; - } + return entry; + } @Override public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener) throws Exception { @@ -623,7 +637,7 @@ public class OfflineMusicService extends RESTMusicService { @Override public MusicDirectory getPodcastEpisodes(boolean refresh, String id, Context context, ProgressListener progressListener) throws Exception { - return getMusicDirectory(FileUtil.getPodcastDirectory(context, id).getPath(), null, false, context, progressListener); + return getMusicDirectory(FileUtil.getPodcastDirectory(context, id).getPath(), null, false, context, progressListener, true); } @Override diff --git a/src/github/daneren2005/dsub/service/parser/AbstractParser.java b/src/github/daneren2005/dsub/service/parser/AbstractParser.java index 1a457754..9db40dad 100644 --- a/src/github/daneren2005/dsub/service/parser/AbstractParser.java +++ b/src/github/daneren2005/dsub/service/parser/AbstractParser.java @@ -50,6 +50,9 @@ public abstract class AbstractParser { int code = getInteger("code"); String message; switch (code) { + case 0: + message = context.getResources().getString(R.string.parser_server_error, get("message")); + break; case 20: message = context.getResources().getString(R.string.parser_upgrade_client); break; diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index 8865c4fa..651f043e 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -77,6 +77,7 @@ public final class Constants { public static final String PREFERENCES_KEY_SERVER_NAME = "serverName"; public static final String PREFERENCES_KEY_SERVER_URL = "serverUrl"; public static final String PREFERENCES_KEY_SERVER_INTERNAL_URL = "serverInternalUrl"; + public static final String PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID = "serverLocalNetworkSSID"; public static final String PREFERENCES_KEY_SERVER_VERSION = "serverVersion"; public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection"; public static final String PREFERENCES_KEY_OPEN_BROWSER = "openBrowser"; diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index ceeb6ade..5dd639c4 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -38,6 +38,7 @@ import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Environment; @@ -65,6 +66,7 @@ import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; + import org.apache.http.HttpEntity; import java.io.ByteArrayOutputStream; @@ -359,9 +361,12 @@ public final class Util { String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); if(allowAltAddress && Util.isWifiConnected(context)) { - String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null); - if(internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) { - serverUrl = internalUrl; + String SSID = prefs.getString(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance, ""); + if("".equals(SSID) || SSID.equals(Util.getSSID(context))) { + String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null); + if(internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) { + serverUrl = internalUrl; + } } } @@ -424,7 +429,14 @@ public final class Util { } public static String parseOfflineIDSearch(Context context, String id, String cacheLocation) { - String name = id.replace(cacheLocation, ""); + // Try to get this info based off of tags first + String name = parseOfflineIDSearch(id); + if(name != null) { + return name; + } + + // Otherwise go nuts trying to parse from file structure + name = id.replace(cacheLocation, ""); if(name.startsWith("/")) { name = name.substring(1); } @@ -461,6 +473,31 @@ public final class Util { return name; } + public static String parseOfflineIDSearch(String id) { + MusicDirectory.Entry entry = new MusicDirectory.Entry(); + File file = new File(id); + + if(file.exists()) { + entry.loadMetadata(file); + + if(entry.getArtist() != null) { + String title = file.getName(); + int index = title.lastIndexOf("."); + title = index == -1 ? title : title.substring(0, index); + title = title.substring(title.indexOf('-') + 1); + + String query = "artist:\"" + entry.getArtist() + "\"" + + " AND title:\"" + title + "\""; + + return query; + } else { + return null; + } + } else { + return null; + } + } + public static String getContentType(HttpEntity entity) { if (entity == null || entity.getContentType() == null) { return null; @@ -855,6 +892,16 @@ public final class Util { boolean connected = networkInfo != null && networkInfo.isConnected(); return connected && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI); } + public static String getSSID(Context context) { + if (isWifiConnected(context)) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + if (wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getSSID() != null) { + return wifiManager.getConnectionInfo().getSSID().replace("\"", ""); + } + return null; + } + return null; + } public static boolean isExternalStoragePresent() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); @@ -1208,32 +1255,13 @@ public final class Util { File albumArtFile = FileUtil.getAlbumArtFile(context, song); intent.putExtra("coverart", albumArtFile.getAbsolutePath()); - - avrcpIntent.putExtra("playing", true); - avrcpIntent.putExtra("track", song.getTitle()); - avrcpIntent.putExtra("artist", song.getArtist()); - avrcpIntent.putExtra("album", song.getAlbum()); - avrcpIntent.putExtra("ListSize",(long) downloadService.getSongs().size()); - avrcpIntent.putExtra("id", (long) downloadService.getCurrentPlayingIndex()+1); - avrcpIntent.putExtra("duration", (long) downloadService.getPlayerDuration()); - avrcpIntent.putExtra("position", (long) downloadService.getPlayerPosition()); - avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath()); } else { intent.putExtra("title", ""); intent.putExtra("artist", ""); intent.putExtra("album", ""); intent.putExtra("coverart", ""); - - avrcpIntent.putExtra("playing", false); - avrcpIntent.putExtra("track", ""); - avrcpIntent.putExtra("artist", ""); - avrcpIntent.putExtra("album", ""); - avrcpIntent.putExtra("ListSize",(long)0); - avrcpIntent.putExtra("id", (long) 0); - avrcpIntent.putExtra("duration", (long )0); - avrcpIntent.putExtra("position", (long) 0); - avrcpIntent.putExtra("coverart", ""); } + addTrackInfo(context, song, avrcpIntent); context.sendBroadcast(intent); context.sendBroadcast(avrcpIntent); @@ -1242,7 +1270,7 @@ public final class Util { /** * <p>Broadcasts the given player state as the one being set.</p> */ - public static void broadcastPlaybackStatusChange(Context context, PlayerState state) { + public static void broadcastPlaybackStatusChange(Context context, MusicDirectory.Entry song, PlayerState state) { Intent intent = new Intent(EVENT_PLAYSTATE_CHANGED); Intent avrcpIntent = new Intent(AVRCP_PLAYSTATE_CHANGED); @@ -1266,11 +1294,39 @@ public final class Util { default: return; // No need to broadcast. } + addTrackInfo(context, song, avrcpIntent); context.sendBroadcast(intent); context.sendBroadcast(avrcpIntent); } + private static void addTrackInfo(Context context, MusicDirectory.Entry song, Intent intent) { + if (song != null) { + DownloadService downloadService = (DownloadServiceImpl)context; + File albumArtFile = FileUtil.getAlbumArtFile(context, song); + + intent.putExtra("playing", true); + intent.putExtra("track", song.getTitle()); + intent.putExtra("artist", song.getArtist()); + intent.putExtra("album", song.getAlbum()); + intent.putExtra("ListSize", (long) downloadService.getSongs().size()); + intent.putExtra("id", (long) downloadService.getCurrentPlayingIndex() + 1); + intent.putExtra("duration", (long) downloadService.getPlayerDuration()); + intent.putExtra("position", (long) downloadService.getPlayerPosition()); + intent.putExtra("coverart", albumArtFile.getAbsolutePath()); + } else { + intent.putExtra("playing", false); + intent.putExtra("track", ""); + intent.putExtra("artist", ""); + intent.putExtra("album", ""); + intent.putExtra("ListSize", (long) 0); + intent.putExtra("id", (long) 0); + intent.putExtra("duration", (long) 0); + intent.putExtra("position", (long) 0); + intent.putExtra("coverart", ""); + } + } + /** * Resolves the default text color for notifications. * |