pull/32/head
kunfei 5 years ago
parent b2add1b84f
commit 7933563e95
  1. 4
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 12
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  3. 18
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  4. 18
      app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt
  5. 2
      app/src/main/res/values/strings.xml

@ -15,7 +15,7 @@ import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.main.bookshelf.BookshelfFragment import io.legado.app.ui.main.bookshelf.BookshelfFragment
import io.legado.app.ui.main.explore.FindBookFragment import io.legado.app.ui.main.explore.ExploreFragment
import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
@ -83,7 +83,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
override fun getItem(position: Int): Fragment { override fun getItem(position: Int): Fragment {
return when (position) { return when (position) {
0 -> BookshelfFragment() 0 -> BookshelfFragment()
1 -> FindBookFragment() 1 -> ExploreFragment()
2 -> RssFragment() 2 -> RssFragment()
else -> MyFragment() else -> MyFragment()
} }

@ -10,6 +10,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.ACache
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.android.synthetic.main.item_find_book.view.*
@ -19,7 +20,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
class FindBookAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) :
SimpleRecyclerAdapter<BookSource>(context, R.layout.item_find_book) { SimpleRecyclerAdapter<BookSource>(context, R.layout.item_find_book) {
var exIndex = 0 var exIndex = 0
@ -40,9 +41,17 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c
ll_title.onLongClick { ll_title.onLongClick {
val popupMenu = PopupMenu(context, ll_title) val popupMenu = PopupMenu(context, ll_title)
popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit) popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit)
popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top)
popupMenu.menu.add(Menu.NONE, R.id.menu_refresh, Menu.NONE, R.string.refresh)
popupMenu.setOnMenuItemClickListener { popupMenu.setOnMenuItemClickListener {
when (it.itemId) { when (it.itemId) {
R.id.menu_edit -> callBack.editSource(item.bookSourceUrl) R.id.menu_edit -> callBack.editSource(item.bookSourceUrl)
R.id.menu_top -> {
}
R.id.menu_refresh -> {
ACache.get(context, "explore").remove(item.bookSourceUrl)
notifyItemChanged(holder.layoutPosition)
}
} }
true true
} }
@ -91,5 +100,6 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c
fun scrollTo(pos: Int) fun scrollTo(pos: Int)
fun openExplore(sourceUrl: String, title: String, exploreUrl: String) fun openExplore(sourceUrl: String, title: String, exploreUrl: String)
fun editSource(sourceUrl: String) fun editSource(sourceUrl: String)
fun toTop(source: BookSource)
} }
} }

@ -7,18 +7,22 @@ import androidx.lifecycle.Observer
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.VMBaseFragment
import io.legado.app.data.entities.BookSource
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.explore.ExploreShowActivity import io.legado.app.ui.explore.ExploreShowActivity
import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.ui.sourceedit.SourceEditActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.fragment_find_book.* import kotlinx.android.synthetic.main.fragment_find_book.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
class FindBookFragment : BaseFragment(R.layout.fragment_find_book), class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_book),
FindBookAdapter.CallBack { ExploreAdapter.CallBack {
override val viewModel: ExploreViewModel
get() = getViewModel(ExploreViewModel::class.java)
private lateinit var adapter: FindBookAdapter private lateinit var adapter: ExploreAdapter
private lateinit var linearLayoutManager: LinearLayoutManager private lateinit var linearLayoutManager: LinearLayoutManager
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -35,7 +39,7 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book),
ATH.applyEdgeEffectColor(rv_find) ATH.applyEdgeEffectColor(rv_find)
linearLayoutManager = LinearLayoutManager(context) linearLayoutManager = LinearLayoutManager(context)
rv_find.layoutManager = linearLayoutManager rv_find.layoutManager = linearLayoutManager
adapter = FindBookAdapter(requireContext(), this, this) adapter = ExploreAdapter(requireContext(), this, this)
rv_find.adapter = adapter rv_find.adapter = adapter
} }
@ -60,4 +64,8 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book),
override fun editSource(sourceUrl: String) { override fun editSource(sourceUrl: String) {
startActivity<SourceEditActivity>(Pair("data", sourceUrl)) startActivity<SourceEditActivity>(Pair("data", sourceUrl))
} }
override fun toTop(source: BookSource) {
viewModel.topSource(source)
}
} }

@ -0,0 +1,18 @@
package io.legado.app.ui.main.explore
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookSource
class ExploreViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) {
execute {
val minXh = App.db.bookSourceDao().minOrder
bookSource.customOrder = minXh - 1
App.db.bookSourceDao().insert(bookSource)
}
}
}

@ -119,7 +119,7 @@
<string name="read_aloud_t">正在朗读</string> <string name="read_aloud_t">正在朗读</string>
<string name="read_aloud_s">点击打开阅读界面</string> <string name="read_aloud_s">点击打开阅读界面</string>
<string name="text_return">返回</string> <string name="text_return">返回</string>
<string name="refresh">重新加载</string> <string name="refresh">刷新</string>
<string name="start">开始</string> <string name="start">开始</string>
<string name="stop">停止</string> <string name="stop">停止</string>
<string name="pause">暂停</string> <string name="pause">暂停</string>

Loading…
Cancel
Save