-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove analytics responsibilities from Pushhandler and move them into…
… separate class
- Loading branch information
Showing
4 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
feature/push/src/main/java/com/jraska/github/client/push/PushAnalytics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jraska.github.client.push | ||
|
||
import com.jraska.github.client.analytics.AnalyticsEvent | ||
import com.jraska.github.client.analytics.EventAnalytics | ||
import com.jraska.github.client.common.BooleanResult | ||
import com.jraska.github.client.identity.IdentityProvider | ||
import javax.inject.Inject | ||
|
||
internal class PushAnalytics @Inject constructor( | ||
private val identityProvider: IdentityProvider, | ||
private val eventAnalytics: EventAnalytics | ||
) { | ||
fun onTokenRefresh() { | ||
val tokenEvent = AnalyticsEvent.builder("push_token_refresh") | ||
.addProperty("session_id", identityProvider.session().id.toString()) | ||
.build() | ||
eventAnalytics.report(tokenEvent) | ||
} | ||
|
||
fun onPushHandled(action: PushAction, result: BooleanResult) { | ||
if (result == BooleanResult.SUCCESS) { | ||
val pushHandled = AnalyticsEvent.builder("push_handled") | ||
.addProperty("push_action", action.name) | ||
.build() | ||
eventAnalytics.report(pushHandled) | ||
} else { | ||
val pushHandled = AnalyticsEvent.builder("push_not_handled") | ||
.addProperty("push_action", action.name) | ||
.build() | ||
eventAnalytics.report(pushHandled) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 2 additions & 27 deletions
29
feature/push/src/main/java/com/jraska/github/client/push/PushHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,25 @@ | ||
package com.jraska.github.client.push | ||
|
||
import com.jraska.github.client.analytics.AnalyticsEvent | ||
import com.jraska.github.client.analytics.EventAnalytics | ||
import com.jraska.github.client.common.BooleanResult | ||
import com.jraska.github.client.identity.IdentityProvider | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
import javax.inject.Provider | ||
|
||
class PushHandler @Inject internal constructor( | ||
private val eventAnalytics: EventAnalytics, | ||
private val tokenSynchronizer: PushTokenSynchronizer, | ||
private val identityProvider: IdentityProvider, | ||
private val pushCommands: Map<String, @JvmSuppressWildcards Provider<PushActionCommand>> | ||
) { | ||
|
||
internal fun handlePush(action: PushAction) { | ||
internal fun handlePush(action: PushAction): BooleanResult { | ||
Timber.v("Push received action: %s", action.name) | ||
|
||
val result = handleInternal(action) | ||
|
||
if (result == BooleanResult.SUCCESS) { | ||
val pushHandled = AnalyticsEvent.builder("push_handled") | ||
.addProperty("push_action", action.name) | ||
.build() | ||
eventAnalytics.report(pushHandled) | ||
} else { | ||
val pushHandled = AnalyticsEvent.builder("push_not_handled") | ||
.addProperty("push_action", action.name) | ||
.build() | ||
eventAnalytics.report(pushHandled) | ||
} | ||
return handleInternal(action) | ||
} | ||
|
||
private fun handleInternal(action: PushAction): BooleanResult { | ||
val actionCommand = pushCommands[action.name] ?: return BooleanResult.FAILURE | ||
|
||
return actionCommand.get().execute(action) | ||
} | ||
|
||
internal fun onTokenRefresh(token: String) { | ||
tokenSynchronizer.synchronizeToken(token) | ||
|
||
val tokenEvent = AnalyticsEvent.builder("push_token_refresh") | ||
.addProperty("session_id", identityProvider.session().id.toString()) | ||
.build() | ||
eventAnalytics.report(tokenEvent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters