mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Removed next button in quiz (#4382)
* issues resolved * modification done * warning fixed * issues resolved * Button added * don't know function added * Button added * modification done * modification done
This commit is contained in:
parent
2ae0cd2c72
commit
8db381885b
3 changed files with 83 additions and 93 deletions
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.quiz;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
|
@ -26,14 +26,22 @@ public class QuizActivity extends AppCompatActivity {
|
|||
@BindView(R.id.question_image) SimpleDraweeView imageView;
|
||||
@BindView(R.id.question_text) TextView questionText;
|
||||
@BindView(R.id.question_title) TextView questionTitle;
|
||||
@BindView(R.id.quiz_positive_answer) RadioButton positiveAnswer;
|
||||
@BindView(R.id.quiz_negative_answer) RadioButton negativeAnswer;
|
||||
@BindView(R.id.quiz_positive_answer) Button positiveAnswer;
|
||||
@BindView(R.id.quiz_negative_answer) Button negativeAnswer;
|
||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||
|
||||
private QuizController quizController = new QuizController();
|
||||
private ArrayList<QuizQuestion> quiz = new ArrayList<>();
|
||||
private int questionIndex = 0;
|
||||
private int score;
|
||||
/**
|
||||
* isPositiveAnswerChecked : represents yes click event
|
||||
*/
|
||||
private boolean isPositiveAnswerChecked;
|
||||
/**
|
||||
* isNegativeAnswerChecked : represents no click event
|
||||
*/
|
||||
private boolean isNegativeAnswerChecked;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -43,25 +51,23 @@ public class QuizActivity extends AppCompatActivity {
|
|||
quizController.initialize(this);
|
||||
ButterKnife.bind(this);
|
||||
setSupportActionBar(toolbar);
|
||||
positiveAnswer = findViewById(R.id.quiz_positive_answer);
|
||||
negativeAnswer = findViewById(R.id.quiz_negative_answer);
|
||||
displayQuestion();
|
||||
}
|
||||
|
||||
/**
|
||||
* to move to next question and check whether answer is selected or not
|
||||
*/
|
||||
@OnClick(R.id.next_button)
|
||||
public void setNextQuestion(){
|
||||
if ( questionIndex <= quiz.size() && (positiveAnswer.isChecked() || negativeAnswer.isChecked())) {
|
||||
if ( questionIndex <= quiz.size() && (isPositiveAnswerChecked || isNegativeAnswerChecked)) {
|
||||
evaluateScore();
|
||||
} else if ( !positiveAnswer.isChecked() && !negativeAnswer.isChecked()){
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(getResources().getString(R.string.warning));
|
||||
alert.setMessage(getResources().getString(R.string.warning_for_no_answer));
|
||||
alert.setPositiveButton(R.string.continue_message, (dialog, which) -> dialog.dismiss());
|
||||
AlertDialog dialog = alert.create();
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.next_button)
|
||||
public void notKnowAnswer(){
|
||||
customAlert("Information", quiz.get(questionIndex).getAnswerMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -98,17 +104,24 @@ public class QuizActivity extends AppCompatActivity {
|
|||
.build());
|
||||
|
||||
imageView.setImageURI(quiz.get(questionIndex).getUrl());
|
||||
new RadioGroupHelper(this, R.id.quiz_positive_answer, R.id.quiz_negative_answer);
|
||||
positiveAnswer.setChecked(false);
|
||||
negativeAnswer.setChecked(false);
|
||||
isPositiveAnswerChecked = false;
|
||||
isNegativeAnswerChecked = false;
|
||||
positiveAnswer.setOnClickListener(view -> {
|
||||
isPositiveAnswerChecked = true;
|
||||
setNextQuestion();
|
||||
});
|
||||
negativeAnswer.setOnClickListener(view -> {
|
||||
isNegativeAnswerChecked = true;
|
||||
setNextQuestion();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* to evaluate score and check whether answer is correct or wrong
|
||||
*/
|
||||
public void evaluateScore() {
|
||||
if ((quiz.get(questionIndex).isAnswer() && positiveAnswer.isChecked()) ||
|
||||
(!quiz.get(questionIndex).isAnswer() && negativeAnswer.isChecked()) ){
|
||||
if ((quiz.get(questionIndex).isAnswer() && isPositiveAnswerChecked) ||
|
||||
(!quiz.get(questionIndex).isAnswer() && isNegativeAnswerChecked) ){
|
||||
customAlert(getResources().getString(R.string.correct),quiz.get(questionIndex).getAnswerMessage() );
|
||||
score++;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -57,22 +57,21 @@
|
|||
android:layout_marginTop="@dimen/activity_margin_vertical"
|
||||
android:layout_marginBottom="@dimen/activity_margin_vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" />
|
||||
android:layout_width="match_parent" />
|
||||
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/next_button"
|
||||
android:layout_gravity="right"
|
||||
style="?android:textAppearanceMedium"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
||||
android:text="NEXT"
|
||||
android:backgroundTint="#D6DCE0"
|
||||
android:layout_marginBottom="@dimen/activity_margin_vertical" />
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/next_button"
|
||||
android:layout_gravity="right"
|
||||
style="?android:textAppearanceMedium"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
||||
android:text="I am not sure"
|
||||
android:backgroundTint="#D6DCE0"
|
||||
android:layout_marginBottom="@dimen/activity_margin_vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
|||
|
|
@ -1,65 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="@dimen/activity_margin_vertical"
|
||||
android:layout_marginBottom="@dimen/activity_margin_vertical">
|
||||
<androidx.constraintlayout.widget.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="wrap_content"
|
||||
android:layout_marginTop="@dimen/activity_margin_vertical"
|
||||
android:layout_marginBottom="@dimen/activity_margin_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent="0.5" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/quiz_positive_answer"
|
||||
android:textIsSelectable="false"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||
android:layout_marginRight="@dimen/activity_margin_horizontal"/>
|
||||
<Button
|
||||
android:id="@+id/quiz_positive_answer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/yes"
|
||||
android:textColor="@color/white"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="YES"
|
||||
style="?android:textAppearanceMedium"
|
||||
android:textColor="@color/secondaryTextColor" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/ic_done_black_24dp"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/activity_margin_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textIsSelectable="false"
|
||||
android:id="@+id/quiz_negative_answer"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||
android:layout_marginRight="@dimen/activity_margin_horizontal"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="NO"
|
||||
style="?android:textAppearanceMedium"
|
||||
android:textColor="@color/secondaryTextColor" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/ic_clear_black_24dp"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/quiz_negative_answer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no"
|
||||
android:textColor="@color/white"
|
||||
android:layout_marginLeft="@dimen/activity_margin_horizontal"
|
||||
android:layout_marginRight="@dimen/activity_margin_horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/guideline"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue