From ddffc25db649272888c891cec80c08f80033ab8c Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sat, 19 Sep 2020 12:42:25 -0400 Subject: [PATCH] implemented dialog --- .../com/wyattjmiller/tictactoeapp/Stats.kt | 10 ++-- .../tictactoeapp/StatsDialogFragment.kt | 53 ++++++++++++++++++- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wyattjmiller/tictactoeapp/Stats.kt b/app/src/main/java/com/wyattjmiller/tictactoeapp/Stats.kt index 749e13e..fb1be6b 100644 --- a/app/src/main/java/com/wyattjmiller/tictactoeapp/Stats.kt +++ b/app/src/main/java/com/wyattjmiller/tictactoeapp/Stats.kt @@ -1,11 +1,11 @@ package com.wyattjmiller.tictactoeapp class Stats { - private var mGamesPlayed: Int = 0 - private var mGamesWonX: Int = 0 - private var mGamesWonO: Int = 0 - private var mGamesCats: Int = 0 - private var mGamePiecesPlaced: Int = 0 + var mGamesPlayed: Int = 0 + var mGamesWonX: Int = 0 + var mGamesWonO: Int = 0 + var mGamesCats: Int = 0 + var mGamePiecesPlaced: Int = 0 fun updateGamesPlayed() { mGamesPlayed++ diff --git a/app/src/main/java/com/wyattjmiller/tictactoeapp/StatsDialogFragment.kt b/app/src/main/java/com/wyattjmiller/tictactoeapp/StatsDialogFragment.kt index 190d249..fc8b4c5 100644 --- a/app/src/main/java/com/wyattjmiller/tictactoeapp/StatsDialogFragment.kt +++ b/app/src/main/java/com/wyattjmiller/tictactoeapp/StatsDialogFragment.kt @@ -1,4 +1,55 @@ package com.wyattjmiller.tictactoeapp -class StatsDialogFragment { +import android.app.Dialog +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.TextView +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.Fragment +import org.w3c.dom.Text + +class StatsDialogFragment(): DialogFragment() { + private lateinit var mGameTitle: TextView + private lateinit var mGamesPlayedTextView: TextView + private lateinit var mGamesWonXTextView: TextView + private lateinit var mGamesWonOTextView: TextView + private lateinit var mGamesCatsTextView: TextView + private lateinit var mGamePiecesPlacedTextView: TextView + private lateinit var mDismissButton: Button + private lateinit var mStats: Stats + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val builder = AlertDialog.Builder(this.activity!!) + val dialogView = activity!!.layoutInflater.inflate(R.layout.dialog_stats, null) + + mGameTitle = dialogView.findViewById(R.id.gameStatsTitle) + mGamesPlayedTextView = dialogView.findViewById(R.id.gamesPlayedTextView) + mGamesWonXTextView = dialogView.findViewById(R.id.gamesWonXTextView) + mGamesWonOTextView = dialogView.findViewById(R.id.gamesWonOTextView) + mGamesCatsTextView = dialogView.findViewById(R.id.gamesCatsTextView) + mGamePiecesPlacedTextView = dialogView.findViewById(R.id.gamePiecesPlacedTextView) + mDismissButton = dialogView.findViewById(R.id.dismissButton) + + mGamesPlayedTextView.text = "Games Played: ${mStats.mGamesPlayed.toString()}" + mGamesWonXTextView.text = "Games Won - X: ${mStats.mGamesWonX.toString()}" + mGamesWonOTextView.text = "Games Won - O: ${mStats.mGamesWonO.toString()}" + mGamesCatsTextView.text = "Games Cats: ${mStats.mGamesCats.toString()}" + mGamePiecesPlacedTextView.text = "Games Pieces Placed: ${mStats.mGamePiecesPlaced.toString()}" + + builder.setView(dialogView) + + mDismissButton.setOnClickListener { + dismiss() + } + + return builder.create() + } + + fun sendStats(statPresent: Stats) { + mStats = statPresent + } } \ No newline at end of file