Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the feature to change template of notification to small #196

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class Data(val args: Map<String, Any?>) {
var from: String = ""

var isCustomNotification: Boolean = false
var isCustomSmallExNotification: Boolean = false
var isShowLogo: Boolean = false
var isShowCallback: Boolean = true
var ringtonePath: String
Expand All @@ -43,6 +44,8 @@ data class Data(val args: Map<String, Any?>) {
val android: HashMap<String, Any?>? = args["android"] as? HashMap<String, Any?>?
if (android != null) {
isCustomNotification = (android["isCustomNotification"] as? Boolean) ?: false
isCustomSmallExNotification =
(android["isCustomSmallExNotification"] as? Boolean) ?: false
isShowLogo = (android["isShowLogo"] as? Boolean) ?: false
isShowCallback = (android["isShowCallback"] as? Boolean) ?: true
ringtonePath = (android["ringtonePath"] as? String) ?: ""
Expand All @@ -54,6 +57,7 @@ data class Data(val args: Map<String, Any?>) {
missedCallNotificationChannelName = android["missedCallNotificationChannelName"] as? String
} else {
isCustomNotification = (args["isCustomNotification"] as? Boolean) ?: false
isCustomSmallExNotification = (args["isCustomSmallExNotification"] as? Boolean) ?: false
isShowLogo = (args["isShowLogo"] as? Boolean) ?: false
isShowCallback = (args["isShowCallback"] as? Boolean) ?: true
ringtonePath = (args["ringtonePath"] as? String) ?: ""
Expand Down Expand Up @@ -93,6 +97,10 @@ data class Data(val args: Map<String, Any?>) {
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION,
isCustomNotification
)
bundle.putBoolean(
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION,
isCustomSmallExNotification
)
bundle.putBoolean(
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_SHOW_LOGO,
isShowLogo
Expand Down Expand Up @@ -157,8 +165,12 @@ data class Data(val args: Map<String, Any?>) {
bundle.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>

data.isCustomNotification = bundle.getBoolean(
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION,
false
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION,
false
)
data.isCustomSmallExNotification = bundle.getBoolean(
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION,
false
)
data.isShowLogo = bundle.getBoolean(
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_IS_SHOW_LOGO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CallkitIncomingBroadcastReceiver : BroadcastReceiver() {
const val EXTRA_CALLKIT_EXTRA = "EXTRA_CALLKIT_EXTRA"
const val EXTRA_CALLKIT_HEADERS = "EXTRA_CALLKIT_HEADERS"
const val EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION = "EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION"
const val EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION =
"EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION"
const val EXTRA_CALLKIT_IS_SHOW_LOGO = "EXTRA_CALLKIT_IS_SHOW_LOGO"
const val EXTRA_CALLKIT_IS_SHOW_MISSED_CALL_NOTIFICATION = "EXTRA_CALLKIT_IS_SHOW_MISSED_CALL_NOTIFICATION"
const val EXTRA_CALLKIT_IS_SHOW_CALLBACK = "EXTRA_CALLKIT_IS_SHOW_CALLBACK"
Expand Down Expand Up @@ -188,13 +190,23 @@ class CallkitIncomingBroadcastReceiver : BroadcastReceiver() {
@Suppress("UNCHECKED_CAST")
private fun sendEventFlutter(event: String, data: Bundle) {
val android = mapOf(
"isCustomNotification" to data.getBoolean(EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION, false),
"ringtonePath" to data.getString(EXTRA_CALLKIT_RINGTONE_PATH, ""),
"backgroundColor" to data.getString(EXTRA_CALLKIT_BACKGROUND_COLOR, ""),
"backgroundUrl" to data.getString(EXTRA_CALLKIT_BACKGROUND_URL, ""),
"actionColor" to data.getString(EXTRA_CALLKIT_ACTION_COLOR, ""),
"incomingCallNotificationChannelName" to data.getString(EXTRA_CALLKIT_INCOMING_CALL_NOTIFICATION_CHANNEL_NAME, ""),
"missedCallNotificationChannelName" to data.getString(EXTRA_CALLKIT_MISSED_CALL_NOTIFICATION_CHANNEL_NAME, ""),
"isCustomNotification" to data.getBoolean(EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION, false),
"isCustomSmallExNotification" to data.getBoolean(
EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION,
false
),
"ringtonePath" to data.getString(EXTRA_CALLKIT_RINGTONE_PATH, ""),
"backgroundColor" to data.getString(EXTRA_CALLKIT_BACKGROUND_COLOR, ""),
"backgroundUrl" to data.getString(EXTRA_CALLKIT_BACKGROUND_URL, ""),
"actionColor" to data.getString(EXTRA_CALLKIT_ACTION_COLOR, ""),
"incomingCallNotificationChannelName" to data.getString(
EXTRA_CALLKIT_INCOMING_CALL_NOTIFICATION_CHANNEL_NAME,
""
),
"missedCallNotificationChannelName" to data.getString(
EXTRA_CALLKIT_MISSED_CALL_NOTIFICATION_CHANNEL_NAME,
""
),
)
val forwardData = mapOf(
"id" to data.getString(EXTRA_CALLKIT_ID, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Comp
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_ID
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_INCOMING_CALL_NOTIFICATION_CHANNEL_NAME
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_MISSED_CALL_NOTIFICATION_CHANNEL_NAME
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_NAME_CALLER
import com.hiennv.flutter_callkit_incoming.CallkitIncomingBroadcastReceiver.Companion.EXTRA_CALLKIT_TEXT_ACCEPT
Expand Down Expand Up @@ -132,13 +133,17 @@ class CallkitNotificationManager(private val context: Context) {
notificationBuilder.setChannelId(NOTIFICATION_CHANNEL_ID_INCOMING)
notificationBuilder.priority = NotificationCompat.PRIORITY_MAX
val isCustomNotification = data.getBoolean(EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION, false)
val isCustomSmallExNotification = data.getBoolean(EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION, false)
if (isCustomNotification) {
notificationViews =
RemoteViews(context.packageName, R.layout.layout_custom_notification)
initNotificationViews(notificationViews!!, data)


if (Build.MANUFACTURER.equals("Samsung", ignoreCase = true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if ((Build.MANUFACTURER.equals(
"Samsung",
ignoreCase = true
) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) || isCustomSmallExNotification
) {
notificationSmallViews =
RemoteViews(context.packageName, R.layout.layout_custom_small_ex_notification)
initNotificationViews(notificationSmallViews!!, data)
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_callkit_incoming
description: Flutter Callkit Incoming to show callkit screen in your Flutter app.
version: 1.0.2+2
version: 1.0.2+3
homepage: https://github.com/hiennguyen92/flutter_callkit_incoming
repository: https://github.com/hiennguyen92/flutter_callkit_incoming
issue_tracker: https://github.com/hiennguyen92/flutter_callkit_incoming/issues
Expand Down