Skip to content

Commit

Permalink
added auto-stop on auto-start
Browse files Browse the repository at this point in the history
  • Loading branch information
smitdol committed Jan 29, 2022
1 parent 625dc3c commit dda3d70
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,28 @@ private void playLastFromHistory() {

private void tryPlayAtStart() {
boolean play = false;
boolean auto_off = false;

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext());
if (!firstPlayAttempted && PlayerServiceUtil.isServiceBound()) {
firstPlayAttempted = true;

if (!PlayerServiceUtil.isPlaying()) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext());
play = sharedPreferences.getBoolean("auto_play_on_startup", false);
}
}

if (play) {
auto_off = sharedPreferences.getBoolean("auto_off_on_startup", false);
if (auto_off) {
int timeout;
try {
timeout = Integer.parseInt(sharedPreferences.getString("auto_off_timeout", "10"));
} catch(Exception e) {
timeout=10;
}
PlayerServiceUtil.addTimer(timeout * 60);
}
playLastFromHistory();
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
<string name="settings_auto_play_on_startup">Auto-play</string>
<string name="settings_auto_play_on_startup_on">Play last station on startup</string>
<string name="settings_auto_play_on_startup_off">Do not play last station on startup</string>
<string name="settings_auto_off_on_startup">Auto-stop</string>
<string name="settings_auto_off_on_startup_on">Use Auto-stop timer with auto-play</string>
<string name="settings_auto_off_on_startup_off">Do not use Auto-stop timer with auto-play</string>
<string name="settings_auto_off_sleep_timer">Auto-stop timer</string>
<string name="settings_auto_off_sleep_timer_desc">Stop playing after %1$s minutes</string>
<string name="settings_play_external">Enable external player</string>
<string name="settings_play_external_desc_on">Play stations with external player</string>
<string name="settings_play_external_desc_off">Play stations with RadioDroid</string>
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@
android:summaryOn="@string/settings_auto_play_on_startup_on"
android:title="@string/settings_auto_play_on_startup" />

<CheckBoxPreference
android:defaultValue="false"
android:key="auto_off_on_startup"
android:dependency="auto_play_on_startup"
android:summaryOff="@string/settings_auto_off_on_startup_off"
android:summaryOn="@string/settings_auto_off_on_startup_on"
android:title="@string/settings_auto_off_on_startup" />

<ListPreference
android:defaultValue="10"
android:dependency="auto_off_on_startup"
android:entries="@array/timeout_minutes"
android:entryValues="@array/timeout_minutes_values"
android:key="auto_off_timeout"
android:summary="@string/settings_auto_off_sleep_timer_desc"
search:summary=""
android:title="@string/settings_auto_off_sleep_timer" />

</PreferenceScreen>

<PreferenceScreen android:title="@string/settings_interaction"
Expand Down

0 comments on commit dda3d70

Please sign in to comment.