Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
fix categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Nov 13, 2022
1 parent 216b61e commit 2ece2e4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OpenTriviaDBHelper : ApiHelper() {

val stats = mutableListOf<String>()

kotlin.runCatching {
runCatching {
val json = mapper.readTree(
mapper.writeValueAsString(metadata.overall)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bnyro.trivia.api.opentriviadb.obj

data class Question(
data class OpenTriviaQuestion(
val category: String? = null,
val correct_answer: String? = null,
val difficulty: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bnyro.trivia.api.opentriviadb.obj

data class Overall(
data class OverallStats(
val total_num_of_pending_questions: Int? = null,
val total_num_of_questions: Int? = null,
val total_num_of_rejected_questions: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.bnyro.trivia.api.opentriviadb.obj

data class QuestionResponse(
val response_code: Int? = null,
val results: List<Question>? = null
val results: List<OpenTriviaQuestion>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.bnyro.trivia.api.opentriviadb.obj

data class StatsResponse(
val categories: Any? = null,
val overall: Overall? = null
val overall: OverallStats? = null
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bnyro.trivia.api.thetriviaapi

import android.util.Log
import com.bnyro.trivia.extensions.formatStats
import com.bnyro.trivia.obj.Category
import com.bnyro.trivia.obj.Question
Expand Down Expand Up @@ -27,20 +28,21 @@ class TheTriviaApiHelper : ApiHelper() {
incorrectAnswers = it.incorrectAnswers
)
}
Log.e("category", apiQuestions.first().category.toString())
return questions
}

override suspend fun getCategories(): List<Category> {
val categories = RetrofitInstance.theTriviaApi.getCategories()

kotlin.runCatching {
runCatching {
val response = mapper.readTree(
mapper.writeValueAsString(categories)
)
val categoriesList = mutableListOf<Category>()
response.fields().forEach {
categoriesList += Category(
id = it.value[0].toString(),
id = it.value.firstOrNull().toString().replace("\"", ""),
name = it.key.toString()
)
}
Expand All @@ -55,7 +57,7 @@ class TheTriviaApiHelper : ApiHelper() {
val stats = mutableListOf<String>()
val mapper = ObjectMapper()

kotlin.runCatching {
runCatching {
val stateStats = mapper.readTree(
mapper.writeValueAsString(metadata.byState)
)
Expand Down
15 changes: 4 additions & 11 deletions app/src/main/java/com/bnyro/trivia/fragments/CategoriesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView.OnItemClickListener
import android.widget.ArrayAdapter
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.bnyro.trivia.R
Expand All @@ -18,12 +19,6 @@ import com.bnyro.trivia.util.BundleArguments
class CategoriesFragment : Fragment() {
private lateinit var binding: FragmentCategoriesBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -65,11 +60,9 @@ class CategoriesFragment : Fragment() {
binding.categoriesLV.visibility = View.VISIBLE

binding.categoriesLV.onItemClickListener = OnItemClickListener { _, _, index, _ ->
val category = categoryQueries[index]
val quizFragment = QuizFragment()
val bundle = Bundle()
bundle.putString(BundleArguments.category, category)
quizFragment.arguments = bundle
val quizFragment = QuizFragment().apply {
arguments = bundleOf(BundleArguments.category to categoryQueries[index])
}

parentFragmentManager.navigate(quizFragment)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ object PreferenceHelper {
context.getString(R.string.questions_delay_default)
)
return when (questionsDelayPref) {
"auto" -> correctAnswer.wordCount() * 400L
"auto" -> correctAnswer.wordCount() * 1000L
"infinite" -> null
else -> questionsDelayPref.toLong()
}
Expand Down

2 comments on commit 2ece2e4

@JonnyTech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fix #13?

@Bnyro
Copy link
Member Author

@Bnyro Bnyro commented on 2ece2e4 Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fix #13?

Yes, it does :)

Please sign in to comment.