Skip to content

Commit

Permalink
add init shuffled to PlayerRoleActivity and margin to RoleDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRezaMousavi committed Mar 22, 2024
1 parent 52f7ca7 commit 6fa1044
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class PlayerRoleActivity : AppCompatActivity() {
binding = ActivityPlayerRoleBinding.inflate(layoutInflater)
setContentView(binding.root)

roleShuffled()

playerRoleAdapter = PlayerRoleAdapter(
SharedData.getPlayers(),
onSelect = { player ->
Expand All @@ -37,7 +39,7 @@ class PlayerRoleActivity : AppCompatActivity() {
binding.peopleRoleToolBar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menuItemRefresh -> {
SharedData.shuffled()
roleShuffled()
Toast.makeText(this, R.string.refresh, Toast.LENGTH_SHORT).show()
true
}
Expand All @@ -48,4 +50,10 @@ class PlayerRoleActivity : AppCompatActivity() {
}
}
}

private fun roleShuffled() {
for (i in 1..2) {
SharedData.shuffled()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class RoleActivity : AppCompatActivity() {
val intent = Intent(this, PlayerRoleActivity::class.java)
startActivity(intent)
} else {
Toast.makeText(this, "Players and Roles doesn't match", Toast.LENGTH_SHORT).show()
Toast.makeText(this, R.string.roles_not_match, Toast.LENGTH_SHORT).show()
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/dialog_role.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_margin="10dp">

<TextView
android:id="@+id/titleText"
Expand Down Expand Up @@ -42,6 +43,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center"
android:text="@string/simple_citizen_desc"
android:textColor="@color/md_theme_onSecondaryContainer"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<string name="settings">تنظیمات</string>

<string name="player_not_enough">حداقل ۳ نفر باید انتخاب کنید</string>
<string name="roles_not_match">Players and Roles doesn\'t match</string>
<string name="select_all">انتخاب همه</string>
<string name="delete_player">حذف بازیکن</string>
<string name="refresh">تازه کردن</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class SharedDataTest {
assertNotEquals(sharedData.getRoles(), roles)
}

@Test
fun test_two_shuffled() {
val roles = arrayListOf(
Role(name = R.string.simple_citizen),
Role(name = R.string.doctor),
Role(name = R.string.detective),
Role(name = R.string.simple_mafia),
Role(name = R.string.godfather),
)
sharedData.setRoles(roles)

sharedData.shuffled()
sharedData.shuffled()

assertNotEquals(sharedData.getRoles(), roles)
}

@Test
fun test_get_role() {
val players = arrayListOf(
Expand Down

0 comments on commit 6fa1044

Please sign in to comment.