@@ -38,6 +38,7 @@ import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteResult
3838import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteSuggestion
3939import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteSuggestion.AutoCompleteBookmarkSuggestion
4040import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteSuggestion.AutoCompleteSearchSuggestion
41+ import com.duckduckgo.app.autocomplete.api.AutoCompleteApi
4142import com.duckduckgo.app.bookmarks.db.BookmarkEntity
4243import com.duckduckgo.app.bookmarks.db.BookmarksDao
4344import com.duckduckgo.app.bookmarks.ui.EditBookmarkDialogFragment.EditBookmarkListener
@@ -61,6 +62,7 @@ import com.duckduckgo.app.browser.model.BasicAuthenticationCredentials
6162import com.duckduckgo.app.browser.model.BasicAuthenticationRequest
6263import com.duckduckgo.app.browser.model.LongPressTarget
6364import com.duckduckgo.app.browser.omnibar.OmnibarEntryConverter
65+ import com.duckduckgo.app.browser.omnibar.QueryUrlConverter
6466import com.duckduckgo.app.browser.session.WebViewSessionStorage
6567import com.duckduckgo.app.browser.ui.HttpAuthenticationDialogFragment.HttpAuthenticationListener
6668import com.duckduckgo.app.cta.ui.*
@@ -73,6 +75,7 @@ import com.duckduckgo.app.global.model.Site
7375import com.duckduckgo.app.global.model.SiteFactory
7476import com.duckduckgo.app.global.model.domain
7577import com.duckduckgo.app.global.model.domainMatchesUrl
78+ import com.duckduckgo.app.global.plugins.view_model.ViewModelFactoryPlugin
7679import com.duckduckgo.app.global.useourapp.UseOurAppDetector
7780import com.duckduckgo.app.global.useourapp.UseOurAppDetector.Companion.USE_OUR_APP_SHORTCUT_TITLE
7881import com.duckduckgo.app.global.useourapp.UseOurAppDetector.Companion.USE_OUR_APP_SHORTCUT_URL
@@ -100,7 +103,12 @@ import com.duckduckgo.app.tabs.model.TabEntity
100103import com.duckduckgo.app.tabs.model.TabRepository
101104import com.duckduckgo.app.trackerdetection.model.TrackingEvent
102105import com.duckduckgo.app.usage.search.SearchCountDao
106+ import com.duckduckgo.di.scopes.AppObjectGraph
103107import com.jakewharton.rxrelay2.PublishRelay
108+ import com.squareup.anvil.annotations.ContributesTo
109+ import dagger.Module
110+ import dagger.Provides
111+ import dagger.multibindings.IntoSet
104112import io.reactivex.android.schedulers.AndroidSchedulers
105113import io.reactivex.disposables.Disposable
106114import io.reactivex.schedulers.Schedulers
@@ -109,6 +117,7 @@ import timber.log.Timber
109117import java.io.File
110118import java.util.*
111119import java.util.concurrent.TimeUnit
120+ import javax.inject.Singleton
112121
113122class BrowserTabViewModel (
114123 private val statisticsUpdater : StatisticsUpdater ,
@@ -1832,3 +1841,118 @@ class BrowserTabViewModel(
18321841 private const val ONE_HOUR_IN_MS = 3_600_000
18331842 }
18341843}
1844+
1845+ @Module
1846+ @ContributesTo(AppObjectGraph ::class )
1847+ class BrowserTabViewModelFactoryModule {
1848+ @Provides
1849+ @Singleton
1850+ @IntoSet
1851+ fun provideBrowserTabViewModelFactory (
1852+ statisticsUpdater : StatisticsUpdater ,
1853+ queryUrlConverter : QueryUrlConverter ,
1854+ duckDuckGoUrlDetector : DuckDuckGoUrlDetector ,
1855+ siteFactory : SiteFactory ,
1856+ tabRepository : TabRepository ,
1857+ userWhitelistDao : UserWhitelistDao ,
1858+ networkLeaderboardDao : NetworkLeaderboardDao ,
1859+ bookmarksDao : BookmarksDao ,
1860+ fireproofWebsiteRepository : FireproofWebsiteRepository ,
1861+ locationPermissionsRepository : LocationPermissionsRepository ,
1862+ geoLocationPermissions : GeoLocationPermissions ,
1863+ navigationAwareLoginDetector : NavigationAwareLoginDetector ,
1864+ autoCompleteApi : AutoCompleteApi ,
1865+ appSettingsPreferencesStore : SettingsDataStore ,
1866+ longPressHandler : LongPressHandler ,
1867+ webViewSessionStorage : WebViewSessionStorage ,
1868+ specialUrlDetector : SpecialUrlDetector ,
1869+ faviconManager : FaviconManager ,
1870+ addToHomeCapabilityDetector : AddToHomeCapabilityDetector ,
1871+ ctaViewModel : CtaViewModel ,
1872+ searchCountDao : SearchCountDao ,
1873+ pixel : Pixel ,
1874+ dispatchers : DispatcherProvider = DefaultDispatcherProvider (),
1875+ userEventsStore : UserEventsStore ,
1876+ notificationDao : NotificationDao ,
1877+ useOurAppDetector : UseOurAppDetector ,
1878+ variantManager : VariantManager ,
1879+ fileDownloader : FileDownloader ,
1880+ globalPrivacyControl : GlobalPrivacyControl ,
1881+ fireproofDialogsEventHandler : FireproofDialogsEventHandler
1882+ ): ViewModelFactoryPlugin {
1883+ return BrowserTabViewModelFactory (
1884+ statisticsUpdater,
1885+ queryUrlConverter,
1886+ duckDuckGoUrlDetector,
1887+ siteFactory,
1888+ tabRepository,
1889+ userWhitelistDao,
1890+ networkLeaderboardDao,
1891+ bookmarksDao,
1892+ fireproofWebsiteRepository,
1893+ locationPermissionsRepository,
1894+ geoLocationPermissions,
1895+ navigationAwareLoginDetector,
1896+ autoCompleteApi,
1897+ appSettingsPreferencesStore,
1898+ longPressHandler,
1899+ webViewSessionStorage,
1900+ specialUrlDetector,
1901+ faviconManager,
1902+ addToHomeCapabilityDetector,
1903+ ctaViewModel,
1904+ searchCountDao,
1905+ pixel,
1906+ dispatchers,
1907+ userEventsStore,
1908+ notificationDao,
1909+ useOurAppDetector,
1910+ variantManager,
1911+ fileDownloader,
1912+ globalPrivacyControl,
1913+ fireproofDialogsEventHandler
1914+ )
1915+ }
1916+ }
1917+
1918+ private class BrowserTabViewModelFactory (
1919+ private val statisticsUpdater : StatisticsUpdater ,
1920+ private val queryUrlConverter : OmnibarEntryConverter ,
1921+ private val duckDuckGoUrlDetector : DuckDuckGoUrlDetector ,
1922+ private val siteFactory : SiteFactory ,
1923+ private val tabRepository : TabRepository ,
1924+ private val userWhitelistDao : UserWhitelistDao ,
1925+ private val networkLeaderboardDao : NetworkLeaderboardDao ,
1926+ private val bookmarksDao : BookmarksDao ,
1927+ private val fireproofWebsiteRepository : FireproofWebsiteRepository ,
1928+ private val locationPermissionsRepository : LocationPermissionsRepository ,
1929+ private val geoLocationPermissions : GeoLocationPermissions ,
1930+ private val navigationAwareLoginDetector : NavigationAwareLoginDetector ,
1931+ private val autoComplete : AutoComplete ,
1932+ private val appSettingsPreferencesStore : SettingsDataStore ,
1933+ private val longPressHandler : LongPressHandler ,
1934+ private val webViewSessionStorage : WebViewSessionStorage ,
1935+ private val specialUrlDetector : SpecialUrlDetector ,
1936+ private val faviconManager : FaviconManager ,
1937+ private val addToHomeCapabilityDetector : AddToHomeCapabilityDetector ,
1938+ private val ctaViewModel : CtaViewModel ,
1939+ private val searchCountDao : SearchCountDao ,
1940+ private val pixel : Pixel ,
1941+ private val dispatchers : DispatcherProvider = DefaultDispatcherProvider (),
1942+ private val userEventsStore : UserEventsStore ,
1943+ private val notificationDao : NotificationDao ,
1944+ private val useOurAppDetector : UseOurAppDetector ,
1945+ private val variantManager : VariantManager ,
1946+ private val fileDownloader : FileDownloader ,
1947+ private val globalPrivacyControl : GlobalPrivacyControl ,
1948+ private val fireproofDialogsEventHandler : FireproofDialogsEventHandler
1949+ ) : ViewModelFactoryPlugin {
1950+ override fun <T : ViewModel ?> create (modelClass : Class <T >): T ? {
1951+ with (modelClass) {
1952+ return when {
1953+ isAssignableFrom(BrowserTabViewModel ::class .java) -> BrowserTabViewModel (statisticsUpdater, queryUrlConverter, duckDuckGoUrlDetector, siteFactory, tabRepository, userWhitelistDao, networkLeaderboardDao, bookmarksDao, fireproofWebsiteRepository, locationPermissionsRepository, geoLocationPermissions, navigationAwareLoginDetector, autoComplete, appSettingsPreferencesStore, longPressHandler, webViewSessionStorage, specialUrlDetector, faviconManager, addToHomeCapabilityDetector, ctaViewModel, searchCountDao, pixel, dispatchers, userEventsStore, notificationDao, useOurAppDetector, variantManager, fileDownloader, globalPrivacyControl, fireproofDialogsEventHandler) as T
1954+ else -> null
1955+ }
1956+ }
1957+ }
1958+ }
0 commit comments