diff --git a/app/src/main/java/com/bykov/footea/details/TeamDetailsActivity.kt b/app/src/main/java/com/bykov/footea/details/TeamDetailsActivity.kt index ee78dab..63017bb 100644 --- a/app/src/main/java/com/bykov/footea/details/TeamDetailsActivity.kt +++ b/app/src/main/java/com/bykov/footea/details/TeamDetailsActivity.kt @@ -6,6 +6,7 @@ import android.app.Activity import android.content.Intent import android.graphics.drawable.ColorDrawable import android.os.Bundle +import android.view.View import android.view.WindowManager import android.widget.ImageView import android.widget.TextView @@ -21,6 +22,7 @@ import com.bykov.footea.extensions.getColorFromAttr import com.bykov.footea.extensions.toast import com.bykov.footea.models.FootballTeamDetails import com.bykov.footea.ui.PaletteRequestListener +import com.bykov.footea.ui.widgets.HalfFieldDrawable import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.CollapsingToolbarLayout @@ -76,6 +78,10 @@ class TeamDetailsActivity : AppCompatActivity(R.layout.activity_team_details), T findViewById(R.id.venue) } + private val lineupContent: View by lazy(LazyThreadSafetyMode.NONE) { + findViewById(R.id.lineup_card_content) + } + private val appBarOffsetChangeListener = AppBarOffsetChangeListener( onOffsetChanged = { _, offsetRange -> teamBadge.alpha = 1 - offsetRange @@ -102,6 +108,7 @@ class TeamDetailsActivity : AppCompatActivity(R.layout.activity_team_details), T } appBarLayout.addOnOffsetChangedListener(appBarOffsetChangeListener) titleViewAnimator.onViewsCreated(teamName, toolbarTitle) + lineupContent.background = HalfFieldDrawable(this) presenter.loadTeamDetails(intent.getIntExtra(EXTRA_TEAM_ID, NO_TEAM_ID)) } diff --git a/app/src/main/java/com/bykov/footea/ui/widgets/HalfFieldDrawable.kt b/app/src/main/java/com/bykov/footea/ui/widgets/HalfFieldDrawable.kt new file mode 100644 index 0000000..bc57e5f --- /dev/null +++ b/app/src/main/java/com/bykov/footea/ui/widgets/HalfFieldDrawable.kt @@ -0,0 +1,118 @@ +package com.bykov.footea.ui.widgets + +import android.content.Context +import android.graphics.Canvas +import android.graphics.ColorFilter +import android.graphics.Paint +import android.graphics.PixelFormat +import android.graphics.Rect +import android.graphics.drawable.Drawable +import androidx.core.content.res.ResourcesCompat +import com.bykov.footea.R + +/** + * Draws half of the field. + * + * Inspired by https://proandroiddev.com/building-a-team-lineup-view-on-android-daaf27e3901e + */ +class HalfFieldDrawable(context: Context) : Drawable() { + + private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { + strokeWidth = context.resources.getDimension(R.dimen.field_line_width) + color = ResourcesCompat.getColor(context.resources, R.color.field_line, context.theme) + style = Paint.Style.STROKE + } + + private val rect = Rect() + private val padding = context.resources.getDimensionPixelSize(R.dimen.field_line_padding) + private val halfInnerGoalWidth = context.resources.getDimensionPixelSize(R.dimen.field_inner_goal_width) + private val halfInnerGoalHeight = context.resources.getDimensionPixelSize(R.dimen.field_inner_goal_height) + private val halfGoalWidth = context.resources.getDimensionPixelSize(R.dimen.field_goal_width) + private val halfGoalHeight = context.resources.getDimensionPixelSize(R.dimen.field_goal_height) + private val cornerSize = context.resources.getDimensionPixelSize(R.dimen.field_corner_size) + private val centerCircleSize = context.resources.getDimensionPixelSize(R.dimen.field_center_circle_size) + private val centerInnerCircleSize = context.resources.getDimensionPixelSize(R.dimen.field_center_inner_circle_size) + + override fun draw(canvas: Canvas) { + val width = bounds.width() + val height = bounds.height() + canvas.apply { + // draw field lines + rect.set(padding, padding, width - padding, height - padding) + drawRect(rect, linePaint) + // draw goals + rect.set( + width / 2 - halfInnerGoalWidth, + padding, + width / 2 + halfInnerGoalWidth, + padding + halfInnerGoalHeight + ) + drawRect(rect, linePaint) + rect.set( + width / 2 - halfGoalWidth, + padding, + width / 2 + halfGoalWidth, + padding + halfGoalHeight + ) + drawRect(rect, linePaint) + // draw corners + drawArc( + padding.toFloat() - cornerSize, + padding.toFloat() - cornerSize, + (padding + cornerSize).toFloat(), + (padding + cornerSize).toFloat(), + 0f, + 90f, + false, + linePaint + ) + drawArc( + (width - padding - cornerSize).toFloat(), + padding.toFloat() - cornerSize, + (width - padding + cornerSize).toFloat(), + (padding + cornerSize).toFloat(), + 90f, + 90f, + false, + linePaint + ) + // draw center circle + drawArc( + (width / 2 - centerCircleSize).toFloat(), + (height - padding - centerCircleSize).toFloat(), + (width / 2 + centerCircleSize).toFloat(), + (height - padding + centerCircleSize).toFloat(), + 180f, + 180f, + false, + linePaint + ) + linePaint.style = Paint.Style.FILL + drawArc( + (width / 2 - centerInnerCircleSize).toFloat(), + (height - padding - centerInnerCircleSize).toFloat(), + (width / 2 + centerInnerCircleSize).toFloat(), + (height - padding + centerInnerCircleSize).toFloat(), + 180f, + 180f, + false, + linePaint + ) + } + } + + override fun setAlpha(alpha: Int) { + // no-op + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + // no-op + } + + @Deprecated("Deprecated in Java", + ReplaceWith("PixelFormat.OPAQUE", "android.graphics.PixelFormat") + ) + override fun getOpacity(): Int { + return PixelFormat.OPAQUE + } +} diff --git a/app/src/main/res/layout/activity_team_details.xml b/app/src/main/res/layout/activity_team_details.xml index 5458081..78d5a19 100644 --- a/app/src/main/res/layout/activity_team_details.xml +++ b/app/src/main/res/layout/activity_team_details.xml @@ -121,27 +121,80 @@ + android:padding="8dp" + android:clipToPadding="false"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + + + + + android:layout_marginTop="8dp" + app:cardBackgroundColor="@color/white_12" + app:cardCornerRadius="6dp" + app:cardElevation="4dp" + app:layout_constraintTop_toBottomOf="@id/venue_card"> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 97a792c..8a8e65f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -9,4 +9,7 @@ #000000 #ffffff #fafafa + + + #808080 \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..eb1b935 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,13 @@ + + + + 2dp + 8dp + 32dp + 24dp + 104dp + 64dp + 12dp + 48dp + 4dp + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8ceb96..a88a1f8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,5 +3,6 @@ Error loading football teams! Team badge National - Venue + Stadium + Starting XI \ No newline at end of file