Skip to content

Commit

Permalink
refactor: 清理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-shop committed May 27, 2023
1 parent d1999c8 commit 276ea04
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions app/src/main/java/net/imshit/aircraftwar/gui/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.os.Handler
import android.os.Looper
import android.os.Message
import android.text.InputType
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams
Expand Down Expand Up @@ -35,6 +36,13 @@ class GameActivity : AppCompatActivity() {
}
}

private fun Window.makeFullScreen() {
WindowInsetsControllerCompat(this, this.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.systemBars())
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// 获取配置
Expand All @@ -56,11 +64,7 @@ class GameActivity : AppCompatActivity() {
root.addView(game, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
setContentView(root)
}
// 隐藏任务栏、导航栏
WindowInsetsControllerCompat(window, window.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.systemBars())
}
window.makeFullScreen()
}

private fun onGameOver(gameMode: Difficulty, score: Int) {
Expand All @@ -79,9 +83,7 @@ class GameActivity : AppCompatActivity() {
val listener = DialogInterface.OnClickListener { _, which ->
val scoreInfo: ScoreInfo? = when (which) {
DialogInterface.BUTTON_POSITIVE -> ScoreInfo(
edit.editText?.text.toString(),
score,
LocalDateTime.now().format(
edit.editText?.text.toString(), score, LocalDateTime.now().format(
DateTimeFormatter.ISO_DATE_TIME
)
)
Expand All @@ -91,17 +93,11 @@ class GameActivity : AppCompatActivity() {
ScoreboardActivity.actionStart(this, gameMode, scoreInfo)
this@GameActivity.finish()
}
val dialog = MaterialAlertDialogBuilder(this).setTitle(R.string.game_dialog_title)
MaterialAlertDialogBuilder(this).setTitle(R.string.game_dialog_title)
.setIcon(R.drawable.ic_assignment_turned_in_24)
.setPositiveButton(android.R.string.ok, listener)
.setNegativeButton(android.R.string.cancel, listener).setView(edit).create()
dialog.window?.let {
WindowInsetsControllerCompat(it, it.decorView).apply {
systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.systemBars())
}
}
dialog.show()
.setNegativeButton(android.R.string.cancel, listener).setView(edit).create().apply {
window?.makeFullScreen()
}.show()
}
}

0 comments on commit 276ea04

Please sign in to comment.