pull/32/head
kunfei 6 years ago
parent 7d684b6668
commit 684be9ec2d
  1. 58
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt
  3. 52
      app/src/main/res/layout/activity_source_edit.xml
  4. 7
      app/src/main/res/values/strings.xml

@ -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<SourceEditViewModel>() {
private val contentEditList: ArrayList<EditEntity> = ArrayList()
override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) {
initRecyclerView()
initView()
viewModel.sourceLiveData.observe(this, Observer {
upRecyclerView(it)
})
@ -63,9 +65,33 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>() {
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<SourceEditViewModel>() {
}
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<SourceEditViewModel>() {
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<SourceEditViewModel>() {
}
}
}
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)

@ -12,6 +12,10 @@ import kotlinx.android.synthetic.main.item_source_edit.view.*
class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() {
var editEntities: ArrayList<SourceEditActivity.EditEntity> = 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))

@ -38,24 +38,50 @@
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/audio" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_edit_find"
<com.google.android.material.tabs.TabItem
android:id="@+id/item_base"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="@color/tv_text_default"
android:background="@drawable/selector_fillet_btn_bg"
android:text="@string/edit_find" />
android:text="@string/source_tab_base" />
</LinearLayout>
<com.google.android.material.tabs.TabItem
android:id="@+id/item_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_tab_search" />
<com.google.android.material.tabs.TabItem
android:id="@+id/item_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_tab_find" />
<com.google.android.material.tabs.TabItem
android:id="@+id/item_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_tab_info" />
<com.google.android.material.tabs.TabItem
android:id="@+id/item_toc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_tab_toc" />
<com.google.android.material.tabs.TabItem
android:id="@+id/item_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source_tab_content" />
</com.google.android.material.tabs.TabLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"

@ -439,6 +439,13 @@
<string name="tip_padding">Tip边距</string>
<string name="text_letter_spacing">字距</string>
<string name="source_tab_base">基本</string>
<string name="source_tab_search">搜索</string>
<string name="source_tab_find">发现</string>
<string name="source_tab_info">详情</string>
<string name="source_tab_toc">目录</string>
<string name="source_tab_content">内容</string>
<string name="e_ink_mode">E-Ink 模式</string>
<string name="e_ink_mode_detail">去除动画,优化电纸书使用体验</string>
<string name="web_menu">Web服务</string>

Loading…
Cancel
Save