diff --git a/apps/android/main/AndroidManifest.xml b/apps/android/main/AndroidManifest.xml new file mode 100644 index 00000000..47609081 --- /dev/null +++ b/apps/android/main/AndroidManifest.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/android/main/java/com/example/ian/titanscout/Match.kt b/apps/android/main/java/com/example/ian/titanscout/Match.kt new file mode 100644 index 00000000..de3a6614 --- /dev/null +++ b/apps/android/main/java/com/example/ian/titanscout/Match.kt @@ -0,0 +1,31 @@ +package com.example.ian.titanscout + + +class Match (var ind: Int, var redTeams: Array, var blueTeams: Array) { + // class body + + fun getScouts(): Int { + var x = 0 + for (red in redTeams) { + if (red.hasScouts()) { + x++ + } + } + for (blue in blueTeams) { + if (blue.hasScouts()) { + x++ + } + } + return x + } +} + +class Team (var num: String, var color:String, var scouts:Array) { + + fun hasScouts() : Boolean { + if (scouts.size > 0 && !scouts[0].equals("")) { + return true + } + return false + } +} \ No newline at end of file diff --git a/apps/android/main/java/com/example/ian/titanscout/MatchAdapter.kt b/apps/android/main/java/com/example/ian/titanscout/MatchAdapter.kt new file mode 100644 index 00000000..647917bb --- /dev/null +++ b/apps/android/main/java/com/example/ian/titanscout/MatchAdapter.kt @@ -0,0 +1,58 @@ +package com.example.ian.titanscout + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.ProgressBar +import android.widget.TextView + +class MatchAdapter(private val context: Context, + private val dataSource: Array) : BaseAdapter() { + + private val inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + + //1 + override fun getCount(): Int { + return dataSource.size + } + + //2 + override fun getItem(position: Int): Any { + return dataSource[position] + } + + //3 + override fun getItemId(position: Int): Long { + return position.toLong() + } + + //4 + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + // Get view for row item + val rowView = inflater.inflate(R.layout.list_item, parent, false) + + + // Get title element + val titleTextView = rowView.findViewById(R.id.titleTV) as TextView + + // Get subtitle element + val subtitleTextView = rowView.findViewById(R.id.subtitle) as TextView + + // Get progressBar element + val progressBar = rowView.findViewById(R.id.progressBar) as ProgressBar + + val match = getItem(position) as Match + + val str = "Match " + match.ind + titleTextView.text = str + val str2 = match.getScouts().toString() + " of 6" + subtitleTextView.text = str2 + progressBar.progress = (1.0 * progressBar.max * match.getScouts() / (6.0)).toInt() + + return rowView + } + + +} \ No newline at end of file diff --git a/apps/android/main/java/com/example/ian/titanscout/MatchesTableView.kt b/apps/android/main/java/com/example/ian/titanscout/MatchesTableView.kt new file mode 100644 index 00000000..df7c58c7 --- /dev/null +++ b/apps/android/main/java/com/example/ian/titanscout/MatchesTableView.kt @@ -0,0 +1,188 @@ +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