From 01e5812356a918da1f526b8476a5775608f3750c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 23 Sep 2016 22:11:25 -0700 Subject: Move cast id over to EnvironmentVariables --- .../github/daneren2005/dsub/service/ChromeCastController.java | 5 +++-- .../java/github/daneren2005/dsub/util/EnvironmentVariables.java | 1 + .../main/java/github/daneren2005/dsub/util/compat/CastCompat.java | 8 ++------ 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/github/daneren2005') 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/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/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); } } -- cgit v1.2.3 From 538cb889c45559f7af54fee33801547de719fbfc Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 27 Sep 2016 17:15:45 -0700 Subject: Fixes #737: Don't show playback speed button on < 6.0 --- .../main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java/github/daneren2005') 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 985b7bec..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); -- cgit v1.2.3 From bc2709aa309d4e62f35903bffb486b1eb1e5726f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 30 Sep 2016 13:49:45 -0700 Subject: Fixes #738: Add support for radio station playlists --- .../SelectInternetRadioStationFragment.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'app/src/main/java/github/daneren2005') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java index 16082cbd..c39e9f61 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java @@ -18,10 +18,18 @@ */ package github.daneren2005.dsub.fragments; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -37,6 +45,8 @@ import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.UpdateView; public class SelectInternetRadioStationFragment extends SelectRecyclerFragment { + private static final String TAG = SelectInternetRadioStationFragment.class.getSimpleName(); + @Override public int getOptionsMenu() { return R.menu.abstract_top_menu; @@ -67,6 +77,7 @@ public class SelectInternetRadioStationFragment extends SelectRecyclerFragment 0 && line.indexOf('#') != 0) { + if(internetRadioStation.getStreamUrl().indexOf(".m3u") != -1) { + internetRadioStation.setStreamUrl(line); + break; + } else { + if(line.indexOf("File1=") == 0) { + internetRadioStation.setStreamUrl(line.replace("File1=", "")); + } else if(line.indexOf("Title1=") == 0) { + internetRadioStation.setTitle(line.replace("Title1=", "")); + } + } + } + } + } finally { + connection.disconnect(); + } + } catch (Exception e) { + Log.e(TAG, "Failed to get stream data from playlist"); + } + + } + } + private void displayInternetRadioStationInfo(final InternetRadioStation station) { List headers = new ArrayList<>(); List details = new ArrayList<>(); -- cgit v1.2.3 From 0e71e6cd066dad690ae433bdc1f279ff82cda871 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 30 Sep 2016 13:50:44 -0700 Subject: Make sure BackgroundTask can add threads when we have too many tasks --- .../github/daneren2005/dsub/util/BackgroundTask.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/github/daneren2005') diff --git a/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java b/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java index 31e83200..2b0c6279 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java +++ b/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import org.xmlpull.v1.XmlPullParserException; @@ -54,6 +55,7 @@ public abstract class BackgroundTask implements ProgressListener { private static final Collection threads = Collections.synchronizedCollection(new ArrayList()); protected static final BlockingQueue queue = new LinkedBlockingQueue(10); private static Handler handler = null; + private static AtomicInteger currentlyRunning = new AtomicInteger(0); static { try { handler = new Handler(Looper.getMainLooper()); @@ -71,6 +73,11 @@ public abstract class BackgroundTask implements ProgressListener { threads.add(thread); thread.start(); } + } else if(currentlyRunning.get() >= threads.size()) { + Log.w(TAG, "Emergency add new thread: " + (threads.size() + 1)); + Thread thread = new Thread(new TaskRunnable(), String.format("BackgroundTask_%d", threads.size())); + threads.add(thread); + thread.start(); } if(handler == null) { try { @@ -304,22 +311,30 @@ public abstract class BackgroundTask implements ProgressListener { @Override public void run() { Looper.prepare(); + final Thread currentThread = Thread.currentThread(); while(running) { try { Task task = queue.take(); + currentlyRunning.incrementAndGet(); task.execute(); } catch(InterruptedException stop) { Log.e(TAG, "Thread died"); running = false; - threads.remove(Thread.currentThread()); } catch(Throwable t) { Log.e(TAG, "Unexpected crash in BackgroundTask thread", t); + running = false; } + + currentlyRunning.decrementAndGet(); + } + + if(threads.contains(currentThread)) { + threads.remove(currentThread); } } } - public static interface OnCancelListener { + public interface OnCancelListener { void onCancel(); } } -- cgit v1.2.3 From 3f3f850ea8328d5846d0e3ae8f600e8068f20ba6 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 1 Oct 2016 21:05:35 -0700 Subject: Workaround for #739 --- .../github/daneren2005/dsub/util/Notifications.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/github/daneren2005') 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 0d4a0f9c..d6a92b07 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java @@ -99,7 +99,12 @@ public final class Notifications { public void run() { downloadService.stopForeground(true); showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); - downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + + try { + downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + } catch(Exception e) { + Log.e(TAG, "Failed to start notifications after stopping foreground download"); + } } }); } else { @@ -107,13 +112,22 @@ public final class Notifications { @Override public void run() { if (playing) { - downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + try { + downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + } catch(Exception e) { + Log.e(TAG, "Failed to start notifications while playing"); + } } else { playShowing = false; persistentPlayingShowing = true; NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); downloadService.stopForeground(false); - notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); + + try { + notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); + } catch(Exception e) { + Log.e(TAG, "Failed to start notifications while paused"); + } } } }); -- cgit v1.2.3