mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +03:00
Cleanup and cancel request properly
This commit is contained in:
parent
dbb77d9dc1
commit
ab9bbe9a48
6 changed files with 41 additions and 34 deletions
|
@ -79,7 +79,7 @@ interface PushersService {
|
|||
appId: String,
|
||||
pushkey: String,
|
||||
eventId: String,
|
||||
callback: MatrixCallback<Unit>)
|
||||
callback: MatrixCallback<Unit>): Cancelable
|
||||
|
||||
/**
|
||||
* Remove the http pusher
|
||||
|
|
|
@ -51,8 +51,8 @@ internal class DefaultPushersService @Inject constructor(
|
|||
appId: String,
|
||||
pushkey: String,
|
||||
eventId: String,
|
||||
callback: MatrixCallback<Unit>) {
|
||||
pushGatewayNotifyTask
|
||||
callback: MatrixCallback<Unit>): Cancelable {
|
||||
return pushGatewayNotifyTask
|
||||
.configureWith(PushGatewayNotifyTask.Params(url, appId, pushkey, eventId)) {
|
||||
this.callback = callback
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import im.vector.app.features.settings.troubleshoot.TroubleshootTest
|
|||
import im.vector.app.push.fcm.FcmHelper
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.pushers.PushGatewayFailure
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
|
@ -37,12 +38,14 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat
|
|||
private val pushersManager: PushersManager)
|
||||
: TroubleshootTest(R.string.settings_troubleshoot_test_push_loop_title) {
|
||||
|
||||
private var action: Cancelable? = null
|
||||
|
||||
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
val fcmToken = FcmHelper.getFcmToken(context) ?: run {
|
||||
status = TestStatus.FAILED
|
||||
return
|
||||
}
|
||||
pushersManager.testPush(fcmToken, object : MatrixCallback<Unit> {
|
||||
action = pushersManager.testPush(fcmToken, object : MatrixCallback<Unit> {
|
||||
override fun onFailure(failure: Throwable) {
|
||||
description = if (failure is PushGatewayFailure.PusherRejected) {
|
||||
stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed)
|
||||
|
@ -64,4 +67,8 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat
|
|||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_notification_clicked)
|
||||
status = TestStatus.SUCCESS
|
||||
}
|
||||
|
||||
override fun cancel() {
|
||||
action?.cancel()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import im.vector.app.core.resources.AppNameProvider
|
|||
import im.vector.app.core.resources.LocaleProvider
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.abs
|
||||
|
@ -34,10 +35,10 @@ class PushersManager @Inject constructor(
|
|||
private val stringProvider: StringProvider,
|
||||
private val appNameProvider: AppNameProvider
|
||||
) {
|
||||
fun testPush(pushKey: String, callback: MatrixCallback<Unit>) {
|
||||
fun testPush(pushKey: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||
val currentSession = activeSessionHolder.getActiveSession()
|
||||
|
||||
currentSession.testPush(
|
||||
return currentSession.testPush(
|
||||
stringProvider.getString(R.string.pusher_http_url),
|
||||
stringProvider.getString(R.string.pusher_app_id),
|
||||
pushKey,
|
||||
|
|
|
@ -41,6 +41,7 @@ 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.orFalse
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -92,8 +93,7 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
|||
}
|
||||
|
||||
private fun startUI() {
|
||||
mSummaryDescription.text = getString(R.string.settings_troubleshoot_diagnostic_running_status,
|
||||
0, 0)
|
||||
mSummaryDescription.text = getString(R.string.settings_troubleshoot_diagnostic_running_status, 0, 0)
|
||||
testManager = testManagerFactory.create(this)
|
||||
testManager?.statusListener = { troubleshootTestManager ->
|
||||
if (isAdded) {
|
||||
|
@ -105,9 +105,8 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
|||
mRunButton.visibility = View.VISIBLE
|
||||
}
|
||||
TroubleshootTest.TestStatus.RUNNING -> {
|
||||
// Forces int type because it's breaking lint
|
||||
val size: Int = troubleshootTestManager.testList.size
|
||||
val currentTestIndex: Int = troubleshootTestManager.currentTestIndex
|
||||
val size = troubleshootTestManager.testListSize
|
||||
val currentTestIndex = troubleshootTestManager.currentTestIndex
|
||||
mSummaryDescription.text = getString(
|
||||
R.string.settings_troubleshoot_diagnostic_running_status,
|
||||
currentTestIndex,
|
||||
|
@ -118,16 +117,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) {
|
||||
if (test.status == TroubleshootTest.TestStatus.FAILED && test.quickFix != null) {
|
||||
hasQuickFix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
val hasQuickFix = testManager?.hasQuickFix().orFalse()
|
||||
if (hasQuickFix) {
|
||||
mSummaryDescription.text = getString(R.string.settings_troubleshoot_diagnostic_failure_status_with_quickfix)
|
||||
} else {
|
||||
|
|
|
@ -23,13 +23,19 @@ import androidx.fragment.app.Fragment
|
|||
import kotlin.properties.Delegates
|
||||
|
||||
class NotificationTroubleshootTestManager(val fragment: Fragment) {
|
||||
private val testList = ArrayList<TroubleshootTest>()
|
||||
|
||||
val testListSize: Int
|
||||
get() = testList.size
|
||||
|
||||
val testList = ArrayList<TroubleshootTest>()
|
||||
var isCancelled = false
|
||||
private set
|
||||
|
||||
var currentTestIndex by Delegates.observable(0) { _, _, _ ->
|
||||
statusListener?.invoke(this)
|
||||
}
|
||||
private set
|
||||
|
||||
val adapter = NotificationTroubleshootRecyclerViewAdapter(testList)
|
||||
|
||||
var statusListener: ((NotificationTroubleshootTestManager) -> Unit)? = null
|
||||
|
@ -37,6 +43,7 @@ class NotificationTroubleshootTestManager(val fragment: Fragment) {
|
|||
var diagStatus: TroubleshootTest.TestStatus by Delegates.observable(TroubleshootTest.TestStatus.NOT_STARTED) { _, _, _ ->
|
||||
statusListener?.invoke(this)
|
||||
}
|
||||
private set
|
||||
|
||||
fun addTest(test: TroubleshootTest) {
|
||||
testList.add(test)
|
||||
|
@ -79,25 +86,27 @@ class NotificationTroubleshootTestManager(val fragment: Fragment) {
|
|||
}
|
||||
|
||||
fun retry(activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
for (test in testList) {
|
||||
test.cancel()
|
||||
test.description = null
|
||||
test.quickFix = null
|
||||
test.status = TroubleshootTest.TestStatus.NOT_STARTED
|
||||
testList.forEach {
|
||||
it.cancel()
|
||||
it.description = null
|
||||
it.quickFix = null
|
||||
it.status = TroubleshootTest.TestStatus.NOT_STARTED
|
||||
}
|
||||
runDiagnostic(activityResultLauncher)
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
isCancelled = true
|
||||
for (test in testList) {
|
||||
test.cancel()
|
||||
fun hasQuickFix(): Boolean {
|
||||
return testList.any { test ->
|
||||
test.status == TroubleshootTest.TestStatus.FAILED && test.quickFix != null
|
||||
}
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
isCancelled = true
|
||||
testList.forEach { it.cancel() }
|
||||
}
|
||||
|
||||
fun onDiagnosticNotificationClicked() {
|
||||
testList.forEach {
|
||||
it.onNotificationClicked()
|
||||
}
|
||||
testList.forEach { it.onNotificationClicked() }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue