aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java13
-rw-r--r--app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java15
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java23
-rw-r--r--app/src/main/res/values/strings.xml2
-rw-r--r--app/src/main/res/xml/settings_cast.xml10
7 files changed, 62 insertions, 5 deletions
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 584a205a..fa2ca340 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java
@@ -59,6 +59,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.LoadingTask;
+import github.daneren2005.dsub.util.MediaRouteManager;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.CacheLocationPreference;
@@ -200,6 +201,18 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
ActivityCompat.requestPermissions(context, new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION }, SubsonicActivity.PERMISSIONS_REQUEST_LOCATION);
}
}
+ } else if(Constants.PREFERENCES_KEY_DLNA_CASTING_ENABLED.equals(key)) {
+ DownloadService downloadService = DownloadService.getInstance();
+ if(downloadService != null) {
+ MediaRouteManager mediaRouter = downloadService.getMediaRouter();
+
+ Boolean enabled = sharedPreferences.getBoolean(key, true);
+ if (enabled) {
+ mediaRouter.addDLNAProvider();
+ } else {
+ mediaRouter.removeDLNAProvider();
+ }
+ }
}
scheduleBackup();
diff --git a/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java b/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java
index 0f6975ba..0ee16723 100644
--- a/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java
+++ b/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java
@@ -71,6 +71,7 @@ public class DLNARouteProvider extends MediaRouteProvider {
private List<String> removing = new ArrayList<String>();
private AndroidUpnpService dlnaService;
private ServiceConnection dlnaServiceConnection;
+ private RegistryListener registryListener;
private boolean searchOnConnect = false;
public DLNARouteProvider(Context context) {
@@ -84,7 +85,7 @@ public class DLNARouteProvider extends MediaRouteProvider {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
dlnaService = (AndroidUpnpService) service;
- dlnaService.getRegistry().addListener(new RegistryListener() {
+ dlnaService.getRegistry().addListener(registryListener = new RegistryListener() {
@Override
public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice remoteDevice) {
@@ -142,6 +143,7 @@ public class DLNARouteProvider extends MediaRouteProvider {
@Override
public void onServiceDisconnected(ComponentName name) {
dlnaService = null;
+ registryListener = null;
}
};
@@ -290,6 +292,17 @@ public class DLNARouteProvider extends MediaRouteProvider {
}
}
+ public void destroy() {
+ if(dlnaService != null) {
+ dlnaService.getRegistry().removeListener(registryListener);
+ registryListener = null;
+ }
+
+ if(dlnaServiceConnection != null) {
+ getContext().getApplicationContext().unbindService(dlnaServiceConnection);
+ }
+ }
+
private class DLNARouteController extends RouteController {
private DLNADevice device;
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 6d85d128..b346f499 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -1665,6 +1665,9 @@ public class DownloadService extends Service {
return controller;
}
+ public MediaRouteManager getMediaRouter() {
+ return mediaRouter;
+ }
public MediaRouteSelector getRemoteSelector() {
return mediaRouter.getSelector();
}
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 b62729ab..281c87d7 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -178,6 +178,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_CAST_CACHE = "castCache";
public static final String PREFERENCES_KEY_PLAYBACK_SPEED = "playbackSpeed";
public static final String PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED = "customPlaybackSpeed";
+ public static final String PREFERENCES_KEY_DLNA_CASTING_ENABLED = "dlnaCastingEnabled";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";
diff --git a/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java b/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java
index 9aa54c4b..73ec6aec 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java
@@ -48,6 +48,7 @@ public class MediaRouteManager extends MediaRouter.Callback {
private MediaRouteSelector selector;
private List<MediaRouteProvider> providers = new ArrayList<MediaRouteProvider>();
private List<MediaRouteProvider> onlineProviders = new ArrayList<MediaRouteProvider>();
+ private DLNARouteProvider dlnaProvider;
static {
try {
@@ -159,10 +160,8 @@ public class MediaRouteManager extends MediaRouter.Callback {
addOnlineProviders();
}
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- DLNARouteProvider dlnaProvider = new DLNARouteProvider(downloadService);
- router.addProvider(dlnaProvider);
- providers.add(dlnaProvider);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && Util.getPreferences(downloadService).getBoolean(Constants.PREFERENCES_KEY_DLNA_CASTING_ENABLED, true)) {
+ addDLNAProvider();
}
}
public void buildSelector() {
@@ -178,4 +177,20 @@ public class MediaRouteManager extends MediaRouter.Callback {
}
selector = builder.build();
}
+
+ public void addDLNAProvider() {
+ if(dlnaProvider == null) {
+ dlnaProvider = new DLNARouteProvider(downloadService);
+ router.addProvider(dlnaProvider);
+ providers.add(dlnaProvider);
+ }
+ }
+ public void removeDLNAProvider() {
+ if(dlnaProvider != null) {
+ router.removeProvider(dlnaProvider);
+ providers.remove(dlnaProvider);
+ dlnaProvider.destroy();
+ dlnaProvider = null;
+ }
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0d9c2aa1..b0104262 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -488,6 +488,8 @@
<string name="settings.heads_up_notification_summary">Show playing notifications as Heads Up notifications (Android Lollipop+ only)</string>
<string name="settings.casting_cache">Cache While Casting</string>
<string name="settings.casting_cache_summary">Cache currently playing songs while casting</string>
+ <string name="settings.casting.dlna_casting_enabled">DLNA Enabled</string>
+ <string name="settings.casting.dlna_casting_enabled.summary">If you are having battery drain problems on Android 7.0 try turning this off</string>
<string name="shuffle.title">Shuffle By</string>
<string name="shuffle.startYear">Start Year:</string>
diff --git a/app/src/main/res/xml/settings_cast.xml b/app/src/main/res/xml/settings_cast.xml
index c23ae04d..78bafdd4 100644
--- a/app/src/main/res/xml/settings_cast.xml
+++ b/app/src/main/res/xml/settings_cast.xml
@@ -28,4 +28,14 @@
android:key="castCache"
android:defaultValue="false"/>
</PreferenceCategory>
+
+ <PreferenceCategory
+ android:title="@string/settings.other_title">
+
+ <CheckBoxPreference
+ android:title="@string/settings.casting.dlna_casting_enabled"
+ android:summary="@string/settings.casting.dlna_casting_enabled.summary"
+ android:key="dlnaCastingEnabled"
+ android:defaultValue="true"/>
+ </PreferenceCategory>
</PreferenceScreen> \ No newline at end of file