mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Push test: success if user click on the notification
This commit is contained in:
parent
5e45f5c3ea
commit
dbb77d9dc1
@ -53,9 +53,15 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat
|
||||
}
|
||||
|
||||
override fun onSuccess(data: Unit) {
|
||||
// Wait for user to click on the notification
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_success)
|
||||
status = TestStatus.SUCCESS
|
||||
status = TestStatus.RUNNING
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onNotificationClicked() {
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_notification_clicked)
|
||||
status = TestStatus.SUCCESS
|
||||
}
|
||||
}
|
||||
|
@ -252,6 +252,10 @@
|
||||
android:name=".features.call.service.CallHeadsUpActionReceiver"
|
||||
android:exported="false" />
|
||||
|
||||
<receiver
|
||||
android:name=".features.settings.troubleshoot.TestNotificationReceiver"
|
||||
android:exported="false" />
|
||||
|
||||
<!-- Exported false, should only be accessible from this app!! -->
|
||||
<receiver
|
||||
android:name=".features.notifications.NotificationBroadcastReceiver"
|
||||
|
@ -51,6 +51,7 @@ import im.vector.app.features.home.HomeActivity
|
||||
import im.vector.app.features.home.room.detail.RoomDetailActivity
|
||||
import im.vector.app.features.home.room.detail.RoomDetailArgs
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.features.settings.troubleshoot.TestNotificationReceiver
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@ -90,6 +91,7 @@ class NotificationUtils @Inject constructor(private val context: Context,
|
||||
const val DISMISS_SUMMARY_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.DISMISS_SUMMARY_ACTION"
|
||||
const val DISMISS_ROOM_NOTIF_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.DISMISS_ROOM_NOTIF_ACTION"
|
||||
private const val TAP_TO_VIEW_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.TAP_TO_VIEW_ACTION"
|
||||
const val DIAGNOSTIC_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.DIAGNOSTIC"
|
||||
|
||||
/* ==========================================================================================
|
||||
* IDs for channels
|
||||
@ -847,6 +849,15 @@ class NotificationUtils @Inject constructor(private val context: Context,
|
||||
}
|
||||
|
||||
fun displayDiagnosticNotification() {
|
||||
val testActionIntent = Intent(context, TestNotificationReceiver::class.java)
|
||||
testActionIntent.action = DIAGNOSTIC_ACTION
|
||||
val testPendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
0,
|
||||
testActionIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
|
||||
notificationManager.notify(
|
||||
"DIAGNOSTIC",
|
||||
888,
|
||||
@ -859,6 +870,7 @@ class NotificationUtils @Inject constructor(private val context: Context,
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(testPendingIntent)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
@ -16,12 +16,16 @@
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -32,10 +36,12 @@ import im.vector.app.core.extensions.cleanup
|
||||
import im.vector.app.core.extensions.registerStartForActivityResult
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.features.notifications.NotificationUtils
|
||||
import im.vector.app.features.rageshake.BugReporter
|
||||
import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
||||
import im.vector.app.features.settings.troubleshoot.TroubleshootTest
|
||||
import im.vector.app.push.fcm.NotificationTroubleshootTestManagerFactory
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
||||
@ -45,12 +51,16 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
||||
|
||||
@BindView(R.id.troubleshoot_test_recycler_view)
|
||||
lateinit var mRecyclerView: RecyclerView
|
||||
|
||||
@BindView(R.id.troubleshoot_bottom_view)
|
||||
lateinit var mBottomView: ViewGroup
|
||||
|
||||
@BindView(R.id.toubleshoot_summ_description)
|
||||
lateinit var mSummaryDescription: TextView
|
||||
|
||||
@BindView(R.id.troubleshoot_summ_button)
|
||||
lateinit var mSummaryButton: Button
|
||||
|
||||
@BindView(R.id.troubleshoot_run_button)
|
||||
lateinit var mRunButton: Button
|
||||
|
||||
@ -108,6 +118,7 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
||||
}
|
||||
TroubleshootTest.TestStatus.FAILED -> {
|
||||
// check if there are quick fixes
|
||||
// TODO Rewrite using firstOrNull
|
||||
var hasQuickFix = false
|
||||
testManager?.testList?.let {
|
||||
for (test in it) {
|
||||
@ -161,6 +172,25 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(activity as? VectorBaseActivity)?.supportActionBar?.setTitle(R.string.settings_notification_troubleshoot)
|
||||
|
||||
tryOrNull("Unable to register the receiver") {
|
||||
LocalBroadcastManager.getInstance(requireContext())
|
||||
.registerReceiver(broadcastReceiver, IntentFilter(NotificationUtils.DIAGNOSTIC_ACTION))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
tryOrNull {
|
||||
LocalBroadcastManager.getInstance(requireContext())
|
||||
.unregisterReceiver(broadcastReceiver)
|
||||
}
|
||||
}
|
||||
|
||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
testManager?.onDiagnosticNotificationClicked()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
|
@ -94,4 +94,10 @@ class NotificationTroubleshootTestManager(val fragment: Fragment) {
|
||||
test.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
fun onDiagnosticNotificationClicked() {
|
||||
testList.forEach {
|
||||
it.onNotificationClicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings.troubleshoot
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
|
||||
class TestNotificationReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
// Internal broadcast to any one interested
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
||||
}
|
||||
}
|
@ -51,4 +51,7 @@ abstract class TroubleshootTest(@StringRes val titleResId: Int) {
|
||||
|
||||
open fun cancel() {
|
||||
}
|
||||
|
||||
open fun onNotificationClicked() {
|
||||
}
|
||||
}
|
||||
|
@ -750,9 +750,10 @@
|
||||
<string name="settings_troubleshoot_test_token_registration_failed">Failed to register FCM token to HomeServer:\n%1$s</string>
|
||||
|
||||
<string name="settings_troubleshoot_test_push_loop_title">Test Push</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_success">The application is receiving PUSH, you should see a notification.</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_success">The application is receiving PUSH, please click on the test notification you just receive.</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_notification_clicked">The notification has been clicked!</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_failed">Failed to receive push. Solution could be to reinstall the application.</string>
|
||||
<string name="settings_troubleshoot_test_push_notification_content">You are receiving PUSH!</string>
|
||||
<string name="settings_troubleshoot_test_push_notification_content">You are receiving PUSH! Click me!</string>
|
||||
|
||||
<string name="settings_troubleshoot_test_foreground_service_started_title">Notifications Service</string>
|
||||
<string name="settings_troubleshoot_test_foreground_service_startedt_success">Notifications Service is running.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user