From 42f019eb4325deff463a53a261a7121cb6b648bf Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 16:03:06 +0800 Subject: [PATCH 01/13] up --- app/src/main/res/layout/activity_search.xml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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"> - - Date: Tue, 10 Sep 2019 16:12:53 +0800 Subject: [PATCH 02/13] up --- .../app/ui/main/bookshelf/BookshelfAdapter.kt | 29 +++++++++---------- .../ui/main/bookshelf/BookshelfFragment.kt | 3 +- 2 files changed, 14 insertions(+), 18 deletions(-) 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..4c2dd9d6e 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 @@ -34,8 +35,6 @@ class BookshelfAdapter : PagedListAdapter(D } } - var callBack: CallBack? = null - fun notification(bookUrl: String) { for (i in 0..itemCount) { getItem(i)?.let { @@ -66,7 +65,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 +78,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) } } From 030b450000ac73e127b3f9de0422ab5ae59536c7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 16:18:07 +0800 Subject: [PATCH 03/13] up --- .../java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 4c2dd9d6e..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 @@ -27,8 +27,7 @@ class BookshelfAdapter(private val callBack: CallBack) : 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 From 277406e0e65b234da0f592203c7e2578f3adceed Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 16:33:16 +0800 Subject: [PATCH 04/13] up --- .../ui/main/bookshelf/BookshelfViewModel.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) 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) From 92d41aa7a4c395249b9c5cbcfe5445c0dfb6e37a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 17:13:37 +0800 Subject: [PATCH 05/13] up --- .../app/ui/readbook/config/ReadStyleDialog.kt | 95 ++++++++++++------- 1 file changed, 59 insertions(+), 36 deletions(-) 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..6232ae321 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,8 +115,8 @@ 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?) {} @@ -131,24 +125,30 @@ class ReadStyleDialog : DialogFragment() { } }) 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?) {} @@ -157,22 +157,28 @@ class ReadStyleDialog : DialogFragment() { } }) 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?) {} @@ -181,13 +187,17 @@ class ReadStyleDialog : DialogFragment() { } }) 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()) From 9ab42d512b8d1daf0f5bbc2d0d212b186e85cff9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 19:05:54 +0800 Subject: [PATCH 06/13] up --- .../java/io/legado/app/ui/readbook/ReadBookActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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) From d37280a30cd333e4524ca332358975148db944d2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 19:12:50 +0800 Subject: [PATCH 07/13] up --- .../ui/readbook/config/PaddingConfigDialog.kt | 16 ++++------------ .../app/ui/readbook/config/ReadAloudDialog.kt | 6 ++---- .../app/ui/readbook/config/ReadStyleDialog.kt | 6 +++--- 3 files changed, 9 insertions(+), 19 deletions(-) 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 6232ae321..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 @@ -119,7 +119,7 @@ class ReadStyleDialog : DialogFragment() { 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) } @@ -151,7 +151,7 @@ class ReadStyleDialog : DialogFragment() { } } - override fun onStartTrackingTouch(seekBar: SeekBar?) {} + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) } @@ -181,7 +181,7 @@ class ReadStyleDialog : DialogFragment() { } } - override fun onStartTrackingTouch(seekBar: SeekBar?) {} + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { postEvent(Bus.UP_CONFIG, true) } From b81bac5a5294b1c3c2f09661900e22943eca7832 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 20:35:41 +0800 Subject: [PATCH 08/13] up --- .../io/legado/app/data/entities/RssArticle.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/src/main/java/io/legado/app/data/entities/RssArticle.kt 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 From 0a179d3a58940c333fd2037fcf14b5642d75e243 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 23:13:19 +0800 Subject: [PATCH 09/13] up --- .../io/legado/app/constant/RSSKeywords.kt | 19 ++++++++++++++++ .../io/legado/app/service/ReadAloudService.kt | 22 +++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/io/legado/app/constant/RSSKeywords.kt 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/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index cdad6785d..c6c2cec12 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -147,13 +147,14 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } initMediaSession() initBroadcastReceiver() - upMediaSessionPlaybackState() + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upSpeechRate() ReadAloudNotification.upNotification(this) } override fun onDestroy() { super.onDestroy() + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) clearTTS() unregisterReceiver(broadcastReceiver) postEvent(Bus.ALOUD_STATE, Status.STOP) @@ -231,6 +232,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,7 +324,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } /** - * 初始化MediaSession + * 初始化MediaSession, 注册多媒体按钮 */ private fun initMediaSession() { val mComponent = ComponentName(packageName, MediaButtonReceiver::class.java.name) @@ -333,17 +335,21 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT ) - mediaSessionCompat = - MediaSessionCompat(this, tag, mComponent, mediaButtonReceiverPendingIntent) + mediaSessionCompat = MediaSessionCompat( + this, tag, mComponent, + mediaButtonReceiverPendingIntent + ) 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 @@ -360,6 +366,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, if (pause) postEvent(Bus.ALOUD_STATE, Status.PAUSE) this.pause = pause textToSpeech?.stop() + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) ReadAloudNotification.upNotification(this) } @@ -386,14 +393,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() ) } From 8882a0bdff9cef4e42194ed5ff246df3ebdc1758 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 Sep 2019 08:42:29 +0800 Subject: [PATCH 10/13] up --- .../java/io/legado/app/ui/booksource/GroupManageDialog.kt | 8 ++++---- .../io/legado/app/ui/replacerule/GroupManageDialog.kt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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/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) } } } } From 0c7c225e9f9cd74727651a306f4949f93b99b0af Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 Sep 2019 09:10:21 +0800 Subject: [PATCH 11/13] up --- app/src/main/java/io/legado/app/service/ReadAloudService.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 c6c2cec12..5e4638dc1 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,7 +146,6 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } initMediaSession() initBroadcastReceiver() - upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upSpeechRate() ReadAloudNotification.upNotification(this) } @@ -363,7 +361,7 @@ 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) From 430a444bf3d68cfe8c1347649c7d1adad13bb38f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 Sep 2019 09:39:28 +0800 Subject: [PATCH 12/13] up --- .../main/java/io/legado/app/service/ReadAloudService.kt | 5 +---- .../io/legado/app/ui/changesource/ChangeSourceDialog.kt | 8 ++++---- .../legado/app/ui/changesource/ChangeSourceViewModel.kt | 7 ++++--- 3 files changed, 9 insertions(+), 11 deletions(-) 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 5e4638dc1..1af82c149 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -333,10 +333,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, 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) 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 From a2fa8e1adb2631132fecec2130fe07c22cb16a02 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 Sep 2019 10:19:24 +0800 Subject: [PATCH 13/13] up --- .../java/io/legado/app/service/ReadAloudService.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 1af82c149..baa368760 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -325,12 +325,14 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, * 初始化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)