Skip to content

Commit c8ffe08

Browse files
committed
Fixed bug which caused player to crash when clicking FM 'save channel' button when the board was initialised. Closes #18
1 parent 428d636 commit c8ffe08

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId 'com.freshollie.monkeyboard.keystoneradio'
99
minSdkVersion 16
1010
targetSdkVersion 27
11-
versionCode 113
12-
versionName "2.1.4-beta"
11+
versionCode 114
12+
versionName "2.1.5-beta"
1313
setProperty("archivesBaseName", "$versionName")
1414
}
1515
buildTypes {
@@ -26,7 +26,7 @@ android {
2626
// Currently disabled due to the addition of constraint layout, please make manually
2727
task generateVerticalLayout(type: Exec) {
2828
workingDir '.'
29-
// Update this with your python
29+
// Update this with your python binary
3030
commandLine "python", "$rootDir/app/build_tools/make_vertical_layout.py"
3131
doLast{
3232
if (execResult.exitValue != 0) {

app/src/main/java/com/freshollie/monkeyboard/keystoneradio/playback/RadioPlayerService.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public class RadioPlayerService extends Service implements AudioManager.OnAudioF
5757
public final static String ACTION_SEARCH_BACKWARDS =
5858
"com.freshollie.monkeyboard.keystoneradio.playback.radioplayerservice.action.SEARCH_BACKWARDS";
5959
public final static String ACTION_NEXT =
60-
"com.freshollie..monkeyboard.keystoneradio.playback.radioplayerservice.action.NEXT";
60+
"com.freshollie.monkeyboard.keystoneradio.playback.radioplayerservice.action.NEXT";
6161
public final static String ACTION_PREVIOUS =
62-
"com.freshollie..monkeyboard.keystoneradio.playback.radioplayerservice.action.PREVIOUS";
62+
"com.freshollie.monkeyboard.keystoneradio.playback.radioplayerservice.action.PREVIOUS";
6363
public final static String ACTION_STOP =
64-
"com.freshollie..monkeyboard.keystoneradio.playback.radioplayerservice.action.STOP";
64+
"com.freshollie.monkeyboard.keystoneradio.playback.radioplayerservice.action.STOP";
6565
public final static String ACTION_PLAY =
66-
"com.freshollie..monkeyboard.keystoneradio.playback.radioplayerservice.action.PLAY";
66+
"com.freshollie.monkeyboard.keystoneradio.playback.radioplayerservice.action.PLAY";
6767
public final static String ACTION_PAUSE =
68-
"com.freshollie..monkeyboard.keystoneradio.playback.radioplayerservice.action.PAUSE";
68+
"com.freshollie.monkeyboard.keystoneradio.playback.radioplayerservice.action.PAUSE";
6969

7070
public final static String ACTION_SET_RADIO_MODE = "";
7171

@@ -509,12 +509,12 @@ private void saveFmStationList() {
509509
}
510510

511511
public boolean saveCurrentFmStation() {
512-
RadioStation radioStationCopy = new RadioStation();
513-
radioStationCopy.setName(currentFmRadioStation.getName());
514-
radioStationCopy.setGenreId(currentFmRadioStation.getGenreId());
515-
radioStationCopy.setFrequency(currentFmRadioStation.getFrequency());
516-
517512
if (currentFmRadioStation != null) {
513+
RadioStation radioStationCopy = new RadioStation();
514+
radioStationCopy.setName(currentFmRadioStation.getName());
515+
radioStationCopy.setGenreId(currentFmRadioStation.getGenreId());
516+
radioStationCopy.setFrequency(currentFmRadioStation.getFrequency());
517+
518518
for (RadioStation station: fmRadioStations) {
519519
if (((station.getFrequency()) / 100) * 100
520520
== ((radioStationCopy.getFrequency()) / 100) * 100) {

app/src/main/java/com/freshollie/monkeyboard/keystoneradio/ui/PlayerActivity.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -440,22 +440,35 @@ public void onStopTrackingTouch(SeekBar seekBar) {
440440
});
441441

442442
fmSeekBar.setVisibility(modeSwitch.isChecked() ? View.VISIBLE: View.GONE);
443+
444+
// Add channel FAB is used to save FM channels to the FM channel list
443445
addChannelFab.setVisibility(modeSwitch.isChecked() ? View.VISIBLE: View.GONE);
444446
addChannelFab.setOnClickListener(new View.OnClickListener() {
445447
@Override
446448
public void onClick(View view) {
447449
if (playerBound) {
450+
// If we are not in delete mode this is a save command
448451
if (stationListAdapter != null && !stationListAdapter.isDeleteMode()) {
449-
if (playerService.saveCurrentFmStation()) {
452+
// If there is no current station, we cannot save it
453+
if (playerService.getCurrentStation() == null) {
454+
Snackbar.make(
455+
stationListRecyclerView,
456+
R.string.cannot_save_station_text,
457+
Snackbar.LENGTH_SHORT
458+
).show();
459+
} else if (playerService.saveCurrentFmStation()) {
460+
// We were able to save a new station, so update the list
450461
updateStationList(playerService.getRadioMode());
451462
} else {
463+
// Otherwise make a snackbar to show we couldn't save this station
452464
Snackbar.make(
453465
stationListRecyclerView,
454466
R.string.channel_already_exists_message,
455467
Snackbar.LENGTH_SHORT
456468
).show();
457469
}
458470
} else {
471+
// As we are in delete mode, this command closes delete mode
459472
stationListAdapter.closeDeleteMode();
460473
}
461474
}

app/src/main/res/values/strings.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<string name="settings_icon_description">Settings</string>
5353

5454
<string name="about_category_title">About</string>
55-
<string name="about_text">Written by Oliver Bell, 2017\nGPL 3.0 Open Source \nhttp://github.com/freshollie/monkeyboard-radio-android/</string>
55+
<string name="about_text">Written by Oliver Bell, 2018\nGPLv3.0 Open Source \nhttp://github.com/freshollie/monkeyboard-radio-android/</string>
5656

5757
<string name="program_datarate_placeholder">%1$d Kbps</string>
5858

@@ -75,7 +75,10 @@
7575
<string name="RADIO_MODE_KEY">radio_mode</string>
7676
<string name="fm_frequency_placeholder">%s MHz</string>
7777
<string name="remove_station_description">Remove this channel</string>
78+
79+
<string name="cannot_save_station_text">Unable to save unknown station</string>
7880
<string name="channel_already_exists_message">Channel already saved</string>
81+
7982
<string name="pref_dab_mode_enabled_key">dab_mode_enabled</string>
8083
<string name="pref_dab_mode_enabled_title">DAB mode</string>
8184
<string name="pref_dab_mode_enabled_summary_on">Enabled</string>
@@ -101,7 +104,6 @@
101104
<string name="fm">FM</string>
102105

103106

104-
105107
<string-array name="STATION_GENRES">
106108
<item /> <!--0 is Nothing-->
107109
<item>News</item>

0 commit comments

Comments
 (0)