Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRalek committed Dec 31, 2023
1 parent b35526a commit cc156fe
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 19 deletions.
7 changes: 3 additions & 4 deletions app/src/main/java/com/example/indangersms/EmergencyWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class EmergencyWidget : AppWidgetProvider() {
if (testMode) {
if (isPermission) {
senderProvider.sendNotification(
"Message Not Sent",
"Message was unsuccesfully sent, please disable Test Mode before using the widget.",
"Test Mode is On",
"Message was not sent, please disable Test Mode before using the widget.",
context
)
}
Expand All @@ -84,7 +84,7 @@ class EmergencyWidget : AppWidgetProvider() {
}
} else if (isPermission) {
senderProvider.sendNotification(
"Message Not Sent",
"Emergency Contact or SMS not set up",
"Please first set your emergency contact and message content.",
context
)
Expand All @@ -101,7 +101,6 @@ class EmergencyWidget : AppWidgetProvider() {
}
}


private fun getPendingSelfIntent(
context: Context,
action: String,
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/indangersms/SenderProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.indangersms
import android.app.AlertDialog
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
Expand Down Expand Up @@ -155,11 +156,23 @@ class SenderProvider(private var context: Context, private var alert: Boolean =
notificationManager.createNotificationChannel(channel)
}

val intent = Intent(context, MainActivity::class.java) // Replace YourMainActivity::class.java with the actual main activity of your app
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

val pendingIntent = PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)

val builder = NotificationCompat.Builder(context, "emergency_alerts")
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.drawable.baseline_warning_amber_24)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.setAutoCancel(true)

notificationManager.notify(1, builder.build())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class HomeFragment : Fragment() {
}
}
}
binding.sendSmsButton.backgroundTintList =
ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.red))
binding.sendSmsButton.backgroundTintList = null
// ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.red))

setSubtitle()

Expand Down
35 changes: 23 additions & 12 deletions app/src/main/res/drawable/round_button.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:right="5dp" android:bottom="5dp">
<item
android:bottom="1dp"
android:right="1dp">
<shape android:shape="oval">
<solid android:color="#FF0000" />
<corners android:radius="15dp" />
<solid android:color="#55000000" />
</shape>
</item>

<item android:left="32dp" android:top="32dp" android:right="36dp" android:bottom="36dp">
<item
android:left="1dp"
android:top="1dp">
<shape android:shape="oval">
<solid android:color="@android:color/transparent" />
<stroke
android:width="5dp"
android:color="#FFFFFF" />
<solid android:color="#55FFFFFF" />
</shape>
</item>

<item android:left="1dp" android:top="1dp">
<item
android:bottom="5dp"
android:right="5dp">
<shape android:shape="oval">
<solid android:color="#55FFFFFF" />
<solid android:color="#FF0000" />
<corners android:radius="15dp" />
</shape>
</item>

<item android:right="1dp" android:bottom="1dp">
<item
android:bottom="29dp"
android:left="25dp"
android:right="29dp"
android:top="25dp">
<shape android:shape="oval">
<solid android:color="#55000000" />
<solid android:color="@android:color/transparent" />
<stroke
android:width="3dp"
android:color="#5F1616" />
</shape>
</item>


</layer-list>
29 changes: 29 additions & 0 deletions app/src/main/res/drawable/round_button_widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:bottom="1dp"
android:right="1dp">
<shape android:shape="oval">
<solid android:color="#55000000" />
</shape>
</item>

<item
android:left="1dp"
android:top="1dp">
<shape android:shape="oval">
<solid android:color="#55FFFFFF" />
</shape>
</item>

<item
android:bottom="5dp"
android:right="5dp">
<shape android:shape="oval">
<solid android:color="#FF0000" />
<corners android:radius="15dp" />
</shape>
</item>

</layer-list>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/widget_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:id="@+id/widgetButton"
android:layout_width="58dp"
android:layout_height="58dp"
android:background="@drawable/round_button"
android:background="@drawable/round_button_widget"
android:textColor="@color/white"
android:contentDescription="Send SMS"
android:textSize="18sp"
Expand Down

0 comments on commit cc156fe

Please sign in to comment.