Skip to content

Commit

Permalink
add version status badge
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed Jun 14, 2024
1 parent b498e22 commit 15a2677
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -163,7 +166,17 @@ class MainActivity : AppCompatActivity() {
private fun updateStatus() {
val host = viewModel.getHost()
val hostView = findViewById<TextView>(R.id.tvCurrentHost)
val statusView = findViewById<TextView>(R.id.tvStatus)
val hostColor = ThemeUtil.getColorFromAttr(this, R.attr.colorHost)
val inactiveColor = ThemeUtil.getColorFromAttr(this, R.attr.colorOnSurface)
val labelTextColor = ThemeUtil.getColorFromAttr(this@MainActivity, R.attr.colorSurface)
val versionColorList = ColorStateList.valueOf(ThemeUtil.getColorFromAttr(this@MainActivity, R.attr.colorPrimary))
val radius = dp2px(2.0f).toFloat()
val shapeAppearanceModel = ShapeAppearanceModel()
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED, radius)
.build()

host.observe(this) {
hostView?.text = if (it.startsWith("https", true)) {
val sIcon = SpannableString(" ")
Expand All @@ -176,17 +189,29 @@ class MainActivity : AppCompatActivity() {
}
val data = viewModel.get()
data.observe(this) {
findViewById<TextView>(R.id.tvStatus)?.text = it
if (it.equals(getString(R.string.server_not_responding)))
hostView.apply {
setTextColor(ThemeUtil.getColorFromAttr(this@MainActivity, R.attr.colorOnSurface))
statusView?.text = it
if (it.equals(getString(R.string.server_not_responding))) {
statusView?.apply {
background = null
setTextColor(inactiveColor)
}
hostView?.apply {
setTextColor(inactiveColor)
alpha = 0.75f
}
else
hostView.apply {
} else {
statusView?.apply {
val shapeDrawable = MaterialShapeDrawable(shapeAppearanceModel)
shapeDrawable.fillColor = versionColorList.withAlpha(160) // 160
shapeDrawable.setStroke(2.0f, versionColorList.withAlpha(100)) // 100
background = shapeDrawable
setTextColor(labelTextColor)
}
hostView?.apply {
setTextColor(hostColor)
alpha = 1.0f
}
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/navigation_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@

<TextView
android:id="@+id/tvStatus"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:includeFontPadding="true"
android:paddingStart="4dp"
android:paddingLeft="4dp"
android:paddingEnd="4dp"
android:paddingRight="4dp"
android:gravity="center"
tools:text="Status"
android:textSize="12sp" />
Expand Down

0 comments on commit 15a2677

Please sign in to comment.