pull/94/head
kunfei 5 years ago
parent c023444ff9
commit 461da74963
  1. 50
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  3. 6
      app/src/main/res/layout/activity_arrange_book.xml
  4. 42
      app/src/main/res/layout/activity_book_source.xml
  5. 6
      app/src/main/res/layout/activity_import_book.xml
  6. 10
      app/src/main/res/menu/book_source.xml
  7. 2
      app/src/main/res/values/strings.xml

@ -36,6 +36,7 @@ import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_source.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
@ -61,6 +62,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
initSearchView()
initLiveDataBookSource()
initLiveDataGroup()
initViewEvent()
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
@ -81,8 +83,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_import_source_local -> selectFileSys()
R.id.menu_select_all -> adapter.selectAll()
R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection())
R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection())
@ -142,11 +142,11 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
App.db.bookSourceDao().liveDataSearch("%$searchKey%")
}
bookSourceLiveDate?.observe(this, Observer {
search_view.queryHint = getString(R.string.search_book_source_num, it.size)
val diffResult = DiffUtil
.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), it))
adapter.setItems(it, false)
diffResult.dispatchUpdatesTo(adapter)
upCountView()
})
}
@ -160,6 +160,16 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
})
}
private fun initViewEvent() {
cb_selected_all.onClick {
adapter.selectAll()
}
btn_revert_selection.onClick {
adapter.revertSelection()
}
}
private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group)
groups.map {
@ -230,6 +240,40 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
)
}
override fun upCountView() {
val selectCount = adapter.getSelection().size
if (selectCount == 0) {
cb_selected_all.isChecked = false
} else {
cb_selected_all.isChecked = selectCount >= adapter.getActualItemCount()
}
//重置全选的文字
if (cb_selected_all.isChecked) {
cb_selected_all.text = getString(
R.string.select_cancel_count,
selectCount,
adapter.getActualItemCount()
)
} else {
cb_selected_all.text = getString(
R.string.select_all_count,
selectCount,
adapter.getActualItemCount()
)
}
setMenuClickable(selectCount > 0)
}
private fun setMenuClickable(isClickable: Boolean) {
//设置是否可删除
btn_delete.isEnabled = isClickable
btn_delete.isClickable = isClickable
//设置是否可添加书籍
btn_revert_selection.isEnabled = isClickable
btn_revert_selection.isClickable = isClickable
}
override fun onFilePicked(requestCode: Int, currentPath: String) {
if (requestCode == importSource) {
Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show()

@ -27,6 +27,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
selected.add(it)
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun revertSelection() {
@ -38,6 +39,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
}
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView()
}
fun getSelection(): LinkedHashSet<BookSource> {
@ -73,6 +75,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} else {
selected.remove(item)
}
callBack.upCountView()
}
iv_edit.onClick { callBack.edit(item) }
iv_menu_more.onClick {
@ -140,5 +143,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
fun update(vararg bookSource: BookSource)
fun toTop(bookSource: BookSource)
fun upOrder()
fun upCountView()
}
}

@ -42,16 +42,16 @@
android:layout_margin="5dp"
android:padding="5dp"
android:gravity="center"
android:minWidth="100dp"
android:minWidth="90dp"
android:text="@string/move_to_group" />
<io.legado.app.lib.theme.view.ATEAccentStrokeTextView
android:id="@+id/btn_delete"
android:layout_width="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:minWidth="100dp"
android:minWidth="90dp"
android:gravity="center"
android:text="@string/delete" />

@ -16,7 +16,8 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="0dp"
android:layout_weight="1">
<io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
android:id="@+id/recycler_view"
@ -25,5 +26,44 @@
</FrameLayout>
<!--文件点击按钮-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:gravity="center_vertical"
android:padding="6dp"
android:elevation="2dp">
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_selected_all"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/select_all_count"
android:textColor="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATEAccentStrokeTextView
android:id="@+id/btn_revert_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:gravity="center"
android:minWidth="90dp"
android:text="@string/revert_selection" />
<io.legado.app.lib.theme.view.ATEAccentStrokeTextView
android:id="@+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:minWidth="90dp"
android:gravity="center"
android:text="@string/delete" />
</LinearLayout>
</LinearLayout>

@ -93,16 +93,16 @@
android:layout_margin="5dp"
android:padding="5dp"
android:gravity="center"
android:minWidth="100dp"
android:minWidth="90dp"
android:text="@string/add_to_shelf" />
<io.legado.app.lib.theme.view.ATEAccentStrokeTextView
android:id="@+id/btn_delete"
android:layout_width="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:minWidth="100dp"
android:minWidth="90dp"
android:gravity="center"
android:text="@string/delete" />

@ -12,16 +12,6 @@
<menu>
<item
android:id="@+id/menu_select_all"
android:title="@string/select_all"
app:showAsAction="never" />
<item
android:id="@+id/menu_revert_selection"
android:title="@string/revert_selection"
app:showAsAction="never" />
<item
android:id="@+id/menu_enable_selection"
android:title="@string/enable_selection"

@ -327,7 +327,7 @@
<string name="volume_key_page_on_play">朗读时音量键翻页</string>
<string name="tip_margin_change">Tip边距跟随边距调整</string>
<string name="allow_update">允许更新</string>
<string name="revert_selection"></string>
<string name="revert_selection">反选</string>
<string name="search_book_key">搜索书名、作者</string>
<string name="debug_hint">书名、作者、URL</string>
<string name="faq">常见问题</string>

Loading…
Cancel
Save