pull/32/head
yangyxd 5 years ago
commit 6870876388
  1. 19
      app/src/main/java/io/legado/app/constant/RSSKeywords.kt
  2. 20
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  3. 33
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  4. 8
      app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt
  5. 8
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  6. 7
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  7. 18
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  8. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  9. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  10. 7
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  11. 16
      app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt
  12. 6
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  13. 53
      app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt
  14. 8
      app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt
  15. 13
      app/src/main/res/layout/activity_search.xml

@ -0,0 +1,19 @@
package io.legado.app.constant
object RSSKeywords {
const val RSS_ITEM = "item"
const val RSS_ITEM_TITLE = "title"
const val RSS_ITEM_LINK = "link"
const val RSS_ITEM_AUTHOR = "dc:creator"
const val RSS_ITEM_CATEGORY = "category"
const val RSS_ITEM_THUMBNAIL = "media:thumbnail"
const val RSS_ITEM_ENCLOSURE = "enclosure"
const val RSS_ITEM_DESCRIPTION = "description"
const val RSS_ITEM_CONTENT = "content:encoded"
const val RSS_ITEM_PUB_DATE = "pubDate"
const val RSS_ITEM_TIME = "time"
const val RSS_ITEM_URL = "url"
const val RSS_ITEM_TYPE = "type"
const val RSS_ITEM_GUID = "guid"
}

@ -0,0 +1,20 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "rssArticles")
data class RssArticle(
var origin: String = "",
@PrimaryKey
var guid: String? = null,
var title: String? = null,
var author: String? = null,
var link: String? = null,
var pubDate: String? = null,
var description: String? = null,
var content: String? = null,
var image: String? = null,
var categories: MutableList<String> = mutableListOf()
)

@ -125,7 +125,6 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
private lateinit var audioManager: AudioManager private lateinit var audioManager: AudioManager
private lateinit var mFocusRequest: AudioFocusRequest private lateinit var mFocusRequest: AudioFocusRequest
private var broadcastReceiver: BroadcastReceiver? = null private var broadcastReceiver: BroadcastReceiver? = null
private var speak: Boolean = true
private var nowSpeak: Int = 0 private var nowSpeak: Int = 0
private val contentList = arrayListOf<String>() private val contentList = arrayListOf<String>()
private var readAloudNumber: Int = 0 private var readAloudNumber: Int = 0
@ -147,13 +146,13 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
} }
initMediaSession() initMediaSession()
initBroadcastReceiver() initBroadcastReceiver()
upMediaSessionPlaybackState()
upSpeechRate() upSpeechRate()
ReadAloudNotification.upNotification(this) ReadAloudNotification.upNotification(this)
} }
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
clearTTS() clearTTS()
unregisterReceiver(broadcastReceiver) unregisterReceiver(broadcastReceiver)
postEvent(Bus.ALOUD_STATE, Status.STOP) postEvent(Bus.ALOUD_STATE, Status.STOP)
@ -231,6 +230,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
return return
} }
if (requestFocus()) { if (requestFocus()) {
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
postEvent(Bus.ALOUD_STATE, Status.PLAY) postEvent(Bus.ALOUD_STATE, Status.PLAY)
ReadAloudNotification.upNotification(this) ReadAloudNotification.upNotification(this)
for (i in nowSpeak until contentList.size) { for (i in nowSpeak until contentList.size) {
@ -322,28 +322,31 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
} }
/** /**
* 初始化MediaSession * 初始化MediaSession, 注册多媒体按钮
*/ */
private fun initMediaSession() { private fun initMediaSession() {
val mComponent = ComponentName(packageName, MediaButtonReceiver::class.java.name) val mediaButtonIntent = Intent(Intent.ACTION_MEDIA_BUTTON).apply {
val mediaButtonIntent = Intent(Intent.ACTION_MEDIA_BUTTON) component = ComponentName(packageName, MediaButtonReceiver::class.java.name)
mediaButtonIntent.component = mComponent }
val mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast( val mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(
this, 0, this,
mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT 0,
mediaButtonIntent,
PendingIntent.FLAG_CANCEL_CURRENT
) )
mediaSessionCompat = mediaSessionCompat = MediaSessionCompat(this, tag)
MediaSessionCompat(this, tag, mComponent, mediaButtonReceiverPendingIntent)
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() { mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean { override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent) return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent)
} }
}) })
mediaSessionCompat?.setMediaButtonReceiver(mediaButtonReceiverPendingIntent) mediaSessionCompat?.setMediaButtonReceiver(mediaButtonReceiverPendingIntent)
mediaSessionCompat?.isActive = true
} }
private fun initBroadcastReceiver() { private fun initBroadcastReceiver() {
//断开耳机监听
broadcastReceiver = object : BroadcastReceiver() { broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
val action = intent.action val action = intent.action
@ -357,9 +360,10 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
} }
private fun pauseReadAloud(pause: Boolean) { private fun pauseReadAloud(pause: Boolean) {
if (pause) postEvent(Bus.ALOUD_STATE, Status.PAUSE) postEvent(Bus.ALOUD_STATE, Status.PAUSE)
this.pause = pause this.pause = pause
textToSpeech?.stop() textToSpeech?.stop()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
ReadAloudNotification.upNotification(this) ReadAloudNotification.upNotification(this)
} }
@ -386,14 +390,11 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
} }
private fun upMediaSessionPlaybackState() { private fun upMediaSessionPlaybackState(state: Int) {
mediaSessionCompat?.setPlaybackState( mediaSessionCompat?.setPlaybackState(
PlaybackStateCompat.Builder() PlaybackStateCompat.Builder()
.setActions(MediaHelp.MEDIA_SESSION_ACTIONS) .setActions(MediaHelp.MEDIA_SESSION_ACTIONS)
.setState( .setState(state, nowSpeak.toLong(), 1f)
if (speak) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED,
nowSpeak.toLong(), 1f
)
.build() .build()
) )
} }

@ -64,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
tool_bar.inflateMenu(R.menu.group_manage) tool_bar.inflateMenu(R.menu.group_manage)
tool_bar.menu.applyTint(requireContext(), false) tool_bar.menu.applyTint(requireContext(), false)
tool_bar.setOnMenuItemClickListener(this) tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext(), this) adapter = GroupAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext())
recycler_view.addItemDecoration( recycler_view.addItemDecoration(
DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) DividerItemDecoration(requireContext(), RecyclerView.VERTICAL)
@ -129,14 +129,14 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
}.show().applyTint().requestInputMethod() }.show().applyTint().requestInputMethod()
} }
class GroupAdapter(context: Context, val dialog: GroupManageDialog) : private inner class GroupAdapter(context: Context) :
SimpleRecyclerAdapter<String>(context, R.layout.item_group_manage) { SimpleRecyclerAdapter<String>(context, R.layout.item_group_manage) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {
tv_group.text = item tv_group.text = item
tv_edit.onClick { dialog.editGroup(item) } tv_edit.onClick { editGroup(item) }
tv_del.onClick { dialog.viewModel.delGroup(item) } tv_del.onClick { viewModel.delGroup(item) }
} }
} }
} }

@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
@ -48,6 +49,9 @@ class ChangeSourceDialog : DialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
viewModel.searchStateData.observe(viewLifecycleOwner, Observer {
refresh_progress_bar.isAutoLoading = it
})
arguments?.let { bundle -> arguments?.let { bundle ->
bundle.getString("name")?.let { bundle.getString("name")?.let {
viewModel.name = it viewModel.name = it
@ -141,10 +145,6 @@ class ChangeSourceDialog : DialogFragment(),
return changeSourceAdapter return changeSourceAdapter
} }
override fun upSearchState(isSearch: Boolean) {
refresh_progress_bar.isAutoLoading = isSearch
}
interface CallBack { interface CallBack {
fun curOrigin(): String? fun curOrigin(): String?
fun oldBook(): Book? fun oldBook(): Book?

@ -1,6 +1,7 @@
package io.legado.app.ui.changesource package io.legado.app.ui.changesource
import android.app.Application import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -17,6 +18,7 @@ import org.jetbrains.anko.debug
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
var callBack: CallBack? = null var callBack: CallBack? = null
val searchStateData = MutableLiveData<Boolean>()
var name: String = "" var name: String = ""
var author: String = "" var author: String = ""
private var task: Coroutine<*>? = null private var task: Coroutine<*>? = null
@ -50,7 +52,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
fun search() { fun search() {
task = execute { task = execute {
callBack?.upSearchState(true) searchStateData.postValue(true)
val bookSourceList = App.db.bookSourceDao().allEnabled val bookSourceList = App.db.bookSourceDao().allEnabled
for (item in bookSourceList) { for (item in bookSourceList) {
//task取消时自动取消 by (scope = this@execute) //task取消时自动取消 by (scope = this@execute)
@ -73,7 +75,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
task?.invokeOnCompletion { task?.invokeOnCompletion {
callBack?.upSearchState(false) searchStateData.postValue(false)
} }
} }
@ -125,6 +127,5 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
interface CallBack { interface CallBack {
fun adapter(): ChangeSourceAdapter fun adapter(): ChangeSourceAdapter
fun upSearchState(isSearch: Boolean)
} }
} }

@ -17,7 +17,8 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookshelfAdapter(private val callBack: CallBack) :
PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object { companion object {
@JvmField @JvmField
@ -26,16 +27,13 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
oldItem.bookUrl == newItem.bookUrl oldItem.bookUrl == newItem.bookUrl
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean = override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean =
oldItem.bookUrl == newItem.bookUrl oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.latestChapterTitle == newItem.latestChapterTitle && oldItem.latestChapterTitle == newItem.latestChapterTitle
&& oldItem.durChapterTime == newItem.durChapterTime && oldItem.durChapterTime == newItem.durChapterTime
&& oldItem.lastCheckTime == newItem.lastCheckTime && oldItem.lastCheckTime == newItem.lastCheckTime
} }
} }
var callBack: CallBack? = null
fun notification(bookUrl: String) { fun notification(bookUrl: String) {
for (i in 0..itemCount) { for (i in 0..itemCount) {
getItem(i)?.let { getItem(i)?.let {
@ -66,7 +64,7 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context)) itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context))
} }
fun bind(book: Book, callBack: CallBack?) = with(itemView) { fun bind(book: Book, callBack: CallBack) = with(itemView) {
this.setBackgroundColor(context.getCompatColor(R.color.background)) this.setBackgroundColor(context.getCompatColor(R.color.background))
tv_name.text = book.name tv_name.text = book.name
tv_author.text = book.author tv_author.text = book.author
@ -79,13 +77,12 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
.centerCrop() .centerCrop()
.setAsDrawable(iv_cover) .setAsDrawable(iv_cover)
} }
itemView.onClick { callBack?.open(book) } itemView.onClick { callBack.open(book) }
itemView.onLongClick { itemView.onLongClick {
callBack?.openBookInfo(book) callBack.openBookInfo(book)
true true
} }
callBack?.let { if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) {
if (book.origin != BookType.local && it.isUpdate(book.bookUrl)) {
bv_unread.invisible() bv_unread.invisible()
rl_loading.show() rl_loading.show()
} else { } else {
@ -93,7 +90,6 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
bv_unread.setBadgeCount(book.getUnreadChapterNum()) bv_unread.setBadgeCount(book.getUnreadChapterNum())
bv_unread.setHighlight(book.lastCheckCount > 0) bv_unread.setHighlight(book.lastCheckCount > 0)
} }
} ?: rl_loading.hide()
} }
} }

@ -85,9 +85,8 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
LinearLayoutManager.VERTICAL LinearLayoutManager.VERTICAL
) )
) )
bookshelfAdapter = BookshelfAdapter() bookshelfAdapter = BookshelfAdapter(this)
rv_bookshelf.adapter = bookshelfAdapter rv_bookshelf.adapter = bookshelfAdapter
bookshelfAdapter.callBack = this
observeEvent<String>(Bus.UP_BOOK) { bookshelfAdapter.notification(it) } observeEvent<String>(Bus.UP_BOOK) { bookshelfAdapter.notification(it) }
} }

@ -31,10 +31,9 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun upChapterList() { fun upChapterList() {
execute { execute {
App.db.bookDao().getRecentRead().map { book -> App.db.bookDao().getRecentRead().forEach { book ->
if (book.origin != BookType.local) { if (book.origin != BookType.local) {
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
bookSource?.let {
synchronized(this) { synchronized(this) {
updateList.add(book.bookUrl) updateList.add(book.bookUrl)
postEvent(Bus.UP_BOOK, book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl)

@ -485,9 +485,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
override fun onDialogDismissed(dialogId: Int) { /**
* colorSelectDialog
} */
override fun onDialogDismissed(dialogId: Int) = Unit
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)

@ -116,9 +116,7 @@ class PaddingConfigDialog : DialogFragment() {
tv_padding_top.text = paddingTop.toString() tv_padding_top.text = paddingTop.toString()
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
}
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
@ -130,9 +128,7 @@ class PaddingConfigDialog : DialogFragment() {
tv_padding_bottom.text = paddingBottom.toString() tv_padding_bottom.text = paddingBottom.toString()
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
}
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
@ -144,9 +140,7 @@ class PaddingConfigDialog : DialogFragment() {
tv_padding_left.text = paddingLeft.toString() tv_padding_left.text = paddingLeft.toString()
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
}
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
@ -158,9 +152,7 @@ class PaddingConfigDialog : DialogFragment() {
tv_padding_right.text = paddingRight.toString() tv_padding_right.text = paddingRight.toString()
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
}
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)

@ -87,8 +87,7 @@ class ReadAloudDialog : DialogFragment() {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
}
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
requireContext().putPrefInt("ttsSpeechRate", seek_tts_SpeechRate.progress) requireContext().putPrefInt("ttsSpeechRate", seek_tts_SpeechRate.progress)
@ -101,8 +100,7 @@ class ReadAloudDialog : DialogFragment() {
tv_timer.text = requireContext().getString(R.string.timer_m, progress) tv_timer.text = requireContext().getString(R.string.timer_m, progress)
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
}
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
ReadAloudService.setTimer(requireContext(), seek_timer.progress) ReadAloudService.setTimer(requireContext(), seek_timer.progress)

@ -71,23 +71,17 @@ class ReadStyleDialog : DialogFragment() {
rg_page_anim.check(rg_page_anim[it].id) rg_page_anim.check(rg_page_anim[it].id)
} }
} }
ReadBookConfig.getConfig().let { upStyle()
tv_text_bold.isSelected = it.textBold
seek_text_size.progress = it.textSize - 5
tv_text_size.text = it.textSize.toString()
seek_text_letter_spacing.progress = (it.letterSpacing * 10).toInt() + 5
tv_text_letter_spacing.text = it.letterSpacing.toString()
seek_line_size.progress = it.lineSpacingExtra
tv_line_size.text = it.lineSpacingExtra.toString()
}
setBg() setBg()
upBg() upBg()
} }
private fun initOnClick() = with(ReadBookConfig.getConfig()) { private fun initOnClick() {
tv_text_bold.onClick { tv_text_bold.onClick {
with(ReadBookConfig.getConfig()) {
textBold = !textBold textBold = !textBold
tv_text_bold.isSelected = textBold tv_text_bold.isSelected = textBold
}
postEvent(Bus.UP_CONFIG, false) postEvent(Bus.UP_CONFIG, false)
} }
tv_text_font.onClick { tv_text_font.onClick {
@ -121,73 +115,89 @@ class ReadStyleDialog : DialogFragment() {
} }
seek_text_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seek_text_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
textSize = progress + 5 ReadBookConfig.getConfig().textSize = progress + 5
tv_text_size.text = textSize.toString() tv_text_size.text = ReadBookConfig.getConfig().textSize.toString()
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) {} override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
}) })
iv_text_size_add.onClick { iv_text_size_add.onClick {
with(ReadBookConfig.getConfig()) {
textSize++ textSize++
if (textSize > 50) textSize = 50 if (textSize > 50) textSize = 50
seek_text_size.progress = textSize - 5 seek_text_size.progress = textSize - 5
tv_text_size.text = textSize.toString() tv_text_size.text = textSize.toString()
}
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
iv_text_size_remove.onClick { iv_text_size_remove.onClick {
with(ReadBookConfig.getConfig()) {
textSize-- textSize--
if (textSize < 5) textSize = 5 if (textSize < 5) textSize = 5
seek_text_size.progress = textSize - 5 seek_text_size.progress = textSize - 5
tv_text_size.text = textSize.toString() tv_text_size.text = textSize.toString()
}
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
seek_text_letter_spacing.setOnSeekBarChangeListener(object : seek_text_letter_spacing.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener { SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
with(ReadBookConfig.getConfig()) {
letterSpacing = (seek_text_letter_spacing.progress - 5) / 10f letterSpacing = (seek_text_letter_spacing.progress - 5) / 10f
tv_text_letter_spacing.text = letterSpacing.toString() tv_text_letter_spacing.text = letterSpacing.toString()
} }
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {} override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
}) })
iv_text_letter_spacing_add.onClick { iv_text_letter_spacing_add.onClick {
with(ReadBookConfig.getConfig()) {
letterSpacing += 0.1f letterSpacing += 0.1f
seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5 seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5
tv_text_letter_spacing.text = letterSpacing.toString() tv_text_letter_spacing.text = letterSpacing.toString()
}
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
iv_text_letter_spacing_remove.onClick { iv_text_letter_spacing_remove.onClick {
with(ReadBookConfig.getConfig()) {
letterSpacing -= 0.1f letterSpacing -= 0.1f
seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5 seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5
tv_text_letter_spacing.text = letterSpacing.toString() tv_text_letter_spacing.text = letterSpacing.toString()
}
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
seek_line_size.setOnSeekBarChangeListener(object : seek_line_size.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener { SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
with(ReadBookConfig.getConfig()) {
lineSpacingExtra = seek_line_size.progress lineSpacingExtra = seek_line_size.progress
tv_line_size.text = lineSpacingExtra.toString() tv_line_size.text = lineSpacingExtra.toString()
} }
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {} override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
}) })
iv_line_size_add.onClick { iv_line_size_add.onClick {
with(ReadBookConfig.getConfig()) {
lineSpacingExtra++ lineSpacingExtra++
tv_line_size.text = lineSpacingExtra.toString() tv_line_size.text = lineSpacingExtra.toString()
}
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
iv_line_size_remove.onClick { iv_line_size_remove.onClick {
with(ReadBookConfig.getConfig()) {
lineSpacingExtra-- lineSpacingExtra--
tv_line_size.text = lineSpacingExtra.toString() tv_line_size.text = lineSpacingExtra.toString()
}
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
rg_page_anim.onCheckedChange { _, checkedId -> rg_page_anim.onCheckedChange { _, checkedId ->
@ -218,6 +228,7 @@ class ReadStyleDialog : DialogFragment() {
if (ReadBookConfig.styleSelect != index) { if (ReadBookConfig.styleSelect != index) {
ReadBookConfig.styleSelect = index ReadBookConfig.styleSelect = index
ReadBookConfig.upBg() ReadBookConfig.upBg()
upStyle()
upBg() upBg()
postEvent(Bus.UP_CONFIG, true) postEvent(Bus.UP_CONFIG, true)
} }
@ -233,6 +244,18 @@ class ReadStyleDialog : DialogFragment() {
return true return true
} }
private fun upStyle() {
ReadBookConfig.getConfig().let {
tv_text_bold.isSelected = it.textBold
seek_text_size.progress = it.textSize - 5
tv_text_size.text = it.textSize.toString()
seek_text_letter_spacing.progress = (it.letterSpacing * 10).toInt() + 5
tv_text_letter_spacing.text = it.letterSpacing.toString()
seek_line_size.progress = it.lineSpacingExtra
tv_line_size.text = it.lineSpacingExtra.toString()
}
}
private fun setBg() { private fun setBg() {
tv_bg0.setTextColor(ReadBookConfig.getConfig(0).textColor()) tv_bg0.setTextColor(ReadBookConfig.getConfig(0).textColor())
tv_bg1.setTextColor(ReadBookConfig.getConfig(1).textColor()) tv_bg1.setTextColor(ReadBookConfig.getConfig(1).textColor())

@ -64,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
tool_bar.inflateMenu(R.menu.group_manage) tool_bar.inflateMenu(R.menu.group_manage)
tool_bar.menu.applyTint(requireContext(), false) tool_bar.menu.applyTint(requireContext(), false)
tool_bar.setOnMenuItemClickListener(this) tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext(), this) adapter = GroupAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext())
recycler_view.addItemDecoration( recycler_view.addItemDecoration(
DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) DividerItemDecoration(requireContext(), RecyclerView.VERTICAL)
@ -129,14 +129,14 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
}.show().applyTint().requestInputMethod() }.show().applyTint().requestInputMethod()
} }
class GroupAdapter(context: Context, val dialog: GroupManageDialog) : private inner class GroupAdapter(context: Context) :
SimpleRecyclerAdapter<String>(context, R.layout.item_group_manage) { SimpleRecyclerAdapter<String>(context, R.layout.item_group_manage) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {
tv_group.text = item tv_group.text = item
tv_edit.onClick { dialog.editGroup(item) } tv_edit.onClick { editGroup(item) }
tv_del.onClick { dialog.viewModel.delGroup(item) } tv_del.onClick { viewModel.delGroup(item) }
} }
} }
} }

@ -16,23 +16,24 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:title="搜索"/> app:title="搜索"/>
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
app:layout_constraintTop_toBottomOf="@id/title_bar" />
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout <io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout
android:id="@+id/content_view" android:id="@+id/content_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_bar"> app:layout_constraintTop_toBottomOf="@id/refresh_progress_bar">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar"
android:layout_width="match_parent"
android:layout_height="2dp" />
</io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout> </io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton

Loading…
Cancel
Save