Skip to content

Commit

Permalink
🎨 Major design update # 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed Apr 22, 2022
1 parent 91bc8f0 commit d475299
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id "androidx.navigation.safeargs.kotlin"
id 'kotlin-parcelize'
id "androidx.navigation.safeargs.kotlin"
id 'com.google.gms.google-services'
}

android {
Expand Down Expand Up @@ -45,9 +46,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version")

/* noinspection GradleDependency */
implementation 'androidx.core:core-ktx:1.6.0'
/* noinspection GradleDependency */
implementation 'androidx.appcompat:appcompat:1.3.1'

implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
Expand All @@ -60,23 +59,18 @@ dependencies {
implementation "io.insert-koin:koin-androidx-compose:$koin_version"
testImplementation "io.insert-koin:koin-test:$koin_version"

/* noinspection GradleDependency */
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation 'com.google.firebase:firebase-analytics:20.1.2'

/* noinspection GradleDependency */
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
/* noinspection GradleDependency */
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

/* noinspection GradleDependency */
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
/* noinspection GradleDependency */
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
/* noinspection GradleDependency */
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version")

testImplementation 'junit:junit:4.13.2'
Expand Down
39 changes: 39 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "426842074858",
"project_id": "kquiz-d931d",
"storage_bucket": "kquiz-d931d.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:426842074858:android:1c4590057b8aa180a1f193",
"android_client_info": {
"package_name": "com.albatros.kquiz"
}
},
"oauth_client": [
{
"client_id": "426842074858-bltgoiv05t38p2l1qerhjqm3cu1g0g7i.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDy4wFdeWnRFDydDSLlTfsLr5MGZoSudXE"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "426842074858-bltgoiv05t38p2l1qerhjqm3cu1g0g7i.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.albatros.kquiz.ui.fragments.game.GameViewModel
import com.albatros.kquiz.ui.fragments.result.ResultViewModel
import com.albatros.kquiz.ui.fragments.host.HostViewModel
import com.albatros.kquiz.ui.fragments.list.ListViewModel
import com.albatros.kquiz.ui.fragments.pedestal.PedestalViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

Expand All @@ -14,6 +15,7 @@ val viewModelModule = module {
viewModel { ListViewModel(get(), get()) }
viewModel { HostViewModel(get(), get()) }
viewModel { ClientViewModel(get(), get()) }
viewModel { PedestalViewModel(get(), get()) }
viewModel { parameters -> GameViewModel(parameters.get(), get(), get()) }
viewModel { parameters -> ResultViewModel(parameters.get(), get(), get()) }
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
package com.albatros.kquiz.ui.adapter.client

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.animation.AnimationUtils
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.info.ClientInfo
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class ResultAdapter(private val clients: MutableList<ClientInfo>) :
class ResultAdapter(private val clients: MutableList<ClientInfo>, private val scope: CoroutineScope) :
RecyclerView.Adapter<ResultAdapter.ResultClientViewHolder>() {

companion object {
private var lastRes: MutableList<ClientInfo>? = null

fun clearLast() {
lastRes = null
}
}

override fun getItemCount(): Int = clients.size

override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
lastRes = clients.toMutableList()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ResultClientViewHolder {
val binding =
ResultClientLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ResultClientViewHolder(binding)
}

override fun onBindViewHolder(holder: ResultClientViewHolder, position: Int) {
holder.client = clients[position]
holder.client = if (lastRes == null) clients[position] else lastRes!![position]
}

inner class ResultClientViewHolder(private val binding: ResultClientLayoutBinding) :
Expand All @@ -34,24 +52,56 @@ class ResultAdapter(private val clients: MutableList<ClientInfo>) :
}

private fun bind(info: ClientInfo?) {
info?.let {
info?.let { last ->
with(binding) {

binding.root.playFadeInAnimation(R.anim.fade_in_animation)
root.animation = AnimationUtils.loadAnimation(root.context, R.anim.list_anim)
val new = clients.find { q -> q.id == last.id }!!

name.text = it.name
score.text = it.score.toString()

place.text = root.context.getString(R.string.place, clients.map(ClientInfo::score).indexOf(it.score) + 1)
scope.launch {
delay(1200)
lastRes?.let {
if (it.indexOf(last) != clients.indexOf(new)) {
val from = it.indexOf(last)
val to = clients.indexOf(new)
it.removeAt(from).also { item ->
it.add(to, item)
}
notifyItemMoved(from, to)
}
}
}

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 }
score.text = last.score.toString()

if (lastCount == 3) {
val hint = it.name + " \uD83D\uDD25"
name.text = hint
scope.launch(Dispatchers.Main) {
while (new.score > last.score) {
delay(10)
last.score += 10
score.text = last.score.toString()
}
}

name.text = last.name

val placeOrd = clients.map(ClientInfo::score).indexOf(new.score) + 1
place.text = if (placeOrd == 1) {
val placeHint = root.context.getString(R.string.place, placeOrd) + " \uD83D\uDC51"
placeHint
} else root.context.getString(R.string.place, placeOrd)

val from = if (new.questionMap.size == 0) 0 else new.questionMap.size - 1
val to = if (new.questionMap.size > 2) new.questionMap.size - 3 else 0
val lastCount = new.questionMap.filterKeys { it in from downTo to }.count { item -> item.value.right }

val hint = last.name + if (lastCount == 3) {
" \uD83D\uDD25"
} else if (new.score > last.score) {
" \uD83D\uDC4D"
} else if (new.score == last.score && lastRes != null) {
" \uD83D\uDE2D"
} else ""
name.text = hint
}
}
}
Expand Down
Loading

0 comments on commit d475299

Please sign in to comment.