From 7be6e4a27897e6ec234457efee8d070fdbfd5380 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 27 Jul 2019 20:34:05 +0800 Subject: [PATCH] up --- app/src/main/AndroidManifest.xml | 1 + .../BookSourceActivity.kt} | 38 +++++++++++-------- .../booksource/BookSourceAdapter.kt | 2 +- .../app/ui/booksource/BookSourceViewModel.kt | 8 ++++ .../io/legado/app/ui/main/MainActivity.kt | 4 +- .../io/legado/app/ui/main/rss/RssAdapter.kt | 2 + .../io/legado/app/ui/main/rss/RssFragment.kt | 8 ++++ ...ok_source.xml => activity_book_source.xml} | 0 app/src/main/res/layout/fragment_rss.xml | 19 ++++++++++ app/src/main/res/values/strings.xml | 1 + 10 files changed, 65 insertions(+), 18 deletions(-) rename app/src/main/java/io/legado/app/ui/{main/booksource/BookSourceFragment.kt => booksource/BookSourceActivity.kt} (74%) rename app/src/main/java/io/legado/app/ui/{main => }/booksource/BookSourceAdapter.kt (98%) create mode 100644 app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt create mode 100644 app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt create mode 100644 app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt rename app/src/main/res/layout/{fragment_book_source.xml => activity_book_source.xml} (100%) create mode 100644 app/src/main/res/layout/fragment_rss.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9111a5a68..db32747e6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ + diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt similarity index 74% rename from app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt rename to app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index d223cf8b4..ceb1d28da 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.main.booksource +package io.legado.app.ui.booksource import android.os.Bundle import android.view.Menu @@ -14,41 +14,48 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R -import io.legado.app.base.BaseFragment +import io.legado.app.base.BaseActivity import io.legado.app.data.entities.BookSource import io.legado.app.help.ItemTouchCallback +import io.legado.app.ui.bookshelf.BookshelfViewModel import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.sourceedit.SourceEditActivity -import kotlinx.android.synthetic.main.fragment_book_source.* +import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.activity_book_source.* import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import org.jetbrains.anko.startActivity -class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSourceAdapter.CallBack, +class BookSourceActivity : BaseActivity(), BookSourceAdapter.CallBack, SearchView.OnQueryTextListener { + override val viewModel: BookshelfViewModel + get() = getViewModel(BookshelfViewModel::class.java) + override val layoutID: Int + get() = R.layout.activity_book_source private lateinit var adapter: BookSourceAdapter private var bookSourceLiveDate: LiveData>? = null - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - setSupportToolbar(toolbar) + override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) { + setSupportActionBar(toolbar) initRecyclerView() initDataObserve() initSearchView() } - override fun onCompatCreateOptionsMenu(menu: Menu) { + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.book_source, menu) + return super.onCompatCreateOptionsMenu(menu) } - override fun onCompatOptionsItemSelected(item: MenuItem) { + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_add_book_source -> { - context?.startActivity() + this.startActivity() } R.id.action_import_book_source_qr -> { - context?.startActivity() + this.startActivity() } R.id.action_select_all -> { launch(IO) { @@ -62,13 +69,14 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour } } } + return super.onCompatOptionsItemSelected(item) } private fun initRecyclerView() { - recycler_view.layoutManager = LinearLayoutManager(context) + recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.addItemDecoration( DividerItemDecoration( - context, + this, LinearLayoutManager.VERTICAL ) ) @@ -90,10 +98,10 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour } private fun initDataObserve(searchKey: String = "") { - bookSourceLiveDate?.removeObservers(viewLifecycleOwner) + bookSourceLiveDate?.removeObservers(this) val dataFactory = App.db.bookSourceDao().observeSearch("%$searchKey%") bookSourceLiveDate = LivePagedListBuilder(dataFactory, 2000).build() - bookSourceLiveDate?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) + bookSourceLiveDate?.observe(this, Observer { adapter.submitList(it) }) } override fun onQueryTextChange(newText: String?): Boolean { @@ -124,6 +132,6 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour } override fun edit(bookSource: BookSource) { - context?.startActivity(Pair("data", bookSource.bookSourceUrl)) + startActivity(Pair("data", bookSource.bookSourceUrl)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt rename to app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt index 2bf43bb1b..60680e083 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.main.booksource +package io.legado.app.ui.booksource import android.view.LayoutInflater import android.view.View diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt new file mode 100644 index 000000000..d7b798bea --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt @@ -0,0 +1,8 @@ +package io.legado.app.ui.booksource + +import android.app.Application +import io.legado.app.base.BaseViewModel + +class BookSourceViewModel(application: Application) : BaseViewModel(application) { + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 1dd6f395d..954bd4692 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -18,9 +18,9 @@ import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.main.bookshelf.BookshelfFragment -import io.legado.app.ui.main.booksource.BookSourceFragment import io.legado.app.ui.main.findbook.FindBookFragment import io.legado.app.ui.main.myconfig.MyConfigFragment +import io.legado.app.ui.main.rss.RssFragment import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefInt import io.legado.app.utils.getViewModel @@ -103,7 +103,7 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavig return when (position) { 0 -> BookshelfFragment() 1 -> FindBookFragment() - 2 -> BookSourceFragment() + 2 -> RssFragment() else -> MyConfigFragment() } } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt new file mode 100644 index 000000000..192f436ee --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -0,0 +1,2 @@ +package io.legado.app.ui.main.rss + 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 new file mode 100644 index 000000000..712c1f945 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -0,0 +1,8 @@ +package io.legado.app.ui.main.rss + +import io.legado.app.R +import io.legado.app.base.BaseFragment + +class RssFragment : BaseFragment(R.layout.fragment_rss) { + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_book_source.xml b/app/src/main/res/layout/activity_book_source.xml similarity index 100% rename from app/src/main/res/layout/fragment_book_source.xml rename to app/src/main/res/layout/activity_book_source.xml diff --git a/app/src/main/res/layout/fragment_rss.xml b/app/src/main/res/layout/fragment_rss.xml new file mode 100644 index 000000000..3d9e9a4b5 --- /dev/null +++ b/app/src/main/res/layout/fragment_rss.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a6cb98462..5736d0bf8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,6 +33,7 @@ 启用 书架 + 订阅 最近阅读 最后阅读 让阅读成为一种习惯。