Skip to content

Commit d29061e

Browse files
committed
2 parents 2c9fa47 + 51e1b79 commit d29061e

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

app/src/main/java/io/legado/app/constant/PreferKey.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ object PreferKey {
164164
const val streamReadAloudAudio = "streamReadAloudAudio"
165165
const val pauseReadAloudWhilePhoneCalls = "pauseReadAloudWhilePhoneCalls"
166166
const val readAloudByMediaButton = "readAloudByMediaButton"
167+
const val readAloudLoopChapter = "readAloudLoopChapter"
167168
const val showMangaUi = "showMangaUi"
168169
const val disableMangaScale = "disableMangaScale"
169170
const val paddingDisplayCutouts = "paddingDisplayCutouts"

app/src/main/java/io/legado/app/service/BaseReadAloudService.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ abstract class BaseReadAloudService : BaseService(),
123123
private var needResumeOnAudioFocusGain = false
124124
private var needResumeOnCallStateIdle = false
125125
private var registeredPhoneStateListener = false
126+
private var manualNextChapter = false
126127
private var dsJob: Job? = null
127128
private var upNotificationJob: Coroutine<*>? = null
128129
private var cover: Bitmap =
@@ -220,7 +221,10 @@ abstract class BaseReadAloudService : BaseService(),
220221
IntentAction.prevParagraph -> prevP()
221222
IntentAction.nextParagraph -> nextP()
222223
IntentAction.prev -> prevChapter()
223-
IntentAction.next -> nextChapter()
224+
IntentAction.next -> {
225+
manualNextChapter = true
226+
nextChapter()
227+
}
224228
IntentAction.addTimer -> addTimer()
225229
IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0))
226230
IntentAction.stop -> stopSelf()
@@ -477,6 +481,7 @@ abstract class BaseReadAloudService : BaseService(),
477481

478482
override fun onSkipToNext() {
479483
if (getPrefBoolean("mediaButtonPerNext", false)) {
484+
manualNextChapter = true
480485
nextChapter()
481486
} else {
482487
nextP()
@@ -682,6 +687,12 @@ abstract class BaseReadAloudService : BaseService(),
682687
}
683688

684689
open fun nextChapter() {
690+
if (!manualNextChapter && getPrefBoolean(PreferKey.readAloudLoopChapter, false)) {
691+
manualNextChapter = false
692+
loopCurrentChapter()
693+
return
694+
}
695+
manualNextChapter = false
685696
ReadBook.upReadTime()
686697
AppLog.putDebug("${ReadBook.curTextChapter?.chapter?.title} 朗读结束跳转下一章并朗读")
687698
play()
@@ -690,6 +701,13 @@ abstract class BaseReadAloudService : BaseService(),
690701
}
691702
}
692703

704+
private fun loopCurrentChapter() {
705+
ReadBook.upReadTime()
706+
AppLog.putDebug("${ReadBook.curTextChapter?.chapter?.title} 朗读结束,循环当前章节")
707+
playStop()
708+
ReadBook.setPageIndex(0)
709+
}
710+
693711
private fun initPhoneStateListener() {
694712
val needRegister = AppConfig.ignoreAudioFocus && AppConfig.pauseReadAloudWhilePhoneCalls
695713
if (needRegister && registeredPhoneStateListener) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,8 @@
11881188
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
11891189
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
11901190
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
1191+
<string name="read_aloud_loop_chapter">循环当前章节</string>
1192+
<string name="read_aloud_loop_chapter_summary">朗读到章节结尾后,从本章开头继续朗读</string>
11911193
<string name="show_same_source">显示重复书源</string>
11921194
<string name="theme_config">主题配置</string>
11931195
<string name="show_manga_ui">漫画浏览</string>

app/src/main/res/xml/pref_config_aloud.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
android:key="readAloudByPage"
4949
app:iconSpaceReserved="false" />
5050

51+
<io.legado.app.lib.prefs.SwitchPreference
52+
android:defaultValue="false"
53+
android:title="@string/read_aloud_loop_chapter"
54+
android:summary="@string/read_aloud_loop_chapter_summary"
55+
android:key="readAloudLoopChapter"
56+
app:iconSpaceReserved="false" />
57+
5158
<io.legado.app.lib.prefs.SwitchPreference
5259
android:defaultValue="false"
5360
android:title="@string/stream_read_aloud_audio"
@@ -69,4 +76,4 @@
6976

7077
</io.legado.app.lib.prefs.PreferenceCategory>
7178

72-
</androidx.preference.PreferenceScreen>
79+
</androidx.preference.PreferenceScreen>

0 commit comments

Comments
 (0)