Commit 36d944e8 authored by Shaun Burch's avatar Shaun Burch

#8 Display dialog for winner, update credits, disable dismiss player dialog on tap outside.

parent 8977f3d5
Pipeline #23093120 passed with stages
in 7 minutes 23 seconds
......@@ -9,7 +9,7 @@ A sample Tic Tac Toe application in Android.
* Allow the user to start a new game
### Credits
* Icon made by [Freepik](https://www.flaticon.com/authors/freepik) from www.flaticon.com
* Icons made by [Freepik](https://www.flaticon.com/authors/freepik) from www.flaticon.com
### Libraries
* RxJava - https://github.com/ReactiveX/RxJava
......
......@@ -6,8 +6,11 @@ import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -104,6 +107,13 @@ public class AddPlayerDialog extends DialogFragment {
return builder.create();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().setCanceledOnTouchOutside(false);
return super.onCreateView(inflater, container, savedInstanceState);
}
/**
* Handle when there is only one {@link Mark} to choose from.
*
......
......@@ -196,9 +196,8 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
if (update.isWinner()) {
// Disable board on win
ButterKnife.apply(mBoardViews, (view, index) -> view.setClickable(false));
// TODO Dialog
String message = String.format("Player %1s has WON!!", update.getPlayer().getName());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
// Celebrate!
showWinningDialog(update.getPlayer());
return;
}
......@@ -237,4 +236,14 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
startGame();
}
}
private void showWinningDialog(Player player) {
new AlertDialog.Builder(this)
.setTitle(R.string.title_winner)
.setIcon(player.getMark().getValue())
.setView(R.layout.dialog_win)
.setMessage(String.format(getString(R.string.message_win), player.getName()))
.setPositiveButton(R.string.woohoo, null)
.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_win" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -8,7 +8,10 @@
<string name="action_credits">Credits</string>
<string name="ok">OK</string>
<string name="title_credits">Credits</string>
<string name="message_credits">Icon made by Freepik from www.flaticon.com</string>
<string name="message_credits">Icons made by Freepik from www.flaticon.com</string>
<string name="title_winner">Winner!</string>
<string name="woohoo">Woo-hoo!</string>
<string name="message_win">Congratulations, %1s, you have won!</string>
<string-array name="mark_options">
<item>X</item>
<item>O</item>
......
package com.example.tictactoe;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment