Skip to content

Commit

Permalink
-fixed bug in list answers achievement feature
Browse files Browse the repository at this point in the history
  • Loading branch information
msuyudia committed Mar 13, 2021
1 parent a68f74e commit 94f5d90
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.suy.squizwardapp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class BottomSheetAlertDialog(private val listener: AlertListener) : BottomSheetD
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
when (title != null) {
true -> binding?.tvTitleBtsAlert?.text = getString(title ?: 0)
}
if (title != null) binding?.tvTitleBtsAlert?.text = getString(title ?: 0)
binding?.btnNoBtsAlert?.setOnClickListener { dismiss() }
binding?.btnYesBtsAlert?.setOnClickListener { listener.onAlertClicked(true) }
}
Expand Down
48 changes: 34 additions & 14 deletions app/src/main/java/com/suy/squizwardapp/ui/result/AnswerAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.suy.squizwardapp.utils.visible

class AnswerAdapter(private val list: List<Result>) :
RecyclerView.Adapter<AnswerAdapter.ViewHolder>() {
private val listAnswerOpened by lazy { mutableListOf<Int>() }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = ItemAnswerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
Expand Down Expand Up @@ -45,31 +46,49 @@ class AnswerAdapter(private val list: List<Result>) :
}
}
tvQuestionAnswer.text = result.question?.questionText
when (listAnswerOpened.contains(adapterPosition)) {
true -> detailAnswerVisible(binding)
false -> detailAnswerHiden(binding)
}
itemView.setOnClickListener {
when (containerDetailAnswer.isVisible) {
false -> {
ivArrowAnswer.setImageDrawable(
ContextCompat.getDrawable(
itemView.context,
R.drawable.ic_drop_up
)
)
containerDetailAnswer.visible()
listAnswerOpened.add(adapterPosition)
detailAnswerVisible(binding)
}
true -> {
ivArrowAnswer.setImageDrawable(
ContextCompat.getDrawable(
itemView.context,
R.drawable.ic_drop_down
)
)
containerDetailAnswer.gone()
listAnswerOpened.remove(adapterPosition)
detailAnswerHiden(binding)
}
}
}
}
}

private fun detailAnswerHiden(binding: ItemAnswerBinding) {
with(binding) {
ivArrowAnswer.setImageDrawable(
ContextCompat.getDrawable(
itemView.context,
R.drawable.ic_drop_down
)
)
containerDetailAnswer.gone()
}
}

private fun detailAnswerVisible(binding: ItemAnswerBinding) {
with(binding) {
ivArrowAnswer.setImageDrawable(
ContextCompat.getDrawable(
itemView.context,
R.drawable.ic_drop_up
)
)
containerDetailAnswer.visible()
}
}

private fun showDetailAnswer(result: Result?) {
val correctAnswer = result?.question?.correctAnswer
val userAnswer = result?.userAnswer
Expand Down Expand Up @@ -139,6 +158,7 @@ class AnswerAdapter(private val list: List<Result>) :
adapterPosition.plus(1),
"Incorrect"
)
tvUserAnswer.visible()
tvUserAnswer.text = itemView.context.getString(R.string.text_user_answer_empty)
tvCorrectAnswer.text = itemView.context.getString(
R.string.text_correction_right_answer_value,
Expand Down
29 changes: 2 additions & 27 deletions app/src/main/java/com/suy/squizwardapp/ui/result/ResultActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.math.roundToInt

class ResultActivity : BaseActivity() {
companion object {
const val EXTRA_CATEGORY = "id"
const val EXTRA_CATEGORY = "category"
var answers = mutableMapOf<Int, String>()
}

Expand Down Expand Up @@ -96,32 +96,7 @@ class ResultActivity : BaseActivity() {
supportActionBar?.elevation = 0F
supportActionBar?.title = getString(R.string.title_achievement)
}
//private fun calculateScore(correctAnswer: String, userAnswer: String?) {
// when (userAnswer.isNullOrEmpty()) {
// true -> totalWrongAnswer += 1
// false -> when (correctAnswer.contains(",")) {
// true -> {
// var isSame = true
// val splitUserAnswer = userAnswer.split(",")
// splitUserAnswer.forEach {
// isSame = correctAnswer.contains(it)
// if (!isSame) {
// totalWrongAnswer += 1
// return
// }
// }
// when (userAnswer.length == correctAnswer.length && isSame) {
// true -> totalCorrectAnswer += 1
// false -> totalWrongAnswer += 1
// }
// }
// false -> when (correctAnswer.contains(userAnswer)) {
// true -> totalCorrectAnswer += 1
// false -> totalWrongAnswer += 1
// }
// }
// }
//}

override fun onDestroy() {
super.onDestroy()
answers.clear()
Expand Down

0 comments on commit 94f5d90

Please sign in to comment.