diff --git a/app/src/main/java/com/albatros/kquiz/model/api/ApiService.kt b/app/src/main/java/com/albatros/kquiz/model/api/ApiService.kt index 239a784..4f81fd9 100644 --- a/app/src/main/java/com/albatros/kquiz/model/api/ApiService.kt +++ b/app/src/main/java/com/albatros/kquiz/model/api/ApiService.kt @@ -1,9 +1,9 @@ package com.albatros.kquiz.model.api -import com.albatros.kquiz.model.data.AnswerSubmit -import com.albatros.kquiz.model.data.ClientInfo -import com.albatros.kquiz.model.data.Quiz -import com.albatros.kquiz.model.data.ResponseData +import com.albatros.kquiz.model.data.response.AnswerSubmit +import com.albatros.kquiz.model.data.info.ClientInfo +import com.albatros.kquiz.model.data.pojo.Quiz +import com.albatros.kquiz.model.data.response.ResponseData import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST diff --git a/app/src/main/java/com/albatros/kquiz/model/data/ClientInfo.kt b/app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt similarity index 78% rename from app/src/main/java/com/albatros/kquiz/model/data/ClientInfo.kt rename to app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt index 8e357af..57f9382 100644 --- a/app/src/main/java/com/albatros/kquiz/model/data/ClientInfo.kt +++ b/app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt @@ -1,4 +1,4 @@ -package com.albatros.kquiz.model.data +package com.albatros.kquiz.model.data.info import com.google.gson.annotations.Expose import com.google.gson.annotations.SerializedName @@ -19,6 +19,6 @@ data class ClientInfo( @SerializedName("questionMap") @Expose - var questionMap: HashMap = HashMap() + var questionMap: HashMap = HashMap() ) \ No newline at end of file diff --git a/app/src/main/java/com/albatros/kquiz/model/data/info/QuestionInfo.kt b/app/src/main/java/com/albatros/kquiz/model/data/info/QuestionInfo.kt new file mode 100644 index 0000000..690d97f --- /dev/null +++ b/app/src/main/java/com/albatros/kquiz/model/data/info/QuestionInfo.kt @@ -0,0 +1,19 @@ +package com.albatros.kquiz.model.data.info + +import android.os.Parcelable +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName +import kotlinx.parcelize.Parcelize + +@Parcelize +data class QuestionInfo( + + @SerializedName("right") + @Expose + var right: Boolean = false, + + @SerializedName("time") + @Expose + var time: Int = 0 + +) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/com/albatros/kquiz/model/data/Question.kt b/app/src/main/java/com/albatros/kquiz/model/data/pojo/Question.kt similarity index 91% rename from app/src/main/java/com/albatros/kquiz/model/data/Question.kt rename to app/src/main/java/com/albatros/kquiz/model/data/pojo/Question.kt index 97a7d90..5302826 100644 --- a/app/src/main/java/com/albatros/kquiz/model/data/Question.kt +++ b/app/src/main/java/com/albatros/kquiz/model/data/pojo/Question.kt @@ -1,4 +1,4 @@ -package com.albatros.kquiz.model.data +package com.albatros.kquiz.model.data.pojo import android.os.Parcelable import com.google.gson.annotations.Expose diff --git a/app/src/main/java/com/albatros/kquiz/model/data/Quiz.kt b/app/src/main/java/com/albatros/kquiz/model/data/pojo/Quiz.kt similarity index 85% rename from app/src/main/java/com/albatros/kquiz/model/data/Quiz.kt rename to app/src/main/java/com/albatros/kquiz/model/data/pojo/Quiz.kt index bc6eece..81e8b6a 100644 --- a/app/src/main/java/com/albatros/kquiz/model/data/Quiz.kt +++ b/app/src/main/java/com/albatros/kquiz/model/data/pojo/Quiz.kt @@ -1,6 +1,7 @@ -package com.albatros.kquiz.model.data +package com.albatros.kquiz.model.data.pojo import android.os.Parcelable +import com.albatros.kquiz.model.data.pojo.Question import com.google.gson.annotations.Expose import com.google.gson.annotations.SerializedName import kotlinx.parcelize.Parcelize diff --git a/app/src/main/java/com/albatros/kquiz/model/data/AnswerSubmit.kt b/app/src/main/java/com/albatros/kquiz/model/data/response/AnswerSubmit.kt similarity index 91% rename from app/src/main/java/com/albatros/kquiz/model/data/AnswerSubmit.kt rename to app/src/main/java/com/albatros/kquiz/model/data/response/AnswerSubmit.kt index 8fafab0..bd15299 100644 --- a/app/src/main/java/com/albatros/kquiz/model/data/AnswerSubmit.kt +++ b/app/src/main/java/com/albatros/kquiz/model/data/response/AnswerSubmit.kt @@ -1,4 +1,4 @@ -package com.albatros.kquiz.model.data +package com.albatros.kquiz.model.data.response import android.os.Parcelable import com.google.gson.annotations.Expose diff --git a/app/src/main/java/com/albatros/kquiz/model/data/ResponseData.kt b/app/src/main/java/com/albatros/kquiz/model/data/response/ResponseData.kt similarity index 79% rename from app/src/main/java/com/albatros/kquiz/model/data/ResponseData.kt rename to app/src/main/java/com/albatros/kquiz/model/data/response/ResponseData.kt index 0de9ae8..6641014 100644 --- a/app/src/main/java/com/albatros/kquiz/model/data/ResponseData.kt +++ b/app/src/main/java/com/albatros/kquiz/model/data/response/ResponseData.kt @@ -1,4 +1,4 @@ -package com.albatros.kquiz.model.data +package com.albatros.kquiz.model.data.response import com.google.gson.annotations.Expose import com.google.gson.annotations.SerializedName diff --git a/app/src/main/java/com/albatros/kquiz/model/repo/ClientRepo.kt b/app/src/main/java/com/albatros/kquiz/model/repo/ClientRepo.kt index 2aa3b19..71c3829 100644 --- a/app/src/main/java/com/albatros/kquiz/model/repo/ClientRepo.kt +++ b/app/src/main/java/com/albatros/kquiz/model/repo/ClientRepo.kt @@ -1,7 +1,7 @@ package com.albatros.kquiz.model.repo -import com.albatros.kquiz.model.data.ClientInfo -import com.albatros.kquiz.model.data.Quiz +import com.albatros.kquiz.model.data.info.ClientInfo +import com.albatros.kquiz.model.data.pojo.Quiz class ClientRepo { var quiz: Quiz = Quiz() diff --git a/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ClientAdapter.kt b/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ClientAdapter.kt index 196671e..5eef1a6 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ClientAdapter.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ClientAdapter.kt @@ -4,7 +4,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.albatros.kquiz.databinding.ClientLayoutBinding -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo class ClientAdapter(private val clients: MutableList) : RecyclerView.Adapter() { diff --git a/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt b/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt index ca3167f..f9876f5 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt @@ -6,7 +6,7 @@ import androidx.recyclerview.widget.RecyclerView import com.albatros.kquiz.R import com.albatros.kquiz.databinding.ResultClientLayoutBinding import com.albatros.kquiz.domain.playFadeInAnimation -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo class ResultAdapter(private val clients: MutableList) : RecyclerView.Adapter() { @@ -38,7 +38,22 @@ class ResultAdapter(private val clients: MutableList) : with(binding) { binding.root.playFadeInAnimation(R.anim.fade_in_animation) name.text = it.name - score.text = (it.questionMap.count { item -> item.value } * 1000).toString() + + val base = it.questionMap.count { item -> item.value.right } * 1000 + var timeDependent = 0 + + val from = if (it.questionMap.size == 0) 0 else it.questionMap.size - 1 + val to = if (it.questionMap.size > 2) it.questionMap.size - 3 else 0 + + val lastCount = it.questionMap.filterKeys { it in from downTo to }.count { item -> item.value.right } + + if (lastCount == 3) { + name.text = it.name + " " + "\uD83D\uDD25" + timeDependent = 200 - (it.questionMap[it.questionMap.size - 1]?.time ?: 20) * 10 + } + + val res = base + timeDependent + score.text = res.toString() } } } diff --git a/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapter.kt b/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapter.kt index e80e899..26fd695 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapter.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapter.kt @@ -6,7 +6,7 @@ import androidx.recyclerview.widget.RecyclerView import com.albatros.kquiz.R import com.albatros.kquiz.databinding.QuizLayoutBinding import com.albatros.kquiz.domain.playFadeInAnimation -import com.albatros.kquiz.model.data.Quiz +import com.albatros.kquiz.model.data.pojo.Quiz class QuizAdapter( private val quizzes: MutableList, diff --git a/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapterListener.kt b/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapterListener.kt index 87cbb3d..b474d5b 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapterListener.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/adapter/quiz/QuizAdapterListener.kt @@ -1,7 +1,7 @@ package com.albatros.kquiz.ui.adapter.quiz import android.view.View -import com.albatros.kquiz.model.data.Quiz +import com.albatros.kquiz.model.data.pojo.Quiz interface QuizAdapterListener { fun onQuizSelected(quiz: Quiz, view: View) diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientFragment.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientFragment.kt index 1022d00..1b041a0 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientFragment.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientFragment.kt @@ -3,7 +3,6 @@ package com.albatros.kquiz.ui.fragments.client import android.os.Bundle import android.transition.TransitionInflater import android.view.* -import android.widget.Toast import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController @@ -11,10 +10,9 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.albatros.kquiz.R import com.albatros.kquiz.databinding.ClientFragmentBinding -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo import com.albatros.kquiz.ui.activity.MainActivity import com.albatros.kquiz.ui.adapter.client.ClientAdapter -import com.albatros.kquiz.ui.fragments.host.HostFragmentDirections import org.koin.androidx.viewmodel.ext.android.viewModel class ClientFragment : Fragment(), MainActivity.IOnBackPressed { diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientViewModel.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientViewModel.kt index afb473d..2ba1099 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientViewModel.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/client/ClientViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.albatros.kquiz.model.api.ApiService -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo import com.albatros.kquiz.model.repo.ClientRepo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -45,14 +45,6 @@ class ClientViewModel(private val api: ApiService, private val repo: ClientRepo) val started: LiveData = _started - - val usersInfo: LiveData> = _usersInfo - fun updateUserInfo() { - viewModelScope.launch(Dispatchers.Main) { - _usersInfo.value = api.getClientsInfo(repo.sessionId) - } - } - } \ No newline at end of file diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameViewModel.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameViewModel.kt index 934dd9f..1e41dbb 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameViewModel.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameViewModel.kt @@ -5,8 +5,8 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.albatros.kquiz.model.api.ApiService -import com.albatros.kquiz.model.data.AnswerSubmit -import com.albatros.kquiz.model.data.Question +import com.albatros.kquiz.model.data.response.AnswerSubmit +import com.albatros.kquiz.model.data.pojo.Question import com.albatros.kquiz.model.repo.ClientRepo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -20,7 +20,10 @@ class GameViewModel( private val _onActionEnd = MutableLiveData().apply { viewModelScope.launch(Dispatchers.Main) { - delay(20_000) + repeat(20) { + delay(1000) + times++ + } value = false } } @@ -40,12 +43,12 @@ class GameViewModel( val onActionEnd: LiveData = _onActionEnd - private val _onSuccessSubmit = MutableLiveData() + var times = 0 - val onSuccessSubmit: LiveData = _onSuccessSubmit + private val _onSuccessSubmit = MutableLiveData() fun submitData(answer: String) { - val data = AnswerSubmit(repo.clientInfo.id, repo.currentPos, answer == question.answer, 0) + val data = AnswerSubmit(repo.clientInfo.id, repo.currentPos, answer == question.answer, times) repo.currentPos++ viewModelScope.launch(Dispatchers.Main) { try { diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostFragment.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostFragment.kt index afbcb3a..54a4a09 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostFragment.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostFragment.kt @@ -14,10 +14,9 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.albatros.kquiz.R import com.albatros.kquiz.databinding.HostFragmentBinding import com.albatros.kquiz.databinding.InfoDialogBinding -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo import com.albatros.kquiz.ui.activity.MainActivity import com.albatros.kquiz.ui.adapter.client.ClientAdapter -import com.albatros.kquiz.ui.fragments.enter.EnterFragmentDirections import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.koin.androidx.viewmodel.ext.android.viewModel diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostViewModel.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostViewModel.kt index 3a55f32..a295ca0 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostViewModel.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/host/HostViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.albatros.kquiz.model.api.ApiService -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo import com.albatros.kquiz.model.repo.ClientRepo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/list/ListViewModel.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/list/ListViewModel.kt index 298afbe..1b0a275 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/list/ListViewModel.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/list/ListViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.albatros.kquiz.model.api.ApiService -import com.albatros.kquiz.model.data.Quiz +import com.albatros.kquiz.model.data.pojo.Quiz import com.albatros.kquiz.model.repo.ClientRepo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/list/QuizListFragment.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/list/QuizListFragment.kt index 02a3968..ede3da7 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/list/QuizListFragment.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/list/QuizListFragment.kt @@ -1,6 +1,5 @@ package com.albatros.kquiz.ui.fragments.list -import android.content.Intent import android.os.Bundle import android.transition.TransitionInflater import android.view.LayoutInflater @@ -15,10 +14,9 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.albatros.kquiz.R -import com.albatros.kquiz.databinding.InfoDialogBinding import com.albatros.kquiz.databinding.NameDialogBinding import com.albatros.kquiz.databinding.QuizListFragmentBinding -import com.albatros.kquiz.model.data.Quiz +import com.albatros.kquiz.model.data.pojo.Quiz import com.albatros.kquiz.ui.adapter.quiz.QuizAdapter import com.albatros.kquiz.ui.adapter.quiz.QuizAdapterListener import com.google.android.material.dialog.MaterialAlertDialogBuilder diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultFragment.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultFragment.kt index 9e3bba7..f99cf6d 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultFragment.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultFragment.kt @@ -3,8 +3,6 @@ package com.albatros.kquiz.ui.fragments.result import android.os.Bundle import android.transition.TransitionInflater import android.view.* -import android.widget.LinearLayout -import android.widget.Toast import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController @@ -12,7 +10,7 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import com.albatros.kquiz.R import com.albatros.kquiz.databinding.ResultFragmentBinding -import com.albatros.kquiz.model.data.ClientInfo +import com.albatros.kquiz.model.data.info.ClientInfo import com.albatros.kquiz.ui.adapter.client.ResultAdapter import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt index ed55cd0..3428b1c 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt @@ -5,8 +5,8 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.albatros.kquiz.model.api.ApiService -import com.albatros.kquiz.model.data.ClientInfo -import com.albatros.kquiz.model.data.Question +import com.albatros.kquiz.model.data.info.ClientInfo +import com.albatros.kquiz.model.data.pojo.Question import com.albatros.kquiz.model.repo.ClientRepo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -35,7 +35,7 @@ class ResultViewModel( private val _usersInfo = MutableLiveData>().apply { viewModelScope.launch(Dispatchers.Main) { value = api.getClientsInfo(repo.sessionId).sortedByDescending { - it.questionMap.count { item -> item.value } + it.questionMap.count { item -> item.value.right } } } } diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index b6cb4e4..0be160d 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -73,7 +73,7 @@ + app:argType="com.albatros.kquiz.model.data.pojo.Question" /> @@ -109,7 +109,7 @@ + app:argType="com.albatros.kquiz.model.data.pojo.Question" />