-
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.
Move Tracker Animation Tile logic to TabSwitcherTileAnimationMonitor
The logic for determining the visibility of the Tracker Animation Tile has been moved to a new `TabSwitcherTileAnimationMonitor` class. This includes: - Determining the tracker count in the last 7 days. - Determining the number of open tabs. - Checking if the animation tile is dismissed. - Defining the minimum requirements for displaying the tile (minimum tracker count and minimum tab count). The `WebTrackersBlockedAppRepository` has been updated to have a new public method to retrieve the number of tracker count for last 7 days. The `TabSwitcherViewModel` was refactored to use the new `TabSwitcherTileAnimationMonitor` and the `observeAnimationTileVisibility` function. The `createTrackerAnimationTile` and `getTrackerCountForLast7Days` were deleted.
- Loading branch information
1 parent
e668ba2
commit 684efba
Showing
3 changed files
with
69 additions
and
24 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherTileAnimationMonitor.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,54 @@ | ||
/* | ||
* Copyright (c) 2025 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.app.tabs.ui | ||
|
||
import com.duckduckgo.app.tabs.model.TabDataRepository | ||
import com.duckduckgo.app.tabs.store.TabSwitcherPrefsDataStore | ||
import com.duckduckgo.app.trackerdetection.api.WebTrackersBlockedAppRepository | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
private const val MINIMUM_TRACKER_COUNT = 10 | ||
private const val MINIMUM_TAB_COUNT = 2 | ||
|
||
class TabSwitcherTileAnimationMonitor @Inject constructor( | ||
private val dispatchProvider: DispatcherProvider, | ||
private val tabSwitcherPrefsDataStore: TabSwitcherPrefsDataStore, | ||
private val tabDataRepository: TabDataRepository, | ||
private val webTrackersBlockedAppRepository: WebTrackersBlockedAppRepository, | ||
) { | ||
|
||
fun observeAnimationTileVisibility(): Flow<Boolean> = tabSwitcherPrefsDataStore.isAnimationTileDismissed() | ||
.map { isAnimationTileDismissed -> | ||
if (!isAnimationTileDismissed) { | ||
shouldDisplayAnimationTile() | ||
} else { | ||
false | ||
} | ||
}.flowOn(dispatchProvider.io()) | ||
|
||
private suspend fun shouldDisplayAnimationTile(): Boolean { | ||
val openedTabs = tabDataRepository.getOpenTabCount() | ||
val trackerCountForLast7Days = webTrackersBlockedAppRepository.getTrackerCountForLast7Days() | ||
|
||
return trackerCountForLast7Days >= MINIMUM_TRACKER_COUNT && | ||
openedTabs >= MINIMUM_TAB_COUNT | ||
} | ||
} |
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