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

Add press-back command push action #227

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class TopActivityProvider(
) {

private val pendingActions = mutableListOf<(Activity) -> Unit>()
private var topActivity: Activity? = null
set(activity) {
var topActivity: Activity? = null
private set(activity) {
field = activity
executePendingActions()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.jraska.github.client.push

import com.jraska.github.client.common.BooleanResult
import com.jraska.github.client.common.BooleanResult.SUCCESS
import com.jraska.github.client.core.android.TopActivityProvider
import javax.inject.Inject

internal class PressBackButtonCommand @Inject constructor(
private val topActivityProvider: TopActivityProvider
) : PushActionCommand {
override fun execute(action: PushAction): BooleanResult {
val activity = topActivityProvider.topActivity ?: return SUCCESS // no-op if in background
activity.onBackPressed()
return SUCCESS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jraska.github.client.push
import com.google.firebase.database.FirebaseDatabase
import com.jraska.github.client.core.android.OnAppCreate
import com.jraska.github.client.core.android.ServiceModel
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.ClassKey
Expand All @@ -11,66 +12,59 @@ import dagger.multibindings.IntoSet
import dagger.multibindings.StringKey
import javax.inject.Singleton

@Module
@Module(includes = [PushModule.Declarations::class])
object PushModule {

@Provides
@IntoSet
internal fun bindObserverSetup(observerSetup: PushIntentObserver.CallbacksSetup): OnAppCreate {
return observerSetup
@Singleton
internal fun firebaseDatabase(): FirebaseDatabase {
return FirebaseDatabase.getInstance()
}

@Provides
@IntoSet
internal fun setupNotificationsOnCreate(notificationSetup: NotificationSetup): OnAppCreate {
return notificationSetup
}
@Module
abstract class Declarations {

@Provides
@IntoMap
@ClassKey(PushHandleModel::class)
internal fun bindServiceModel(pushHandleModel: PushHandleModel): ServiceModel {
return pushHandleModel
}
@Binds
@IntoSet
internal abstract fun bindObserverSetup(observerSetup: PushIntentObserver.CallbacksSetup): OnAppCreate

@Provides
@IntoMap
@StringKey("refresh_config")
internal fun refreshConfigCommand(command: RefreshConfigCommand): PushActionCommand {
return command
}
@Binds
@IntoSet
internal abstract fun setupNotificationsOnCreate(notificationSetup: NotificationSetup): OnAppCreate

@Provides
@IntoMap
@StringKey("set_config_as_property")
internal fun configAsPropertyCommand(command: ConfigAsPropertyCommand): PushActionCommand {
return command
}
@Binds
@IntoMap
@ClassKey(PushHandleModel::class)
internal abstract fun bindServiceModel(pushHandleModel: PushHandleModel): ServiceModel

@Provides
@IntoMap
@StringKey("set_analytics_property")
internal fun setAnalyticsProperty(command: SetAnalyticsPropertyCommand): PushActionCommand {
return command
}
@Binds
@IntoMap
@StringKey("refresh_config")
internal abstract fun refreshConfigCommand(command: RefreshConfigCommand): PushActionCommand

@Provides
@IntoMap
@StringKey("notification")
internal fun notificationCommand(command: ShowNotificationCommand): PushActionCommand {
return command
}
@Binds
@IntoMap
@StringKey("set_config_as_property")
internal abstract fun configAsPropertyCommand(command: ConfigAsPropertyCommand): PushActionCommand

@Provides
@IntoMap
@StringKey("launch_deep_link")
internal fun deepLinkCommand(command: LaunchDeepLinkCommand): PushActionCommand {
return command
}
@Binds
@IntoMap
@StringKey("set_analytics_property")
internal abstract fun setAnalyticsProperty(command: SetAnalyticsPropertyCommand): PushActionCommand

@Provides
@Singleton
internal fun firebaseDatabase(): FirebaseDatabase {
return FirebaseDatabase.getInstance()
@Binds
@IntoMap
@StringKey("notification")
internal abstract fun notificationCommand(command: ShowNotificationCommand): PushActionCommand

@Binds
@IntoMap
@StringKey("launch_deep_link")
internal abstract fun deepLinkCommand(command: LaunchDeepLinkCommand): PushActionCommand

@Binds
@IntoMap
@StringKey("press_back")
internal abstract fun pressBackCommand(command: PressBackButtonCommand): PushActionCommand
}
}