Victory!
This commit is contained in:
		
							
								
								
									
										4
									
								
								.idea/assetWizardSettings.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										4
									
								
								.idea/assetWizardSettings.xml
									
									
									
										generated
									
									
									
								
							| @ -65,7 +65,7 @@ | |||||||
|                                 <PersistentState> |                                 <PersistentState> | ||||||
|                                   <option name="values"> |                                   <option name="values"> | ||||||
|                                     <map> |                                     <map> | ||||||
|                                       <entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/action/ic_swap_vert_black_24dp.xml" /> |                                       <entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/social/ic_share_black_24dp.xml" /> | ||||||
|                                     </map> |                                     </map> | ||||||
|                                   </option> |                                   </option> | ||||||
|                                 </PersistentState> |                                 </PersistentState> | ||||||
| @ -76,7 +76,7 @@ | |||||||
|                         <option name="values"> |                         <option name="values"> | ||||||
|                           <map> |                           <map> | ||||||
|                             <entry key="color" value="ffffff" /> |                             <entry key="color" value="ffffff" /> | ||||||
|                             <entry key="outputName" value="ic_swap_vert" /> |                             <entry key="outputName" value="ic_share" /> | ||||||
|                             <entry key="sourceFile" value="C:\Users\adima" /> |                             <entry key="sourceFile" value="C:\Users\adima" /> | ||||||
|                           </map> |                           </map> | ||||||
|                         </option> |                         </option> | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity | |||||||
| import android.support.v7.app.AppCompatDelegate | import android.support.v7.app.AppCompatDelegate | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.arch.lifecycle.ViewModelProviders | import android.arch.lifecycle.ViewModelProviders | ||||||
|  | import android.content.Intent | ||||||
| import android.speech.tts.TextToSpeech | import android.speech.tts.TextToSpeech | ||||||
| import android.support.design.widget.Snackbar | import android.support.design.widget.Snackbar | ||||||
| import android.text.method.LinkMovementMethod | import android.text.method.LinkMovementMethod | ||||||
| @ -53,20 +54,17 @@ class MatchActivity : AppCompatActivity() { | |||||||
|         matchModel = ViewModelProviders.of(this).get(MatchModel::class.java) |         matchModel = ViewModelProviders.of(this).get(MatchModel::class.java) | ||||||
|         matchModel?.let { |         matchModel?.let { | ||||||
|             if (!it.matchStarted) { |             if (!it.matchStarted) { | ||||||
|  |                 intent.apply { | ||||||
|                     it.startMatch( |                     it.startMatch( | ||||||
|                     intent.getStringExtra("player1Name"), |                         getStringExtra("player1Name"), | ||||||
|                     intent.getStringExtra("player2Name"), |                         getStringExtra("player2Name"), | ||||||
|                     intent.getIntExtra("starterId", 0), |                         getIntExtra("starterId", 0), | ||||||
|                     intent.getBooleanExtra("enableTTS", false), |                         getBooleanExtra("enableTTS", false), | ||||||
|                     intent.getBooleanExtra("enableSTT", false) |                         getBooleanExtra("enableSTT", false) | ||||||
|                     ) |                     ) | ||||||
|                 if (it.ttsEnabled) { |  | ||||||
|                     tts = TextToSpeech( |  | ||||||
|                         this, |  | ||||||
|                         TextToSpeech.OnInitListener { |  | ||||||
|                             fun onInit(status: Int) {} |  | ||||||
|                 } |                 } | ||||||
|                     ) |                 if (it.ttsEnabled) { | ||||||
|  |                     tts = TextToSpeech(this, TextToSpeech.OnInitListener { fun onInit(status: Int) {} }) | ||||||
|                 } |                 } | ||||||
|                 Snackbar.make( |                 Snackbar.make( | ||||||
|                     findViewById(R.id.coordinatorLayout), |                     findViewById(R.id.coordinatorLayout), | ||||||
| @ -102,22 +100,19 @@ class MatchActivity : AppCompatActivity() { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun updateUI() { |     fun updateUI() { | ||||||
|         matchModel?.apply { |         matchModel?.let { | ||||||
|             if (matchFinished) { |  | ||||||
|  |  | ||||||
|             } else { |  | ||||||
|             textScore?.text = getString( |             textScore?.text = getString( | ||||||
|                 R.string.score, |                 R.string.score, | ||||||
|                     players[serviceSide].score, |                 it.players[it.serviceSide].score, | ||||||
|                     players[relaunchSide].score |                 it.players[it.relaunchSide].score | ||||||
|             ) |             ) | ||||||
|                 textService?.text = getString(R.string.service, players[serviceSide].name) |             textService?.text = getString(R.string.service, it.players[it.serviceSide].name) | ||||||
|  |  | ||||||
|                 for ((button, player) in buttons.zip(players)) { |             for ((button, player) in buttons.zip(it.players)) { | ||||||
|                 button.text = fromHtml(getString(R.string.button_text, player.name, player.score)) |                 button.text = fromHtml(getString(R.string.button_text, player.name, player.score)) | ||||||
|             } |             } | ||||||
|  |  | ||||||
|                 when (serviceSide) { |             when (it.serviceSide) { | ||||||
|                 0 -> { |                 0 -> { | ||||||
|                     imageViews[0]?.setImageResource(R.drawable.ic_service_0) |                     imageViews[0]?.setImageResource(R.drawable.ic_service_0) | ||||||
|                     imageViews[1]?.setImageResource(0) |                     imageViews[1]?.setImageResource(0) | ||||||
| @ -128,28 +123,43 @@ class MatchActivity : AppCompatActivity() { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|                 undo?.isVisible = when (playId) { |             undo?.isVisible = when (it.playId) { | ||||||
|                 0 -> false |                 0 -> false | ||||||
|                 else -> true |                 else -> true | ||||||
|             } |             } | ||||||
|                 redo?.isVisible = when (playId) { |             redo?.isVisible = when (it.playId) { | ||||||
|                     history.size - 1 -> false |                 it.history.size - 1 -> false | ||||||
|                 else -> true |                 else -> true | ||||||
|             } |             } | ||||||
|  |  | ||||||
|                 if (ttsEnabled) { |             if (it.ttsEnabled) { | ||||||
|  |                 if (it.matchFinished) { | ||||||
|  |                     val (loser, winner) = it.players.sortedBy { player -> player.score } | ||||||
|  |                     tts?.speak( | ||||||
|  |                         getString( | ||||||
|  |                             R.string.victory_speech, | ||||||
|  |                             winner.name, | ||||||
|  |                             winner.score, | ||||||
|  |                             loser.score | ||||||
|  |                         ), | ||||||
|  |                         TextToSpeech.QUEUE_FLUSH, | ||||||
|  |                         hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "Victory") | ||||||
|  |                     ) | ||||||
|  |                 } else { | ||||||
|                     tts?.speak( |                     tts?.speak( | ||||||
|                         getString( |                         getString( | ||||||
|                             R.string.update_score_speech, |                             R.string.update_score_speech, | ||||||
|                             players[serviceSide].score, |                             it.players[it.serviceSide].score, | ||||||
|                             players[relaunchSide].score, |                             it.players[it.relaunchSide].score, | ||||||
|                             players[serviceSide].name |                             it.players[it.serviceSide].name | ||||||
|                         ), |                         ), | ||||||
|                         TextToSpeech.QUEUE_FLUSH, |                         TextToSpeech.QUEUE_FLUSH, | ||||||
|                         hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "MessageId") |                         hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "MessageId") | ||||||
|                     ) |                     ) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             if (it.matchFinished) endMatch() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -166,4 +176,17 @@ class MatchActivity : AppCompatActivity() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fun endMatch() { | ||||||
|  |         matchModel?.let { | ||||||
|  |             startActivity( | ||||||
|  |                 Intent(this, VictoryActivity::class.java).apply { | ||||||
|  |                     putExtra("winnerName", it.players.maxBy{ player -> player.score }?.name) | ||||||
|  |                     putExtra("player1Name", it.players[0].name) | ||||||
|  |                     putExtra("player2Name", it.players[1].name) | ||||||
|  |                     putExtra("score", getString(R.string.score_only, it.players[0].score, it.players[1].score)) | ||||||
|  |                 } | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -53,6 +53,7 @@ class MatchModel : ViewModel() { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun undo() { |     fun undo() { | ||||||
|  |         matchFinished = false | ||||||
|         playId-- |         playId-- | ||||||
|         reloadState() |         reloadState() | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,12 +1,92 @@ | |||||||
| package adrienmalin.pingpoints | package adrienmalin.pingpoints | ||||||
|  |  | ||||||
| import android.support.v7.app.AppCompatActivity | import android.arch.lifecycle.ViewModelProviders | ||||||
|  | import android.content.Context | ||||||
|  | import android.content.Intent | ||||||
| import android.os.Bundle | import android.os.Bundle | ||||||
|  | import android.support.v7.app.AppCompatActivity | ||||||
|  | import android.support.v7.app.AppCompatDelegate | ||||||
|  | import android.view.View | ||||||
|  | import android.widget.TextView | ||||||
|  |  | ||||||
|  |  | ||||||
| class VictoryActivity : AppCompatActivity() { | class VictoryActivity : AppCompatActivity() { | ||||||
|  |  | ||||||
|  |     var victoryModel: VictoryModel? = null | ||||||
|  |  | ||||||
|     override fun onCreate(savedInstanceState: Bundle?) { |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
|  |         AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) | ||||||
|         setContentView(R.layout.activity_victory) |         setContentView(R.layout.activity_victory) | ||||||
|  |         setSupportActionBar(findViewById(R.id.toolbar)) | ||||||
|  |  | ||||||
|  |         val previousMatch = getPreferences(Context.MODE_PRIVATE) | ||||||
|  |  | ||||||
|  |         // Init victoryModel | ||||||
|  |         victoryModel = ViewModelProviders.of(this).get(VictoryModel::class.java) | ||||||
|  |  | ||||||
|  |         victoryModel?.let { | ||||||
|  |             if (!it.matchFinished) { | ||||||
|  |                 it.matchFinished = true | ||||||
|  |                 it.winnerName = intent.getStringExtra("winnerName") | ||||||
|  |                 it.player1Name = intent.getStringExtra("player1Name") | ||||||
|  |                 it.player2Name = intent.getStringExtra("player2Name") | ||||||
|  |                 it.score = intent.getStringExtra("score") | ||||||
|  |  | ||||||
|  |                 it.previousMatches = previousMatch.getString("previousMatches", "") | ||||||
|  |                 previousMatch.edit().apply { | ||||||
|  |                     putString( | ||||||
|  |                         "previousMatches", | ||||||
|  |                         getString( | ||||||
|  |                             R.string.score_names, | ||||||
|  |                             it.player1Name, | ||||||
|  |                             it.score, | ||||||
|  |                             it.player2Name | ||||||
|  |                         ) + '\n' + it.previousMatches | ||||||
|  |                     ) | ||||||
|  |                     commit() | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // UpdateUI | ||||||
|  |             findViewById<TextView>(R.id.congrats).text = getString(R.string.congrats, it.winnerName) | ||||||
|  |             findViewById<TextView>(R.id.scoreNames).text = getString(R.string.score_names, it.player1Name, it.score, it.player2Name) | ||||||
|  |             findViewById<TextView>(R.id.previousMatches).text = it.previousMatches | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     fun newMatch(view: View) { | ||||||
|  |         startActivity( | ||||||
|  |             Intent(this, StarterNameActivity::class.java) | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     fun share(view: View) { | ||||||
|  |         victoryModel?.let { | ||||||
|  |             startActivity( | ||||||
|  |                 Intent().apply { | ||||||
|  |                     action = Intent.ACTION_SEND | ||||||
|  |                     putExtra( | ||||||
|  |                         Intent.EXTRA_SUBJECT, | ||||||
|  |                         getString( | ||||||
|  |                             R.string.share_subject, | ||||||
|  |                             it.player1Name, | ||||||
|  |                             it.player2Name | ||||||
|  |                         ) | ||||||
|  |                     ) | ||||||
|  |                     putExtra( | ||||||
|  |                         Intent.EXTRA_TEXT, | ||||||
|  |                         getString( | ||||||
|  |                             R.string.share_message, | ||||||
|  |                             it.player1Name, | ||||||
|  |                             it.player2Name, | ||||||
|  |                             it.winnerName, | ||||||
|  |                             it.score | ||||||
|  |                         ) | ||||||
|  |                     ) | ||||||
|  |                     type = "text/plain" | ||||||
|  |                 } | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										12
									
								
								app/src/main/java/adrienmalin/pingpoints/VictoryModel.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/src/main/java/adrienmalin/pingpoints/VictoryModel.kt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | package adrienmalin.pingpoints | ||||||
|  |  | ||||||
|  | import android.arch.lifecycle.ViewModel | ||||||
|  |  | ||||||
|  | class VictoryModel : ViewModel() { | ||||||
|  |     var matchFinished: Boolean = false | ||||||
|  |     var winnerName:String = "" | ||||||
|  |     var player1Name = "" | ||||||
|  |     var player2Name = "" | ||||||
|  |     var score = "" | ||||||
|  |     var previousMatches: String = "" | ||||||
|  | } | ||||||
							
								
								
									
										5
									
								
								app/src/main/res/drawable/ic_share.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/src/main/res/drawable/ic_share.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | <vector android:height="24dp" android:tint="#FFFFFF" | ||||||
|  |     android:viewportHeight="24.0" android:viewportWidth="24.0" | ||||||
|  |     android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||||||
|  |     <path android:fillColor="#FF000000" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/> | ||||||
|  | </vector> | ||||||
| @ -25,10 +25,60 @@ | |||||||
|                 android:theme="@style/ThemeOverlay.AppCompat.ActionBar" |                 android:theme="@style/ThemeOverlay.AppCompat.ActionBar" | ||||||
|                 app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:layout_weight="0"/> |                 app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:layout_weight="0"/> | ||||||
|         <TextView |         <TextView | ||||||
|                 android:text="TextView" |  | ||||||
|                 android:layout_width="wrap_content" |                 android:layout_width="wrap_content" | ||||||
|                 android:layout_height="wrap_content" tools:layout_editor_absoluteY="106dp" |                 android:layout_height="wrap_content" | ||||||
|                 tools:layout_editor_absoluteX="57dp" android:id="@+id/textView"/> |                 android:id="@+id/congrats" | ||||||
|  |                 android:textAppearance="@style/TextAppearance.AppCompat.Headline" | ||||||
|  |                 android:layout_marginTop="13dp" app:layout_constraintTop_toBottomOf="@+id/toolbar" | ||||||
|  |                 android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent" | ||||||
|  |                 android:layout_marginRight="8dp" android:layout_marginStart="8dp" | ||||||
|  |                 app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp" | ||||||
|  |                 android:text="@string/congrats"/> | ||||||
|  |         <TextView | ||||||
|  |                 android:text="@string/score_names" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:id="@+id/scoreNames" android:layout_marginTop="8dp" | ||||||
|  |                 app:layout_constraintTop_toBottomOf="@+id/congrats" app:layout_constraintEnd_toEndOf="parent" | ||||||
|  |                 android:layout_marginEnd="8dp" android:layout_marginRight="8dp" | ||||||
|  |                 app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp" | ||||||
|  |                 android:layout_marginStart="8dp" android:textAppearance="@style/TextAppearance.AppCompat.Large"/> | ||||||
|  |         <TextView | ||||||
|  |                 android:text="@string/previous_matches" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:id="@+id/textView3" android:layout_marginTop="24dp" | ||||||
|  |                 app:layout_constraintTop_toBottomOf="@+id/scoreNames" app:layout_constraintEnd_toEndOf="parent" | ||||||
|  |                 android:layout_marginEnd="8dp" android:layout_marginRight="8dp" | ||||||
|  |                 app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="7dp" | ||||||
|  |                 android:layout_marginStart="7dp" | ||||||
|  |                 android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAllCaps="true"/> | ||||||
|  |         <Button | ||||||
|  |                 android:text="@string/new_match" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:id="@+id/button3" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp" | ||||||
|  |                 android:layout_marginRight="8dp" android:layout_marginBottom="8dp" | ||||||
|  |                 app:layout_constraintBottom_toBottomOf="parent" android:drawableStart="@drawable/ic_new_match" | ||||||
|  |                 android:onClick="newMatch"/> | ||||||
|  |         <Button | ||||||
|  |                 android:text="@string/share" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:id="@+id/button4" android:layout_marginBottom="8dp" | ||||||
|  |                 app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" | ||||||
|  |                 android:layout_marginLeft="8dp" android:layout_marginStart="8dp" | ||||||
|  |                 android:drawableStart="@drawable/ic_share" android:onClick="share"/> | ||||||
|  |         <TextView | ||||||
|  |                 android:text="TextView" | ||||||
|  |                 android:layout_width="0dp" | ||||||
|  |                 android:layout_height="0dp" | ||||||
|  |                 android:id="@+id/previousMatches" app:layout_constraintEnd_toEndOf="parent" | ||||||
|  |                 android:layout_marginEnd="8dp" | ||||||
|  |                 android:layout_marginRight="8dp" app:layout_constraintStart_toStartOf="parent" | ||||||
|  |                 android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" | ||||||
|  |                 app:layout_constraintTop_toBottomOf="@+id/textView3" android:layout_marginBottom="8dp" | ||||||
|  |                 android:gravity="center_horizontal" app:layout_constraintBottom_toBottomOf="parent"/> | ||||||
|  |  | ||||||
|     </android.support.constraint.ConstraintLayout> |     </android.support.constraint.ConstraintLayout> | ||||||
|  |  | ||||||
|  | |||||||
| @ -29,4 +29,12 @@ Vous pouvez à tout moment changer la permission dans les paramètres Android." | |||||||
|     <string name="button_hint">Cliquez sur le joueur qui a marqué</string> |     <string name="button_hint">Cliquez sur le joueur qui a marqué</string> | ||||||
|     <string name="redo">Rétablir</string> |     <string name="redo">Rétablir</string> | ||||||
|     <string name="undo">Annuler</string> |     <string name="undo">Annuler</string> | ||||||
|  |     <string name="congrats">Bravo %s !</string> | ||||||
|  |     <string name="previous_matches">Matchs précédents</string> | ||||||
|  |     <string name="new_match">Nouveau match</string> | ||||||
|  |     <string name="share">Partager</string> | ||||||
|  |     <string name="victory_speech">%s gagne par %d à %d.</string> | ||||||
|  |     <string name="share_subject">Match Ping Points : %s contre %s</string> | ||||||
|  |     <string name="share_message">"%s contre %s:\n%s a gagné par %s\nPing Points est disponible sur Google Play\n "</string> | ||||||
|  |     <string name="score_only">%d - %d</string> | ||||||
| </resources> | </resources> | ||||||
| @ -34,4 +34,13 @@ | |||||||
|     <string name="button_hint">Click on the scoring player</string> |     <string name="button_hint">Click on the scoring player</string> | ||||||
|     <string name="undo">Undo</string> |     <string name="undo">Undo</string> | ||||||
|     <string name="redo">Redo</string> |     <string name="redo">Redo</string> | ||||||
|  |     <string name="congrats">Congratulations, %s!</string> | ||||||
|  |     <string name="previous_matches">Previous matches</string> | ||||||
|  |     <string name="new_match">New match</string> | ||||||
|  |     <string name="share">Share</string> | ||||||
|  |     <string name="score_names" translatable="false">%s  %s  %s</string> | ||||||
|  |     <string name="victory_speech">%s wins by %d to %d.</string> | ||||||
|  |     <string name="share_subject">Ping Points Match: %s vs. %s</string> | ||||||
|  |     <string name="share_message">%s vs. %s:\n%s won by %s\nGet Ping Points on Google Play</string> | ||||||
|  |     <string name="score_only">%d - %d</string> | ||||||
| </resources> | </resources> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user