Skip to content

Commit edc57a9

Browse files
committed
fixed notifs
1 parent 47bdae9 commit edc57a9

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

app/src/main/java/com/atom/letmein/MainActivity.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ class MainActivity : AppCompatActivity() {
7979
"LOCATION" -> {
8080
if (idWS == 0) {
8181
idWS = it
82-
sendPermanentPush("LetMeIn", "${getString(R.string.req_sent)} (45s)", it)
82+
sendPermanentPush(getString(R.string.req_sent), "${getString(R.string.req_sent_exp)} (${response?.currentTime}s)", it)
8383
}
8484
}
85-
"COUNTDOWN" -> updatePush("${getString(R.string.req_sent)} (${response?.currentTime}s)", it)
85+
"COUNTDOWN" -> updatePush("${getString(R.string.req_sent_exp)} (${response?.currentTime}s)", it)
8686
"TIMEOUT" -> {
87-
sendTemporaryPush("LetMeIn", getString(R.string.req_timeout))
87+
sendTemporaryPush(getString(R.string.req_timeout), getString(R.string.req_timeout_exp))
8888
this.close()
8989
}
9090
"ACKNOWLEDGE" -> {
91-
sendTemporaryPush("LetMeIn", getString(R.string.req_ack))
91+
sendTemporaryPush(getString(R.string.req_ack), getString(R.string.req_ack_exp))
9292
this.close()
9393
}
9494
}
@@ -99,18 +99,18 @@ class MainActivity : AppCompatActivity() {
9999
override fun onClose(code: Int, reason: String?, remote: Boolean) {
100100
println("Connection was closed! Reason: $reason")
101101
notificationManager.cancel(idWS)
102-
sendTemporaryPush("Error", getString(R.string.req_error))
103102
}
104103

105104
override fun onError(ex: Exception?) {
106105
println("Connection ran into an error: ${ex.toString()}")
107106
ex?.printStackTrace()
108107
notificationManager.cancel(idWS)
108+
sendTemporaryPush(getString(R.string.req_error), getString(R.string.req_error_exp), 2024)
109109
}
110110
}
111111
}
112112

113-
fun sendPermanentPush(title: String, description: String, code: Int = 2023) {
113+
fun sendPermanentPush(subject: String, description: String, code: Int = 2023) {
114114
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
115115
notificationChannel =
116116
NotificationChannel(channelId, description, NotificationManager.IMPORTANCE_HIGH)
@@ -123,18 +123,21 @@ class MainActivity : AppCompatActivity() {
123123
}
124124
builder.setSmallIcon(R.drawable.csh_logo)
125125
.setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.csh_logo))
126+
.setContentTitle(subject)
126127
.setContentText(description)
127-
.setContentTitle(title)
128128
.setAutoCancel(false)
129129
.setOngoing(true)
130130
.setOnlyAlertOnce(true)
131+
.setColor(Color.MAGENTA)
132+
.style = Notification.BigTextStyle()
133+
.bigText(description)
131134
notificationManager.notify(code, builder.build())
132135
}
133136

134-
fun sendTemporaryPush(title: String, description: String, code: Int = 2023) {
137+
fun sendTemporaryPush(subject: String, description: String, code: Int = 2023) {
135138
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
136139
notificationChannel =
137-
NotificationChannel(channelId, description, NotificationManager.IMPORTANCE_HIGH)
140+
NotificationChannel(channelId, description, NotificationManager.IMPORTANCE_LOW)
138141
notificationChannel.lightColor = Color.MAGENTA
139142
notificationManager.createNotificationChannel(notificationChannel)
140143

@@ -144,13 +147,18 @@ class MainActivity : AppCompatActivity() {
144147
}
145148
builder.setSmallIcon(R.drawable.csh_logo)
146149
.setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.csh_logo))
150+
.setContentTitle(subject)
147151
.setContentText(description)
148-
.setContentTitle(title)
152+
.setColor(Color.MAGENTA)
153+
.style = Notification.BigTextStyle()
154+
.bigText(description)
149155
notificationManager.notify(code, builder.build())
150156
}
151157

152158
fun updatePush(description: String, code: Int = 2023) {
153159
builder.setContentText(description)
160+
.style = Notification.BigTextStyle()
161+
.bigText(description)
154162
notificationManager.notify(code, builder.build())
155163
}
156164

app/src/main/res/values/strings.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
<string name="l_well">L Well</string>
1212

1313
<string name="wsURI">letmein2-dev.cs.house</string>
14-
<string name="req_sent">Your request has been sent!</string>
15-
<string name="req_timeout">Your request timed out unfortunately. Please try again later.</string>
16-
<string name="req_ack">Someone answered your request! They will be arriving shortly.</string>
17-
<string name="req_error">Unfortunately, there was an error in your request. Please try again later.</string>
14+
<string name="req_sent">Your request has been sent! </string>
15+
<string name="req_sent_exp">Sit tight while we wait for someone to respond to your request!</string>
16+
<string name="req_timeout">Your request timed out! 🔴</string>
17+
<string name="req_timeout_exp">Your request timed out unfortunately. Please try again later.</string>
18+
<string name="req_ack">Request answered! 🟢</string>
19+
<string name="req_ack_exp">Someone answered your request! They will be arriving shortly.</string>
20+
<string name="req_error">Connection failed! 🔴</string>
21+
<string name="req_error_exp">Unfortunately, there was an error in your request. Please try again later.</string>
1822
</resources>

0 commit comments

Comments
 (0)