Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 5a84332

Browse files
committed
changed the station shortcut icon for Android O - the old one did not look good
1 parent 4c58f4c commit 5a84332

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

app/src/main/java/org/y20k/transistor/PlayerService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,19 +522,17 @@ private void startPlayback() {
522522
/* Stops playback */
523523
private void stopPlayback(boolean dismissNotification) {
524524
// check for null - can happen after a crash during playback
525-
if (mStation == null || !mExoPlayer.getPlayWhenReady() || mSession== null) {
526-
LogHelper.e(LOG_TAG, "Stopping playback. Station is null.");
525+
if (mStation == null || mExoPlayer == null || !mExoPlayer.getPlayWhenReady() || mSession == null) {
526+
LogHelper.e(LOG_TAG, "Stopping playback. An error occurred. Station is probably NULL.");
527527
saveAppState();
528528
// send local broadcast: playback stopped
529529
Intent intent = new Intent();
530530
intent.setAction(ACTION_PLAYBACK_STATE_CHANGED);
531531
intent.putExtra(EXTRA_ERROR_OCCURED, true);
532532
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
533-
533+
// stop player service
534534
stopSelf();
535535
return;
536-
} else {
537-
LogHelper.v(LOG_TAG, "Stopping playback. Station name:" + mStation.getStationName());
538536
}
539537

540538
// set and save state
@@ -554,6 +552,7 @@ private void stopPlayback(boolean dismissNotification) {
554552
// stop playback
555553
mExoPlayer.setPlayWhenReady(false); // todo empty buffer
556554
mExoPlayer.stop();
555+
LogHelper.v(LOG_TAG, "Stopping playback. Station name:" + mStation.getStationName());
557556

558557
// give up audio focus
559558
giveUpAudioFocus();

app/src/main/java/org/y20k/transistor/core/Station.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ private ContentType getContentType(Uri streamUri) {
362362
// determine content type of remote file
363363
URL streamURL = new URL(streamUri.toString());
364364
return getContentType(streamURL);
365-
366365
} catch (MalformedURLException e) {
367366
e.printStackTrace();
368367
return null;
@@ -533,12 +532,15 @@ public void writePlaylistFile(File folder) {
533532
/* Fetches station image from the internet */
534533
public Bitmap fetchImageFile(URL stationURL) {
535534

536-
LogHelper.v(LOG_TAG, "fetching favicon: " + mStationImageFile.toString());
535+
// check image file and url for null
536+
if (mStationImageFile == null || stationURL == null) {
537+
LogHelper.e(LOG_TAG, "Unable to fetch favicon.");
538+
return null;
539+
}
537540

538-
//
541+
// initialize stationImage to NULL
539542
Bitmap stationImage = null;
540543

541-
542544
// Get favicon address
543545
String host = stationURL.getHost();
544546
if (!host.startsWith("www")) {
@@ -548,6 +550,7 @@ public Bitmap fetchImageFile(URL stationURL) {
548550
String faviconUrlString = "http://" + host + "/favicon.ico";
549551

550552
// Try to get image from favicon location
553+
LogHelper.v(LOG_TAG, "fetching favicon " + mStationImageFile.toString() + "from " + faviconUrlString);
551554
try {
552555
// open connection
553556
HttpURLConnection connection = (HttpURLConnection)(new URL(faviconUrlString).openConnection());
@@ -687,6 +690,7 @@ public int getBitrate() {
687690
return mBitrate;
688691
}
689692

693+
690694
/* Setter for playlist file object of station */
691695
public void setStationPlaylistFile(File folder) {
692696
if (mStationName != null) {
@@ -695,6 +699,8 @@ public void setStationPlaylistFile(File folder) {
695699
// construct location of m3u playlist file from station name and folder
696700
String fileLocation = folder.toString() + "/" + stationNameCleaned + ".m3u";
697701
mStationPlaylistFile = new File(fileLocation);
702+
} else {
703+
mStationPlaylistFile = null;
698704
}
699705
}
700706

@@ -709,6 +715,7 @@ public void setStationImageFile(File folder) {
709715
mStationImageFile = new File(fileLocation);
710716
mStationImageSize = mStationImageFile.length();
711717
} else {
718+
mStationImageFile = null;
712719
mStationImageSize = 0;
713720
}
714721
}

app/src/main/java/org/y20k/transistor/helpers/ShortcutHelper.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,22 @@ private Intent createShortcutIntent (Station station) {
106106

107107
/* Create shortcut icon */
108108
private Bitmap createShortcutIcon(Station station) {
109-
ImageHelper imageHelper;
110109
Bitmap stationImage;
111-
112110
if (station.getStationImageFile().exists()) {
113111
// use station image
114112
stationImage = BitmapFactory.decodeFile(station.getStationImageFile().toString());
115113
} else {
116114
stationImage = null;
117115
}
118-
imageHelper = new ImageHelper(stationImage, mContext);
119116

120-
return imageHelper.createShortcut(192);
117+
ImageHelper imageHelper = new ImageHelper(stationImage, mContext);
118+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
119+
// only return the station image
120+
return imageHelper.getInputImage();
121+
} else {
122+
// return station image in circular frame
123+
return imageHelper.createShortcut(192);
124+
}
121125
}
122126

123127
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ allprojects {
2121
}
2222
project.ext {
2323
applicationId = 'org.y20k.transistor'
24-
versionCode = 42
25-
versionName = '2.3.0 (Kooks)'
24+
versionCode = 43
25+
versionName = '2.3.1 (Kooks)'
2626
minSdkVersion = 19
2727
compileSdkVersion = 26
2828
targetSdkVersion = 26

0 commit comments

Comments
 (0)