kunfei 3 سال پیش
والد
کامیت
e6dda5c810

+ 1 - 0
app/src/main/java/io/legado/app/constant/PreferKey.kt

@@ -13,6 +13,7 @@ object PreferKey {
     const val coverShowAuthor = "coverShowAuthor"
     const val coverShowAuthor = "coverShowAuthor"
     const val coverShowNameN = "coverShowNameN"
     const val coverShowNameN = "coverShowNameN"
     const val coverShowAuthorN = "coverShowAuthorN"
     const val coverShowAuthorN = "coverShowAuthorN"
+    const val remoteServerId = "remoteServerId"
     const val hideStatusBar = "hideStatusBar"
     const val hideStatusBar = "hideStatusBar"
     const val clickActionTL = "clickActionTopLeft"
     const val clickActionTL = "clickActionTopLeft"
     const val clickActionTC = "clickActionTopCenter"
     const val clickActionTC = "clickActionTopCenter"

+ 6 - 0
app/src/main/java/io/legado/app/help/config/AppConfig.kt

@@ -174,6 +174,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
             appCtx.putPrefInt(PreferKey.threadCount, value)
             appCtx.putPrefInt(PreferKey.threadCount, value)
         }
         }
 
 
+    var remoteServerId: Long
+        get() = appCtx.getPrefLong(PreferKey.remoteServerId)
+        set(value) {
+            appCtx.putPrefLong(PreferKey.remoteServerId, value)
+        }
+
     // 添加本地选择的目录
     // 添加本地选择的目录
     var importBookPath: String?
     var importBookPath: String?
         get() = appCtx.getPrefString("importBookPath")
         get() = appCtx.getPrefString("importBookPath")

+ 7 - 5
app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt

@@ -7,6 +7,7 @@ import io.legado.app.constant.BookType
 import io.legado.app.data.appDb
 import io.legado.app.data.appDb
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.help.AppWebDav
 import io.legado.app.help.AppWebDav
+import io.legado.app.help.config.AppConfig
 import io.legado.app.lib.webdav.Authorization
 import io.legado.app.lib.webdav.Authorization
 import io.legado.app.model.analyzeRule.CustomUrl
 import io.legado.app.model.analyzeRule.CustomUrl
 import io.legado.app.model.localBook.LocalBook
 import io.legado.app.model.localBook.LocalBook
@@ -79,12 +80,13 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
 
 
     fun initData(onSuccess: () -> Unit) {
     fun initData(onSuccess: () -> Unit) {
         execute {
         execute {
-            val config = appDb.serverDao.get(10001)?.getConfigJsonObject()
-            if (config != null && config.has("url")) {
-                val url = config.getString("url")
+            val server = appDb.serverDao.get(AppConfig.remoteServerId)
+            val serverConfig = server?.getConfigJsonObject()
+            if (serverConfig != null && serverConfig.has("url")) {
+                val url = serverConfig.getString("url")
                 if (url.isNotBlank()) {
                 if (url.isNotBlank()) {
-                    val user = config.getString("user")
-                    val password = config.getString("password")
+                    val user = serverConfig.getString("user")
+                    val password = serverConfig.getString("password")
                     val authorization = Authorization(user, password)
                     val authorization = Authorization(user, password)
                     remoteBookWebDav = RemoteBookWebDav(url, authorization, 10001)
                     remoteBookWebDav = RemoteBookWebDav(url, authorization, 10001)
                     return@execute
                     return@execute

+ 20 - 2
app/src/main/java/io/legado/app/ui/book/import/remote/ServersDialog.kt

@@ -17,6 +17,7 @@ import io.legado.app.data.appDb
 import io.legado.app.data.entities.Server
 import io.legado.app.data.entities.Server
 import io.legado.app.databinding.DialogRecyclerViewBinding
 import io.legado.app.databinding.DialogRecyclerViewBinding
 import io.legado.app.databinding.ItemServerSelectBinding
 import io.legado.app.databinding.ItemServerSelectBinding
+import io.legado.app.help.config.AppConfig
 import io.legado.app.lib.dialogs.alert
 import io.legado.app.lib.dialogs.alert
 import io.legado.app.lib.theme.backgroundColor
 import io.legado.app.lib.theme.backgroundColor
 import io.legado.app.lib.theme.primaryColor
 import io.legado.app.lib.theme.primaryColor
@@ -25,6 +26,7 @@ import io.legado.app.utils.applyTint
 import io.legado.app.utils.setLayout
 import io.legado.app.utils.setLayout
 import io.legado.app.utils.showDialogFragment
 import io.legado.app.utils.showDialogFragment
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import io.legado.app.utils.viewbindingdelegate.viewBinding
+import io.legado.app.utils.visible
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
 
 
 class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
 class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
@@ -56,6 +58,21 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
         binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
         binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
         binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
         binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
         binding.recyclerView.adapter = adapter
         binding.recyclerView.adapter = adapter
+        binding.tvFooterLeft.text = getString(R.string.text_default)
+        binding.tvFooterLeft.visible()
+        binding.tvFooterLeft.setOnClickListener {
+            AppConfig.remoteServerId = 0
+            dismissAllowingStateLoss()
+        }
+        binding.tvCancel.visible()
+        binding.tvCancel.setOnClickListener {
+            dismissAllowingStateLoss()
+        }
+        binding.tvOk.visible()
+        binding.tvOk.setOnClickListener {
+            AppConfig.remoteServerId = adapter.selectServerId
+            dismissAllowingStateLoss()
+        }
     }
     }
 
 
     private fun initData() {
     private fun initData() {
@@ -81,7 +98,7 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
     inner class ServersAdapter(context: Context) :
     inner class ServersAdapter(context: Context) :
         RecyclerAdapter<Server, ItemServerSelectBinding>(context) {
         RecyclerAdapter<Server, ItemServerSelectBinding>(context) {
 
 
-        private var selectServerId: Long? = null
+        var selectServerId: Long = AppConfig.remoteServerId
 
 
         override fun getViewBinding(parent: ViewGroup): ItemServerSelectBinding {
         override fun getViewBinding(parent: ViewGroup): ItemServerSelectBinding {
             return ItemServerSelectBinding.inflate(inflater, parent, false)
             return ItemServerSelectBinding.inflate(inflater, parent, false)
@@ -90,7 +107,8 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
         override fun registerListener(holder: ItemViewHolder, binding: ItemServerSelectBinding) {
         override fun registerListener(holder: ItemViewHolder, binding: ItemServerSelectBinding) {
             binding.rbServer.setOnCheckedChangeListener { buttonView, isChecked ->
             binding.rbServer.setOnCheckedChangeListener { buttonView, isChecked ->
                 if (buttonView.isPressed && isChecked) {
                 if (buttonView.isPressed && isChecked) {
-                    selectServerId = getItemByLayoutPosition(holder.layoutPosition)?.id
+                    selectServerId = getItemByLayoutPosition(holder.layoutPosition)!!.id
+                    adapter.updateItems(0, itemCount - 1, "upSelect")
                 }
                 }
             }
             }
             binding.ivEdit.setOnClickListener {
             binding.ivEdit.setOnClickListener {

+ 1 - 0
app/src/main/res/layout/dialog_webdav_server.xml

@@ -39,6 +39,7 @@
                 android:id="@+id/et_id"
                 android:id="@+id/et_id"
                 android:layout_width="match_parent"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_height="wrap_content"
+                android:numeric="integer"
                 tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
                 tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
         </io.legado.app.ui.widget.text.TextInputLayout>
         </io.legado.app.ui.widget.text.TextInputLayout>
 
 

+ 1 - 1
app/src/main/res/values-es-rES/strings.xml

@@ -992,7 +992,7 @@
     <string name="download_book_success">Download Success</string>
     <string name="download_book_success">Download Success</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="upload_to_remote">Upload</string>
     <string name="upload_to_remote">Upload</string>
-    <string name="add_remote_book">WebDavBook</string>
+    <string name="add_remote_book">RemoteBook</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="export_pics_file">Export Picture Files</string>
     <string name="export_pics_file">Export Picture Files</string>

+ 1 - 1
app/src/main/res/values-ja-rJP/strings.xml

@@ -995,7 +995,7 @@
     <string name="download_book_success">Download Success</string>
     <string name="download_book_success">Download Success</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="upload_to_remote">Upload</string>
     <string name="upload_to_remote">Upload</string>
-    <string name="add_remote_book">WebDavBook</string>
+    <string name="add_remote_book">RemoteBook</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="export_pics_file">Export Picture Files</string>
     <string name="export_pics_file">Export Picture Files</string>

+ 1 - 1
app/src/main/res/values-pt-rBR/strings.xml

@@ -995,7 +995,7 @@
     <string name="download_book_success">Download Success</string>
     <string name="download_book_success">Download Success</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="upload_to_remote">Upload</string>
     <string name="upload_to_remote">Upload</string>
-    <string name="add_remote_book">WebDavBook</string>
+    <string name="add_remote_book">RemoteBook</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="export_pics_file">Export Picture Files</string>
     <string name="export_pics_file">Export Picture Files</string>

+ 1 - 1
app/src/main/res/values-zh-rHK/strings.xml

@@ -992,7 +992,7 @@
     <string name="download_book_success">Download Success</string>
     <string name="download_book_success">Download Success</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="upload_to_remote">Upload</string>
     <string name="upload_to_remote">Upload</string>
-    <string name="add_remote_book">WebDav书籍</string>
+    <string name="add_remote_book">远程书籍</string>
     <string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
     <string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
     <string name="bitmap_cache_size">图片绘制缓存</string>
     <string name="bitmap_cache_size">图片绘制缓存</string>
     <string name="export_pics_file">TXT导出图片</string>
     <string name="export_pics_file">TXT导出图片</string>

+ 1 - 1
app/src/main/res/values-zh-rTW/strings.xml

@@ -994,7 +994,7 @@
     <string name="download_book_success">下載成功</string>
     <string name="download_book_success">下載成功</string>
     <string name="download_book_fail">下載失敗</string>
     <string name="download_book_fail">下載失敗</string>
     <string name="upload_to_remote">上傳</string>
     <string name="upload_to_remote">上傳</string>
-    <string name="add_remote_book">WebDav書籍</string>
+    <string name="add_remote_book">远程書籍</string>
     <string name="bitmap_cache_size_summary">目前最大快取 %1$s MB</string>
     <string name="bitmap_cache_size_summary">目前最大快取 %1$s MB</string>
     <string name="bitmap_cache_size">圖片繪製快取</string>
     <string name="bitmap_cache_size">圖片繪製快取</string>
     <string name="export_pics_file">TXT匯出圖片</string>
     <string name="export_pics_file">TXT匯出圖片</string>

+ 1 - 1
app/src/main/res/values-zh/strings.xml

@@ -994,7 +994,7 @@
     <string name="download_book_success">下载成功</string>
     <string name="download_book_success">下载成功</string>
     <string name="download_book_fail">下载失败</string>
     <string name="download_book_fail">下载失败</string>
     <string name="upload_to_remote">上传 WebDav</string>
     <string name="upload_to_remote">上传 WebDav</string>
-    <string name="add_remote_book">WebDav 书籍</string>
+    <string name="add_remote_book">远程书籍</string>
     <string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
     <string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
     <string name="bitmap_cache_size">图片绘制缓存</string>
     <string name="bitmap_cache_size">图片绘制缓存</string>
     <string name="export_pics_file">TXT 导出图片</string>
     <string name="export_pics_file">TXT 导出图片</string>

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -996,7 +996,7 @@
     <string name="download_book_success">Download Success</string>
     <string name="download_book_success">Download Success</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="download_book_fail">Download Fail</string>
     <string name="upload_to_remote">Upload</string>
     <string name="upload_to_remote">Upload</string>
-    <string name="add_remote_book">WebDavBook</string>
+    <string name="add_remote_book">RemoteBook</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="bitmap_cache_size">bitmap cache size</string>
     <string name="export_pics_file">Export Picture Files</string>
     <string name="export_pics_file">Export Picture Files</string>