Skip to content

Commit

Permalink
Added a reset button and the foundation for a dice button
Browse files Browse the repository at this point in the history
  • Loading branch information
ToastedLoaf committed Aug 4, 2019
1 parent d9d3495 commit f261e59
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
import kotlinx.android.synthetic.*
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.dialog_dice.*
Expand All @@ -24,10 +25,12 @@ class DiceDialogFragment : DialogFragment() {
// Get the layout inflater
val inflater = requireActivity().layoutInflater
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog_dice, null))
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
builder.run {
setView(inflater.inflate(R.layout.dialog_dice, null))
create()
}

} ?: throw IllegalStateException("Activity cannot be null")
}
}

Expand Down Expand Up @@ -334,13 +337,13 @@ class MainActivity : AppCompatActivity() {
fun menuDice() {
val newFragment = DiceDialogFragment()
newFragment.show(supportFragmentManager, "dice")
val diceImageView = diceDialog.findViewById<ImageView>(R.id.diceImage) as ImageView // this line of code crashes the app
val diceImageView: ImageView = diceDialog.findViewById(R.id.diceImage) // this line of code crashes the app
val drawableRes = when(Random.nextInt(1, 6)){
1 -> R.drawable.dice1
else -> R.drawable.dice2
}
diceImageView.setImageResource(drawableRes)

diceImageView.setImageResource(drawableRes)
}

fun menuReset(v: View) {
Expand Down

0 comments on commit f261e59

Please sign in to comment.