Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 229bc8f

Browse files
committed
add ability to set dash message text color as desired
1 parent cae5e52 commit 229bc8f

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/dashboard/DashMessage.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.matthewnelson.sampleapp.ui.fragments.dashboard
22

3+
import androidx.annotation.ColorRes
34
import androidx.annotation.DrawableRes
5+
import io.matthewnelson.sampleapp.R
46

57
class DashMessage(
68
val message: String,
79
@DrawableRes val background: Int,
8-
val showLength: Long
10+
val showLength: Long,
11+
@ColorRes val textColor: Int = R.color.tor_service_white
912
) {
1013
companion object {
1114
const val EXCEPTION = "~~~ EXCEPTION ~~~\n"

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/dashboard/DashboardFragment.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.app.NotificationManager
55
import android.app.PendingIntent
66
import android.content.Context
77
import android.content.Intent
8+
import android.graphics.Color
89
import android.os.Build
910
import android.os.Bundle
1011
import androidx.fragment.app.Fragment
@@ -13,6 +14,7 @@ import android.view.View
1314
import android.view.ViewGroup
1415
import android.widget.Button
1516
import android.widget.TextView
17+
import androidx.annotation.ColorRes
1618
import androidx.core.app.NotificationCompat
1719
import androidx.core.content.ContextCompat
1820
import androidx.lifecycle.*
@@ -98,6 +100,8 @@ class DashboardFragment : Fragment() {
98100
liveDashMessage.observe(owner, Observer {
99101
if (it != null) {
100102
textViewMessage.text = it.message
103+
val colorHex = colorResToHexString(textViewMessage.context, it.textColor)
104+
textViewMessage.setTextColor(Color.parseColor(colorHex))
101105
textViewMessage.background = ContextCompat.getDrawable(textViewMessage.context, it.background)
102106
textViewMessage.visibility = View.VISIBLE
103107
launchCleanUpMessageJob(it.showLength)
@@ -127,6 +131,9 @@ class DashboardFragment : Fragment() {
127131
}
128132
}
129133

134+
private fun colorResToHexString(context: Context, @ColorRes colorRes: Int): String =
135+
"#${Integer.toHexString(ContextCompat.getColor(context, colorRes))}"
136+
130137
private var showMessageCleanUpJob: Job? = null
131138

132139
private fun launchCleanUpMessageJob(delayLength: Long) {

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/settings/library/SettingsLibraryFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ class SettingsLibraryFragment : Fragment() {
179179
)
180180
} else {
181181
DashboardFragment.showMessage(
182-
DashMessage("No Changes", R.drawable.dash_message_color_secondary_light, 2_000)
182+
DashMessage(
183+
"No Changes",
184+
R.drawable.dash_message_color_secondary_light,
185+
2_000,
186+
R.color.black
187+
)
183188
)
184189
}
185190
}

sampleapp/src/main/res/layout/fragment_dashboard.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@
208208
android:layout_marginEnd="8dp"
209209
android:gravity="center_horizontal"
210210
android:padding="8dp"
211-
android:textColor="@color/black"
212211
android:visibility="gone"
213212
app:layout_constraintEnd_toEndOf="@+id/dash_text_view_tor_network_state"
214213
app:layout_constraintStart_toStartOf="@+id/dash_text_view_tor_state"

0 commit comments

Comments
 (0)