try to make viewmodel work
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -9,3 +9,4 @@ | ||||
| /build | ||||
| /captures | ||||
| .externalNativeBuild | ||||
| *.ser | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								.idea/caches/build_file_checksums.ser
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.idea/caches/build_file_checksums.ser
									
									
									
										generated
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -12,7 +12,6 @@ android { | ||||
|         targetSdkVersion 28 | ||||
|         versionCode 1 | ||||
|         versionName "1.0" | ||||
|         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||||
|         vectorDrawables.useSupportLibrary true | ||||
|     } | ||||
|     buildTypes { | ||||
| @ -24,15 +23,13 @@ android { | ||||
| } | ||||
|  | ||||
| dependencies { | ||||
|     def lifecycle_version = "2.0.0" | ||||
|  | ||||
|     implementation fileTree(dir: 'libs', include: ['*.jar']) | ||||
|     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||||
|     implementation 'com.android.support:appcompat-v7:28.0.0' | ||||
|     implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||||
|     implementation 'com.android.support:design:28.0.0' | ||||
|     implementation "androidx.lifecycle:lifecycle-extensions-ktx:$lifecycle_version" | ||||
|     testImplementation 'junit:junit:4.12' | ||||
|     androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||||
|     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||||
|     implementation 'com.android.support:support-v4:28.0.0' | ||||
|     implementation 'android.arch.lifecycle:extensions:1.1.1' | ||||
|     annotationProcessor 'android.arch.lifecycle:compiler:1.1.1' | ||||
|     implementation 'com.android.support:design:28.0.0' | ||||
| } | ||||
|  | ||||
| @ -1,24 +0,0 @@ | ||||
| package adrienmalin.pingpoints | ||||
|  | ||||
| import android.support.test.InstrumentationRegistry | ||||
| import android.support.test.runner.AndroidJUnit4 | ||||
|  | ||||
| import org.junit.Test | ||||
| import org.junit.runner.RunWith | ||||
|  | ||||
| import org.junit.Assert.* | ||||
|  | ||||
| /** | ||||
|  * Instrumented test, which will execute on an Android device. | ||||
|  * | ||||
|  * See [testing documentation](http://d.android.com/tools/testing). | ||||
|  */ | ||||
| @RunWith(AndroidJUnit4::class) | ||||
| class ExampleInstrumentedTest { | ||||
|     @Test | ||||
|     fun useAppContext() { | ||||
|         // Context of the app under test. | ||||
|         val appContext = InstrumentationRegistry.getTargetContext() | ||||
|         assertEquals("adrienmalin.pingpoints", appContext.packageName) | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								app/src/main/java/adrienmalin/pingpoints/Html.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/src/main/java/adrienmalin/pingpoints/Html.kt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| package adrienmalin.pingpoints | ||||
|  | ||||
| import android.os.Build | ||||
| import android.text.Html | ||||
|  | ||||
|  | ||||
| fun Html.fromHtml2(source: String) { | ||||
|     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||||
|         Html.fromHtml(source, Html.FROM_HTML_MODE_COMPACT) | ||||
|     } else { | ||||
|         Html.fromHtml(source) | ||||
|     } | ||||
| } | ||||
| @ -9,16 +9,39 @@ import android.arch.lifecycle.ViewModelProviders | ||||
|  | ||||
| class MatchActivity : AppCompatActivity() { | ||||
|  | ||||
|     var textScore: android.widget.TextView? = null | ||||
|     var textService: android.widget.TextView? = null | ||||
|     var buttons: Array<Button> = emptyArray() | ||||
|     var imageViews: Array<ImageView?> = emptyArray() | ||||
|     var matchModel: MatchModel? = null | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|         AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) | ||||
|         setContentView(R.layout.activity_match) | ||||
|         setSupportActionBar(findViewById(R.id.toolbar)) | ||||
|         val matchModel = ViewModelProviders.of(this).get(MatchModel::class.java) | ||||
|         textScore = findViewById(R.id.textScore) | ||||
|         textService = findViewById(R.id.textService) | ||||
|         buttons = arrayOf( | ||||
|             findViewById(R.id.buttonPlayer0), | ||||
|             findViewById(R.id.buttonPlayer1) | ||||
|         ) | ||||
|         imageViews = arrayOf( | ||||
|             findViewById(R.id.imgService0), | ||||
|             findViewById(R.id.imgService1) | ||||
|         ) | ||||
|         updateUI() | ||||
|     } | ||||
|  | ||||
|     fun updateUI() { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     fun updateScore(view: View) { | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,16 +1,19 @@ | ||||
| package adrienmalin.pingpoints | ||||
|  | ||||
| import android.arch.lifecycle.LiveData | ||||
| import android.arch.lifecycle.MutableLiveData | ||||
| import android.arch.lifecycle.ViewModel | ||||
|  | ||||
|  | ||||
| class MatchModel : ViewModel() { | ||||
|     lateinit var players: List<Player> | ||||
|     lateinit var server: Int | ||||
|     lateinit var ttsEnabled: Boolean | ||||
|     lateinit var sttEnabled: Boolean | ||||
|     var players: List<Player> = emptyList() | ||||
|     var serverId: Int = 0 | ||||
|     var ttsEnabled: Boolean = false | ||||
|     var sttEnabled: Boolean = false | ||||
|  | ||||
|     fun startMatch(player1Name: String, player2Name:String, starterId: Int, enableTTS: Boolean, enableSTT: Boolean) { | ||||
|         players = listOf(Player(player1Name), Player(player2Name)) | ||||
|         server = starterId | ||||
|         serverId = starterId | ||||
|         ttsEnabled = enableTTS | ||||
|         sttEnabled = enableSTT | ||||
|     } | ||||
|  | ||||
| @ -14,6 +14,7 @@ import android.support.v4.app.ActivityCompat | ||||
| import android.support.v4.content.ContextCompat | ||||
| import android.support.v7.app.AlertDialog | ||||
| import android.support.v7.app.AppCompatActivity | ||||
| import android.text.Html | ||||
| import android.text.method.LinkMovementMethod | ||||
| import android.view.View | ||||
| import android.widget.* | ||||
| @ -39,7 +40,7 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|         setSupportActionBar(findViewById(R.id.toolbar)) | ||||
|         // Set HTML text for icons credits | ||||
|         findViewById<TextView>(R.id.iconsCredit).run { | ||||
|             setHtmlText(getString(R.string.iconCredits)) | ||||
|             setText(Html.fromHtml2(getString(R.string.iconCredits))) | ||||
|             movementMethod = LinkMovementMethod.getInstance() | ||||
|         } | ||||
|         // Find views | ||||
|  | ||||
							
								
								
									
										7
									
								
								app/src/main/res/drawable/ic_left_service.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/src/main/res/drawable/ic_left_service.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| <vector | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:autoMirrored="true" | ||||
|     android:height="48dp" android:width="48dp" | ||||
|     android:viewportHeight="285.876" android:viewportWidth="285.876"> | ||||
|     <path android:fillColor="#FFFFFF" android:pathData="M261.207,76.226c-8.573,9.43 -20.236,13.134 -27.668,9.293c0.605,6.751 -3.436,13.287 -10.141,15.544c-18.231,6.139 -37.408,9.21 -56.583,9.21c-10.257,0 -20.512,-0.885 -30.624,-2.643c15.289,20.576 39.358,32.753 65.156,32.753c8.284,0 15,6.716 15,15s-6.716,15 -15,15c-32.82,0 -63.598,-14.394 -84.591,-39.029l-26.497,44.097c30.164,25.599 53.935,55.258 70.763,88.411c3.749,7.387 0.801,16.415 -6.587,20.165c-2.176,1.104 -4.494,1.627 -6.777,1.627c-5.47,0 -10.742,-3.002 -13.388,-8.214c-14.607,-28.78 -35.188,-54.695 -61.282,-77.281c-3.667,27.708 -13.553,54.145 -29.537,78.86c-2.871,4.438 -7.69,6.855 -12.609,6.855c-2.792,0 -5.614,-0.778 -8.132,-2.406c-6.957,-4.499 -8.935,-13.785 -4.436,-20.741c17.485,-27.035 26.365,-56.402 26.365,-87.284v-3.058c0,-4.645 0.568,-9.303 3.111,-13.535L92.94,83.63c6.162,-13.495 19.867,-12.797 26.78,-11.028l0.941,0.311c30.074,9.922 63.158,9.825 93.164,-0.28c4.559,-1.533 9.328,-0.743 13.052,1.715c-0.392,-6.599 2.662,-14.617 8.781,-21.348c9.621,-10.583 23.14,-13.963 30.195,-7.549C272.908,51.864 270.828,65.643 261.207,76.226zM244.508,138.119c-4.768,0 -8.632,3.865 -8.632,8.632s3.865,8.632 8.632,8.632c4.768,0 8.632,-3.865 8.632,-8.632S249.276,138.119 244.508,138.119zM121.3,62.781c17.337,0 31.391,-14.054 31.391,-31.391S138.636,0 121.3,0c-17.337,0 -31.391,14.054 -31.391,31.391S103.963,62.781 121.3,62.781z"/> | ||||
| </vector> | ||||
							
								
								
									
										7
									
								
								app/src/main/res/drawable/ic_right_service.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/src/main/res/drawable/ic_right_service.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| <vector | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:autoMirrored="true" | ||||
|     android:height="48dp" android:width="48dp" | ||||
|     android:viewportHeight="285.876" android:viewportWidth="285.876"> | ||||
|     <path android:fillColor="#ffffff" android:pathData="m24.693,76.226c8.573,9.43 20.236,13.134 27.668,9.293 -0.605,6.751 3.436,13.287 10.141,15.544 18.231,6.139 37.408,9.21 56.583,9.21 10.257,0 20.512,-0.885 30.624,-2.643 -15.289,20.576 -39.358,32.753 -65.156,32.753 -8.284,0 -15,6.716 -15,15 -0,8.284 6.716,15 15,15 32.82,0 63.598,-14.394 84.591,-39.029l26.497,44.097c-30.164,25.599 -53.935,55.258 -70.763,88.411 -3.749,7.387 -0.801,16.415 6.587,20.165 2.176,1.104 4.494,1.627 6.777,1.627 5.47,0 10.742,-3.002 13.388,-8.214 14.607,-28.78 35.188,-54.695 61.282,-77.281 3.667,27.708 13.553,54.145 29.537,78.86 2.871,4.438 7.69,6.855 12.609,6.855 2.792,0 5.614,-0.778 8.132,-2.406 6.957,-4.499 8.935,-13.785 4.436,-20.741 -17.485,-27.035 -26.365,-56.402 -26.365,-87.284l-0,-3.058c-0,-4.645 -0.568,-9.303 -3.111,-13.535L192.96,83.63c-6.162,-13.495 -19.867,-12.797 -26.78,-11.028l-0.941,0.311c-30.074,9.922 -63.158,9.825 -93.164,-0.28 -4.559,-1.533 -9.328,-0.743 -13.052,1.715 0.392,-6.599 -2.662,-14.617 -8.781,-21.348 -9.621,-10.583 -23.14,-13.963 -30.195,-7.549 -7.055,6.413 -4.975,20.192 4.646,30.775zM41.392,138.119c4.768,0 8.632,3.865 8.632,8.632 -0,4.767 -3.865,8.632 -8.632,8.632 -4.768,0 -8.632,-3.865 -8.632,-8.632 -0,-4.767 3.864,-8.632 8.632,-8.632zM164.6,62.781c-17.337,0 -31.391,-14.054 -31.391,-31.391C133.209,14.053 147.264,0 164.6,0 181.937,0 195.991,14.054 195.991,31.391c-0,17.337 -14.054,31.39 -31.391,31.39z"/> | ||||
| </vector> | ||||
| @ -73,7 +73,7 @@ | ||||
|                 android:orientation="horizontal"> | ||||
|  | ||||
|             <ImageView | ||||
|                     android:id="@+id/imgService1" | ||||
|                     android:id="@+id/imgService0" | ||||
|                     android:layout_width="48dp" | ||||
|                     android:layout_margin="8dp" | ||||
|                     android:layout_weight="0" | ||||
| @ -82,7 +82,7 @@ | ||||
|                     tools:layout_editor_absoluteY="120dp" android:layout_height="match_parent"/> | ||||
|  | ||||
|             <Button | ||||
|                     android:id="@+id/buttonPlayer1" | ||||
|                     android:id="@+id/buttonPlayer0" | ||||
|                     style="@style/Widget.AppCompat.Button.Colored" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
| @ -99,12 +99,12 @@ | ||||
|                     android:textSize="24sp" | ||||
|                     android:textStyle="bold" | ||||
|                     app:layout_constraintBottom_toBottomOf="parent" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/imgService1" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/imgService0" | ||||
|                     app:layout_constraintTop_toTopOf="parent" | ||||
|                     tools:text="@string/button_text" android:layout_marginRight="8dp"/> | ||||
|  | ||||
|             <Button | ||||
|                     android:id="@+id/buttonPlayer2" | ||||
|                     android:id="@+id/buttonPlayer1" | ||||
|                     style="@style/Widget.AppCompat.Button.Colored" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
| @ -123,12 +123,12 @@ | ||||
|                     android:textSize="24sp" | ||||
|                     android:textStyle="bold" | ||||
|                     app:layout_constraintBottom_toBottomOf="parent" | ||||
|                     app:layout_constraintEnd_toStartOf="@+id/imgService2" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/buttonPlayer1" | ||||
|                     app:layout_constraintEnd_toStartOf="@+id/imgService1" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/buttonPlayer0" | ||||
|                     tools:text="@string/button_text"/> | ||||
|  | ||||
|             <ImageView | ||||
|                     android:id="@+id/imgService2" | ||||
|                     android:id="@+id/imgService1" | ||||
|                     android:layout_width="48dp" | ||||
|                     android:layout_height="match_parent" | ||||
|                     android:layout_margin="8dp" | ||||
|  | ||||
| @ -72,7 +72,7 @@ | ||||
|                 android:orientation="vertical"> | ||||
|  | ||||
|             <ImageView | ||||
|                     android:id="@+id/imgService1" | ||||
|                     android:id="@+id/imgService0" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="48dp" | ||||
|                     android:layout_margin="8dp" | ||||
| @ -82,7 +82,7 @@ | ||||
|                     tools:layout_editor_absoluteY="120dp"/> | ||||
|  | ||||
|             <Button | ||||
|                     android:id="@+id/buttonPlayer1" | ||||
|                     android:id="@+id/buttonPlayer0" | ||||
|                     style="@style/Widget.AppCompat.Button.Colored" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
| @ -96,12 +96,12 @@ | ||||
|                     android:textSize="24sp" | ||||
|                     android:textStyle="bold" | ||||
|                     app:layout_constraintBottom_toBottomOf="parent" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/imgService1" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/imgService0" | ||||
|                     app:layout_constraintTop_toTopOf="parent" | ||||
|                     tools:text="@string/button_text" android:layout_margin="8dp"/> | ||||
|  | ||||
|             <Button | ||||
|                     android:id="@+id/buttonPlayer2" | ||||
|                     android:id="@+id/buttonPlayer1" | ||||
|                     style="@style/Widget.AppCompat.Button.Colored" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
| @ -116,12 +116,12 @@ | ||||
|                     android:textSize="24sp" | ||||
|                     android:textStyle="bold" | ||||
|                     app:layout_constraintBottom_toBottomOf="parent" | ||||
|                     app:layout_constraintEnd_toStartOf="@+id/imgService2" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/buttonPlayer1" | ||||
|                     app:layout_constraintEnd_toStartOf="@+id/imgService1" | ||||
|                     app:layout_constraintStart_toEndOf="@+id/buttonPlayer0" | ||||
|                     tools:text="@string/button_text" android:layout_margin="8dp"/> | ||||
|  | ||||
|             <ImageView | ||||
|                     android:id="@+id/imgService2" | ||||
|                     android:id="@+id/imgService1" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="48dp" | ||||
|                     android:layout_margin="8dp" | ||||
|  | ||||
| @ -1,17 +0,0 @@ | ||||
| package adrienmalin.pingpoints | ||||
|  | ||||
| import org.junit.Test | ||||
|  | ||||
| import org.junit.Assert.* | ||||
|  | ||||
| /** | ||||
|  * Example local unit test, which will execute on the development machine (host). | ||||
|  * | ||||
|  * See [testing documentation](http://d.android.com/tools/testing). | ||||
|  */ | ||||
| class ExampleUnitTest { | ||||
|     @Test | ||||
|     fun addition_isCorrect() { | ||||
|         assertEquals(4, 2 + 2) | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user