Skip to content

Commit

Permalink
Created layout for QuestionResultFragment,
Browse files Browse the repository at this point in the history
Navigation actions for QuestionShow-QuestionResult created.
  • Loading branch information
kirkaDev committed Dec 6, 2020
1 parent 8b89d3a commit b9ea9a7
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.navArgs
import com.desiredsoftware.socialquiz.R

class QuestionResultFragment : Fragment() {
Expand All @@ -15,11 +18,37 @@ class QuestionResultFragment : Fragment() {

private lateinit var viewModel: QuestionResultViewModel

val args: QuestionResultFragmentArgs by navArgs()

lateinit var root : View

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_question_result, container, false)

root = inflater.inflate(R.layout.fragment_question_result, container, false)

val buttonNextQuestion: View = root.findViewById(R.id.buttonNextQuestion)
var textviewNextQuestion: TextView = buttonNextQuestion.findViewById(R.id.textView)
textviewNextQuestion.setText(R.string.nextQuestion)

val buttonChangeCategory: View = root.findViewById(R.id.buttonChangeCategory)
var textviewChangeCategory: TextView = buttonChangeCategory.findViewById(R.id.textView)
textviewChangeCategory.setText(R.string.changeCategory)



if (args.answerIsCorrect)
{
configureCorrectAnswer()
}
else {
configureWrongAnswer()
}

return root

}

/* override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand All @@ -28,4 +57,18 @@ class QuestionResultFragment : Fragment() {
// TODO: Use the ViewModel
}*/

fun configureWrongAnswer() {
val viewTryAgain: View = root.findViewById(R.id.buttonTryAgain)
var textviewTryAgain: TextView = viewTryAgain.findViewById(R.id.textView)
textviewTryAgain.setText(R.string.tryAgain)
}

fun configureCorrectAnswer() {
val textViewResult : TextView = root.findViewById(R.id.textViewResult)
textViewResult.setText(R.string.congrat)
val viewTryAgain: View = root.findViewById(R.id.buttonTryAgain)
viewTryAgain.isVisible = false
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -62,6 +63,10 @@ class QuestionShowingFragment : Fragment() {
object : OnClickAnswerListener{
override fun onClicked(answerVariant: Question.Answer) {
// TODO: Show QuestionResultsFragment
val answerIsCorrect : Boolean = answerVariant.isCorrect
val action = QuestionShowingFragmentDirections.actionQuestionShowingFragmentToQuestionResultFragment(answerIsCorrect)
val navController = requireParentFragment().findNavController()
navController.navigate(action)
}

})
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/res/layout/button_with_icon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
Expand All @@ -10,7 +10,7 @@

<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
Expand All @@ -20,21 +20,23 @@
android:id="@+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"
tools:srcCompat="@mipmap/ic_launcher_round">

</ImageView>

<TextView
<Button
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:textColor="@color/bottomToolbar"
tools:text="Your text">
</TextView>
android:text="Your text">
</Button>

</androidx.appcompat.widget.LinearLayoutCompat>

Expand Down
61 changes: 42 additions & 19 deletions app/src/main/res/layout/fragment_question_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,68 @@
tools:context=".ui.question.QuestionResultFragment">

<TextView
android:id="@+id/labelResult"
style="@style/TextViewStyle"
android:layout_marginStart="8dp"
android:layout_marginTop="108dp"
android:layout_marginEnd="8dp"
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="50dp"
android:background="@color/yellowMain"
android:textColor="@color/bottomToolbar"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:paddingRight="20dp"
android:paddingBottom="20dp"
android:text="Wrong answer"
android:textAlignment="center"
android:textColor="@color/bottomToolbar"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<include
android:id="@+id/buttonTryAgain"
layout="@layout/button_with_icon"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="136dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="50dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/labelResult" />
app:layout_constraintTop_toBottomOf="@+id/textViewResult" />

<include
android:id="@+id/buttonNextQuestion"
layout="@layout/button_with_icon"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="104dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="40dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonTryAgain"
app:layout_constraintVertical_bias="0.0" />


<include
android:id="@+id/buttonChangeCategory"
layout="@layout/button_with_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="?attr/actionBarSize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonNextQuestion"
app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/fragment_question_showing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
android:id="@+id/recyclerViewAnswerVariants"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"

android:layout_marginBottom="?attr/actionBarSize"
app:layout_constraintTop_toBottomOf="@id/framePlayerLayout"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_answer_variant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buttonAnswerVariant"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="answer variant"
android:layout_gravity="center_horizontal"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<action
android:id="@+id/action_questionResultFragment_to_questionShowingFragment"
app:destination="@id/questionShowingFragment" />
<argument
android:name="answerIsCorrect"
app:argType="boolean" />
</fragment>
<fragment
android:id="@+id/addOwnQuestionFragment"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<string name="title_notifications">Notifications</string>
<string name="profile">Profile</string>
<string name="selectCategory">Select category</string>
<string name="tryAgain">Try again</string>
<string name="nextQuestion">Next question</string>
<string name="congrat">Congratulations!</string>
<string name="changeCategory">Change category</string>
</resources>

0 comments on commit b9ea9a7

Please sign in to comment.