Skip to content

Commit

Permalink
feat: 登录界面
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-shop committed May 25, 2023
1 parent df40803 commit 43255b7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,46 @@ package net.imshit.aircraftwar.data.account

import android.content.Context
import android.content.DialogInterface
import android.view.LayoutInflater
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import net.imshit.aircraftwar.R
import net.imshit.aircraftwar.databinding.DialogLoginBinding
import java.net.URL

object AccountManager {
fun showLoginDialog(context: Context, onSuccess: Runnable) {
val dialogListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEGATIVE -> {}
DialogInterface.BUTTON_POSITIVE -> {
// TODO()
onSuccess.run()
}
private const val SALT = "HITsz520"
private val REMOTE = URL("https://haxiaoshen.top/")

fun login(account: String, password: String, onSuccess: Runnable) {
// TODO
onSuccess.run()
}

DialogInterface.BUTTON_NEUTRAL -> {
// TODO()
onSuccess.run()
fun register(account: String, password: String, onSuccess: Runnable) {
// TODO
login(account, password, onSuccess)
}

fun showLoginDialog(context: Context, onSuccess: Runnable) {
with(MaterialAlertDialogBuilder(context)) {
with(DialogLoginBinding.inflate(LayoutInflater.from(context), null, false)) {
val dialogListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_POSITIVE -> ::login
DialogInterface.BUTTON_NEUTRAL -> ::register
else -> null
}?.invoke(
dlTietAc.text.toString(), dlTietPw.text.toString(), onSuccess
)
}
setView(root)
setTitle(R.string.dialog_login_title)
setIcon(R.drawable.ic_login_24)
setPositiveButton(android.R.string.ok, dialogListener)
setNeutralButton(R.string.dialog_login_button_register, dialogListener)
setNegativeButton(android.R.string.cancel, dialogListener)
show()
}
}
MaterialAlertDialogBuilder(context).setTitle(R.string.dialog_login_title)
.setIcon(R.drawable.ic_login_24).setPositiveButton(android.R.string.ok, dialogListener)
.setNeutralButton(R.string.dialog_login_button_register, dialogListener)
.setNegativeButton(android.R.string.cancel, dialogListener)
.setView(R.layout.dialog_login).show()
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/layout/dialog_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textPersonName"
android:id="@+id/dl_tiet_ac"
tools:text="NAME" />

</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -43,6 +44,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:id="@+id/dl_tiet_pw"
tools:text="PASSWORD" />

</com.google.android.material.textfield.TextInputLayout>
Expand Down

0 comments on commit 43255b7

Please sign in to comment.