Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Add coloured statuses for build list #370

Merged
merged 3 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ interface BuildListDataModel :
* @return {true} if build is queued
*/
fun isQueued(position: Int): Boolean

/**
* @param position - Adapter position
* @return {true} if build is success
*/
fun isSuccess(position: Int): Boolean

/**
* @param position - Adapter position
* @return {true} if build is failed
*/
fun isFailed(position: Int): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ class BuildListDataModelImpl(private val buildDetailsList: MutableList<BuildDeta
return buildDetailsList[position].isQueued
}

/**
* {@inheritDoc}
*/
override fun isSuccess(position: Int): Boolean {
return buildDetailsList[position].isSuccess
}

/**
* {@inheritDoc}
*/
override fun isFailed(position: Int): Boolean {
return buildDetailsList[position].isFailed
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Andrey Tolpeev
* Copyright 2020 Andrey Tolpeev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,17 +16,21 @@

package com.github.vase4kin.teamcityapp.buildlist.view

import android.content.res.ColorStateList
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.widget.ImageViewCompat
import butterknife.BindView
import butterknife.ButterKnife
import com.github.vase4kin.teamcityapp.R
import com.github.vase4kin.teamcityapp.base.list.view.BaseViewHolder
import com.github.vase4kin.teamcityapp.buildlist.data.BuildListDataModel
import teamcityapp.libraries.utils.getThemeColor

/**
* Changes single item view holder
Expand All @@ -40,16 +44,22 @@ class BuildViewHolder(parent: ViewGroup) : BaseViewHolder<BuildListDataModel>(
) {
@BindView(R.id.branchName)
lateinit var branchName: TextView

@BindView(R.id.buildStatus)
lateinit var buildStatus: TextView

@BindView(R.id.buildStatusImage)
lateinit var buildStatusImage: ImageView

@BindView(R.id.buildNumber)
lateinit var buildNumber: TextView

@BindView(R.id.isPersonal)
lateinit var isPersonalImage: View

@BindView(R.id.isPinned)
lateinit var isPinnedImage: View

@BindView(R.id.buildStatusProgress)
lateinit var buildStatusProgress: ProgressBar

Expand All @@ -66,6 +76,32 @@ class BuildViewHolder(parent: ViewGroup) : BaseViewHolder<BuildListDataModel>(
buildStatusImage.visibility = View.VISIBLE
val iconImageRes = dataModel.getBuildStatusIcon(position)
buildStatusImage.setImageResource(iconImageRes)
when {
dataModel.isSuccess(position) -> {
val color = itemView.context.getThemeColor(R.attr.colorSuccessState)
ImageViewCompat.setImageTintList(
buildStatusImage,
ColorStateList.valueOf(color)
)
}
dataModel.isFailed(position) -> {
val color = itemView.context.getThemeColor(R.attr.colorFailedState)
ImageViewCompat.setImageTintList(
buildStatusImage,
ColorStateList.valueOf(color)
)
}
else -> {
val color = ContextCompat.getColor(
itemView.context,
R.color.material_on_surface_emphasis_high_type
)
ImageViewCompat.setImageTintList(
buildStatusImage,
ColorStateList.valueOf(color)
)
}
}
}
buildStatus.text = dataModel.getStatusText(position)
val buildNumber = dataModel.getBuildNumber(position)
Expand Down
7 changes: 5 additions & 2 deletions libraries/resources/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<color name="green_200">#03dac6</color> <!--Color secondary (light)-->
<color name="green_500">#018786</color> <!--Color secondary variant (light)-->

<color name="cyan_200">#80DEEA</color> <!--Color secondary (light)-->
<color name="cyan_500">#00BCD4</color> <!--Color secondary variant (light)-->
<color name="cyan_200">#80DEEA</color> <!--Color secondary (dark)-->
<color name="cyan_500">#00BCD4</color> <!--Color secondary variant (dark)-->

<color name="red_200">#cf6679</color> <!--Color error (dark)-->
<color name="red_600">#b00020</color> <!--Color error (light)-->
Expand All @@ -41,5 +41,8 @@

<!--Custom colors-->
<color name="grey_100">#f5f5f5</color>
<color name="green_600">#00897b</color>
<color name="cyan_900">#00acc1</color>
<color name="pink_900">#d81b60</color>

</resources>
3 changes: 3 additions & 0 deletions libraries/theme/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
<item name="colorOnError">@color/black_900</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
<!--Custom attrs-->
<item name="colorSuccessState">@color/cyan_900</item>
<item name="colorFailedState">@color/pink_900</item>
</style>
</resources>
20 changes: 20 additions & 0 deletions libraries/theme/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2020 Andrey Tolpeev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>
<attr name="colorSuccessState" format="color" />
<attr name="colorFailedState" format="color" />
</resources>
3 changes: 3 additions & 0 deletions libraries/theme/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<item name="bottomNavigationStyle">
@style/Widget.MaterialComponents.BottomNavigationView.PrimarySurface
</item>
<!--Custom attrs-->
<item name="colorSuccessState">@color/green_600</item>
<item name="colorFailedState">@color/red_600</item>
</style>

<style name="Base.Theme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
Expand Down