|
|
@ -1,8 +1,10 @@ |
|
|
|
package io.legado.app.ui.rss.source.manage |
|
|
|
package io.legado.app.ui.rss.source.manage |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.widget.PopupMenu |
|
|
|
import android.widget.PopupMenu |
|
|
|
|
|
|
|
import androidx.core.os.bundleOf |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
@ -10,6 +12,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.help.ItemTouchCallback |
|
|
|
import io.legado.app.help.ItemTouchCallback |
|
|
|
import io.legado.app.lib.theme.backgroundColor |
|
|
|
import io.legado.app.lib.theme.backgroundColor |
|
|
|
|
|
|
|
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper |
|
|
|
import kotlinx.android.synthetic.main.item_rss_source.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_rss_source.view.* |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
@ -24,7 +27,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : |
|
|
|
getItems().forEach { |
|
|
|
getItems().forEach { |
|
|
|
selected.add(it) |
|
|
|
selected.add(it) |
|
|
|
} |
|
|
|
} |
|
|
|
notifyItemRangeChanged(0, itemCount, 1) |
|
|
|
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) |
|
|
|
callBack.upCountView() |
|
|
|
callBack.upCountView() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -36,7 +39,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : |
|
|
|
selected.add(it) |
|
|
|
selected.add(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
notifyItemRangeChanged(0, itemCount, 1) |
|
|
|
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) |
|
|
|
callBack.upCountView() |
|
|
|
callBack.upCountView() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -52,7 +55,8 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : |
|
|
|
|
|
|
|
|
|
|
|
override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList<Any>) { |
|
|
|
override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList<Any>) { |
|
|
|
with(holder.itemView) { |
|
|
|
with(holder.itemView) { |
|
|
|
if (payloads.isEmpty()) { |
|
|
|
val bundle = payloads.getOrNull(0) as? Bundle |
|
|
|
|
|
|
|
if (bundle == null) { |
|
|
|
this.setBackgroundColor(context.backgroundColor) |
|
|
|
this.setBackgroundColor(context.backgroundColor) |
|
|
|
if (item.sourceGroup.isNullOrEmpty()) { |
|
|
|
if (item.sourceGroup.isNullOrEmpty()) { |
|
|
|
cb_source.text = item.sourceName |
|
|
|
cb_source.text = item.sourceName |
|
|
@ -63,9 +67,18 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : |
|
|
|
swt_enabled.isChecked = item.enabled |
|
|
|
swt_enabled.isChecked = item.enabled |
|
|
|
cb_source.isChecked = selected.contains(item) |
|
|
|
cb_source.isChecked = selected.contains(item) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
when (payloads[0]) { |
|
|
|
bundle.keySet().map { |
|
|
|
1 -> cb_source.isChecked = selected.contains(item) |
|
|
|
when (it) { |
|
|
|
2 -> swt_enabled.isChecked = item.enabled |
|
|
|
"name", "group" -> |
|
|
|
|
|
|
|
if (item.sourceGroup.isNullOrEmpty()) { |
|
|
|
|
|
|
|
cb_source.text = item.sourceName |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cb_source.text = |
|
|
|
|
|
|
|
String.format("%s (%s)", item.sourceName, item.sourceGroup) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
"selected" -> cb_source.isChecked = selected.contains(item) |
|
|
|
|
|
|
|
"enabled" -> swt_enabled.isChecked = item.enabled |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -147,6 +160,32 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback { |
|
|
|
|
|
|
|
return object : DragSelectTouchHelper.AdvanceCallback<RssSource>(Mode.ToggleAndReverse) { |
|
|
|
|
|
|
|
override fun currentSelectedId(): MutableSet<RssSource> { |
|
|
|
|
|
|
|
return selected |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun getItemId(position: Int): RssSource { |
|
|
|
|
|
|
|
return getItem(position)!! |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun updateSelectState(position: Int, isSelected: Boolean): Boolean { |
|
|
|
|
|
|
|
getItem(position)?.let { |
|
|
|
|
|
|
|
if (isSelected) { |
|
|
|
|
|
|
|
selected.add(it) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
selected.remove(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
notifyItemChanged(position, bundleOf(Pair("selected", null))) |
|
|
|
|
|
|
|
callBack.upCountView() |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun del(source: RssSource) |
|
|
|
fun del(source: RssSource) |
|
|
|
fun edit(source: RssSource) |
|
|
|
fun edit(source: RssSource) |
|
|
|