This commit is contained in:
Horis 2023-04-21 12:52:10 +08:00
parent 1dbe4b4ec0
commit 8c2420da8f
12 changed files with 62 additions and 3 deletions

View File

@ -126,6 +126,7 @@ object PreferKey {
const val readAloudWakeLock = "readAloudWakeLock"
const val showLastUpdateTime = "showLastUpdateTime"
const val clearWebViewData = "clearWebViewData"
const val onlyLatestBackup = "onlyLatestBackup"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"

View File

@ -365,6 +365,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val ignoreAudioFocus get() = appCtx.getPrefBoolean(PreferKey.ignoreAudioFocus, false)
val onlyLatestBackup get() = appCtx.getPrefBoolean(PreferKey.onlyLatestBackup, false)
val doublePageHorizontal: String?
get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)

View File

@ -159,18 +159,23 @@ object Backup {
paths[i] = backupPath + File.separator + paths[i]
}
FileUtils.delete(zipFilePath)
val backupFileName = if (AppConfig.onlyLatestBackup) {
"backup.zip"
} else {
zipFileName
}
if (ZipUtils.zipFiles(paths, zipFilePath)) {
when {
path.isNullOrBlank() -> {
copyBackup(context.getExternalFilesDir(null)!!, zipFileName)
copyBackup(context.getExternalFilesDir(null)!!, backupFileName)
}
path.isContentScheme() -> {
copyBackup(context, Uri.parse(path), zipFileName)
copyBackup(context, Uri.parse(path), backupFileName)
}
else -> {
copyBackup(File(path), zipFileName)
copyBackup(File(path), backupFileName)
}
}
AppWebDav.backUpWebDav(zipFileName)

View File

@ -10,6 +10,7 @@ import android.media.AudioManager
import android.net.Uri
import android.os.Build
import android.os.PowerManager
import android.support.v4.media.MediaMetadataCompat
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import androidx.core.app.NotificationCompat
@ -119,6 +120,7 @@ class AudioPlayService : BaseService(),
IntentAction.adjustProgress -> {
adjustProgress(intent.getIntExtra("position", position))
}
else -> stopSelf()
}
}
@ -250,9 +252,11 @@ class AudioPlayService : BaseService(),
Player.STATE_IDLE -> {
// 空闲
}
Player.STATE_BUFFERING -> {
// 缓冲中
}
Player.STATE_READY -> {
// 准备好
if (exoPlayer.currentPosition != position.toLong()) {
@ -266,9 +270,15 @@ class AudioPlayService : BaseService(),
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
}
postEvent(EventBus.AUDIO_SIZE, exoPlayer.duration)
mediaSessionCompat?.setMetadata(
MediaMetadataCompat.Builder()
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, exoPlayer.duration)
.build()
)
upPlayProgress()
AudioPlay.saveDurChapter(exoPlayer.duration)
}
Player.STATE_ENDED -> {
// 结束
upPlayProgressJob?.cancel()
@ -340,6 +350,13 @@ class AudioPlayService : BaseService(),
postEvent(EventBus.AUDIO_BUFFER_PROGRESS, exoPlayer.bufferedPosition.toInt())
it.durChapterPos = exoPlayer.currentPosition.toInt()
postEvent(EventBus.AUDIO_PROGRESS, it.durChapterPos)
mediaSessionCompat?.setPlaybackState(
PlaybackStateCompat.Builder()
.setActions(PlaybackStateCompat.ACTION_SEEK_TO)
.setState(PlaybackStateCompat.STATE_NONE, exoPlayer.currentPosition, 1f)
.setBufferedPosition(exoPlayer.bufferedPosition)
.build()
)
saveProgress(it)
}
delay(1000)
@ -430,6 +447,11 @@ class AudioPlayService : BaseService(),
private fun initMediaSession() {
mediaSessionCompat = MediaSessionCompat(this, "readAloud")
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
override fun onSeekTo(pos: Long) {
position = pos.toInt()
exoPlayer.seekTo(pos)
}
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
return MediaButtonReceiver.handleIntent(this@AudioPlayService, mediaButtonEvent)
}
@ -472,10 +494,12 @@ class AudioPlayService : BaseService(),
AppLog.put("音频焦点获得")
}
}
AudioManager.AUDIOFOCUS_LOSS -> {
AppLog.put("音频焦点丢失,暂停播放")
pause()
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
AppLog.put("音频焦点暂时丢失并会很快再次获得,暂停播放")
needResumeOnAudioFocusGain = true
@ -484,6 +508,7 @@ class AudioPlayService : BaseService(),
pause(false)
}
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
// 短暂丢失焦点,这种情况是被其他应用申请了短暂的焦点希望其他声音能压低音量(或者关闭声音)凸显这个声音(比如短信提示音),
AppLog.put("音频焦点短暂丢失,不做处理")
@ -491,6 +516,7 @@ class AudioPlayService : BaseService(),
}
}
/**
* 更新通知
*/
@ -502,6 +528,7 @@ class AudioPlayService : BaseService(),
R.string.playing_timer,
timeMinute
)
else -> getString(R.string.audio_play_t)
}
nTitle += ": ${AudioPlay.book?.name}"
@ -555,6 +582,7 @@ class AudioPlayService : BaseService(),
builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setMediaSession(mediaSessionCompat?.sessionToken)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
builder

View File

@ -1096,4 +1096,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -1099,4 +1099,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -1099,4 +1099,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -1096,4 +1096,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -1098,4 +1098,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -1098,4 +1098,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -1099,4 +1099,6 @@
<string name="select_update_source">选中更新源</string>
<string name="set_local_password">设置本地密码</string>
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
<string name="only_latest_backup_t">仅保留最新备份</string>
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
</resources>

View File

@ -88,6 +88,15 @@
android:summary="@string/import_old_summary"
app:iconSpaceReserved="false" />
<io.legado.app.lib.prefs.SwitchPreference
android:key="onlyLatestBackup"
android:defaultValue="false"
android:title="@string/only_latest_backup_t"
android:summary="@string/only_latest_backup_s"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
</io.legado.app.lib.prefs.PreferenceCategory>
</androidx.preference.PreferenceScreen>