-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create RMF matchers for duckPlayerOnboarded and duckPlayerEnabled
- Loading branch information
1 parent
dc3c086
commit a795252
Showing
8 changed files
with
189 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
74 changes: 74 additions & 0 deletions
74
...mpl/src/main/java/com/duckduckgo/duckplayer/impl/DuckPlayerEnabledRMFMatchingAttribute.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,74 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* 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 com.duckduckgo.duckplayer.impl | ||
|
||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.duckplayer.api.DuckPlayer | ||
import com.duckduckgo.duckplayer.api.DuckPlayer.DuckPlayerState.ENABLED | ||
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.AlwaysAsk | ||
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Enabled | ||
import com.duckduckgo.remote.messaging.api.AttributeMatcherPlugin | ||
import com.duckduckgo.remote.messaging.api.JsonMatchingAttribute | ||
import com.duckduckgo.remote.messaging.api.JsonToMatchingAttributeMapper | ||
import com.duckduckgo.remote.messaging.api.MatchingAttribute | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import dagger.SingleInstanceIn | ||
import javax.inject.Inject | ||
|
||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = JsonToMatchingAttributeMapper::class, | ||
) | ||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = AttributeMatcherPlugin::class, | ||
) | ||
@SingleInstanceIn(AppScope::class) | ||
class DuckPlayerEnabledRMFMatchingAttribute @Inject constructor( | ||
private val duckPlayer: DuckPlayer, | ||
) : JsonToMatchingAttributeMapper, AttributeMatcherPlugin { | ||
override suspend fun evaluate(matchingAttribute: MatchingAttribute): Boolean? { | ||
val duckPlayerEnabled = duckPlayer.getDuckPlayerState() == ENABLED && | ||
duckPlayer.getUserPreferences().privatePlayerMode.let { it == AlwaysAsk || it == Enabled } | ||
return when (matchingAttribute) { | ||
is DuckPlayerEnabledMatchingAttribute -> duckPlayerEnabled == matchingAttribute.remoteValue | ||
else -> null | ||
} | ||
} | ||
|
||
override fun map( | ||
key: String, | ||
jsonMatchingAttribute: JsonMatchingAttribute, | ||
): MatchingAttribute? { | ||
return when (key) { | ||
DuckPlayerEnabledMatchingAttribute.KEY -> { | ||
jsonMatchingAttribute.value?.let { | ||
DuckPlayerEnabledMatchingAttribute(jsonMatchingAttribute.value as Boolean) | ||
} | ||
} | ||
else -> null | ||
} | ||
} | ||
} | ||
|
||
internal data class DuckPlayerEnabledMatchingAttribute( | ||
val remoteValue: Boolean, | ||
) : MatchingAttribute { | ||
companion object { | ||
const val KEY = "duckPlayerEnabled" | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...l/src/main/java/com/duckduckgo/duckplayer/impl/DuckPlayerOnboardedRMFMatchingAttribute.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,68 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* 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 com.duckduckgo.duckplayer.impl | ||
|
||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.remote.messaging.api.AttributeMatcherPlugin | ||
import com.duckduckgo.remote.messaging.api.JsonMatchingAttribute | ||
import com.duckduckgo.remote.messaging.api.JsonToMatchingAttributeMapper | ||
import com.duckduckgo.remote.messaging.api.MatchingAttribute | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import dagger.SingleInstanceIn | ||
import javax.inject.Inject | ||
|
||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = JsonToMatchingAttributeMapper::class, | ||
) | ||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = AttributeMatcherPlugin::class, | ||
) | ||
@SingleInstanceIn(AppScope::class) | ||
class DuckPlayerOnboardedRMFMatchingAttribute @Inject constructor( | ||
private val duckPlayerFeatureRepository: DuckPlayerFeatureRepository, | ||
) : JsonToMatchingAttributeMapper, AttributeMatcherPlugin { | ||
override suspend fun evaluate(matchingAttribute: MatchingAttribute): Boolean? { | ||
return when (matchingAttribute) { | ||
is DuckPlayerOnboardedMatchingAttribute -> duckPlayerFeatureRepository.isOnboarded() == matchingAttribute.remoteValue | ||
else -> null | ||
} | ||
} | ||
|
||
override fun map( | ||
key: String, | ||
jsonMatchingAttribute: JsonMatchingAttribute, | ||
): MatchingAttribute? { | ||
return when (key) { | ||
DuckPlayerOnboardedMatchingAttribute.KEY -> { | ||
jsonMatchingAttribute.value?.let { | ||
DuckPlayerOnboardedMatchingAttribute(jsonMatchingAttribute.value as Boolean) | ||
} | ||
} | ||
else -> null | ||
} | ||
} | ||
} | ||
|
||
internal data class DuckPlayerOnboardedMatchingAttribute( | ||
val remoteValue: Boolean, | ||
) : MatchingAttribute { | ||
companion object { | ||
const val KEY = "duckPlayerOnboarded" | ||
} | ||
} |
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