Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -126,6 +126,7 @@ object PreferKey {
|
|||||||
const val readAloudWakeLock = "readAloudWakeLock"
|
const val readAloudWakeLock = "readAloudWakeLock"
|
||||||
const val showLastUpdateTime = "showLastUpdateTime"
|
const val showLastUpdateTime = "showLastUpdateTime"
|
||||||
const val clearWebViewData = "clearWebViewData"
|
const val clearWebViewData = "clearWebViewData"
|
||||||
|
const val onlyLatestBackup = "onlyLatestBackup"
|
||||||
|
|
||||||
const val cPrimary = "colorPrimary"
|
const val cPrimary = "colorPrimary"
|
||||||
const val cAccent = "colorAccent"
|
const val cAccent = "colorAccent"
|
||||||
|
|||||||
@@ -365,6 +365,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
|
|
||||||
val ignoreAudioFocus get() = appCtx.getPrefBoolean(PreferKey.ignoreAudioFocus, false)
|
val ignoreAudioFocus get() = appCtx.getPrefBoolean(PreferKey.ignoreAudioFocus, false)
|
||||||
|
|
||||||
|
val onlyLatestBackup get() = appCtx.getPrefBoolean(PreferKey.onlyLatestBackup, false)
|
||||||
|
|
||||||
val doublePageHorizontal: String?
|
val doublePageHorizontal: String?
|
||||||
get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)
|
get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)
|
||||||
|
|
||||||
|
|||||||
@@ -159,18 +159,23 @@ object Backup {
|
|||||||
paths[i] = backupPath + File.separator + paths[i]
|
paths[i] = backupPath + File.separator + paths[i]
|
||||||
}
|
}
|
||||||
FileUtils.delete(zipFilePath)
|
FileUtils.delete(zipFilePath)
|
||||||
|
val backupFileName = if (AppConfig.onlyLatestBackup) {
|
||||||
|
"backup.zip"
|
||||||
|
} else {
|
||||||
|
zipFileName
|
||||||
|
}
|
||||||
if (ZipUtils.zipFiles(paths, zipFilePath)) {
|
if (ZipUtils.zipFiles(paths, zipFilePath)) {
|
||||||
when {
|
when {
|
||||||
path.isNullOrBlank() -> {
|
path.isNullOrBlank() -> {
|
||||||
copyBackup(context.getExternalFilesDir(null)!!, zipFileName)
|
copyBackup(context.getExternalFilesDir(null)!!, backupFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
path.isContentScheme() -> {
|
path.isContentScheme() -> {
|
||||||
copyBackup(context, Uri.parse(path), zipFileName)
|
copyBackup(context, Uri.parse(path), backupFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
copyBackup(File(path), zipFileName)
|
copyBackup(File(path), backupFileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AppWebDav.backUpWebDav(zipFileName)
|
AppWebDav.backUpWebDav(zipFileName)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.media.AudioManager
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
|
import android.support.v4.media.MediaMetadataCompat
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
import android.support.v4.media.session.PlaybackStateCompat
|
import android.support.v4.media.session.PlaybackStateCompat
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
@@ -119,6 +120,7 @@ class AudioPlayService : BaseService(),
|
|||||||
IntentAction.adjustProgress -> {
|
IntentAction.adjustProgress -> {
|
||||||
adjustProgress(intent.getIntExtra("position", position))
|
adjustProgress(intent.getIntExtra("position", position))
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> stopSelf()
|
else -> stopSelf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,9 +252,11 @@ class AudioPlayService : BaseService(),
|
|||||||
Player.STATE_IDLE -> {
|
Player.STATE_IDLE -> {
|
||||||
// 空闲
|
// 空闲
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.STATE_BUFFERING -> {
|
Player.STATE_BUFFERING -> {
|
||||||
// 缓冲中
|
// 缓冲中
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.STATE_READY -> {
|
Player.STATE_READY -> {
|
||||||
// 准备好
|
// 准备好
|
||||||
if (exoPlayer.currentPosition != position.toLong()) {
|
if (exoPlayer.currentPosition != position.toLong()) {
|
||||||
@@ -266,9 +270,15 @@ class AudioPlayService : BaseService(),
|
|||||||
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
|
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
|
||||||
}
|
}
|
||||||
postEvent(EventBus.AUDIO_SIZE, exoPlayer.duration)
|
postEvent(EventBus.AUDIO_SIZE, exoPlayer.duration)
|
||||||
|
mediaSessionCompat?.setMetadata(
|
||||||
|
MediaMetadataCompat.Builder()
|
||||||
|
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, exoPlayer.duration)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
upPlayProgress()
|
upPlayProgress()
|
||||||
AudioPlay.saveDurChapter(exoPlayer.duration)
|
AudioPlay.saveDurChapter(exoPlayer.duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.STATE_ENDED -> {
|
Player.STATE_ENDED -> {
|
||||||
// 结束
|
// 结束
|
||||||
upPlayProgressJob?.cancel()
|
upPlayProgressJob?.cancel()
|
||||||
@@ -340,6 +350,13 @@ class AudioPlayService : BaseService(),
|
|||||||
postEvent(EventBus.AUDIO_BUFFER_PROGRESS, exoPlayer.bufferedPosition.toInt())
|
postEvent(EventBus.AUDIO_BUFFER_PROGRESS, exoPlayer.bufferedPosition.toInt())
|
||||||
it.durChapterPos = exoPlayer.currentPosition.toInt()
|
it.durChapterPos = exoPlayer.currentPosition.toInt()
|
||||||
postEvent(EventBus.AUDIO_PROGRESS, it.durChapterPos)
|
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)
|
saveProgress(it)
|
||||||
}
|
}
|
||||||
delay(1000)
|
delay(1000)
|
||||||
@@ -430,6 +447,11 @@ class AudioPlayService : BaseService(),
|
|||||||
private fun initMediaSession() {
|
private fun initMediaSession() {
|
||||||
mediaSessionCompat = MediaSessionCompat(this, "readAloud")
|
mediaSessionCompat = MediaSessionCompat(this, "readAloud")
|
||||||
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
|
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
|
||||||
|
override fun onSeekTo(pos: Long) {
|
||||||
|
position = pos.toInt()
|
||||||
|
exoPlayer.seekTo(pos)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
|
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
|
||||||
return MediaButtonReceiver.handleIntent(this@AudioPlayService, mediaButtonEvent)
|
return MediaButtonReceiver.handleIntent(this@AudioPlayService, mediaButtonEvent)
|
||||||
}
|
}
|
||||||
@@ -472,10 +494,12 @@ class AudioPlayService : BaseService(),
|
|||||||
AppLog.put("音频焦点获得")
|
AppLog.put("音频焦点获得")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioManager.AUDIOFOCUS_LOSS -> {
|
AudioManager.AUDIOFOCUS_LOSS -> {
|
||||||
AppLog.put("音频焦点丢失,暂停播放")
|
AppLog.put("音频焦点丢失,暂停播放")
|
||||||
pause()
|
pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
|
||||||
AppLog.put("音频焦点暂时丢失并会很快再次获得,暂停播放")
|
AppLog.put("音频焦点暂时丢失并会很快再次获得,暂停播放")
|
||||||
needResumeOnAudioFocusGain = true
|
needResumeOnAudioFocusGain = true
|
||||||
@@ -484,6 +508,7 @@ class AudioPlayService : BaseService(),
|
|||||||
pause(false)
|
pause(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
|
||||||
// 短暂丢失焦点,这种情况是被其他应用申请了短暂的焦点希望其他声音能压低音量(或者关闭声音)凸显这个声音(比如短信提示音),
|
// 短暂丢失焦点,这种情况是被其他应用申请了短暂的焦点希望其他声音能压低音量(或者关闭声音)凸显这个声音(比如短信提示音),
|
||||||
AppLog.put("音频焦点短暂丢失,不做处理")
|
AppLog.put("音频焦点短暂丢失,不做处理")
|
||||||
@@ -491,6 +516,7 @@ class AudioPlayService : BaseService(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新通知
|
* 更新通知
|
||||||
*/
|
*/
|
||||||
@@ -502,6 +528,7 @@ class AudioPlayService : BaseService(),
|
|||||||
R.string.playing_timer,
|
R.string.playing_timer,
|
||||||
timeMinute
|
timeMinute
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> getString(R.string.audio_play_t)
|
else -> getString(R.string.audio_play_t)
|
||||||
}
|
}
|
||||||
nTitle += ": ${AudioPlay.book?.name}"
|
nTitle += ": ${AudioPlay.book?.name}"
|
||||||
@@ -555,6 +582,7 @@ class AudioPlayService : BaseService(),
|
|||||||
builder.setStyle(
|
builder.setStyle(
|
||||||
androidx.media.app.NotificationCompat.MediaStyle()
|
androidx.media.app.NotificationCompat.MediaStyle()
|
||||||
.setShowActionsInCompactView(0, 1, 2)
|
.setShowActionsInCompactView(0, 1, 2)
|
||||||
|
.setMediaSession(mediaSessionCompat?.sessionToken)
|
||||||
)
|
)
|
||||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
builder
|
builder
|
||||||
|
|||||||
@@ -1096,4 +1096,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1099,4 +1099,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1099,4 +1099,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1096,4 +1096,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1098,4 +1098,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1098,4 +1098,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1099,4 +1099,6 @@
|
|||||||
<string name="select_update_source">选中更新源</string>
|
<string name="select_update_source">选中更新源</string>
|
||||||
<string name="set_local_password">设置本地密码</string>
|
<string name="set_local_password">设置本地密码</string>
|
||||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||||
|
<string name="only_latest_backup_t">仅保留最新备份</string>
|
||||||
|
<string name="only_latest_backup_s">本地备份仅保留最新备份文件</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -88,6 +88,15 @@
|
|||||||
android:summary="@string/import_old_summary"
|
android:summary="@string/import_old_summary"
|
||||||
app:iconSpaceReserved="false" />
|
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>
|
</io.legado.app.lib.prefs.PreferenceCategory>
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
||||||
|
|||||||
Reference in New Issue
Block a user