aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-09-28 15:35:54 -0700
committerScott Jackson <daneren2005@gmail.com>2016-09-28 15:35:54 -0700
commit6958e7943bec8680ea5b3f59315af04dfe669341 (patch)
treecfb894cd9fb2bcf5564c111b0e5a101640981662 /app/src/main/java
parent7cbd580a5b1745fb72c00de097aef19a822fc10f (diff)
parent538cb889c45559f7af54fee33801547de719fbfc (diff)
downloaddsub-6958e7943bec8680ea5b3f59315af04dfe669341.tar.gz
dsub-6958e7943bec8680ea5b3f59315af04dfe669341.tar.bz2
dsub-6958e7943bec8680ea5b3f59315af04dfe669341.zip
Merge branch 'edge' into connection
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java12
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java34
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/InternetRadioStationAdapter.java56
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/InternetRadioStation.java43
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java15
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java64
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java112
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java9
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java17
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java14
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java74
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java4
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/MusicService.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java13
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/Scrobbler.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/InternetRadioStationParser.java63
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Notifications.java28
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/UserUtil.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Util.java14
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/InternetRadioStationView.java39
29 files changed, 596 insertions, 62 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
index 8882ad98..9b14f4f6 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -162,6 +162,9 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED:
setDrawerItemVisible(R.id.drawer_bookmarks, false);
break;
+ case Constants.PREFERENCES_KEY_INTERNET_RADIO_ENABLED:
+ setDrawerItemVisible(R.id.drawer_internet_radio_stations, false);
+ break;
case Constants.PREFERENCES_KEY_SHARED_ENABLED:
setDrawerItemVisible(R.id.drawer_shares, false);
break;
@@ -311,6 +314,9 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
case R.id.drawer_bookmarks:
drawerItemSelected("Bookmark");
return true;
+ case R.id.drawer_internet_radio_stations:
+ drawerItemSelected("Internet Radio");
+ return true;
case R.id.drawer_shares:
drawerItemSelected("Share");
return true;
@@ -586,6 +592,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
SharedPreferences prefs = Util.getPreferences(this);
boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true);
boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true) && !Util.isOffline(this) && ServerInfo.canBookmark(this);
+ boolean internetRadioEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_INTERNET_RADIO_ENABLED, true) && !Util.isOffline(this) && ServerInfo.canInternetRadio(this);
boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this);
boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true) && !Util.isOffline(this);
boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true) && !Util.isOffline(this);
@@ -615,6 +622,9 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
if(!bookmarksEnabled) {
setDrawerItemVisible(R.id.drawer_bookmarks, false);
}
+ if(!internetRadioEnabled) {
+ setDrawerItemVisible(R.id.drawer_internet_radio_stations, false);
+ }
if(!sharedEnabled) {
setDrawerItemVisible(R.id.drawer_shares, false);
}
@@ -1191,6 +1201,8 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
return R.id.drawer_podcasts;
case "Bookmark":
return R.id.drawer_bookmarks;
+ case "Internet Radio":
+ return R.id.drawer_internet_radio_stations;
case "Share":
return R.id.drawer_shares;
case "Chat":
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index ca6dd168..c7190046 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -66,6 +66,7 @@ import github.daneren2005.dsub.fragments.SearchFragment;
import github.daneren2005.dsub.fragments.SelectArtistFragment;
import github.daneren2005.dsub.fragments.SelectBookmarkFragment;
import github.daneren2005.dsub.fragments.SelectDirectoryFragment;
+import github.daneren2005.dsub.fragments.SelectInternetRadioStationFragment;
import github.daneren2005.dsub.fragments.SelectPlaylistFragment;
import github.daneren2005.dsub.fragments.SelectPodcastsFragment;
import github.daneren2005.dsub.fragments.SelectShareFragment;
@@ -662,6 +663,8 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
return new SelectPodcastsFragment();
} else if("Bookmark".equals(fragmentType)) {
return new SelectBookmarkFragment();
+ } else if("Internet Radio".equals(fragmentType)) {
+ return new SelectInternetRadioStationFragment();
} else if("Share".equals(fragmentType)) {
return new SelectShareFragment();
} else if("Admin".equals(fragmentType)) {
@@ -922,7 +925,13 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
if (currentPlaying != null) {
song = currentPlaying.getSong();
trackView.setText(song.getTitle());
- artistView.setText(song.getArtist());
+
+ if(song.getArtist() != null) {
+ artistView.setVisibility(View.VISIBLE);
+ artistView.setText(song.getArtist());
+ } else {
+ artistView.setVisibility(View.GONE);
+ }
} else {
trackView.setText(R.string.main_title);
artistView.setText(R.string.main_artist);
@@ -939,18 +948,25 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
getImageLoader().loadImage(coverArtView, song, false, height, false);
}
- if(currentPlaying != null && currentPlaying.getSong() != null && (currentPlaying.getSong().isPodcast() || currentPlaying.getSong().isAudioBook())) {
+ if(getDownloadService().isCurrentPlayingSingle()) {
previousButton.setVisibility(View.GONE);
nextButton.setVisibility(View.GONE);
-
- rewindButton.setVisibility(View.VISIBLE);
- fastforwardButton.setVisibility(View.VISIBLE);
- } else {
- previousButton.setVisibility(View.VISIBLE);
- nextButton.setVisibility(View.VISIBLE);
-
rewindButton.setVisibility(View.GONE);
fastforwardButton.setVisibility(View.GONE);
+ } else {
+ if (currentPlaying != null && currentPlaying.getSong() != null && (currentPlaying.getSong().isPodcast() || currentPlaying.getSong().isAudioBook())) {
+ previousButton.setVisibility(View.GONE);
+ nextButton.setVisibility(View.GONE);
+
+ rewindButton.setVisibility(View.VISIBLE);
+ fastforwardButton.setVisibility(View.VISIBLE);
+ } else {
+ previousButton.setVisibility(View.VISIBLE);
+ nextButton.setVisibility(View.VISIBLE);
+
+ rewindButton.setVisibility(View.GONE);
+ fastforwardButton.setVisibility(View.GONE);
+ }
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/InternetRadioStationAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/InternetRadioStationAdapter.java
new file mode 100644
index 00000000..9d47d70c
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/InternetRadioStationAdapter.java
@@ -0,0 +1,56 @@
+/*
+ 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 2016 (C) Scott Jackson
+*/
+package github.daneren2005.dsub.adapter;
+
+import android.content.Context;
+import android.view.ViewGroup;
+
+import java.util.List;
+
+import github.daneren2005.dsub.domain.InternetRadioStation;
+import github.daneren2005.dsub.view.FastScroller;
+import github.daneren2005.dsub.view.InternetRadioStationView;
+import github.daneren2005.dsub.view.UpdateView;
+
+public class InternetRadioStationAdapter extends SectionAdapter<InternetRadioStation> implements FastScroller.BubbleTextGetter {
+ public static int VIEW_TYPE_INTERNET_RADIO_STATION = 1;
+
+ public InternetRadioStationAdapter(Context context, List<InternetRadioStation> stations, OnItemClickedListener listener) {
+ super(context, stations);
+ this.onItemClickedListener = listener;
+ }
+
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ return new UpdateView.UpdateViewHolder(new InternetRadioStationView(context));
+ }
+
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, InternetRadioStation station, int viewType) {
+ holder.getUpdateView().setObject(station);
+ holder.setItem(station);
+ }
+
+ @Override
+ public int getItemViewType(InternetRadioStation station) {
+ return VIEW_TYPE_INTERNET_RADIO_STATION;
+ }
+
+ @Override
+ public String getTextToShowInBubble(int position) {
+ InternetRadioStation item = getItemForPosition(position);
+ return item.getTitle();
+ }
+}
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/InternetRadioStation.java b/app/src/main/java/github/daneren2005/dsub/domain/InternetRadioStation.java
new file mode 100644
index 00000000..47d79b99
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/domain/InternetRadioStation.java
@@ -0,0 +1,43 @@
+/*
+ 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 2016 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.domain;
+
+public class InternetRadioStation extends MusicDirectory.Entry {
+ private String streamUrl;
+ private String homePageUrl;
+
+ public InternetRadioStation() {}
+
+ public String getStreamUrl() {
+ return streamUrl;
+ }
+
+ public void setStreamUrl(String streamUrl) {
+ this.streamUrl = streamUrl;
+ }
+
+ public String getHomePageUrl() {
+ return homePageUrl;
+ }
+
+ public void setHomePageUrl(String homePageUrl) {
+ this.homePageUrl = homePageUrl;
+ }
+}
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java
index 7f538484..e41a9503 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java
@@ -24,6 +24,7 @@ import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
@@ -215,6 +216,9 @@ public class ServerInfo implements Serializable {
public static boolean canBookmark(Context context) {
return checkServerVersion(context, "1.9");
}
+ public static boolean canInternetRadio(Context context) {
+ return checkServerVersion(context, "1.9");
+ }
public static boolean canSavePlayQueue(Context context) {
return ServerInfo.checkServerVersion(context, "1.12") && (!ServerInfo.isMadsonic(context) || checkServerVersion(context, "2.0"));
@@ -231,8 +235,15 @@ public class ServerInfo implements Serializable {
return canUseToken(context, Util.getActiveServer(context));
}
public static boolean canUseToken(Context context, int instance) {
- return false; /*isStockSubsonic(context, instance) && checkServerVersion(context, "1.13", instance) ||
- isMadsonic(context, instance) && checkServerVersion(context, "2.0", instance);*/
+ if(isStockSubsonic(context, instance) && checkServerVersion(context, "1.14", instance)) {
+ if(Util.getBlockTokenUse(context, instance)) {
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
}
public static boolean hasSimilarArtists(Context context) {
return !ServerInfo.isMadsonic(context) || ServerInfo.checkServerVersion(context, "2.0");
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
index 187f0d55..552712f7 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
@@ -47,7 +47,7 @@ public class AdminFragment extends SelectRecyclerFragment<User> {
switch (item.getItemId()) {
case R.id.menu_add_user:
- UserUtil.addNewUser(context, this, objects.get(0));
+ UserUtil.addNewUser(context, this, (objects.size() > 0) ? objects.get(0) : null);
break;
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index 9eddbc89..f55dbe1d 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -522,7 +522,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
menu.removeItem(R.id.menu_equalizer);
}
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isRemoteEnabled) {
+ if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M || isRemoteEnabled) {
playbackSpeedButton.setVisibility(View.GONE);
} else {
playbackSpeedButton.setVisibility(View.VISIBLE);
@@ -535,6 +535,15 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
mediaRouteButton.setDialogFactory(new CustomMediaRouteDialogFactory());
mediaRouteButton.setRouteSelector(downloadService.getRemoteSelector());
}
+
+ if(downloadService.isCurrentPlayingSingle()) {
+ if(!Util.isOffline(context)) {
+ menu.removeItem(R.id.menu_save_playlist);
+ }
+
+ menu.removeItem(R.id.menu_batch_mode);
+ menu.removeItem(R.id.menu_remove_played);
+ }
}
if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, false)) {
@@ -867,6 +876,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
private void setControlsVisible(boolean visible) {
+ DownloadService downloadService = getDownloadService();
+ if(downloadService != null && downloadService.isCurrentPlayingSingle()) {
+ return;
+ }
+
try {
long duration = 1700L;
FadeOutAnimation.createAndStart(rootView.findViewById(R.id.download_overlay_buttons), !visible, duration);
@@ -1242,18 +1256,25 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
this.currentPlaying = currentPlaying;
setupSubtitle(currentPlayingIndex);
- if(currentPlaying != null && !currentPlaying.isSong()) {
+ if(getDownloadService().isCurrentPlayingSingle()) {
previousButton.setVisibility(View.GONE);
nextButton.setVisibility(View.GONE);
-
- rewindButton.setVisibility(View.VISIBLE);
- fastforwardButton.setVisibility(View.VISIBLE);
- } else {
- previousButton.setVisibility(View.VISIBLE);
- nextButton.setVisibility(View.VISIBLE);
-
rewindButton.setVisibility(View.GONE);
fastforwardButton.setVisibility(View.GONE);
+ } else {
+ if (currentPlaying != null && !currentPlaying.isSong()) {
+ previousButton.setVisibility(View.GONE);
+ nextButton.setVisibility(View.GONE);
+
+ rewindButton.setVisibility(View.VISIBLE);
+ fastforwardButton.setVisibility(View.VISIBLE);
+ } else {
+ previousButton.setVisibility(View.VISIBLE);
+ nextButton.setVisibility(View.VISIBLE);
+
+ rewindButton.setVisibility(View.GONE);
+ fastforwardButton.setVisibility(View.GONE);
+ }
}
updateTitle();
}
@@ -1265,7 +1286,9 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
getImageLoader().loadImage(albumArtImageView, song, true, true);
DownloadService downloadService = getDownloadService();
- if(downloadService.isShufflePlayEnabled()) {
+ if(downloadService.isCurrentPlayingSingle()) {
+ setSubtitle(null);
+ } else if(downloadService.isShufflePlayEnabled()) {
setSubtitle(context.getResources().getString(R.string.download_playerstate_playing_shuffle));
} else if(downloadService.isArtistRadio()) {
setSubtitle(context.getResources().getString(R.string.download_playerstate_playing_artist_radio));
@@ -1314,6 +1337,14 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
} else {
setupSubtitle(currentPlayingIndex);
}
+
+ if(downloadService.isCurrentPlayingSingle()) {
+ toggleListButton.setVisibility(View.GONE);
+ repeatButton.setVisibility(View.GONE);
+ } else {
+ toggleListButton.setVisibility(View.VISIBLE);
+ repeatButton.setVisibility(View.VISIBLE);
+ }
}
@Override
@@ -1368,11 +1399,16 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
break;
default:
if(currentPlaying != null) {
- String artist = "";
- if(currentPlaying.getSong().getArtist() != null) {
- artist = currentPlaying.getSong().getArtist() + " - ";
+ Entry entry = currentPlaying.getSong();
+ if(entry.getAlbum() != null) {
+ String artist = "";
+ if (entry.getArtist() != null) {
+ artist = currentPlaying.getSong().getArtist() + " - ";
+ }
+ statusTextView.setText(artist + entry.getAlbum());
+ } else {
+ statusTextView.setText(null);
}
- statusTextView.setText(artist + currentPlaying.getSong().getAlbum());
} else {
statusTextView.setText(null);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java
new file mode 100644
index 00000000..16082cbd
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java
@@ -0,0 +1,112 @@
+/*
+ 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 2016 (C) Scott Jackson
+*/
+package github.daneren2005.dsub.fragments;
+
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.adapter.InternetRadioStationAdapter;
+import github.daneren2005.dsub.adapter.SectionAdapter;
+import github.daneren2005.dsub.domain.InternetRadioStation;
+import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.util.ProgressListener;
+import github.daneren2005.dsub.util.TabBackgroundTask;
+import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.UpdateView;
+
+public class SelectInternetRadioStationFragment extends SelectRecyclerFragment<InternetRadioStation> {
+ @Override
+ public int getOptionsMenu() {
+ return R.menu.abstract_top_menu;
+ }
+
+ @Override
+ public SectionAdapter<InternetRadioStation> getAdapter(List<InternetRadioStation> objs) {
+ return new InternetRadioStationAdapter(context, objs, this);
+ }
+
+ @Override
+ public List<InternetRadioStation> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
+ return musicService.getInternetRadioStations(refresh, context, listener);
+ }
+
+ @Override
+ public int getTitleResource() {
+ return R.string.button_bar_internet_radio;
+ }
+
+ @Override
+ public void onItemClicked(UpdateView<InternetRadioStation> updateView, final InternetRadioStation item) {
+ new TabBackgroundTask<Void>(this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ DownloadService downloadService = getDownloadService();
+ if(downloadService == null) {
+ return null;
+ }
+
+ downloadService.download(item);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ context.openNowPlaying();
+ }
+ }.execute();
+ }
+
+ @Override
+ public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<InternetRadioStation> updateView, InternetRadioStation item) {
+ menuInflater.inflate(R.menu.select_internet_radio_context, menu);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem, UpdateView<InternetRadioStation> updateView, InternetRadioStation item) {
+ switch (menuItem.getItemId()) {
+ case R.id.internet_radio_info:
+ displayInternetRadioStationInfo(item);
+ break;
+ }
+
+ return false;
+ }
+
+ private void displayInternetRadioStationInfo(final InternetRadioStation station) {
+ List<Integer> headers = new ArrayList<>();
+ List<String> details = new ArrayList<>();
+
+ headers.add(R.string.details_title);
+ details.add(station.getTitle());
+
+ headers.add(R.string.details_home_page);
+ details.add(station.getHomePageUrl());
+
+ headers.add(R.string.details_stream_url);
+ details.add(station.getStreamUrl());
+
+ Util.showDetailsDialog(context, R.string.details_title_internet_radio_station, headers, details);
+ }
+}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java
index ad064d01..d5ba25f5 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java
@@ -431,6 +431,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
for (ServerSettings ss : serverSettings.values()) {
if(!ss.update()) {
serversCategory.removePreference(ss.getScreen());
+ serverCount--;
}
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
index b7478c8a..818324ed 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -309,6 +309,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(entry.getBookmark() == null) {
menu.removeItem(R.id.bookmark_menu_delete);
}
+
+
+ String songPressAction = Util.getSongPressAction(context);
+ if(!"next".equals(songPressAction) && !"last".equals(songPressAction)) {
+ menu.setGroupVisible(R.id.hide_play_now, false);
+ }
}
} else {
if(Util.isOffline(context)) {
@@ -430,6 +436,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
case R.id.album_menu_share:
createShare(songs);
break;
+ case R.id.song_menu_play_now:
+ playNow(songs);
+ break;
case R.id.song_menu_play_next:
getDownloadService().download(songs, false, false, true, false);
break;
diff --git a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
index 014c2aa6..e3990453 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
@@ -39,6 +39,7 @@ import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.ChatMessage;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.Indexes;
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.PlayerQueue;
import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.domain.RemoteStatus;
@@ -1233,6 +1234,22 @@ public class CachedMusicService implements MusicService {
}
@Override
+ public List<InternetRadioStation> getInternetRadioStations(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ List<InternetRadioStation> result = null;
+
+ if(!refresh) {
+ result = FileUtil.deserialize(context, getCacheName(context, "internetRadioStations"), ArrayList.class);
+ }
+
+ if(result == null) {
+ result = musicService.getInternetRadioStations(refresh, context, progressListener);
+ FileUtil.serialize(context, new ArrayList<>(result), getCacheName(context, "internetRadioStations"));
+ }
+
+ return result;
+ }
+
+ @Override
public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{
return musicService.processOfflineSyncs(context, progressListener);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java
index c2007139..2df290cf 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java
@@ -41,6 +41,7 @@ import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.EnvironmentVariables;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.util.compat.CastCompat;
@@ -465,14 +466,14 @@ public class ChromeCastController extends RemoteController {
void launchApplication() {
try {
- Cast.CastApi.launchApplication(apiClient, CastCompat.APPLICATION_ID, false).setResultCallback(resultCallback);
+ Cast.CastApi.launchApplication(apiClient, EnvironmentVariables.CAST_APPLICATION_ID, false).setResultCallback(resultCallback);
} catch (Exception e) {
Log.e(TAG, "Failed to launch application", e);
}
}
void reconnectApplication() {
try {
- Cast.CastApi.joinApplication(apiClient, CastCompat.APPLICATION_ID, sessionId).setResultCallback(resultCallback);
+ Cast.CastApi.joinApplication(apiClient, EnvironmentVariables.CAST_APPLICATION_ID, sessionId).setResultCallback(resultCallback);
} catch (Exception e) {
Log.e(TAG, "Failed to reconnect application", e);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
index e4bab798..d1c594ce 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
@@ -29,6 +29,8 @@ import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.PowerManager;
import android.util.Log;
+
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.SilentBackgroundTask;
@@ -377,6 +379,18 @@ public class DownloadFile implements BufferFile {
}
}
+ public boolean isStream() {
+ return song != null && song instanceof InternetRadioStation;
+ }
+ public String getStream() {
+ if(song != null && song instanceof InternetRadioStation) {
+ InternetRadioStation station = (InternetRadioStation) song;
+ return station.getStreamUrl();
+ } else {
+ return null;
+ }
+ }
+
@Override
public String toString() {
return "DownloadFile (" + song + ")";
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index cec98865..a6bbc327 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -35,6 +35,7 @@ import github.daneren2005.dsub.activity.SubsonicActivity;
import github.daneren2005.dsub.audiofx.AudioEffectsController;
import github.daneren2005.dsub.audiofx.EqualizerController;
import github.daneren2005.dsub.domain.Bookmark;
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.PodcastEpisode;
@@ -60,6 +61,7 @@ import github.daneren2005.serverproxy.BufferProxy;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
@@ -123,7 +125,7 @@ public class DownloadService extends Service {
private RemoteControlClientBase mRemoteControl;
- private final IBinder binder = new SimpleServiceBinder<DownloadService>(this);
+ private final IBinder binder = new SimpleServiceBinder<>(this);
private Looper mediaPlayerLooper;
private MediaPlayer mediaPlayer;
private MediaPlayer nextMediaPlayer;
@@ -382,6 +384,10 @@ public class DownloadService extends Service {
handler.postDelayed(r, millis);
}
+ public synchronized void download(InternetRadioStation station) {
+ clear();
+ download(Arrays.asList((MusicDirectory.Entry) station), false, true, false, false);
+ }
public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle) {
download(songs, save, autoplay, playNext, shuffle, 0, 0);
}
@@ -394,7 +400,10 @@ public class DownloadService extends Service {
if (songs.isEmpty()) {
return;
+ } else if(isCurrentPlayingSingle()) {
+ clear();
}
+
if (playNext) {
if (autoplay && getCurrentPlayingIndex() >= 0) {
offset = 0;
@@ -996,6 +1005,21 @@ public class DownloadService extends Service {
public List<DownloadFile> getToDelete() { return toDelete; }
+ public boolean isCurrentPlayingSingle() {
+ if(currentPlaying != null && currentPlaying.getSong() instanceof InternetRadioStation) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ public boolean isCurrentPlayingStream() {
+ if(currentPlaying != null) {
+ return currentPlaying.isStream();
+ } else {
+ return false;
+ }
+ }
+
public synchronized List<DownloadFile> getDownloads() {
List<DownloadFile> temp = new ArrayList<DownloadFile>();
temp.addAll(downloadList);
@@ -1819,7 +1843,7 @@ public class DownloadService extends Service {
bufferAndPlay(position, true);
}
private synchronized void bufferAndPlay(int position, boolean start) {
- if(!currentPlaying.isCompleteFileAvailable()) {
+ if(!currentPlaying.isCompleteFileAvailable() && !currentPlaying.isStream()) {
if(Util.isAllowedToDownload(this)) {
reset();
@@ -1835,11 +1859,6 @@ public class DownloadService extends Service {
private synchronized void doPlay(final DownloadFile downloadFile, final int position, final boolean start) {
try {
- downloadFile.setPlaying(true);
- final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
- boolean isPartial = file.equals(downloadFile.getPartialFile());
- downloadFile.updateModificationDate();
-
subtractPosition = 0;
mediaPlayer.setOnCompletionListener(null);
mediaPlayer.setOnPreparedListener(null);
@@ -1851,19 +1870,33 @@ public class DownloadService extends Service {
} catch(Throwable e) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
- String dataSource = file.getAbsolutePath();
- if(isPartial && !Util.isOffline(this)) {
- if (proxy == null) {
- proxy = new BufferProxy(this);
- proxy.start();
- }
- proxy.setBufferFile(downloadFile);
- dataSource = proxy.getPrivateAddress(dataSource);
+
+ String dataSource;
+ boolean isPartial = false;
+ if(downloadFile.isStream()) {
+ dataSource = downloadFile.getStream();
Log.i(TAG, "Data Source: " + dataSource);
- } else if(proxy != null) {
- proxy.stop();
- proxy = null;
+ } else {
+ downloadFile.setPlaying(true);
+ final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
+ isPartial = file.equals(downloadFile.getPartialFile());
+ downloadFile.updateModificationDate();
+
+ dataSource = file.getAbsolutePath();
+ if (isPartial && !Util.isOffline(this)) {
+ if (proxy == null) {
+ proxy = new BufferProxy(this);
+ proxy.start();
+ }
+ proxy.setBufferFile(downloadFile);
+ dataSource = proxy.getPrivateAddress(dataSource);
+ Log.i(TAG, "Data Source: " + dataSource);
+ } else if (proxy != null) {
+ proxy.stop();
+ proxy = null;
+ }
}
+
mediaPlayer.setDataSource(dataSource);
setPlayerState(PREPARING);
@@ -2160,13 +2193,16 @@ public class DownloadService extends Service {
checkArtistRadio();
}
- if (!Util.isNetworkConnected(this, true) || Util.isOffline(this)) {
+ if (!Util.isAllowedToDownload(this)) {
return;
}
if (downloadList.isEmpty() && backgroundDownloadList.isEmpty()) {
return;
}
+ if(currentPlaying != null && currentPlaying.isStream()) {
+ return;
+ }
// Need to download current playing and not casting?
if (currentPlaying != null && remoteState == LOCAL && currentPlaying != currentDownloading && !currentPlaying.isWorkDone()) {
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 726840b2..1c80b622 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -36,6 +36,8 @@ import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.KeyEvent;
+
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerQueue;
import github.daneren2005.dsub.domain.PlayerState;
@@ -310,7 +312,7 @@ public class DownloadServiceLifecycleSupport {
FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER);
// If we are on Subsonic 5.2+, save play queue
- if(serializeRemote && ServerInfo.canSavePlayQueue(downloadService) && !Util.isOffline(downloadService) && state.songs.size() > 0) {
+ if(serializeRemote && ServerInfo.canSavePlayQueue(downloadService) && !Util.isOffline(downloadService) && state.songs.size() > 0 && !(state.songs.get(0) instanceof InternetRadioStation)) {
// Cancel any currently running tasks
if(currentSavePlayQueueTask != null) {
currentSavePlayQueueTask.cancel();
diff --git a/app/src/main/java/github/daneren2005/dsub/service/MusicService.java b/app/src/main/java/github/daneren2005/dsub/service/MusicService.java
index 22f154c4..1e275108 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/MusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/MusicService.java
@@ -30,6 +30,7 @@ import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.ChatMessage;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.Indexes;
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.PlayerQueue;
import github.daneren2005.dsub.domain.RemoteStatus;
import github.daneren2005.dsub.domain.Lyrics;
@@ -194,6 +195,8 @@ public interface MusicService {
void savePlayQueue(List<MusicDirectory.Entry> songs, MusicDirectory.Entry currentPlaying, int position, Context context, ProgressListener progressListener) throws Exception;
PlayerQueue getPlayQueue(Context context, ProgressListener progressListener) throws Exception;
+
+ List<InternetRadioStation> getInternetRadioStations(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception;
diff --git a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
index e004101d..2c439ec4 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -41,6 +41,7 @@ import github.daneren2005.dsub.domain.ArtistInfo;
import github.daneren2005.dsub.domain.ChatMessage;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.Indexes;
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.PlayerQueue;
import github.daneren2005.dsub.domain.PodcastEpisode;
@@ -890,6 +891,11 @@ public class OfflineMusicService implements MusicService {
}
@Override
+ public List<InternetRadioStation> getInternetRadioStations(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException(ERRORMSG);
+ }
+
+ @Override
public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{
throw new OfflineException(ERRORMSG);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
index 0b67af9c..50404ffe 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
@@ -82,6 +82,7 @@ import github.daneren2005.dsub.service.parser.ChatMessageParser;
import github.daneren2005.dsub.service.parser.ErrorParser;
import github.daneren2005.dsub.service.parser.GenreParser;
import github.daneren2005.dsub.service.parser.IndexesParser;
+import github.daneren2005.dsub.service.parser.InternetRadioStationParser;
import github.daneren2005.dsub.service.parser.JukeboxStatusParser;
import github.daneren2005.dsub.service.parser.LicenseParser;
import github.daneren2005.dsub.service.parser.LyricsParser;
@@ -1731,6 +1732,18 @@ public class RESTMusicService implements MusicService {
}
@Override
+ public List<InternetRadioStation> getInternetRadioStations(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ checkServerVersion(context, "1.9", null);
+
+ Reader reader = getReader(context, progressListener, "getInternetRadioStations", null);
+ try {
+ return new InternetRadioStationParser(context, getInstance(context)).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{
return processOfflineScrobbles(context, progressListener) + processOfflineStars(context, progressListener);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/Scrobbler.java b/app/src/main/java/github/daneren2005/dsub/service/Scrobbler.java
index 168a7777..c7ad639e 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/Scrobbler.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/Scrobbler.java
@@ -3,6 +3,7 @@ package github.daneren2005.dsub.service;
import android.content.Context;
import android.util.Log;
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.util.SilentBackgroundTask;
@@ -69,7 +70,7 @@ public class Scrobbler {
return null;
}
// Ignore podcasts
- else if(song.getSong() instanceof PodcastEpisode) {
+ else if(song.getSong() instanceof PodcastEpisode || song.getSong() instanceof InternetRadioStation) {
return null;
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
index d6e1a002..d4c090c1 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
@@ -18,6 +18,7 @@
*/
package github.daneren2005.dsub.service.parser;
+import java.io.IOException;
import java.io.Reader;
import org.xmlpull.v1.XmlPullParser;
@@ -72,6 +73,11 @@ public abstract class AbstractParser {
case 40:
message = context.getResources().getString(R.string.parser_not_authenticated);
break;
+ case 41:
+ Util.setBlockTokenUse(context, instance, true);
+
+ // Throw IOException so RESTMusicService knows to retry
+ throw new IOException();
case 50:
message = context.getResources().getString(R.string.parser_not_authorized);
break;
diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/InternetRadioStationParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/InternetRadioStationParser.java
new file mode 100644
index 00000000..77d7bc4a
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/service/parser/InternetRadioStationParser.java
@@ -0,0 +1,63 @@
+/*
+ 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 2016 (C) Scott Jackson
+*/
+package github.daneren2005.dsub.service.parser;
+
+import android.content.Context;
+import github.daneren2005.dsub.domain.InternetRadioStation;
+import github.daneren2005.dsub.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+public class InternetRadioStationParser extends ErrorParser {
+ public InternetRadioStationParser(Context context, int instance) {
+ super(context, instance);
+ }
+
+ public List<InternetRadioStation> parse(Reader reader, ProgressListener progressListener) throws Exception {
+ init(reader);
+
+ List<InternetRadioStation> result = new ArrayList<>();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("internetRadioStation".equals(name)) {
+ InternetRadioStation station = new InternetRadioStation();
+
+ station.setId(get("id"));
+ station.setTitle(get("name"));
+ station.setStreamUrl(get("streamUrl"));
+ station.setHomePageUrl(get("homePageUrl"));
+
+ result.add(station);
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ return result;
+ }
+
+} \ No newline at end of file
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
index b7a68962..2d4301d9 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -134,6 +134,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_HIDE_WIDGET = "hideWidget";
public static final String PREFERENCES_KEY_PODCASTS_ENABLED = "podcastsEnabled";
public static final String PREFERENCES_KEY_BOOKMARKS_ENABLED = "bookmarksEnabled";
+ public static final String PREFERENCES_KEY_INTERNET_RADIO_ENABLED = "internetRadioEnabled";
public static final String PREFERENCES_KEY_CUSTOM_SORT_ENABLED = "customSortEnabled";
public static final String PREFERENCES_KEY_MENU_PLAY_NOW = "showPlayNow";
public static final String PREFERENCES_KEY_MENU_PLAY_SHUFFLED = "showPlayShuffled";
@@ -189,6 +190,7 @@ public final class Constants {
public static final String CACHE_KEY_IGNORE = "ignoreArticles";
public static final String CACHE_AUDIO_SESSION_ID = "audioSessionId";
+ public static final String CACHE_BLOCK_TOKEN_USE = "blockTokenUse";
public static final String MAIN_BACK_STACK = "backStackIds";
public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize";
diff --git a/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java b/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java
index d8046d1b..710d5232 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java
@@ -17,4 +17,5 @@ package github.daneren2005.dsub.util;
public final class EnvironmentVariables {
public static final String PASTEBIN_DEV_KEY = "";
+ public static final String CAST_APPLICATION_ID = "";
}
diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
index a85141df..2321e69e 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
@@ -43,6 +43,7 @@ import java.lang.ref.WeakReference;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.ArtistInfo;
+import github.daneren2005.dsub.domain.InternetRadioStation;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.PodcastChannel;
@@ -221,8 +222,11 @@ public class ImageLoader {
return loadImage(view, entry, large, size, crossfade);
}
public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, int size, boolean crossfade) {
- // TODO: If we know this a artist, try to load artist info instead
- if(entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11") && !Util.isOffline(context)) {
+ if(entry != null && entry instanceof InternetRadioStation) {
+ // Continue on and load a null bitmap
+ }
+ // If we know this a artist, try to load artist info instead
+ else if(entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11") && !Util.isOffline(context)) {
SilentBackgroundTask task = new ArtistImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade);
task.execute();
return task;
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
index 2948844b..0d4a0f9c 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
@@ -67,9 +67,10 @@ public final class Notifications {
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
}
boolean remote = downloadService.isRemoteEnabled();
+ boolean isSingle = downloadService.isCurrentPlayingSingle();
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){
RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
- setupViews(expandedContentView ,context, song, true, playing, remote);
+ setupViews(expandedContentView ,context, song, true, playing, remote, isSingle);
notification.bigContentView = expandedContentView;
notification.priority = Notification.PRIORITY_HIGH;
}
@@ -82,7 +83,7 @@ public final class Notifications {
}
RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
- setupViews(smallContentView, context, song, false, playing, remote);
+ setupViews(smallContentView, context, song, false, playing, remote, isSingle);
notification.contentView = smallContentView;
Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
@@ -122,7 +123,7 @@ public final class Notifications {
DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}
- private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote) {
+ private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote, boolean isSingleFile) {
boolean isLongFile = song.isAudioBook() || song.isPodcast();
// Use the same text for the ticker and the expanded notification
@@ -209,6 +210,27 @@ public final class Notifications {
close = R.id.notification_close;
rv.setViewVisibility(close, View.VISIBLE);
}
+
+ if(isSingleFile) {
+ if(previous > 0) {
+ rv.setViewVisibility(previous, View.GONE);
+ previous = 0;
+ }
+ if(rewind > 0) {
+ rv.setViewVisibility(rewind, View.GONE);
+ rewind = 0;
+ }
+
+ if(next > 0) {
+ rv.setViewVisibility(next, View.GONE);
+ next = 0;
+ }
+
+ if(fastForward > 0) {
+ rv.setViewVisibility(fastForward, View.GONE);
+ fastForward = 0;
+ }
+ }
if(previous > 0) {
Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
diff --git a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
index 24d3906b..db1c628f 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
@@ -406,7 +406,7 @@ public final class UserUtil {
}
}
- if(sampleUser.getMusicFolderSettings() != null) {
+ if(sampleUser != null && sampleUser.getMusicFolderSettings() != null) {
for(User.Setting setting: sampleUser.getMusicFolderSettings()) {
User.MusicFolderSetting musicFolderSetting = (User.MusicFolderSetting) setting;
user.addMusicFolder(musicFolderSetting, true);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java
index b1f1617d..b69ea55e 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Util.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java
@@ -421,6 +421,18 @@ public final class Util {
return builder.toString().hashCode();
}
+ public static String getBlockTokenUsePref(Context context, int instance) {
+ return Constants.CACHE_BLOCK_TOKEN_USE + Util.getRestUrl(context, null, instance, false);
+ }
+ public static boolean getBlockTokenUse(Context context, int instance) {
+ return getPreferences(context).getBoolean(getBlockTokenUsePref(context, instance), false);
+ }
+ public static void setBlockTokenUse(Context context, int instance, boolean block) {
+ SharedPreferences.Editor editor = getPreferences(context).edit();
+ editor.putBoolean(getBlockTokenUsePref(context, instance), block);
+ editor.commit();
+ }
+
public static String replaceInternalUrl(Context context, String url) {
// Only change to internal when using https
if(url.indexOf("https") != -1) {
@@ -1113,7 +1125,7 @@ public final class Util {
}
public static boolean isAllowedToDownload(Context context) {
- return !isWifiRequiredForDownload(context) || isWifiConnected(context);
+ return isNetworkConnected(context, true) && !isOffline(context);
}
public static boolean isWifiRequiredForDownload(Context context) {
SharedPreferences prefs = getPreferences(context);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java b/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java
index ab64bca9..415106db 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java
@@ -23,13 +23,9 @@ import com.google.android.gms.cast.CastMediaControlIntent;
import github.daneren2005.dsub.service.ChromeCastController;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.RemoteController;
+import github.daneren2005.dsub.util.EnvironmentVariables;
-/**
- * Created by owner on 2/9/14.
- */
public final class CastCompat {
- public static final String APPLICATION_ID = "5F85EBEB";
-
static {
try {
Class.forName("com.google.android.gms.cast.CastDevice");
@@ -52,6 +48,6 @@ public final class CastCompat {
}
public static String getCastControlCategory() {
- return CastMediaControlIntent.categoryForCast(APPLICATION_ID);
+ return CastMediaControlIntent.categoryForCast(EnvironmentVariables.CAST_APPLICATION_ID);
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/view/InternetRadioStationView.java b/app/src/main/java/github/daneren2005/dsub/view/InternetRadioStationView.java
new file mode 100644
index 00000000..36aaa8af
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/view/InternetRadioStationView.java
@@ -0,0 +1,39 @@
+/*
+ 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 2016 (C) Scott Jackson
+*/
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.InternetRadioStation;
+
+public class InternetRadioStationView extends UpdateView<InternetRadioStation> {
+ private TextView titleView;
+
+ public InternetRadioStationView(Context context) {
+ super(context);
+ LayoutInflater.from(context).inflate(R.layout.basic_list_item, this, true);
+
+ titleView = (TextView) findViewById(R.id.item_name);
+ moreButton = (ImageView) findViewById(R.id.item_more);
+ }
+
+ protected void setObjectImpl(InternetRadioStation station) {
+ titleView.setText(station.getTitle());
+ }
+}