try to make viewmodel work

This commit is contained in:
adrienmalin
2018-12-03 22:25:24 +01:00
parent ef230d5520
commit 621c035c74
13 changed files with 79 additions and 68 deletions

View 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)
}
}

View File

@ -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) {
}
}

View File

@ -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
}

View File

@ -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