parent
							
								
									24fb8dbcfa
								
							
						
					
					
						commit
						c056b5d3f1
					
				| @ -0,0 +1,50 @@ | ||||
| package io.legado.app.ui.book.search | ||||
| 
 | ||||
| import io.legado.app.data.appDb | ||||
| import io.legado.app.data.entities.BookSource | ||||
| 
 | ||||
| /** | ||||
|  * 搜索范围 | ||||
|  */ | ||||
| data class SearchScope( | ||||
|     private val groups: List<String>? = null, | ||||
|     private val sources: List<BookSource>? = null | ||||
| ) { | ||||
| 
 | ||||
|     /** | ||||
|      * 搜索范围显示 | ||||
|      */ | ||||
|     fun getShowNames(): List<String> { | ||||
|         val list = arrayListOf<String>() | ||||
|         groups?.let { | ||||
|             list.addAll(it) | ||||
|         } | ||||
|         sources?.forEach { | ||||
|             list.add(it.bookSourceName) | ||||
|         } | ||||
|         if (list.isEmpty()) { | ||||
|             list.add("全部书源") | ||||
|         } | ||||
|         return list | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 搜索范围书源 | ||||
|      */ | ||||
|     fun getBookSources(): List<BookSource> { | ||||
|         val list = hashSetOf<BookSource>() | ||||
|         sources?.let { | ||||
|             list.addAll(sources) | ||||
|         } | ||||
|         groups?.forEach { group -> | ||||
|             appDb.bookSourceDao.getEnabledByGroup(group).let { | ||||
|                 list.addAll(it) | ||||
|             } | ||||
|         } | ||||
|         if (list.isEmpty()) { | ||||
|             return appDb.bookSourceDao.allEnabled | ||||
|         } | ||||
|         return list.sortedBy { it.customOrder } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,31 @@ | ||||
| package io.legado.app.ui.book.search | ||||
| 
 | ||||
| import android.content.Context | ||||
| import android.view.ViewGroup | ||||
| import io.legado.app.base.adapter.ItemViewHolder | ||||
| import io.legado.app.base.adapter.RecyclerAdapter | ||||
| import io.legado.app.databinding.ItemFilletTextBinding | ||||
| 
 | ||||
| class SearchScopeAdapter(context: Context) : | ||||
|     RecyclerAdapter<String, ItemFilletTextBinding>(context) { | ||||
| 
 | ||||
|     override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding { | ||||
|         return ItemFilletTextBinding.inflate(inflater, parent, false) | ||||
|     } | ||||
| 
 | ||||
|     override fun convert( | ||||
|         holder: ItemViewHolder, | ||||
|         binding: ItemFilletTextBinding, | ||||
|         item: String, | ||||
|         payloads: MutableList<Any> | ||||
|     ) { | ||||
|         binding.run { | ||||
|             textView.text = item | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue