Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Mar 12, 2023
1 parent d70dee1 commit 2623b9a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.legado.app.ui.book.import.remote

import android.content.DialogInterface
import android.os.Bundle
import android.text.InputType
import android.view.MenuItem
Expand All @@ -18,7 +17,6 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.GSON
import io.legado.app.utils.applyTint
import io.legado.app.utils.setLayout
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.json.JSONObject

Expand Down Expand Up @@ -57,7 +55,7 @@ class ServerConfigDialog() : BaseDialogFragment(R.layout.dialog_webdav_server, t

override fun onMenuItemClick(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_save -> getServer()?.let {
R.id.menu_save -> getServer().let {
viewModel.save(it) {
dismissAllowingStateLoss()
}
Expand Down Expand Up @@ -107,7 +105,7 @@ class ServerConfigDialog() : BaseDialogFragment(R.layout.dialog_webdav_server, t
}
}

private fun getServer(): Server? {
private fun getServer(): Server {
val server = viewModel.mServer?.copy() ?: Server()
server.name = binding.etName.text.toString()
server.type = when (binding.spType.selectedItemPosition) {
Expand All @@ -130,16 +128,4 @@ class ServerConfigDialog() : BaseDialogFragment(R.layout.dialog_webdav_server, t
return data
}


// override fun onDismiss(dialog: DialogInterface) {
// super.onDismiss(dialog)
// ((parentFragment as? Callback) ?: (activity as? Callback))
// ?.onDialogDismiss("serverConfig")
// }

// interface Callback {

// fun onDialogDismiss(tag: String)

// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class ServerConfigViewModel(application: Application): BaseViewModel(application
var mServer: Server? = null

fun init(id: Long?, onSuccess: () -> Unit) {
//mServer不为空可能是旋转屏幕界面重新创建,不用更新数据
if (mServer != null) return
execute {
if (mServer == null && id != null) {
if (id != null) {
mServer = appDb.serverDao.get(id)
mServer
} else {
null
mServer = Server()
}
}.onSuccess {
onSuccess.invoke()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/dialog_webdav_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:background="@color/background_menu"
android:elevation="5dp"
android:theme="?attr/actionBarStyle"
Expand Down

0 comments on commit 2623b9a

Please sign in to comment.