diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 8adac6170..17a7064e9 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -21,5 +21,6 @@ data class RssSource( var ruleDescription: String? = null, var ruleContent: String? = null, var ruleImage: String? = null, - var ruleCategories: String? = null + var ruleCategories: String? = null, + var customOrder: Int = 0 ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/RssSourceActivity.kt index b6707bf0e..0b4240f60 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/RssSourceActivity.kt @@ -1,18 +1,66 @@ package io.legado.app.ui.rss.source import android.os.Bundle +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.ItemTouchHelper +import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.data.entities.RssSource +import io.legado.app.help.ItemTouchCallback +import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.activity_rss_source.* -class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source) { +class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), + RssSourceAdapter.CallBack { + override val viewModel: RssSourceViewModel get() = getViewModel(RssSourceViewModel::class.java) + private lateinit var adapter: RssSourceAdapter + override fun onActivityCreated(savedInstanceState: Bundle?) { } + private fun initRecyclerView() { + ATH.applyEdgeEffectColor(recycler_view) + recycler_view.layoutManager = LinearLayoutManager(this) + recycler_view.addItemDecoration( + DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { + ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { + this.setDrawable(it) + } + }) + adapter = RssSourceAdapter(this, this) + recycler_view.adapter = adapter + val itemTouchCallback = ItemTouchCallback() + itemTouchCallback.onItemTouchCallbackListener = adapter + itemTouchCallback.isCanDrag = true + ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) + } + + override fun del(source: RssSource) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun edit(source: RssSource) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun update(vararg source: RssSource) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun toTop(source: RssSource) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun upOrder() { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/RssSourceAdapter.kt new file mode 100644 index 000000000..a6ef803c4 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/source/RssSourceAdapter.kt @@ -0,0 +1,46 @@ +package io.legado.app.ui.rss.source + +import android.content.Context +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.data.entities.RssSource +import io.legado.app.help.ItemTouchCallback + +class RssSourceAdapter(context: Context, val callBack: CallBack) : + SimpleRecyclerAdapter(context, R.layout.item_rss_source), + ItemTouchCallback.OnItemTouchCallbackListener { + + override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList) { + + } + + + override fun onSwiped(adapterPosition: Int) { + + } + + override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + val srcItem = getItem(srcPosition) + val targetItem = getItem(targetPosition) + if (srcItem != null && targetItem != null) { + if (srcItem.customOrder == targetItem.customOrder) { + callBack.upOrder() + } else { + val srcOrder = srcItem.customOrder + srcItem.customOrder = targetItem.customOrder + targetItem.customOrder = srcOrder + callBack.update(srcItem, targetItem) + } + } + return true + } + + interface CallBack { + fun del(source: RssSource) + fun edit(source: RssSource) + fun update(vararg source: RssSource) + fun toTop(source: RssSource) + fun upOrder() + } +} diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index e884787c0..839d228fb 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -1,27 +1,27 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:contentInsetStartWithNavigation="0dp" + app:contentLayout="@layout/view_search" + app:displayHomeAsUp="true" + app:title="@string/book_source" /> + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:id="@+id/recycler_view" + android:layout_width="match_parent" + android:layout_height="match_parent" /> diff --git a/app/src/main/res/layout/activity_rss_source.xml b/app/src/main/res/layout/activity_rss_source.xml index d829e291c..e3c5bd53e 100644 --- a/app/src/main/res/layout/activity_rss_source.xml +++ b/app/src/main/res/layout/activity_rss_source.xml @@ -1,7 +1,28 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss_source.xml b/app/src/main/res/layout/item_rss_source.xml new file mode 100644 index 000000000..7d9513d98 --- /dev/null +++ b/app/src/main/res/layout/item_rss_source.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f95f3b249..1d20b0eec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -504,5 +504,6 @@ 输入你的WebDav授权密码 输入你的服务器地址 输入你的WebDav账号 + 订阅源