pull/32/head
kunfei 5 years ago
parent 43f43ca31b
commit 7be6e4a278
  1. 1
      app/src/main/AndroidManifest.xml
  2. 38
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt
  4. 8
      app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt
  5. 4
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  6. 2
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  7. 8
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  8. 0
      app/src/main/res/layout/activity_book_source.xml
  9. 19
      app/src/main/res/layout/fragment_rss.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -53,6 +53,7 @@
<activity android:name=".ui.bookinfo.BookInfoActivity" /> <activity android:name=".ui.bookinfo.BookInfoActivity" />
<activity android:name=".ui.bookinfo.BookInfoEditActivity" /> <activity android:name=".ui.bookinfo.BookInfoEditActivity" />
<activity android:name=".ui.sourcedebug.SourceDebugActivity" /> <activity android:name=".ui.sourcedebug.SourceDebugActivity" />
<activity android:name=".ui.booksource.BookSourceActivity" />
<service android:name=".service.CheckSourceService" /> <service android:name=".service.CheckSourceService" />
<service android:name=".service.DownloadService" /> <service android:name=".service.DownloadService" />

@ -1,4 +1,4 @@
package io.legado.app.ui.main.booksource package io.legado.app.ui.booksource
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
@ -14,41 +14,48 @@ import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R 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.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback 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.qrcode.QrCodeActivity
import io.legado.app.ui.sourceedit.SourceEditActivity 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.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSourceAdapter.CallBack, class BookSourceActivity : BaseActivity<BookshelfViewModel>(), BookSourceAdapter.CallBack,
SearchView.OnQueryTextListener { 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 lateinit var adapter: BookSourceAdapter
private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar) setSupportActionBar(toolbar)
initRecyclerView() initRecyclerView()
initDataObserve() initDataObserve()
initSearchView() initSearchView()
} }
override fun onCompatCreateOptionsMenu(menu: Menu) { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_source, menu) 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) { when (item.itemId) {
R.id.action_add_book_source -> { R.id.action_add_book_source -> {
context?.startActivity<SourceEditActivity>() this.startActivity<SourceEditActivity>()
} }
R.id.action_import_book_source_qr -> { R.id.action_import_book_source_qr -> {
context?.startActivity<QrCodeActivity>() this.startActivity<QrCodeActivity>()
} }
R.id.action_select_all -> { R.id.action_select_all -> {
launch(IO) { launch(IO) {
@ -62,13 +69,14 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
} }
} }
} }
return super.onCompatOptionsItemSelected(item)
} }
private fun initRecyclerView() { private fun initRecyclerView() {
recycler_view.layoutManager = LinearLayoutManager(context) recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.addItemDecoration( recycler_view.addItemDecoration(
DividerItemDecoration( DividerItemDecoration(
context, this,
LinearLayoutManager.VERTICAL LinearLayoutManager.VERTICAL
) )
) )
@ -90,10 +98,10 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
} }
private fun initDataObserve(searchKey: String = "") { private fun initDataObserve(searchKey: String = "") {
bookSourceLiveDate?.removeObservers(viewLifecycleOwner) bookSourceLiveDate?.removeObservers(this)
val dataFactory = App.db.bookSourceDao().observeSearch("%$searchKey%") val dataFactory = App.db.bookSourceDao().observeSearch("%$searchKey%")
bookSourceLiveDate = LivePagedListBuilder(dataFactory, 2000).build() 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 { override fun onQueryTextChange(newText: String?): Boolean {
@ -124,6 +132,6 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
} }
override fun edit(bookSource: BookSource) { override fun edit(bookSource: BookSource) {
context?.startActivity<SourceEditActivity>(Pair("data", bookSource.bookSourceUrl)) startActivity<SourceEditActivity>(Pair("data", bookSource.bookSourceUrl))
} }
} }

@ -1,4 +1,4 @@
package io.legado.app.ui.main.booksource package io.legado.app.ui.booksource
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View

@ -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) {
}

@ -18,9 +18,9 @@ import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.main.bookshelf.BookshelfFragment 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.findbook.FindBookFragment
import io.legado.app.ui.main.myconfig.MyConfigFragment 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.getCompatColor
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
@ -103,7 +103,7 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
return when (position) { return when (position) {
0 -> BookshelfFragment() 0 -> BookshelfFragment()
1 -> FindBookFragment() 1 -> FindBookFragment()
2 -> BookSourceFragment() 2 -> RssFragment()
else -> MyConfigFragment() else -> MyConfigFragment()
} }
} }

@ -0,0 +1,2 @@
package io.legado.app.ui.main.rss

@ -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) {
}

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:attachToActivity="false"
app:title="@string/rss" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

@ -33,6 +33,7 @@
<string name="enable">启用</string> <string name="enable">启用</string>
<string name="bookshelf">书架</string> <string name="bookshelf">书架</string>
<string name="rss">订阅</string>
<string name="recent_reading">最近阅读</string> <string name="recent_reading">最近阅读</string>
<string name="last_read">最后阅读</string> <string name="last_read">最后阅读</string>
<string name="read_summary">让阅读成为一种习惯。</string> <string name="read_summary">让阅读成为一种习惯。</string>

Loading…
Cancel
Save