This commit is contained in:
kunfei 2023-03-10 17:23:26 +08:00
parent f0f5304ee2
commit 0155358081
12 changed files with 42 additions and 14 deletions

View File

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

View File

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

View File

@ -7,6 +7,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.appDb
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.AppWebDav
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.webdav.Authorization
import io.legado.app.model.analyzeRule.CustomUrl
import io.legado.app.model.localBook.LocalBook
@ -79,12 +80,13 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
fun initData(onSuccess: () -> Unit) {
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()) {
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)
remoteBookWebDav = RemoteBookWebDav(url, authorization, 10001)
return@execute

View File

@ -17,6 +17,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Server
import io.legado.app.databinding.DialogRecyclerViewBinding
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.theme.backgroundColor
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.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
import kotlinx.coroutines.launch
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.addItemDecoration(VerticalDivider(requireContext()))
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() {
@ -81,7 +98,7 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
inner class ServersAdapter(context: Context) :
RecyclerAdapter<Server, ItemServerSelectBinding>(context) {
private var selectServerId: Long? = null
var selectServerId: Long = AppConfig.remoteServerId
override fun getViewBinding(parent: ViewGroup): ItemServerSelectBinding {
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) {
binding.rbServer.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView.isPressed && isChecked) {
selectServerId = getItemByLayoutPosition(holder.layoutPosition)?.id
selectServerId = getItemByLayoutPosition(holder.layoutPosition)!!.id
adapter.updateItems(0, itemCount - 1, "upSelect")
}
}
binding.ivEdit.setOnClickListener {

View File

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

View File

@ -992,7 +992,7 @@
<string name="download_book_success">Download Success</string>
<string name="download_book_fail">Download Fail</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">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>

View File

@ -995,7 +995,7 @@
<string name="download_book_success">Download Success</string>
<string name="download_book_fail">Download Fail</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">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>

View File

@ -995,7 +995,7 @@
<string name="download_book_success">Download Success</string>
<string name="download_book_fail">Download Fail</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">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>

View File

@ -992,7 +992,7 @@
<string name="download_book_success">Download Success</string>
<string name="download_book_fail">Download Fail</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">图片绘制缓存</string>
<string name="export_pics_file">TXT导出图片</string>

View File

@ -994,7 +994,7 @@
<string name="download_book_success">下載成功</string>
<string name="download_book_fail">下載失敗</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">圖片繪製快取</string>
<string name="export_pics_file">TXT匯出圖片</string>

View File

@ -994,7 +994,7 @@
<string name="download_book_success">下载成功</string>
<string name="download_book_fail">下载失败</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">图片绘制缓存</string>
<string name="export_pics_file">TXT 导出图片</string>

View File

@ -996,7 +996,7 @@
<string name="download_book_success">Download Success</string>
<string name="download_book_fail">Download Fail</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">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>