package com.example.ian.titanscout import android.graphics.Color import android.os.Bundle import android.support.design.widget.FloatingActionButton import android.support.v7.app.AlertDialog import android.support.v7.app.AppCompatActivity; import com.google.firebase.firestore.FirebaseFirestore import org.json.JSONObject import com.google.zxing.WriterException import android.graphics.Bitmap import android.widget.* import net.glxn.qrgen.android.QRCode class MatchesTableView : AppCompatActivity() { var shouldShow = true // Reference the database to be used in the rest of the class. val db = FirebaseFirestore.getInstance() var alias = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_matches_table_view) // setSupportActionBar(toolbar) var matches = arrayOf() val TAG = "MainActivity" val docRef = db.collection("appBuilding").document("schedule") docRef.get().addOnSuccessListener { documentSnapshot -> val stringData = documentSnapshot.data.toString() // Get data from the database and process it into an array of Matches. val schedule = Response(stringData).getJSONArray("matches") for (i in 0..(schedule.length() - 1)) { val item = schedule.getJSONObject(i) val reds = Response(item["RED"].toString()) val blues = Response(item["BLUE"].toString()) val redTeams = getTeamArrayFromJSON(reds, "RED") val blueTeams = getTeamArrayFromJSON(blues, "BLUE") matches += Match(i+1, redTeams, blueTeams) } // update the user's alias alias = intent.getStringExtra("alias") updateAlias(alias) val listView = findViewById(R.id.match_list_view) val listItems = arrayOfNulls(matches.size) for (i in 0 until matches.size) { val match = matches[i] listItems[i] = "Match " + match.ind } // val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems) // listView.adapter = adapter val adapter = MatchAdapter(this, matches) listView.adapter = adapter } val fab = findViewById(R.id.fab) fab.setImageResource(R.drawable.qrcodeicon) fab.setColorFilter(Color.parseColor("#FFFFFF")) fab.setOnClickListener { view -> // QR Button pressed if (shouldShow) { try { val bitmap = TextToImageEncode(intent.getStringExtra("auth")) findViewById(R.id.imageView).setImageBitmap(bitmap) } catch (e: WriterException) { e.printStackTrace() } } else { findViewById(R.id.imageView).setImageResource(android.R.color.transparent) } shouldShow = !shouldShow } findViewById