Commit b367ef90 by likorn

RadioButtons are uncheckable after answering

parent 138ec96f
...@@ -9,7 +9,7 @@ android { ...@@ -9,7 +9,7 @@ android {
buildToolsVersion "29.0.2" buildToolsVersion "29.0.2"
defaultConfig { defaultConfig {
applicationId "com.example.quickmax" applicationId "com.example.quickmax"
minSdkVersion 17 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
...@@ -30,8 +30,10 @@ dependencies { ...@@ -30,8 +30,10 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'com.android.support.test:rules:1.0.2' androidTestImplementation 'androidx.test:rules:1.2.0'
} }
...@@ -67,7 +67,7 @@ class MainActivityTest { ...@@ -67,7 +67,7 @@ class MainActivityTest {
@Test @Test
fun fragment_when_time_is_over() { fun fragment_when_time_is_over() {
Thread.sleep(3000) Thread.sleep(4000)
assertNotNull(testRule.activity.supportFragmentManager.fragments.find { assertNotNull(testRule.activity.supportFragmentManager.fragments.find {
f -> f is TimeIsOverFragment }) f -> f is TimeIsOverFragment })
} }
......
...@@ -5,30 +5,29 @@ import android.os.CountDownTimer ...@@ -5,30 +5,29 @@ import android.os.CountDownTimer
import android.view.View import android.view.View
import android.widget.RadioButton import android.widget.RadioButton
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.get
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
var numberSet = NumberSet(4, 3) var numberSet = NumberSet(4, 3)
private var toAcceptAnswer = true
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
addRadioButtons() addRadioButtons()
setTimer() setTimer()
} }
private fun setTimer() { private fun setTimer() {
object : CountDownTimer(3000, 1000) { object : CountDownTimer(4000, 1000) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
tv_time_left.text = (millisUntilFinished / 1000).toString() tv_time_left.text = (millisUntilFinished / 1000).toString()
} }
override fun onFinish() { override fun onFinish() {
makeRadioButtonsUncheckable()
supportFragmentManager supportFragmentManager
.beginTransaction() .beginTransaction()
.add(R.id.main_layout, TimeIsOverFragment.newInstance(), "time_is_over") .add(R.id.main_layout, TimeIsOverFragment.newInstance(), "time_is_over")
...@@ -48,9 +47,6 @@ class MainActivity : AppCompatActivity() { ...@@ -48,9 +47,6 @@ class MainActivity : AppCompatActivity() {
} }
private fun processAnswer(answer: Int) { private fun processAnswer(answer: Int) {
if (!toAcceptAnswer)
return
toAcceptAnswer = false
val responseFragment: Fragment = if (numberSet.isCorrect(answer)) { val responseFragment: Fragment = if (numberSet.isCorrect(answer)) {
ResponseCorrectFragment.newInstance() ResponseCorrectFragment.newInstance()
} else } else
...@@ -60,5 +56,12 @@ class MainActivity : AppCompatActivity() { ...@@ -60,5 +56,12 @@ class MainActivity : AppCompatActivity() {
.beginTransaction() .beginTransaction()
.add(R.id.main_layout, responseFragment, "response") .add(R.id.main_layout, responseFragment, "response")
.commitAllowingStateLoss() .commitAllowingStateLoss()
makeRadioButtonsUncheckable()
}
private fun makeRadioButtonsUncheckable() {
for (i in 0 until radio_group.childCount) {
radio_group[i].isClickable = false
}
} }
} }
...@@ -2,16 +2,32 @@ ...@@ -2,16 +2,32 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="#A80C0000">
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:tint="#F44336" android:tint="#F44336"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toTopOf="@id/textView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:srcCompat="@drawable/ic_timer_big" /> app:srcCompat="@drawable/ic_timer_big" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/time_is_over"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textColor="#F44336"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
<string name="second_max">Выберите второе наибольшее число</string> <string name="second_max">Выберите второе наибольшее число</string>
<string name="response_correct">CORRECT</string> <string name="response_correct">CORRECT</string>
<string name="response_wrong">WRONG</string> <string name="response_wrong">WRONG</string>
<string name="time_is_over">TIME IS OVER</string>
</resources> </resources>
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 sign in to comment