From 40ca49a99ab8994c8c9b7f02ac03131b39b02936 Mon Sep 17 00:00:00 2001 From: AlbatovK Date: Mon, 4 Apr 2022 18:39:52 +0600 Subject: [PATCH] :pencil: Minor improvements --- .../com/albatros/kquiz/ui/fragments/enter/EnterFragment.kt | 7 +++---- .../com/albatros/kquiz/ui/fragments/game/GameFragment.kt | 5 ++++- .../albatros/kquiz/ui/fragments/result/ResultFragment.kt | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/enter/EnterFragment.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/enter/EnterFragment.kt index 4f37182..40d63de 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/enter/EnterFragment.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/enter/EnterFragment.kt @@ -89,11 +89,10 @@ class EnterFragment : Fragment(), MainActivity.IOnBackPressed { dialog.show() } - override fun onBackPressed(): Boolean { + override fun onBackPressed(): Boolean = activity?.let { it.finish() it.finishAffinity() - } - return true - } + true + } ?: false } \ No newline at end of file diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameFragment.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameFragment.kt index d59cb41..a8c9d1a 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameFragment.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/game/GameFragment.kt @@ -17,6 +17,7 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.albatros.kquiz.R import com.albatros.kquiz.databinding.GameFragmentBinding +import com.albatros.kquiz.ui.activity.MainActivity import com.albatros.kquiz.ui.adapter.answer.AnswerAdapter import com.albatros.kquiz.ui.adapter.answer.AnswerAdapterListener import kotlinx.coroutines.Dispatchers @@ -25,7 +26,7 @@ import kotlinx.coroutines.launch import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf -class GameFragment : Fragment() { +class GameFragment : Fragment(), MainActivity.IOnBackPressed { private lateinit var binding: GameFragmentBinding private val args by navArgs() @@ -33,6 +34,8 @@ class GameFragment : Fragment() { private var answered = false private var currentAnswer = "" + override fun onBackPressed(): Boolean = true + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, 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 f99cf6d..d5d1042 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 @@ -11,16 +11,19 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.albatros.kquiz.R import com.albatros.kquiz.databinding.ResultFragmentBinding import com.albatros.kquiz.model.data.info.ClientInfo +import com.albatros.kquiz.ui.activity.MainActivity import com.albatros.kquiz.ui.adapter.client.ResultAdapter import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf -class ResultFragment : Fragment() { +class ResultFragment : Fragment(), MainActivity.IOnBackPressed { private lateinit var binding: ResultFragmentBinding private val args by navArgs() private val viewModel: ResultViewModel by viewModel { parametersOf(args.question) } + override fun onBackPressed(): Boolean = true + private val onPassiveStateEndedObserver = Observer { value -> if (value) { viewModel.getNextQuestion()?.let {