-
-
Notifications
You must be signed in to change notification settings - Fork 45
Solved Android 15 edge to edge issue + added loading blocking UI #3421
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,20 @@ import android.view.Menu | |
| import android.view.MenuItem | ||
| import android.view.View | ||
| import android.widget.Toast | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.lifecycle.ViewModelProvider | ||
| import org.commcare.activities.connect.viewmodel.PushNotificationViewModel | ||
| import org.commcare.adapters.PushNotificationAdapter | ||
| import org.commcare.android.database.connect.models.PushNotificationRecord | ||
| import org.commcare.dalvik.R | ||
| import org.commcare.dalvik.databinding.ActivityPushNotificationBinding | ||
| import org.commcare.google.services.analytics.AnalyticsParamValue | ||
| import org.commcare.google.services.analytics.CCAnalyticsParam | ||
| import org.commcare.google.services.analytics.FirebaseAnalyticsUtil | ||
| import org.commcare.pn.helper.NotificationBroadcastHelper | ||
| import org.commcare.preferences.NotificationPrefs | ||
| import org.commcare.utils.FirebaseMessagingUtil.getIntentForPNClick | ||
| import org.commcare.views.dialogs.CustomProgressDialog | ||
|
|
||
| class PushNotificationActivity : AppCompatActivity() { | ||
| class PushNotificationActivity : CommCareActivity<PushNotificationActivity>() { | ||
| private val binding: ActivityPushNotificationBinding by lazy { | ||
| ActivityPushNotificationBinding.inflate(layoutInflater) | ||
| } | ||
|
|
@@ -32,7 +31,7 @@ class PushNotificationActivity : AppCompatActivity() { | |
| initViews() | ||
| observeRetrieveNotificationApi() | ||
| registerForNewNotification() | ||
| pushNotificationViewModel.loadNotifications(isRefreshed = false) | ||
| pushNotificationViewModel.loadNotifications(isRefreshed = false, this) | ||
| } | ||
|
|
||
| private fun observeRetrieveNotificationApi() { | ||
|
|
@@ -109,7 +108,7 @@ class PushNotificationActivity : AppCompatActivity() { | |
| } | ||
|
|
||
| R.id.notification_cloud_sync -> { | ||
| pushNotificationViewModel.loadNotifications(isRefreshed = true) | ||
| pushNotificationViewModel.loadNotifications(isRefreshed = true, this) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: same as above |
||
| true | ||
| } | ||
|
|
||
|
|
@@ -121,7 +120,10 @@ class PushNotificationActivity : AppCompatActivity() { | |
| // Whenever new notification is received, signalling is calling retrieve_notifications api | ||
| // so whenever this broadcast is received, new notification is already stored in local DB | ||
| // that's the reason that isRefreshed = false is required | ||
| pushNotificationViewModel.loadNotifications(false) | ||
| pushNotificationViewModel.loadNotifications(false, this) | ||
| } | ||
| } | ||
|
|
||
| override fun generateProgressDialog(taskId: Int): CustomProgressDialog = | ||
| CustomProgressDialog.newInstance(null, getString(R.string.please_wait), taskId) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,32 +7,38 @@ import android.content.IntentFilter | |
| import androidx.lifecycle.DefaultLifecycleObserver | ||
| import androidx.lifecycle.LifecycleOwner | ||
| import androidx.localbroadcastmanager.content.LocalBroadcastManager | ||
|
|
||
| object NotificationBroadcastHelper { | ||
| const val ACTION_NEW_NOTIFICATIONS = "org.commcare.dalvik.action.NEW_NOTIFICATION" | ||
|
|
||
| fun registerForNotifications( | ||
| context: Context, | ||
| owner: LifecycleOwner, | ||
| onNewNotification: () -> Unit | ||
| onNewNotification: () -> Unit, | ||
| ) { | ||
| val receiver = object : BroadcastReceiver() { | ||
| override fun onReceive(c: Context?, i: Intent?) { | ||
| onNewNotification() | ||
| val receiver = | ||
| object : BroadcastReceiver() { | ||
| override fun onReceive( | ||
| c: Context?, | ||
| i: Intent?, | ||
| ) { | ||
| onNewNotification() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| val manager = LocalBroadcastManager.getInstance(context) | ||
|
|
||
| owner.lifecycle.addObserver(object : DefaultLifecycleObserver { | ||
| override fun onResume(owner: LifecycleOwner) { | ||
| manager.registerReceiver(receiver, IntentFilter(ACTION_NEW_NOTIFICATIONS)) | ||
| onNewNotification() | ||
| } | ||
| owner.lifecycle.addObserver( | ||
| object : DefaultLifecycleObserver { | ||
| override fun onResume(owner: LifecycleOwner) { | ||
| manager.registerReceiver(receiver, IntentFilter(ACTION_NEW_NOTIFICATIONS)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see onNewNotification was removed here, just making sure that was intentional?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it was intentional. Whenever any activity register for new notification broadcast, it was calling onNewNotification even though there were no new notifications. |
||
| } | ||
|
|
||
| override fun onPause(owner: LifecycleOwner) { | ||
| manager.unregisterReceiver(receiver) | ||
| } | ||
| }) | ||
| override fun onPause(owner: LifecycleOwner) { | ||
| manager.unregisterReceiver(receiver) | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| fun sendNewNotificationBroadcast(context: Context) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Having an unlabeled input after a labeled one feels odd to me, thinking maybe better to remove the label here? So it looks like line 123