Skip to content

Commit

Permalink
Merge pull request #744 from daneren2005/edge
Browse files Browse the repository at this point in the history
Edge
  • Loading branch information
daneren2005 authored Oct 5, 2016
2 parents 72751ea + 54da131 commit 2b973ff
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 39 deletions.
2 changes: 1 addition & 1 deletion ServerProxy
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "github.daneren2005.dsub"
minSdkVersion 14
targetSdkVersion 23
versionCode 186
versionName '5.3'
versionCode 187
versionName '5.3.1'
setProperty("archivesBaseName", "DSub $versionName")
resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,6 +45,8 @@
import github.daneren2005.dsub.view.UpdateView;

public class SelectInternetRadioStationFragment extends SelectRecyclerFragment<InternetRadioStation> {
private static final String TAG = SelectInternetRadioStationFragment.class.getSimpleName();

@Override
public int getOptionsMenu() {
return R.menu.abstract_top_menu;
Expand Down Expand Up @@ -67,6 +77,7 @@ protected Void doInBackground() throws Throwable {
return null;
}

getStreamFromPlaylist(item);
downloadService.download(item);
return null;
}
Expand Down Expand Up @@ -94,6 +105,40 @@ public boolean onContextItemSelected(MenuItem menuItem, UpdateView<InternetRadio
return false;
}

private void getStreamFromPlaylist(InternetRadioStation internetRadioStation) {
if(internetRadioStation.getStreamUrl() != null && (internetRadioStation.getStreamUrl().indexOf(".m3u") != -1 || internetRadioStation.getStreamUrl().indexOf(".pls") != -1)) {
try {
URL url = new URL(internetRadioStation.getStreamUrl());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

try {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while((line = in.readLine()) != null) {
// Not blank line or comment
if(line.length() > 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<Integer> headers = new ArrayList<>();
List<String> details = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -465,14 +466,14 @@ public void onConnectionSuspended(int cause) {

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);
}
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;

Expand Down Expand Up @@ -54,6 +55,7 @@ public abstract class BackgroundTask<T> implements ProgressListener {
private static final Collection<Thread> threads = Collections.synchronizedCollection(new ArrayList<Thread>());
protected static final BlockingQueue<BackgroundTask.Task> queue = new LinkedBlockingQueue<BackgroundTask.Task>(10);
private static Handler handler = null;
private static AtomicInteger currentlyRunning = new AtomicInteger(0);
static {
try {
handler = new Handler(Looper.getMainLooper());
Expand All @@ -71,6 +73,11 @@ public BackgroundTask(Context context) {
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 {
Expand Down Expand Up @@ -304,22 +311,30 @@ public TaskRunnable() {
@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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

public final class EnvironmentVariables {
public static final String PASTEBIN_DEV_KEY = "";
public static final String CAST_APPLICATION_ID = "";
}
20 changes: 17 additions & 3 deletions app/src/main/java/github/daneren2005/dsub/util/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,35 @@ public static void showPlayingNotification(final Context context, final Download
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 {
handler.post(new Runnable() {
@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");
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
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");
Expand All @@ -52,6 +48,6 @@ public static RemoteController getController(DownloadService downloadService, Me
}

public static String getCastControlCategory() {
return CastMediaControlIntent.categoryForCast(APPLICATION_ID);
return CastMediaControlIntent.categoryForCast(EnvironmentVariables.CAST_APPLICATION_ID);
}
}
8 changes: 7 additions & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<string name="button_bar.now_playing">Várólista</string>
<string name="button_bar.podcasts">Podcastok</string>
<string name="button_bar.bookmarks">Könyvjelzők</string>
<string name="button_bar.internet_radio">Internet rádió</string>
<string name="button_bar.shares">Megosztások</string>
<string name="button_bar.chat">Csevegés (Chat)</string>
<string name="button_bar.admin">Admin</string>
Expand Down Expand Up @@ -225,6 +226,7 @@
<string name="download.playback_speed_one_half">1.5x</string>
<string name="download.playback_speed_double">2x</string>
<string name="download.playback_speed_tripple">3x</string>
<string name="download.playback_speed_custom">Egyéni</string>

<string name="sync.new_podcasts">Új podcastok: \"%s\"</string>
<string name="sync.new_playlists">Új lejátszási listák: \"%s\"</string>
Expand Down Expand Up @@ -305,6 +307,8 @@
<string name="settings.theme_dark">Sötét</string>
<string name="settings.theme_black">Fekete</string>
<string name="settings.theme_holo">Holo</string>
<string name="settings.theme_day_night">Nappal/Éjszaka</string>
<string name="settings.theme_day_black_night">Nappal/Fekete éjszaka</string>
<string name="settings.theme_fullscreen">Teljes képernyős</string>
<string name="settings.theme_fullscreen_summary">Teljes képernyős üzemmód (értesítési sáv elrejtése).</string>
<string name="settings.track_title">Dalsorszám megjelenítése</string>
Expand Down Expand Up @@ -407,6 +411,8 @@
<string name="settings.podcasts_enabled_summary">Podcastok menüpont megjelenítése az elhúzható oldalsávon.</string>
<string name="settings.bookmarks_enabled">Könyvjelzők engedélyezése</string>
<string name="settings.bookmarks_enabled_summary">Könyvjelzők menüpont megjelenítése az elhúzható oldalsávon.</string>
<string name="settings.internet_radio_enabled">Internet rádió engedélyezése</string>
<string name="settings.internet_radio_enabled_summary">Internet rádió menüpont megjelenítése az elhúzható oldalsávon.</string>
<string name="settings.shares_enabled">Megosztások engedélyezése</string>
<string name="settings.shares_enabled_summary">Megosztások menüpont megjelenítése az elhúzható oldalsávon.</string>
<string name="settings.sync_title">Szinkronizálás</string>
Expand Down Expand Up @@ -464,7 +470,7 @@
<string name="settings.replay_gain_type.track">Dal értékeiből</string>
<string name="settings.replay_gain_bump">Hangerő-kiegyenlítés előerősítése</string>
<string name="settings.replay_gain_untagged">Dalok hangerő-kiegyenlítés nélkül</string>
<string name="settings.casting">Casting (Tartalmak átküldése)</string>
<string name="settings.casting">Casting (tartalmak átküldése)</string>
<string name="settings.casting_proxy">Eszköz használata proxyként</string>
<string name="settings.casting_proxy_summary">Streamelés az eszközön (mint egy proxyn) keresztül. Ez megoldást jelenthet néhány esetben, pl. saját aláírású tanúsítvány használatakor.</string>
<string name="settings.rename_duplicates">Duplikált dalok átnevezése</string>
Expand Down
Loading

0 comments on commit 2b973ff

Please sign in to comment.