Skip to content

Commit 6bf1074

Browse files
committed
rename to BrowserAndInputScreenTransitionProviderImpl and use DI
1 parent d384d98 commit 6bf1074

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ import com.duckduckgo.downloads.api.DownloadsFileActions
287287
import com.duckduckgo.downloads.api.FileDownloader
288288
import com.duckduckgo.downloads.api.FileDownloader.PendingFileDownload
289289
import com.duckduckgo.duckchat.api.DuckChat
290-
import com.duckduckgo.duckchat.api.InputScreenAnimationResourceProvider
290+
import com.duckduckgo.duckchat.api.inputscreen.BrowserAndInputScreenTransitionProvider
291291
import com.duckduckgo.duckchat.impl.inputscreen.ui.InputScreenActivity.Companion.QUERY
292292
import com.duckduckgo.duckchat.impl.inputscreen.ui.InputScreenActivity.Companion.TAB_ID
293293
import com.duckduckgo.duckchat.impl.inputscreen.ui.InputScreenActivityParams
@@ -574,6 +574,9 @@ class BrowserTabFragment :
574574
@Inject
575575
lateinit var omnibarTypeResolver: OmnibarTypeResolver
576576

577+
@Inject
578+
lateinit var browserAndInputScreenTransitionProvider: BrowserAndInputScreenTransitionProvider
579+
577580
/**
578581
* We use this to monitor whether the user was seeing the in-context Email Protection signup prompt
579582
* This is needed because the activity stack will be cleared if an external link is opened in our browser
@@ -1075,8 +1078,8 @@ class BrowserTabFragment :
10751078
requireContext(),
10761079
InputScreenActivityParams(query = query),
10771080
)
1078-
val enterTransition = InputScreenAnimationResourceProvider.getInputScreenEnterAnimation()
1079-
val exitTransition = InputScreenAnimationResourceProvider.getBrowserExitAnimation(appTheme.isLightModeEnabled())
1081+
val enterTransition = browserAndInputScreenTransitionProvider.getInputScreenEnterAnimation()
1082+
val exitTransition = browserAndInputScreenTransitionProvider.getBrowserExitAnimation()
10801083
val options = ActivityOptionsCompat.makeCustomAnimation(
10811084
requireActivity(),
10821085
enterTransition,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.duckchat.api.inputscreen
18+
19+
/**
20+
* Provides animation resources for activity transitions between browser and input screen.
21+
*/
22+
interface BrowserAndInputScreenTransitionProvider {
23+
24+
fun getBrowserEnterAnimation(): Int
25+
26+
fun getBrowserExitAnimation(): Int
27+
28+
fun getInputScreenEnterAnimation(): Int
29+
30+
fun getInputScreenExitAnimation(): Int
31+
}

duckchat/duckchat-api/src/main/java/com/duckduckgo/duckchat/api/InputScreenAnimationResourceProvider.kt renamed to duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/inputscreen/ui/BrowserAndInputScreenTransitionProviderImpl.kt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.duckduckgo.duckchat.api
17+
package com.duckduckgo.duckchat.impl.inputscreen.ui
1818

1919
import android.os.Build.VERSION
20+
import com.duckduckgo.common.ui.store.AppTheme
21+
import com.duckduckgo.di.scopes.AppScope
22+
import com.duckduckgo.duckchat.api.R
23+
import com.duckduckgo.duckchat.api.inputscreen.BrowserAndInputScreenTransitionProvider
24+
import com.squareup.anvil.annotations.ContributesBinding
25+
import javax.inject.Inject
2026

2127
/**
22-
* Provides animation resources for activity transitions between input screens and browser.
28+
* Provides animation resources for activity transitions between browser and input screen.
2329
*
2430
* ### API Level Behavior
2531
* - **API < 33**: Uses simple fade animations as slide animations don't seem to be supported (on tested devices).
@@ -38,11 +44,14 @@ import android.os.Build.VERSION
3844
* - Cannot use themeable attributes (`?attr`) as they cause crashes of the whole launcher (on tested devices).
3945
* Instead, we use fixed color values and filter resources by current theme state.
4046
*/
41-
object InputScreenAnimationResourceProvider {
47+
@ContributesBinding(scope = AppScope::class)
48+
class BrowserAndInputScreenTransitionProviderImpl @Inject constructor(
49+
private val appTheme: AppTheme,
50+
) : BrowserAndInputScreenTransitionProvider {
4251

43-
fun getBrowserEnterAnimation(isLightModeEnabled: Boolean): Int {
52+
override fun getBrowserEnterAnimation(): Int {
4453
return if (VERSION.SDK_INT >= 33) {
45-
if (isLightModeEnabled) {
54+
if (appTheme.isLightModeEnabled()) {
4655
R.anim.slide_in_from_bottom_fade_in_light
4756
} else {
4857
R.anim.slide_in_from_bottom_fade_in_dark
@@ -52,29 +61,29 @@ object InputScreenAnimationResourceProvider {
5261
}
5362
}
5463

55-
fun getInputScreenExitAnimation(): Int {
64+
override fun getBrowserExitAnimation(): Int {
5665
return if (VERSION.SDK_INT >= 33) {
57-
R.anim.slide_out_to_top_fade_out
66+
if (appTheme.isLightModeEnabled()) {
67+
R.anim.slide_out_to_bottom_fade_out_light
68+
} else {
69+
R.anim.slide_out_to_bottom_fade_out_dark
70+
}
5871
} else {
5972
R.anim.fade_out
6073
}
6174
}
6275

63-
fun getInputScreenEnterAnimation(): Int {
76+
override fun getInputScreenEnterAnimation(): Int {
6477
return if (VERSION.SDK_INT >= 33) {
6578
R.anim.slide_in_from_top_fade_in
6679
} else {
6780
R.anim.fade_in
6881
}
6982
}
7083

71-
fun getBrowserExitAnimation(isLightModeEnabled: Boolean): Int {
84+
override fun getInputScreenExitAnimation(): Int {
7285
return if (VERSION.SDK_INT >= 33) {
73-
if (isLightModeEnabled) {
74-
R.anim.slide_out_to_bottom_fade_out_light
75-
} else {
76-
R.anim.slide_out_to_bottom_fade_out_dark
77-
}
86+
R.anim.slide_out_to_top_fade_out
7887
} else {
7988
R.anim.fade_out
8089
}

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/inputscreen/ui/InputScreenActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import android.os.Bundle
2121
import com.duckduckgo.anvil.annotations.ContributeToActivityStarter
2222
import com.duckduckgo.anvil.annotations.InjectWith
2323
import com.duckduckgo.common.ui.DuckDuckGoActivity
24-
import com.duckduckgo.common.ui.store.BrowserAppTheme
2524
import com.duckduckgo.di.scopes.ActivityScope
26-
import com.duckduckgo.duckchat.api.InputScreenAnimationResourceProvider
25+
import com.duckduckgo.duckchat.api.inputscreen.BrowserAndInputScreenTransitionProvider
2726
import com.duckduckgo.duckchat.impl.R
2827
import com.duckduckgo.navigation.api.GlobalActivityStarter
2928
import javax.inject.Inject
@@ -37,7 +36,7 @@ data class InputScreenActivityParams(
3736
class InputScreenActivity : DuckDuckGoActivity() {
3837

3938
@Inject
40-
lateinit var appTheme: BrowserAppTheme
39+
lateinit var browserAndInputScreenTransitionProvider: BrowserAndInputScreenTransitionProvider
4140

4241
override fun onCreate(savedInstanceState: Bundle?) {
4342
super.onCreate(savedInstanceState)
@@ -50,8 +49,8 @@ class InputScreenActivity : DuckDuckGoActivity() {
5049
}
5150

5251
private fun applyExitTransition() {
53-
val enterTransition = InputScreenAnimationResourceProvider.getBrowserEnterAnimation(appTheme.isLightModeEnabled())
54-
val exitTransition = InputScreenAnimationResourceProvider.getInputScreenExitAnimation()
52+
val enterTransition = browserAndInputScreenTransitionProvider.getBrowserEnterAnimation()
53+
val exitTransition = browserAndInputScreenTransitionProvider.getInputScreenExitAnimation()
5554

5655
if (VERSION.SDK_INT >= 34) {
5756
overrideActivityTransition(

0 commit comments

Comments
 (0)