Remove menu, action bar, redo
This commit is contained in:
		| @ -11,8 +11,6 @@ import android.support.design.widget.Snackbar | ||||
| import android.support.v7.app.AppCompatActivity | ||||
| import android.support.v7.app.AppCompatDelegate | ||||
| import android.text.method.LinkMovementMethod | ||||
| import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import android.view.View | ||||
| import android.widget.Button | ||||
| import android.widget.ImageView | ||||
| @ -46,15 +44,12 @@ class MatchActivity : AppCompatActivity() { | ||||
|     var buttons: Array<Button> = emptyArray() | ||||
|     var imageViews: Array<ImageView?> = emptyArray() | ||||
|     var tts: TextToSpeech? = null | ||||
|     var undo: MenuItem? = null | ||||
|     var redo: MenuItem? = null | ||||
|     var numSttCancelled:Int = 0 | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|         AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) | ||||
|         setContentView(R.layout.activity_match) | ||||
|         setSupportActionBar(findViewById(R.id.toolbar)) | ||||
|  | ||||
|         // Set HTML text for icons credits | ||||
|         findViewById<TextView>(R.id.iconsCredit).run { | ||||
| @ -103,31 +98,8 @@ class MatchActivity : AppCompatActivity() { | ||||
|         updateUI() | ||||
|     } | ||||
|  | ||||
|     override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||||
|         menuInflater.inflate(R.menu.match_menu, menu) | ||||
|         undo = menu.findItem(R.id.action_undo) | ||||
|         redo = menu.findItem(R.id.action_redo) | ||||
|         return super.onCreateOptionsMenu(menu) | ||||
|     } | ||||
|  | ||||
|     override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) { | ||||
|         R.id.action_undo -> { | ||||
|             matchModel?.undo() | ||||
|             updateUI() | ||||
|             true | ||||
|         } | ||||
|         R.id.action_redo -> { | ||||
|             matchModel?.redo() | ||||
|             updateUI() | ||||
|             true | ||||
|         } | ||||
|         else -> { | ||||
|             super.onOptionsItemSelected(item) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onBackPressed() { | ||||
|         if (matchModel?.playId == 0) | ||||
|         if (matchModel?.pointId == 0) | ||||
|             super.onBackPressed() | ||||
|         else { | ||||
|             matchModel?.undo() | ||||
| @ -137,15 +109,6 @@ class MatchActivity : AppCompatActivity() { | ||||
|  | ||||
|     fun updateUI() { | ||||
|         matchModel?.apply { | ||||
|             undo?.isVisible = when (playId) { | ||||
|                 0 -> false | ||||
|                 else -> true | ||||
|             } | ||||
|             redo?.isVisible = when (playId) { | ||||
|                 history.size - 1 -> false | ||||
|                 else -> true | ||||
|             } | ||||
|  | ||||
|             textScore?.text = getString( | ||||
|                 R.string.score_score, | ||||
|                 players[serviceSide].score, | ||||
|  | ||||
| @ -12,7 +12,7 @@ class MatchModel : ViewModel() { | ||||
|     var relaunchSide: Int = 1 | ||||
|     var ttsEnabled: Boolean = false | ||||
|     var sttEnabled: Boolean = false | ||||
|     var playId: Int = 0 | ||||
|     var pointId: Int = 0 | ||||
|     var history: MutableList<Point> = ArrayList() | ||||
|  | ||||
|     fun startMatch(player1Name: String, player2Name:String, starterId: Int, enableTTS: Boolean, enableSTT: Boolean) { | ||||
| @ -29,7 +29,7 @@ class MatchModel : ViewModel() { | ||||
|     } | ||||
|  | ||||
|     fun updateScore(scorer: Player) { | ||||
|         playId++ | ||||
|         pointId++ | ||||
|         scorer.score++ | ||||
|         if ((players.sumBy { it.score } % 2 == 0) or (players.all { it.score >= 10 })) { | ||||
|             serviceSide = relaunchSide.also { relaunchSide = serviceSide } | ||||
| @ -45,27 +45,16 @@ class MatchModel : ViewModel() { | ||||
|     } | ||||
|  | ||||
|     fun saveState() { | ||||
|         val play = Point(players.map { it.score }, serviceSide) | ||||
|         if (playId == history.size) { | ||||
|             history.add(play) | ||||
|         val point = Point(players.map { it.score }, serviceSide) | ||||
|         if (pointId == history.size) { | ||||
|             history.add(point) | ||||
|         } else { | ||||
|             history[playId] = play | ||||
|             history = history.subList(0, playId+1).toMutableList() | ||||
|             history[pointId] = point | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fun undo() { | ||||
|         playId-- | ||||
|         reloadState() | ||||
|     } | ||||
|  | ||||
|     fun redo() { | ||||
|         playId++ | ||||
|         reloadState() | ||||
|     } | ||||
|  | ||||
|     fun reloadState() { | ||||
|         history[playId].let{ | ||||
|         history[pointId--].let{ | ||||
|             players.zip(it.score).forEach{(player, score) -> player.score = score} | ||||
|             serviceSide = it.serviceSide | ||||
|             relaunchSide = when(serviceSide) { | ||||
|  | ||||
| @ -32,7 +32,6 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|         setContentView(R.layout.activity_starter_name) | ||||
|         setSupportActionBar(findViewById(R.id.toolbar)) | ||||
|  | ||||
|         // Find views | ||||
|         player1NameInput = findViewById(R.id.player1Name) | ||||
|  | ||||
| @ -20,7 +20,6 @@ class VictoryActivity : AppCompatActivity() { | ||||
|         super.onCreate(savedInstanceState) | ||||
|         AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) | ||||
|         setContentView(R.layout.activity_victory) | ||||
|         setSupportActionBar(findViewById(R.id.toolbar)) | ||||
|  | ||||
|         val previousMatch = getPreferences(Context.MODE_PRIVATE) | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user