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

feat: Implement Firebase Cloud Messaging & In-app Messaging #296

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

andhikayuana
Copy link
Contributor

@andhikayuana andhikayuana commented Dec 14, 2024

Overview

Simple implementation for Firebase Cloud Messaging and Firebase In-app Messaging

Issue

https://github.com/litecoin-foundation/litewallet-engineering/issues/3

Self Test

will share on slack

@kcw-grunt
Copy link
Contributor

👀

// .addOnSuccessListener(new OnSuccessListener<String>() {
// @Override
// public void onSuccess(String s) {
// Timber.d("timber: fcm getToken= %s", s);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to log fcm token, in case we need to test fcm with specific device

if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
DISPLAY_HEIGHT_PX = Resources.getSystem().getDisplayMetrics().heightPixels;

String afID = Utils.fetchPartnerKey(this, PartnerNames.AFDEVID);
AppsFlyerLib.getInstance().init(afID, null, this);
AppsFlyerLib.getInstance().start(this);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this is I am using the shortcut/menu that mentioned before

private final ActivityResultLauncher<String> requestNotificationPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) {
Toast.makeText(app, R.string.permission_notification_granted, Toast.LENGTH_SHORT).show();
Copy link
Contributor Author

@andhikayuana andhikayuana Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if granted just show toast here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

showInAppReviewDialogIfNeeded();
}

private void setupNotificationPermission() {
//https://developer.android.com/develop/ui/views/notifications/notification-permission
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notification runtime permission available from API level 33 and higher

if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.POST_NOTIFICATIONS)) {
new AlertDialog.Builder(this)
.setTitle(R.string.permission_info)
.setMessage(R.string.please_grant_notification_permission)
Copy link
Contributor Author

@andhikayuana andhikayuana Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just show dialog if shouldShowRequestPermissionRationale return true

@@ -141,6 +141,7 @@ private BRConstants() {
public static final String _20240101_US = "user_signup";
public static final String _20241006_DRR = "did_request_rating";
public static final String _20241006_UCR = "user_completed_rating";
public static final String _HOME_OPEN = "home_open";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is event to trigger display in-app messaging, will share the video on slack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

val channelId = remoteMessage.notification?.channelId ?: NOTIFICATION_CHANNEL_ID_GENERAL
val title = remoteMessage.data["title"] ?: return false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -776,4 +776,13 @@
<string name="Announce.no_thanks">No, thanks!</string>
<string name="Fees.Service">Service</string>
<string name="ConfirmationAllFees.Label">Fees:</string>

<string name="notification_channel_name_general" translatable="false">General</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently I just create this new copy, do we have to translate into all of languages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. What do you think @kcw-grunt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for channel name maybe no need to translate, but like please_grant_notification_permission I think we need to translate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Im wrapping my head around leveraging the Google Translate in the FCM dashboard @andhikayuana

mockkStatic(NotificationManagerCompat::class)
every { NotificationManagerCompat.from(context).notify(any()) } just Runs

//todo: revisit, test still fail because specific platform API e.g. android.app.Notification$Builder
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to revisit later, since error with specific API platform here

@andhikayuana andhikayuana marked this pull request as ready for review December 14, 2024 12:14
@andhikayuana andhikayuana self-assigned this Dec 14, 2024
.setContentIntent(pendingIntent)
.setAutoCancel(true)

NotificationManagerCompat.from(context)
Copy link
Contributor

@josikie josikie Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does NotificationManagerCompat do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to post/cancel android notification on the status bar android
more https://developer.android.com/develop/ui/views/notifications/build-notification#notify

) == PackageManager.PERMISSION_GRANTED
}

@JvmStatic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this ask user the permission for notifications when user open the app for the first time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josikie this allows us to reach the users that are using the app. So, we dont need push notification authorization
@andhikayuana please correct me if I got this wrong...;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, noted! @kcw-grunt

Copy link
Contributor

@josikie josikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you! @andhikayuana

Copy link
Contributor

@kcw-grunt kcw-grunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
But, everyone in the Litewallet team needs to test this feature and we need to ilicit feedback as we do iOS version

) == PackageManager.PERMISSION_GRANTED
}

@JvmStatic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josikie this allows us to reach the users that are using the app. So, we dont need push notification authorization
@andhikayuana please correct me if I got this wrong...;)

object PermissionUtil {

@JvmStatic
fun hasPermissions(context: Context, permissions: Array<String>): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andhikayuana is this for inapp only permission? Or is this for auth for when the app is closed. Or is it both?

private final ActivityResultLauncher<String> requestNotificationPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) {
Toast.makeText(app, R.string.permission_notification_granted, Toast.LENGTH_SHORT).show();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@@ -776,4 +776,13 @@
<string name="Announce.no_thanks">No, thanks!</string>
<string name="Fees.Service">Service</string>
<string name="ConfirmationAllFees.Label">Fees:</string>

<string name="notification_channel_name_general" translatable="false">General</string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Im wrapping my head around leveraging the Google Translate in the FCM dashboard @andhikayuana

@kcw-grunt kcw-grunt added the 🥳 feature New feature or enhancement request label Dec 19, 2024
@kcw-grunt kcw-grunt added this to the v2.13.X milestone Dec 19, 2024
@kcw-grunt kcw-grunt merged commit 39d6fdd into develop Dec 19, 2024
0 of 2 checks passed
losh11 pushed a commit that referenced this pull request Feb 7, 2025
* feat: add notification channel

* feat: add PermissionUtil

* feat: request notification permission for API 33 or above

* feat: implement firebase in-app messaging

* feat: implement simple cloud messaging

* feat: add NotificationHandlerTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🥳 feature New feature or enhancement request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants