diff --git a/app/src/main/java/io/legado/app/constant/RSSKeywords.kt b/app/src/main/java/io/legado/app/constant/RSSKeywords.kt new file mode 100644 index 000000000..5a4119e05 --- /dev/null +++ b/app/src/main/java/io/legado/app/constant/RSSKeywords.kt @@ -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" +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt new file mode 100644 index 000000000..6f8773ba3 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -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 = mutableListOf() +) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index cdad6785d..baa368760 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -125,7 +125,6 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, private lateinit var audioManager: AudioManager private lateinit var mFocusRequest: AudioFocusRequest private var broadcastReceiver: BroadcastReceiver? = null - private var speak: Boolean = true private var nowSpeak: Int = 0 private val contentList = arrayListOf() private var readAloudNumber: Int = 0 @@ -147,13 +146,13 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } initMediaSession() initBroadcastReceiver() - upMediaSessionPlaybackState() upSpeechRate() ReadAloudNotification.upNotification(this) } override fun onDestroy() { super.onDestroy() + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) clearTTS() unregisterReceiver(broadcastReceiver) postEvent(Bus.ALOUD_STATE, Status.STOP) @@ -231,6 +230,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, return } if (requestFocus()) { + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) postEvent(Bus.ALOUD_STATE, Status.PLAY) ReadAloudNotification.upNotification(this) for (i in nowSpeak until contentList.size) { @@ -322,28 +322,31 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } /** - * 初始化MediaSession + * 初始化MediaSession, 注册多媒体按钮 */ private fun initMediaSession() { - val mComponent = ComponentName(packageName, MediaButtonReceiver::class.java.name) - val mediaButtonIntent = Intent(Intent.ACTION_MEDIA_BUTTON) - mediaButtonIntent.component = mComponent + val mediaButtonIntent = Intent(Intent.ACTION_MEDIA_BUTTON).apply { + component = ComponentName(packageName, MediaButtonReceiver::class.java.name) + } val mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast( - this, 0, - mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT + this, + 0, + mediaButtonIntent, + PendingIntent.FLAG_CANCEL_CURRENT ) - mediaSessionCompat = - MediaSessionCompat(this, tag, mComponent, mediaButtonReceiverPendingIntent) + mediaSessionCompat = MediaSessionCompat(this, tag) mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() { override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean { return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent) } }) mediaSessionCompat?.setMediaButtonReceiver(mediaButtonReceiverPendingIntent) + mediaSessionCompat?.isActive = true } private fun initBroadcastReceiver() { + //断开耳机监听 broadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val action = intent.action @@ -357,9 +360,10 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } private fun pauseReadAloud(pause: Boolean) { - if (pause) postEvent(Bus.ALOUD_STATE, Status.PAUSE) + postEvent(Bus.ALOUD_STATE, Status.PAUSE) this.pause = pause textToSpeech?.stop() + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) ReadAloudNotification.upNotification(this) } @@ -386,14 +390,11 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED } - private fun upMediaSessionPlaybackState() { + private fun upMediaSessionPlaybackState(state: Int) { mediaSessionCompat?.setPlaybackState( PlaybackStateCompat.Builder() .setActions(MediaHelp.MEDIA_SESSION_ACTIONS) - .setState( - if (speak) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED, - nowSpeak.toLong(), 1f - ) + .setState(state, nowSpeak.toLong(), 1f) .build() ) } diff --git a/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt index 5d4996fb0..e5ed98578 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/GroupManageDialog.kt @@ -64,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.inflateMenu(R.menu.group_manage) tool_bar.menu.applyTint(requireContext(), false) tool_bar.setOnMenuItemClickListener(this) - adapter = GroupAdapter(requireContext(), this) + adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration( DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) @@ -129,14 +129,14 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { }.show().applyTint().requestInputMethod() } - class GroupAdapter(context: Context, val dialog: GroupManageDialog) : + private inner class GroupAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_group_manage) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { with(holder.itemView) { tv_group.text = item - tv_edit.onClick { dialog.editGroup(item) } - tv_del.onClick { dialog.viewModel.delGroup(item) } + tv_edit.onClick { editGroup(item) } + tv_del.onClick { viewModel.delGroup(item) } } } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index f5a1a6699..df03b920e 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -8,6 +8,7 @@ import android.view.ViewGroup import android.widget.LinearLayout import androidx.appcompat.widget.SearchView import androidx.fragment.app.DialogFragment +import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R @@ -48,6 +49,9 @@ class ChangeSourceDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.searchStateData.observe(viewLifecycleOwner, Observer { + refresh_progress_bar.isAutoLoading = it + }) arguments?.let { bundle -> bundle.getString("name")?.let { viewModel.name = it @@ -141,10 +145,6 @@ class ChangeSourceDialog : DialogFragment(), return changeSourceAdapter } - override fun upSearchState(isSearch: Boolean) { - refresh_progress_bar.isAutoLoading = isSearch - } - interface CallBack { fun curOrigin(): String? fun oldBook(): Book? diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 3839bebef..3159db258 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.changesource import android.app.Application +import androidx.lifecycle.MutableLiveData import androidx.recyclerview.widget.DiffUtil import io.legado.app.App import io.legado.app.R @@ -17,6 +18,7 @@ import org.jetbrains.anko.debug class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { var callBack: CallBack? = null + val searchStateData = MutableLiveData() var name: String = "" var author: String = "" private var task: Coroutine<*>? = null @@ -50,7 +52,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio fun search() { task = execute { - callBack?.upSearchState(true) + searchStateData.postValue(true) val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) @@ -73,7 +75,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } task?.invokeOnCompletion { - callBack?.upSearchState(false) + searchStateData.postValue(false) } } @@ -125,6 +127,5 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio interface CallBack { fun adapter(): ChangeSourceAdapter - fun upSearchState(isSearch: Boolean) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index 4f5a271c2..34172056d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt @@ -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.onLongClick -class BookshelfAdapter : PagedListAdapter(DIFF_CALLBACK) { +class BookshelfAdapter(private val callBack: CallBack) : + PagedListAdapter(DIFF_CALLBACK) { companion object { @JvmField @@ -26,16 +27,13 @@ class BookshelfAdapter : PagedListAdapter(D oldItem.bookUrl == newItem.bookUrl 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.durChapterTime == newItem.durChapterTime && oldItem.lastCheckTime == newItem.lastCheckTime } } - var callBack: CallBack? = null - fun notification(bookUrl: String) { for (i in 0..itemCount) { getItem(i)?.let { @@ -66,7 +64,7 @@ class BookshelfAdapter : PagedListAdapter(D 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)) tv_name.text = book.name tv_author.text = book.author @@ -79,21 +77,19 @@ class BookshelfAdapter : PagedListAdapter(D .centerCrop() .setAsDrawable(iv_cover) } - itemView.onClick { callBack?.open(book) } + itemView.onClick { callBack.open(book) } itemView.onLongClick { - callBack?.openBookInfo(book) + callBack.openBookInfo(book) true } - callBack?.let { - if (book.origin != BookType.local && it.isUpdate(book.bookUrl)) { - bv_unread.invisible() - rl_loading.show() - } else { - rl_loading.hide() - bv_unread.setBadgeCount(book.getUnreadChapterNum()) - bv_unread.setHighlight(book.lastCheckCount > 0) - } - } ?: rl_loading.hide() + if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) { + bv_unread.invisible() + rl_loading.show() + } else { + rl_loading.hide() + bv_unread.setBadgeCount(book.getUnreadChapterNum()) + bv_unread.setHighlight(book.lastCheckCount > 0) + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 415a7cafe..77a91e0a6 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -85,9 +85,8 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b LinearLayoutManager.VERTICAL ) ) - bookshelfAdapter = BookshelfAdapter() + bookshelfAdapter = BookshelfAdapter(this) rv_bookshelf.adapter = bookshelfAdapter - bookshelfAdapter.callBack = this observeEvent(Bus.UP_BOOK) { bookshelfAdapter.notification(it) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index b1fd24966..c9baf1494 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -31,31 +31,30 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun upChapterList() { execute { - App.db.bookDao().getRecentRead().map { book -> + App.db.bookDao().getRecentRead().forEach { book -> if (book.origin != BookType.local) { - val bookSource = App.db.bookSourceDao().getBookSource(book.origin) - bookSource?.let { + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> synchronized(this) { updateList.add(book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl) } WebBook(bookSource).getChapterList(book) .onSuccess(IO) { - it?.let { - App.db.bookDao().update(book) - App.db.bookChapterDao().delByBook(book.bookUrl) - App.db.bookChapterDao().insert(*it.toTypedArray()) - } + it?.let { + App.db.bookDao().update(book) + App.db.bookChapterDao().delByBook(book.bookUrl) + App.db.bookChapterDao().insert(*it.toTypedArray()) + } } .onError { it.printStackTrace() } .onFinally { - synchronized(this) { - updateList.remove(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) + synchronized(this) { + updateList.remove(book.bookUrl) + postEvent(Bus.UP_BOOK, book.bookUrl) + } } - } } } delay(50) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 3e45d65d2..da9028d0e 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -485,9 +485,10 @@ class ReadBookActivity : VMBaseActivity(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?) { super.onActivityResult(requestCode, resultCode, data) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt index 779ba3dab..4d349b9cb 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt @@ -116,9 +116,7 @@ class PaddingConfigDialog : DialogFragment() { tv_padding_top.text = paddingTop.toString() } - override fun onStartTrackingTouch(seekBar: SeekBar?) { - - } + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) @@ -130,9 +128,7 @@ class PaddingConfigDialog : DialogFragment() { tv_padding_bottom.text = paddingBottom.toString() } - override fun onStartTrackingTouch(seekBar: SeekBar?) { - - } + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) @@ -144,9 +140,7 @@ class PaddingConfigDialog : DialogFragment() { tv_padding_left.text = paddingLeft.toString() } - override fun onStartTrackingTouch(seekBar: SeekBar?) { - - } + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) @@ -158,9 +152,7 @@ class PaddingConfigDialog : DialogFragment() { tv_padding_right.text = paddingRight.toString() } - override fun onStartTrackingTouch(seekBar: SeekBar?) { - - } + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index 3922ee122..686c0e7b5 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -87,8 +87,7 @@ class ReadAloudDialog : DialogFragment() { 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?) { requireContext().putPrefInt("ttsSpeechRate", seek_tts_SpeechRate.progress) @@ -101,8 +100,7 @@ class ReadAloudDialog : DialogFragment() { 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?) { ReadAloudService.setTimer(requireContext(), seek_timer.progress) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index 15fa51590..a0080036c 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt @@ -71,23 +71,17 @@ class ReadStyleDialog : DialogFragment() { rg_page_anim.check(rg_page_anim[it].id) } } - 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() - } + upStyle() setBg() upBg() } - private fun initOnClick() = with(ReadBookConfig.getConfig()) { + private fun initOnClick() { tv_text_bold.onClick { - textBold = !textBold - tv_text_bold.isSelected = textBold + with(ReadBookConfig.getConfig()) { + textBold = !textBold + tv_text_bold.isSelected = textBold + } postEvent(Bus.UP_CONFIG, false) } tv_text_font.onClick { @@ -121,73 +115,89 @@ class ReadStyleDialog : DialogFragment() { } seek_text_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - textSize = progress + 5 - tv_text_size.text = textSize.toString() + ReadBookConfig.getConfig().textSize = progress + 5 + tv_text_size.text = ReadBookConfig.getConfig().textSize.toString() } - override fun onStartTrackingTouch(seekBar: SeekBar?) {} + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) } }) iv_text_size_add.onClick { - textSize++ - if (textSize > 50) textSize = 50 - seek_text_size.progress = textSize - 5 - tv_text_size.text = textSize.toString() + with(ReadBookConfig.getConfig()) { + textSize++ + if (textSize > 50) textSize = 50 + seek_text_size.progress = textSize - 5 + tv_text_size.text = textSize.toString() + } postEvent(Bus.UP_CONFIG, true) } iv_text_size_remove.onClick { - textSize-- - if (textSize < 5) textSize = 5 - seek_text_size.progress = textSize - 5 - tv_text_size.text = textSize.toString() + with(ReadBookConfig.getConfig()) { + textSize-- + if (textSize < 5) textSize = 5 + seek_text_size.progress = textSize - 5 + tv_text_size.text = textSize.toString() + } postEvent(Bus.UP_CONFIG, true) } seek_text_letter_spacing.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - letterSpacing = (seek_text_letter_spacing.progress - 5) / 10f - tv_text_letter_spacing.text = letterSpacing.toString() + with(ReadBookConfig.getConfig()) { + letterSpacing = (seek_text_letter_spacing.progress - 5) / 10f + tv_text_letter_spacing.text = letterSpacing.toString() + } } - override fun onStartTrackingTouch(seekBar: SeekBar?) {} + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) } }) iv_text_letter_spacing_add.onClick { - letterSpacing += 0.1f - seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5 - tv_text_letter_spacing.text = letterSpacing.toString() + with(ReadBookConfig.getConfig()) { + letterSpacing += 0.1f + seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5 + tv_text_letter_spacing.text = letterSpacing.toString() + } postEvent(Bus.UP_CONFIG, true) } iv_text_letter_spacing_remove.onClick { - letterSpacing -= 0.1f - seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5 - tv_text_letter_spacing.text = letterSpacing.toString() + with(ReadBookConfig.getConfig()) { + letterSpacing -= 0.1f + seek_text_letter_spacing.progress = (letterSpacing * 10).toInt() + 5 + tv_text_letter_spacing.text = letterSpacing.toString() + } postEvent(Bus.UP_CONFIG, true) } seek_line_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - lineSpacingExtra = seek_line_size.progress - tv_line_size.text = lineSpacingExtra.toString() + with(ReadBookConfig.getConfig()) { + lineSpacingExtra = seek_line_size.progress + tv_line_size.text = lineSpacingExtra.toString() + } } - override fun onStartTrackingTouch(seekBar: SeekBar?) {} + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) } }) iv_line_size_add.onClick { - lineSpacingExtra++ - tv_line_size.text = lineSpacingExtra.toString() + with(ReadBookConfig.getConfig()) { + lineSpacingExtra++ + tv_line_size.text = lineSpacingExtra.toString() + } postEvent(Bus.UP_CONFIG, true) } iv_line_size_remove.onClick { - lineSpacingExtra-- - tv_line_size.text = lineSpacingExtra.toString() + with(ReadBookConfig.getConfig()) { + lineSpacingExtra-- + tv_line_size.text = lineSpacingExtra.toString() + } postEvent(Bus.UP_CONFIG, true) } rg_page_anim.onCheckedChange { _, checkedId -> @@ -218,6 +228,7 @@ class ReadStyleDialog : DialogFragment() { if (ReadBookConfig.styleSelect != index) { ReadBookConfig.styleSelect = index ReadBookConfig.upBg() + upStyle() upBg() postEvent(Bus.UP_CONFIG, true) } @@ -233,6 +244,18 @@ class ReadStyleDialog : DialogFragment() { 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() { tv_bg0.setTextColor(ReadBookConfig.getConfig(0).textColor()) tv_bg1.setTextColor(ReadBookConfig.getConfig(1).textColor()) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt index a7799cc87..e653947f8 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt @@ -64,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.inflateMenu(R.menu.group_manage) tool_bar.menu.applyTint(requireContext(), false) tool_bar.setOnMenuItemClickListener(this) - adapter = GroupAdapter(requireContext(), this) + adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration( DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) @@ -129,14 +129,14 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { }.show().applyTint().requestInputMethod() } - class GroupAdapter(context: Context, val dialog: GroupManageDialog) : + private inner class GroupAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_group_manage) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { with(holder.itemView) { tv_group.text = item - tv_edit.onClick { dialog.editGroup(item) } - tv_del.onClick { dialog.viewModel.delGroup(item) } + tv_edit.onClick { editGroup(item) } + tv_del.onClick { viewModel.delGroup(item) } } } } diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index 7d74faad8..b840cd032 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -16,23 +16,24 @@ app:layout_constraintTop_toTopOf="parent" app:title="搜索"/> + + + app:layout_constraintTop_toBottomOf="@id/refresh_progress_bar"> - -