diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt index 9d971e7b7..bd5181efa 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt @@ -5,10 +5,12 @@ import android.view.Menu import android.view.MenuItem import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.tabs.TabLayout import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.rule.* +import io.legado.app.utils.GSON import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_source_edit.* import org.jetbrains.anko.toast @@ -28,7 +30,7 @@ class SourceEditActivity : BaseActivity() { private val contentEditList: ArrayList = ArrayList() override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) { - initRecyclerView() + initView() viewModel.sourceLiveData.observe(this, Observer { upRecyclerView(it) }) @@ -63,9 +65,33 @@ class SourceEditActivity : BaseActivity() { return super.onCompatOptionsItemSelected(item) } - private fun initRecyclerView() { + private fun initView() { recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter + tab_layout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + override fun onTabReselected(tab: TabLayout.Tab?) { + + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + + } + + override fun onTabSelected(tab: TabLayout.Tab?) { + setEditEntities(tab?.position) + } + }) + } + + private fun setEditEntities(tabPosition: Int?) { + when (tabPosition) { + 1 -> adapter.editEntities = searchEditList + 2 -> adapter.editEntities = findEditList + 3 -> adapter.editEntities = infoEditList + 4 -> adapter.editEntities = tocEditList + 5 -> adapter.editEntities = contentEditList + else -> adapter.editEntities = sourceEditList + } } private fun upRecyclerView(bookSource: BookSource?) { @@ -141,9 +167,13 @@ class SourceEditActivity : BaseActivity() { } private fun getSource(): BookSource? { - val bookSource = BookSource() - bookSource.enabled = cb_is_enable.isChecked - bookSource.enabledExplore = cb_is_enable_find.isChecked + val source = BookSource() + source.enabled = cb_is_enable.isChecked + source.enabledExplore = cb_is_enable_find.isChecked + viewModel.sourceLiveData.value?.let { + source.customOrder = it.customOrder + source.weight = it.weight + } val searchRule = SearchRule() val exploreRule = ExploreRule() val bookInfoRule = BookInfoRule() @@ -152,11 +182,11 @@ class SourceEditActivity : BaseActivity() { for (entity in sourceEditList) { with(entity) { when (key) { - "bookSourceUrl" -> if (value != null) bookSource.bookSourceUrl = value!! else return null - "bookSourceName" -> if (value != null) bookSource.bookSourceName = value!! else return null - "bookSourceGroup" -> bookSource.bookSourceGroup = value - "loginUrl" -> bookSource.loginUrl = value - "header" -> bookSource.header = value + "bookSourceUrl" -> if (value != null) source.bookSourceUrl = value!! else return null + "bookSourceName" -> if (value != null) source.bookSourceName = value!! else return null + "bookSourceGroup" -> source.bookSourceGroup = value + "loginUrl" -> source.loginUrl = value + "header" -> source.header = value } } } @@ -246,7 +276,13 @@ class SourceEditActivity : BaseActivity() { } } } - return bookSource + source.ruleSearch = GSON.toJson(searchRule) + source.ruleExplore = GSON.toJson(exploreRule) + source.ruleBookInfo = GSON.toJson(bookInfoRule) + source.ruleToc = GSON.toJson(tocRule) + source.ruleContent = GSON.toJson(contentRule) + setEditEntities(tab_layout.selectedTabPosition) + return source } class EditEntity(var key: String, var value: String?, var hint: Int) diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt index e6ecc8891..87f977082 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt @@ -12,6 +12,10 @@ import kotlinx.android.synthetic.main.item_source_edit.view.* class SourceEditAdapter : RecyclerView.Adapter() { var editEntities: ArrayList = ArrayList() + set(value) { + field = value + notifyDataSetChanged() + } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_source_edit, parent, false)) diff --git a/app/src/main/res/layout/activity_source_edit.xml b/app/src/main/res/layout/activity_source_edit.xml index 7724e61eb..332109230 100644 --- a/app/src/main/res/layout/activity_source_edit.xml +++ b/app/src/main/res/layout/activity_source_edit.xml @@ -38,24 +38,50 @@ android:layout_height="wrap_content" android:checked="false" android:text="@string/audio" /> + - + - + android:text="@string/source_tab_base" /> - + + + + + + + + + + + Tip边距 字距 + 基本 + 搜索 + 发现 + 详情 + 目录 + 内容 + E-Ink 模式 去除动画,优化电纸书使用体验 Web服务