Skip to content

Commit

Permalink
🎨 Major design update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed Apr 9, 2022
1 parent 40ca49a commit df0f859
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 55 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

7 changes: 6 additions & 1 deletion .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import android.view.WindowInsets
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
Expand All @@ -24,6 +25,14 @@ class MainActivity : AppCompatActivity() {
setWindowState()
}

fun setBackground(id: Int) {
binding.root.background = ResourcesCompat.getDrawable(resources, id, theme)
}

fun setDefaultColor() {
binding.root.background = ResourcesCompat.getDrawable(resources, R.drawable.main_grad, theme)
}

@Suppress("deprecation")
private fun setWindowState() {
window.setFlags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ class ResultAdapter(private val clients: MutableList<ClientInfo>) :
private fun bind(info: ClientInfo?) {
info?.let {
with(binding) {

binding.root.playFadeInAnimation(R.anim.fade_in_animation)
name.text = it.name

val base = it.questionMap.count { item -> item.value.right } * 1000
var timeDependent = 0
val scr = it.questionMap.values.filter { item -> item.right }.sumOf {
1200 - it.time * 10
}

score.text = scr.toString()

place.text = root.context.getString(R.string.place, clients.map {
item -> item.questionMap.values.sumOf { q -> if (q.right) 1200 - q.time * 10 else 0 }
}.indexOf(scr) + 1)

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 hint = it.name + " \uD83D\uDD25"
name.text = hint
}

val res = base + timeDependent
score.text = res.toString()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ClientViewModel(private val api: ApiService, private val repo: ClientRepo)
try {
value = api.hasStarted(repo.sessionId)
} catch (e: Exception) {}
delay(1_000)
delay(500)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.os.Bundle
import android.transition.TransitionInflater
import android.view.*
import androidx.cardview.widget.CardView
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -97,6 +99,18 @@ class GameFragment : Fragment(), MainActivity.IOnBackPressed {
postponeEnterTransition()
sharedElementEnterTransition = TransitionInflater.from(context)
.inflateTransition(android.R.transition.move)

val gradIds = listOf(
R.drawable.grad_1,
R.drawable.grad_2,
R.drawable.grad_3,
R.drawable.grad_4
)

val gradient = gradIds.random()

(activity as MainActivity).setBackground(gradient)

startPostponedEnterTransition()

with(binding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class ResultFragment : Fragment(), MainActivity.IOnBackPressed {
postponeEnterTransition()
sharedElementEnterTransition = TransitionInflater.from(context)
.inflateTransition(android.R.transition.move)

(activity as MainActivity).setDefaultColor()

startPostponedEnterTransition()

viewModel.onPassiveStateEnded.observe(viewLifecycleOwner, onPassiveStateEndedObserver)
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable-v24/grad_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="45"
android:startColor="#ff9a27"
android:endColor="#ed7ff4" />
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable-v24/grad_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="45"
android:startColor="#a4e82e"
android:endColor="#69a7d8" />
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable-v24/grad_3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="45"
android:startColor="#d86969"
android:endColor="#392ee8" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable-v24/grad_4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="45"
android:startColor="#b800c3"
android:centerColor="#34a793"
android:endColor="#f99898" />
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/main_grad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="270"
android:startColor="@color/dark_gray"
android:endColor="#7f7bc5" />
</shape>
41 changes: 0 additions & 41 deletions app/src/main/res/drawable/progress.xml

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_gray"
android:background="@drawable/main_grad"
android:fitsSystemWindows="true"
tools:context=".ui.activity.MainActivity">

Expand All @@ -13,6 +13,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:elevation="0dp"
android:background="@android:color/transparent"
android:fitsSystemWindows="true"
android:layoutAnimation="@null"
android:paddingStart="12dp"
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/res/layout/result_client_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:layout_margin="12dp">

<TextView
android:id="@+id/name"
android:id="@+id/place"
style="@style/CardTextStyleTitle"
android:textSize="16sp"
android:alpha="0.7"
Expand All @@ -17,14 +17,25 @@
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/score"
android:id="@+id/name"
android:textSize="22sp"
style="@style/CardTextStyleTitle"
android:layout_width="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginStart="10dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/place" />

<TextView
android:id="@+id/score"
android:textSize="22sp"
style="@style/CardTextStyleTitle"
android:layout_width="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginStart="20dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name" />

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="app_name">KQuiz</string>
<string name="question_size">%d %s</string>
<string name="place">%d место</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/test/java/com/albatros/kquiz/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import org.junit.Assert.*
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
assertEquals(4L, 2 + 2 as Long)
}
}

0 comments on commit df0f859

Please sign in to comment.