@@ -22,6 +22,9 @@ import androidx.drawerlayout.widget.DrawerLayout
2222import androidx.lifecycle.ViewModelProvider
2323import androidx.lifecycle.lifecycleScope
2424import com.google.android.material.floatingactionbutton.FloatingActionButton
25+ import com.google.android.material.shape.CornerFamily
26+ import com.google.android.material.shape.MaterialShapeDrawable
27+ import com.google.android.material.shape.ShapeAppearanceModel
2528import com.google.firebase.analytics.FirebaseAnalytics
2629import kotlinx.coroutines.Dispatchers
2730import kotlinx.coroutines.launch
@@ -163,7 +166,17 @@ class MainActivity : AppCompatActivity() {
163166 private fun updateStatus () {
164167 val host = viewModel.getHost()
165168 val hostView = findViewById<TextView >(R .id.tvCurrentHost)
169+ val statusView = findViewById<TextView >(R .id.tvStatus)
166170 val hostColor = ThemeUtil .getColorFromAttr(this , R .attr.colorHost)
171+ val inactiveColor = ThemeUtil .getColorFromAttr(this , R .attr.colorOnSurface)
172+ val labelTextColor = ThemeUtil .getColorFromAttr(this @MainActivity, R .attr.colorSurface)
173+ val versionColorList = ColorStateList .valueOf(ThemeUtil .getColorFromAttr(this @MainActivity, R .attr.colorPrimary))
174+ val radius = dp2px(2.0f ).toFloat()
175+ val shapeAppearanceModel = ShapeAppearanceModel ()
176+ .toBuilder()
177+ .setAllCorners(CornerFamily .ROUNDED , radius)
178+ .build()
179+
167180 host.observe(this ) {
168181 hostView?.text = if (it.startsWith(" https" , true )) {
169182 val sIcon = SpannableString (" " )
@@ -176,17 +189,29 @@ class MainActivity : AppCompatActivity() {
176189 }
177190 val data = viewModel.get()
178191 data.observe(this ) {
179- findViewById<TextView >(R .id.tvStatus)?.text = it
180- if (it.equals(getString(R .string.server_not_responding)))
181- hostView.apply {
182- setTextColor(ThemeUtil .getColorFromAttr(this @MainActivity, R .attr.colorOnSurface))
192+ statusView?.text = it
193+ if (it.equals(getString(R .string.server_not_responding))) {
194+ statusView?.apply {
195+ background = null
196+ setTextColor(inactiveColor)
197+ }
198+ hostView?.apply {
199+ setTextColor(inactiveColor)
183200 alpha = 0.75f
184201 }
185- else
186- hostView.apply {
202+ } else {
203+ statusView?.apply {
204+ val shapeDrawable = MaterialShapeDrawable (shapeAppearanceModel)
205+ shapeDrawable.fillColor = versionColorList.withAlpha(160 ) // 160
206+ shapeDrawable.setStroke(2.0f , versionColorList.withAlpha(100 )) // 100
207+ background = shapeDrawable
208+ setTextColor(labelTextColor)
209+ }
210+ hostView?.apply {
187211 setTextColor(hostColor)
188212 alpha = 1.0f
189213 }
214+ }
190215 }
191216 }
192217
0 commit comments