diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index bfd63c362..6c5741414 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -2,7 +2,6 @@ package io.legado.app.ui.association import android.content.Intent import android.os.Bundle -import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Theme @@ -23,12 +22,12 @@ class FileAssociationActivity : VMBaseActivity( override fun onActivityCreated(savedInstanceState: Bundle?) { rotate_loading.show() - viewModel.errorLiveData.observe(this, Observer { + viewModel.errorLiveData.observe(this, { rotate_loading.hide() toast(it) finish() }) - viewModel.successLiveData.observe(this, Observer { + viewModel.successLiveData.observe(this, { rotate_loading.hide() startActivity(it) finish() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index 874bb9e5e..0b74690f2 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -9,7 +9,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -41,11 +40,11 @@ class ImportBookSourceActivity : VMBaseActivity( override fun onActivityCreated(savedInstanceState: Bundle?) { rotate_loading.show() - viewModel.errorLiveData.observe(this, Observer { + viewModel.errorLiveData.observe(this, { rotate_loading.hide() errorDialog(it) }) - viewModel.successLiveData.observe(this, Observer { + viewModel.successLiveData.observe(this, { rotate_loading.hide() if (it > 0) { successDialog() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt index c5d757597..12ae447d1 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.association import android.os.Bundle -import androidx.lifecycle.Observer import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity @@ -26,11 +25,11 @@ class ImportReplaceRuleActivity : VMBaseActivity( override fun onActivityCreated(savedInstanceState: Bundle?) { rotate_loading.show() - viewModel.errorLiveData.observe(this, Observer { + viewModel.errorLiveData.observe(this, { rotate_loading.hide() errorDialog(it) }) - viewModel.successLiveData.observe(this, Observer { + viewModel.successLiveData.observe(this, { rotate_loading.hide() if (it.size > 0) { successDialog(it) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt index 35e3ca284..8862f2dbe 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt @@ -9,7 +9,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -41,11 +40,11 @@ class ImportRssSourceActivity : VMBaseActivity( override fun onActivityCreated(savedInstanceState: Bundle?) { rotate_loading.show() - viewModel.errorLiveData.observe(this, Observer { + viewModel.errorLiveData.observe(this, { rotate_loading.hide() errorDialog(it) }) - viewModel.successLiveData.observe(this, Observer { + viewModel.successLiveData.observe(this, { rotate_loading.hide() if (it > 0) { successDialog() diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index 9ed2b173d..f1d2883fb 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -8,7 +8,6 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.widget.SeekBar -import androidx.lifecycle.Observer import com.bumptech.glide.RequestBuilder import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions.bitmapTransform @@ -48,8 +47,8 @@ class AudioPlayActivity : override fun onActivityCreated(savedInstanceState: Bundle?) { title_bar.transparent() - AudioPlay.titleData.observe(this, Observer { title_bar.title = it }) - AudioPlay.coverData.observe(this, Observer { upCover(it) }) + AudioPlay.titleData.observe(this, { title_bar.title = it }) + AudioPlay.coverData.observe(this, { upCover(it) }) viewModel.initData(intent) initView() } diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 491922cb1..ab37c5fe1 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -5,7 +5,6 @@ import android.view.Menu import android.view.MenuItem import androidx.appcompat.widget.PopupMenu import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App @@ -94,7 +93,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private fun initGroupData() { groupLiveData?.removeObservers(this) groupLiveData = App.db.bookGroupDao().liveDataAll() - groupLiveData?.observe(this, Observer { + groupLiveData?.observe(this, { groupList.clear() groupList.addAll(it) adapter.notifyDataSetChanged() @@ -112,7 +111,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } - booksLiveData?.observe(this, Observer { list -> + booksLiveData?.observe(this, { list -> val books = when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> list.sortedByDescending { it.latestChapterTime } 2 -> list.sortedBy { it.name } diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt index 2539e6dc9..4a898fed4 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt @@ -8,7 +8,6 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.R @@ -83,7 +82,7 @@ class ChangeCoverDialog : BaseDialogFragment(), override fun observeLiveBus() { super.observeLiveBus() - viewModel.searchStateData.observe(viewLifecycleOwner, Observer { + viewModel.searchStateData.observe(viewLifecycleOwner, { refresh_progress_bar.isAutoLoading = it if (it) { stopMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) @@ -92,7 +91,7 @@ class ChangeCoverDialog : BaseDialogFragment(), } tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) }) - viewModel.searchBooksLiveData.observe(viewLifecycleOwner, Observer { + viewModel.searchBooksLiveData.observe(viewLifecycleOwner, { val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it)) adapter.setItems(it) diffResult.dispatchUpdatesTo(adapter) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index d27f8b756..7ebb4c0db 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -9,7 +9,6 @@ import android.view.ViewGroup import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -135,7 +134,7 @@ class ChangeSourceDialog : BaseDialogFragment(), } private fun initLiveData() { - viewModel.searchStateData.observe(viewLifecycleOwner, Observer { + viewModel.searchStateData.observe(viewLifecycleOwner, { refresh_progress_bar.isAutoLoading = it if (it) { stopMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) @@ -144,7 +143,7 @@ class ChangeSourceDialog : BaseDialogFragment(), } tool_bar.menu.applyTint(requireContext()) }) - viewModel.searchBooksLiveData.observe(viewLifecycleOwner, Observer { + viewModel.searchBooksLiveData.observe(viewLifecycleOwner, { val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it)) adapter.setItems(it) diffResult.dispatchUpdatesTo(adapter) diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt index ef47cd2c0..b24d438e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt @@ -8,7 +8,6 @@ import android.os.Bundle import android.view.View import android.widget.EditText import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.paging.LivePagedListBuilder import androidx.paging.PagedList import androidx.recyclerview.widget.LinearLayoutManager @@ -59,7 +58,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ LivePagedListBuilder( App.db.bookmarkDao().observeByBook(book.bookUrl, book.name, book.author), 20 ).build() - bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) + bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) } } @@ -74,7 +73,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ newText ), 20 ).build() - bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) + bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) } } diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt index 677d623e2..58d47efeb 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.os.Bundle import android.view.View import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment @@ -89,7 +88,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme private fun initDoc() { tocLiveData?.removeObservers(this@ChapterListFragment) tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) - tocLiveData?.observe(viewLifecycleOwner, Observer { + tocLiveData?.observe(viewLifecycleOwner, { adapter.setItems(it) if (!scrollToDurChapter) { mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) @@ -124,7 +123,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } else { tocLiveData?.removeObservers(this) tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText) - tocLiveData?.observe(viewLifecycleOwner, Observer { + tocLiveData?.observe(viewLifecycleOwner, { adapter.setItems(it) }) } diff --git a/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt index ecb9c6b67..d4c629381 100644 --- a/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.Snackbar import io.legado.app.App @@ -129,7 +128,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } - booksLiveData?.observe(this, Observer { list -> + booksLiveData?.observe(this, { list -> val booksDownload = list.filter { it.isOnLineTxt() } @@ -147,7 +146,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow private fun initGroupData() { groupLiveData?.removeObservers(this) groupLiveData = App.db.bookGroupDao().liveDataAll() - groupLiveData?.observe(this, Observer { + groupLiveData?.observe(this, { groupList.clear() groupList.addAll(it) adapter.notifyDataSetChanged() diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt index dbba6b63e..a447bb9e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.book.explore import android.os.Bundle -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -27,7 +26,7 @@ class ExploreShowActivity : VMBaseActivity(R.layout.activi override fun onActivityCreated(savedInstanceState: Bundle?) { title_bar.title = intent.getStringExtra("exploreName") initRecyclerView() - viewModel.booksData.observe(this, Observer { upData(it) }) + viewModel.booksData.observe(this, { upData(it) }) viewModel.initData(intent) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 73bdd8595..d5efe8126 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -10,7 +10,6 @@ import android.view.View import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -78,7 +77,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener tv_ok.setTextColor(requireContext().accentColor) tv_ok.visible() tv_ok.onClick { dismiss() } - App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { + App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, { val diffResult = DiffUtil.calculateDiff(GroupDiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, diffResult) diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index df058b901..7a83ab140 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -11,7 +11,6 @@ import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager -import androidx.lifecycle.Observer import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -113,7 +112,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } private fun initData() { - App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { + App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, { adapter.setItems(it) }) } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 906cacaf7..2591a30c4 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -9,7 +9,6 @@ import android.view.Menu import android.view.MenuItem import android.widget.CheckBox import android.widget.LinearLayout -import androidx.lifecycle.Observer import com.bumptech.glide.RequestBuilder import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions.bitmapTransform @@ -66,8 +65,8 @@ class BookInfoActivity : scroll_view.setBackgroundColor(backgroundColor) fl_action.setBackgroundColor(bottomBackground) tv_shelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground))) - viewModel.bookData.observe(this, Observer { showBook(it) }) - viewModel.chapterListData.observe(this, Observer { upLoading(false, it) }) + viewModel.bookData.observe(this, { showBook(it) }) + viewModel.chapterListData.observe(this, { upLoading(false, it) }) viewModel.initData(intent) initOnClick() } diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index ce8fe76fc..3e4986bde 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.documentfile.provider.DocumentFile -import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book @@ -30,7 +29,7 @@ class BookInfoEditActivity : get() = getViewModel(BookInfoEditViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { - viewModel.bookData.observe(this, Observer { upView(it) }) + viewModel.bookData.observe(this, { upView(it) }) if (viewModel.bookData.value == null) { intent.getStringExtra("bookUrl")?.let { viewModel.loadBook(it) diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 994b7d8ca..86c5e5ecd 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -12,7 +12,6 @@ import android.view.View import androidx.appcompat.widget.PopupMenu import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -114,7 +113,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun initData() { localUriLiveData?.removeObservers(this) localUriLiveData = App.db.bookDao().observeLocalUri() - localUriLiveData?.observe(this, Observer { + localUriLiveData?.observe(this, { adapter.upBookHas(it) }) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 22ae62c18..4603a0d33 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -11,7 +11,6 @@ import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -104,7 +103,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private fun initData() { tocRegexLiveData?.removeObservers(viewLifecycleOwner) tocRegexLiveData = App.db.txtTocRule().observeAll() - tocRegexLiveData?.observe(viewLifecycleOwner, Observer { tocRules -> + tocRegexLiveData?.observe(viewLifecycleOwner, { tocRules -> initSelectedName(tocRules) adapter.setItems(tocRules) }) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index acf63099b..681e9aa9e 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -7,7 +7,6 @@ import android.view.View.GONE import android.view.View.VISIBLE import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.flexbox.FlexboxLayoutManager @@ -176,17 +175,17 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } private fun initLiveData() { - App.db.bookSourceDao().liveGroupEnabled().observe(this, Observer { + App.db.bookSourceDao().liveGroupEnabled().observe(this, { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) } upGroupMenu() }) - viewModel.searchBookLiveData.observe(this, Observer { + viewModel.searchBookLiveData.observe(this, { upSearchItems(it) }) - viewModel.isSearchLiveData.observe(this, Observer { + viewModel.isSearchLiveData.observe(this, { if (it) { startSearch() } else { @@ -254,7 +253,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se rv_bookshelf_search.gone() } else { bookData = App.db.bookDao().liveDataSearch(key) - bookData?.observe(this, Observer { + bookData?.observe(this, { if (it.isEmpty()) { tv_book_show.gone() rv_bookshelf_search.gone() @@ -272,7 +271,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } else { App.db.searchKeywordDao().liveDataSearch(key) } - historyData?.observe(this, Observer { + historyData?.observe(this, { historyKeyAdapter.setItems(it) if (it.isEmpty()) { tv_clear_history.invisible() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index da57654f4..c06110f12 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -11,7 +11,6 @@ import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -164,7 +163,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity App.db.bookSourceDao().liveDataSearch("%$searchKey%") } } - bookSourceLiveDate?.observe(this, Observer { data -> + bookSourceLiveDate?.observe(this, { data -> val sourceList = when (sort) { 1 -> data.sortedBy { it.weight } 2 -> data.sortedBy { it.bookSourceName } @@ -179,7 +178,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun initLiveDataGroup() { - App.db.bookSourceDao().liveGroup().observe(this, Observer { + App.db.bookSourceDao().liveGroup().observe(this, { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index b4c8f70d6..3724694d4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -11,7 +11,6 @@ import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -69,7 +68,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } private fun initData() { - App.db.bookSourceDao().liveGroup().observe(viewLifecycleOwner, Observer { + App.db.bookSourceDao().liveGroup().observe(viewLifecycleOwner, { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index f0731f1ed..c03292011 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.main.bookshelf.books import android.os.Bundle import android.view.View import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -106,7 +105,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } - bookshelfLiveData?.observe(this, Observer { list -> + bookshelfLiveData?.observe(this, { list -> val books = when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> list.sortedByDescending { it.latestChapterTime } 2 -> list.sortedBy { it.name } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 334ce9e64..82ccf867f 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View -import androidx.lifecycle.Observer import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.App import io.legado.app.R @@ -56,7 +55,7 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), } private fun initData() { - App.db.rssSourceDao().liveEnabled().observe(viewLifecycleOwner, Observer { + App.db.rssSourceDao().liveEnabled().observe(viewLifecycleOwner, { if (it.isEmpty()) { getViewModelOfActivity(MainViewModel::class.java).initRss() } 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 adc0d5cbb..17d5bcd53 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 @@ -11,7 +11,6 @@ import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -69,7 +68,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter - App.db.replaceRuleDao().liveGroup().observe(viewLifecycleOwner, Observer { + App.db.replaceRuleDao().liveGroup().observe(viewLifecycleOwner, { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 554bf635b..adf9fbb03 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -11,7 +11,6 @@ import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -133,7 +132,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi } else { App.db.replaceRuleDao().liveDataSearch(key) } - replaceRuleLiveData?.observe(this, Observer { + replaceRuleLiveData?.observe(this, { if (dataInit) { setResult(Activity.RESULT_OK) } @@ -146,7 +145,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi } private fun observeGroupData() { - App.db.replaceRuleDao().liveGroup().observe(this, Observer { + App.db.replaceRuleDao().liveGroup().observe(this, { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt index 012a042a9..1ee635f56 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt @@ -11,7 +11,6 @@ import android.widget.EditText import android.widget.PopupWindow import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager -import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.AppConst @@ -71,7 +70,7 @@ class ReplaceEditDialog : BaseDialogFragment(), tool_bar.inflateMenu(R.menu.replace_edit) tool_bar.menu.applyTint(requireContext()) tool_bar.setOnMenuItemClickListener(this) - viewModel.replaceRuleData.observe(viewLifecycleOwner, Observer { + viewModel.replaceRuleData.observe(viewLifecycleOwner, { upReplaceView(it) }) arguments?.let { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index f2329cb84..f9b684592 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.rss.article import android.os.Bundle import android.view.View import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -87,7 +86,7 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme activityViewModel.url?.let { rssArticlesData?.removeObservers(this) rssArticlesData = App.db.rssArticleDao().liveByOriginSort(it, viewModel.sortName) - rssArticlesData?.observe(viewLifecycleOwner, Observer { list -> + rssArticlesData?.observe(viewLifecycleOwner, { list -> adapter.setItems(list) }) } @@ -104,7 +103,7 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme } override fun observeLiveBus() { - viewModel.loadFinally.observe(viewLifecycleOwner, Observer { + viewModel.loadFinally.observe(viewLifecycleOwner, { refresh_recycler_view.stopLoading() if (it) { loadMoreView.startLoad() diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 41fad7292..307374f9f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -8,7 +8,6 @@ import android.view.MenuItem import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter -import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity @@ -30,7 +29,7 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a adapter = TabFragmentPageAdapter(supportFragmentManager) tab_layout.setupWithViewPager(view_pager) view_pager.adapter = adapter - viewModel.titleLiveData.observe(this, Observer { + viewModel.titleLiveData.observe(this, { title_bar.title = it }) viewModel.initData(intent) { @@ -85,7 +84,7 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a } } - private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : + private inner class TabFragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { override fun getItemPosition(`object`: Any): Int { diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index f50329296..09f6d1549 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -2,7 +2,6 @@ package io.legado.app.ui.rss.favorites import android.os.Bundle import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -37,7 +36,7 @@ class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites), private fun initData() { liveData?.removeObservers(this) liveData = App.db.rssStarDao().liveAll() - liveData?.observe(this, Observer { + liveData?.observe(this, { adapter.setItems(it) }) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index e11293cc4..908afa311 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -8,7 +8,6 @@ import android.os.Bundle import android.view.* import android.webkit.* import androidx.core.view.size -import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.lib.theme.DrawableUtils @@ -155,7 +154,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r @SuppressLint("SetJavaScriptEnabled") private fun initLiveData() { - viewModel.contentLiveData.observe(this, Observer { content -> + viewModel.contentLiveData.observe(this, { content -> viewModel.rssArticle?.let { upJavaScriptEnable() val url = NetworkUtils.getAbsoluteURL(it.origin, it.link) @@ -179,7 +178,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } } }) - viewModel.urlLiveData.observe(this, Observer { + viewModel.urlLiveData.observe(this, { upJavaScriptEnable() web_view.loadUrl(it.url, it.headerMap) }) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index 5f78beeda..bfb876e0b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -10,7 +10,6 @@ import android.view.View import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -63,7 +62,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener tv_ok.setTextColor(requireContext().accentColor) tv_ok.visible() tv_ok.onClick { dismiss() } - App.db.rssSourceDao().liveGroup().observe(viewLifecycleOwner, Observer { + App.db.rssSourceDao().liveGroup().observe(viewLifecycleOwner, { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index d28ae94a8..2f9050f37 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -11,7 +11,6 @@ import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -142,7 +141,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } private fun initLiveDataGroup() { - App.db.rssSourceDao().liveGroup().observe(this, Observer { + App.db.rssSourceDao().liveGroup().observe(this, { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(",", ";")) @@ -195,7 +194,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } else { App.db.rssSourceDao().liveSearch("%$key%") } - sourceLiveData?.observe(this, Observer { + sourceLiveData?.observe(this, { val diffResult = DiffUtil .calculateDiff(DiffCallBack(adapter.getItems(), it)) adapter.setItems(it, diffResult)