diff --git a/app/src/main/java/net/imshit/aircraftwar/data/account/AccountManager.kt b/app/src/main/java/net/imshit/aircraftwar/data/account/AccountManager.kt
index 2500f25..6590528 100644
--- a/app/src/main/java/net/imshit/aircraftwar/data/account/AccountManager.kt
+++ b/app/src/main/java/net/imshit/aircraftwar/data/account/AccountManager.kt
@@ -57,24 +57,38 @@ object AccountManager {
}
private fun register(account: String, password: String, onSuccess: Runnable, onFail: Runnable) {
- Thread {
- // TODO
- login(account, password, onSuccess, onFail)
- }.start()
+ val requestBody =
+ FormBody.Builder().add("user", account).add("password", encodePassword(password))
+ .build()
+ val request = Request.Builder().url(REGISTER_URL).post(requestBody).build()
+ httpClient.newCall(request).enqueue(object : Callback {
+ override fun onFailure(call: Call, e: IOException) {
+ onFail.run()
+ }
+
+ override fun onResponse(call: Call, response: Response) {
+ if (response.isSuccessful) {
+ // TODO
+ login(account, password, onSuccess, onFail)
+ } else {
+ onFail.run()
+ }
+ }
+ })
}
fun showLoginDialog(context: Context, onSuccess: Runnable, onFail: Runnable) {
- with(MaterialAlertDialogBuilder(context)) {
- with(DialogLoginBinding.inflate(LayoutInflater.from(context), null, false)) {
- val dialogListener = DialogInterface.OnClickListener { _, which ->
- val account = dlTietAc.text.toString()
- val password = dlTietPw.text.toString()
- when (which) {
- DialogInterface.BUTTON_POSITIVE -> ::login
- DialogInterface.BUTTON_NEUTRAL -> ::register
- else -> null
- }?.invoke(account, password, onSuccess, onFail)
- }
+ with(DialogLoginBinding.inflate(LayoutInflater.from(context), null, false)) {
+ val dialogListener = DialogInterface.OnClickListener { _, which ->
+ val account = dlTietAc.text.toString()
+ val password = dlTietPw.text.toString()
+ when (which) {
+ DialogInterface.BUTTON_POSITIVE -> ::login
+ DialogInterface.BUTTON_NEUTRAL -> ::register
+ else -> null
+ }?.invoke(account, password, onSuccess, onFail)
+ }
+ MaterialAlertDialogBuilder(context).run {
setView(root)
setTitle(R.string.dialog_login_title)
setIcon(R.drawable.ic_login_24)
@@ -83,6 +97,7 @@ object AccountManager {
setNegativeButton(android.R.string.cancel, dialogListener)
show()
}
+
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/net/imshit/aircraftwar/gui/MainActivity.kt b/app/src/main/java/net/imshit/aircraftwar/gui/MainActivity.kt
index af1d6fc..02cddbe 100644
--- a/app/src/main/java/net/imshit/aircraftwar/gui/MainActivity.kt
+++ b/app/src/main/java/net/imshit/aircraftwar/gui/MainActivity.kt
@@ -8,6 +8,9 @@ import net.imshit.aircraftwar.databinding.ActivityMainBinding
import net.imshit.aircraftwar.logic.game.Difficulty
class MainActivity : AppCompatActivity() {
+
+ var gameMode = Difficulty.EASY
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -25,15 +28,19 @@ class MainActivity : AppCompatActivity() {
return@setOnMenuItemClickListener true
}
- // setup listener
- amBtnEasy.setOnClickListener {
- GameActivity.actionStart(this@MainActivity, Difficulty.EASY, amSwSound.isChecked)
- }
- amBtnMedium.setOnClickListener {
- GameActivity.actionStart(this@MainActivity, Difficulty.MEDIUM, amSwSound.isChecked)
+ amMbtgMode.addOnButtonCheckedListener { toggleButton, checkedId, isChecked ->
+ if (isChecked) {
+ gameMode = when (checkedId) {
+ R.id.am_btn_easy -> Difficulty.EASY
+ R.id.am_btn_medium -> Difficulty.MEDIUM
+ R.id.am_btn_hard -> Difficulty.HARD
+ else -> Difficulty.EASY
+ }
+ }
}
- amBtnHard.setOnClickListener {
- GameActivity.actionStart(this@MainActivity, Difficulty.HARD, amSwSound.isChecked)
+
+ amBtnOffline.setOnClickListener {
+ GameActivity.actionStart(this@MainActivity, gameMode, amSwSound.isChecked)
}
}
}
diff --git a/app/src/main/res/drawable/ic_public_24.xml b/app/src/main/res/drawable/ic_public_24.xml
new file mode 100644
index 0000000..c5b8e48
--- /dev/null
+++ b/app/src/main/res/drawable/ic_public_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_public_off_24.xml b/app/src/main/res/drawable/ic_public_off_24.xml
new file mode 100644
index 0000000..21ff840
--- /dev/null
+++ b/app/src/main/res/drawable/ic_public_off_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4c43bfb..904d33d 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -17,10 +17,10 @@
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:menu="@menu/main"
- app:subtitle="@string/main_subtitle"
- app:subtitleCentered="true"
app:navigationContentDescription="@string/main_account"
app:navigationIcon="@drawable/ic_account_circle_24"
+ app:subtitle="@string/main_subtitle"
+ app:subtitleCentered="true"
app:title="@string/main_label"
app:titleCentered="true" />
@@ -29,52 +29,84 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+
+
+ app:layout_constraintTop_toTopOf="parent"
+ app:selectionRequired="true"
+ app:singleSelection="true">
-
+
-
+ app:layout_constraintTop_toBottomOf="@id/am_mbtg_mode">
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
index 986da35..be1ab0f 100644
--- a/app/src/main/res/values-en/strings.xml
+++ b/app/src/main/res/values-en/strings.xml
@@ -31,4 +31,6 @@
- %d item selected.
- %d items selected.
+ Play offline
+ Compete online
\ No newline at end of file
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 90095e8..eb2af7c 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -27,6 +27,8 @@
注册
用户信息
返回
+ 单机游戏
+ 在线对战
- 已选中 %d 项
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 90095e8..eb2af7c 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -27,6 +27,8 @@
注册
用户信息
返回
+ 单机游戏
+ 在线对战
- 已选中 %d 项
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a6598e3..8873712 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -31,6 +31,8 @@
注册
用户信息
返回
+ 单机游戏
+ 在线对战
- 已选中 %d 项