Skip to content

Commit

Permalink
added auto-stop on auto-start (#1072)
Browse files Browse the repository at this point in the history
Co-authored-by: smitdol <smitdol@debian>
  • Loading branch information
smitdol and smitdol authored Sep 28, 2023
1 parent 4d0cf72 commit ee7dcb1
Show file tree
Hide file tree
Showing 3 changed files with 36 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
19 changes: 19 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@
android:summaryOff="@string/settings_auto_play_on_startup_off"
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 ee7dcb1

Please sign in to comment.