From 914e5408d2a991fffb91324fca4def0367fc583f Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Wed, 18 Oct 2023 07:07:53 +0530 Subject: [PATCH] Replace callback for opening links with link handler composition local --- androidApp/build.gradle.kts | 1 - .../dev/sasikanth/rss/reader/MainActivity.kt | 33 +---------- .../dev/sasikanth/rss/reader/app/App.kt | 55 +++++++------------ .../sasikanth/rss/reader/app/AppPresenter.kt | 26 --------- .../dev/sasikanth/rss/reader/app/AppState.kt | 28 ---------- .../reader/bookmarks/ui/BookmarksScreen.kt | 12 +++- .../rss/reader/home/ui/HomeScreen.kt | 14 ++--- .../rss/reader/search/ui/SearchScreen.kt | 19 ++++--- .../rss/reader/settings/ui/SettingsScreen.kt | 16 +++++- .../rss/reader/HomeViewController.kt | 27 +-------- 10 files changed, 62 insertions(+), 169 deletions(-) delete mode 100644 shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppState.kt diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index e8183c93a..1c7299ac2 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -92,5 +92,4 @@ dependencies { implementation(libs.androidx.work) implementation(libs.sentry) coreLibraryDesugaring(libs.desugarJdk) - implementation(libs.androidx.browser) } diff --git a/androidApp/src/androidMain/kotlin/dev/sasikanth/rss/reader/MainActivity.kt b/androidApp/src/androidMain/kotlin/dev/sasikanth/rss/reader/MainActivity.kt index 158c9f7fb..e3deff6a0 100644 --- a/androidApp/src/androidMain/kotlin/dev/sasikanth/rss/reader/MainActivity.kt +++ b/androidApp/src/androidMain/kotlin/dev/sasikanth/rss/reader/MainActivity.kt @@ -16,24 +16,17 @@ package dev.sasikanth.rss.reader import android.app.Activity -import android.content.Intent import android.graphics.Color -import android.net.Uri import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import androidx.browser.customtabs.CustomTabsIntent -import androidx.core.net.toUri import androidx.core.view.WindowCompat import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.defaultComponentContext import dev.sasikanth.rss.reader.app.App import dev.sasikanth.rss.reader.di.ApplicationComponent import dev.sasikanth.rss.reader.di.scopes.ActivityScope -import dev.sasikanth.rss.reader.repository.BrowserType -import dev.sasikanth.rss.reader.repository.BrowserType.Default -import dev.sasikanth.rss.reader.repository.BrowserType.InApp import me.tatarka.inject.annotations.Component import me.tatarka.inject.annotations.Provides @@ -47,31 +40,7 @@ class MainActivity : AppCompatActivity() { val activityComponent = ActivityComponent::class.create(activity = this) - setContent { - activityComponent.app(::openLink) { reportIssueLink -> openLink(reportIssueLink, Default) } - } - } - - private fun openLink(url: String, browserType: BrowserType) { - when (browserType) { - Default -> { - val intent = - Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK } - if (intent.resolveActivity(packageManager) != null) { - startActivity(intent) - } else { - openCustomTab(url) - } - } - InApp -> { - openCustomTab(url) - } - } - } - - private fun openCustomTab(url: String) { - val intent = CustomTabsIntent.Builder().build() - intent.launchUrl(this, url.toUri()) + setContent { activityComponent.app() } } } diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/App.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/App.kt index d2aeeaba1..d7bd5f038 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/App.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/App.kt @@ -20,7 +20,6 @@ import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSiz import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children @@ -33,20 +32,17 @@ import dev.sasikanth.rss.reader.components.image.ImageLoader import dev.sasikanth.rss.reader.components.image.LocalImageLoader import dev.sasikanth.rss.reader.components.rememberDynamicColorState import dev.sasikanth.rss.reader.home.ui.HomeScreen -import dev.sasikanth.rss.reader.repository.BrowserType +import dev.sasikanth.rss.reader.platform.LinkHandler +import dev.sasikanth.rss.reader.platform.LocalLinkHandler import dev.sasikanth.rss.reader.resources.strings.ProvideStrings import dev.sasikanth.rss.reader.search.ui.SearchScreen import dev.sasikanth.rss.reader.settings.ui.SettingsScreen import dev.sasikanth.rss.reader.share.LocalShareHandler import dev.sasikanth.rss.reader.share.ShareHandler -import dev.sasikanth.rss.reader.utils.Constants import dev.sasikanth.rss.reader.utils.LocalWindowSizeClass -import me.tatarka.inject.annotations.Assisted import me.tatarka.inject.annotations.Inject -typealias App = - @Composable - (openLink: (String, BrowserType) -> Unit, openReportIssuePage: (String) -> Unit) -> Unit +typealias App = @Composable () -> Unit @Inject @Composable @@ -55,8 +51,7 @@ fun App( appPresenter: AppPresenter, imageLoader: ImageLoader, shareHandler: ShareHandler, - @Assisted openLink: (String, BrowserType) -> Unit, - @Assisted openReportIssuePage: (String) -> Unit + linkHandler: LinkHandler, ) { val dynamicColorState = rememberDynamicColorState(imageLoader = imageLoader) @@ -64,12 +59,11 @@ fun App( LocalImageLoader provides imageLoader, LocalWindowSizeClass provides calculateWindowSizeClass(), LocalDynamicColorState provides dynamicColorState, - LocalShareHandler provides shareHandler + LocalShareHandler provides shareHandler, + LocalLinkHandler provides linkHandler ) { DynamicContentTheme(dynamicColorState) { ProvideStrings { - val state by appPresenter.state.collectAsState() - Children( modifier = Modifier.fillMaxSize(), stack = appPresenter.screenStack, @@ -79,31 +73,20 @@ fun App( onBack = appPresenter::onBackClicked ) ) { child -> + val fillMaxSizeModifier = Modifier.fillMaxSize() when (val screen = child.instance) { - is Screen.Home -> - HomeScreen( - homePresenter = screen.presenter, - openLink = { openLink(it, state.browserType) }, - modifier = Modifier.fillMaxSize() - ) - is Screen.Search -> - SearchScreen( - searchPresenter = screen.presenter, - openLink = { openLink(it, state.browserType) }, - modifier = Modifier.fillMaxSize() - ) - is Screen.Bookmarks -> - BookmarksScreen( - bookmarksPresenter = screen.presenter, - openLink = { openLink(it, state.browserType) }, - modifier = Modifier.fillMaxSize() - ) - is Screen.Settings -> - SettingsScreen( - settingsPresenter = screen.presenter, - modifier = Modifier.fillMaxSize(), - openReportIssuePage = { openReportIssuePage(Constants.REPORT_ISSUE_LINK) } - ) + is Screen.Home -> { + HomeScreen(homePresenter = screen.presenter, modifier = fillMaxSizeModifier) + } + is Screen.Search -> { + SearchScreen(searchPresenter = screen.presenter, modifier = fillMaxSizeModifier) + } + is Screen.Bookmarks -> { + BookmarksScreen(bookmarksPresenter = screen.presenter, modifier = fillMaxSizeModifier) + } + is Screen.Settings -> { + SettingsScreen(settingsPresenter = screen.presenter, modifier = fillMaxSizeModifier) + } } } } diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt index 3635174d2..bae953987 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt @@ -32,20 +32,12 @@ import dev.sasikanth.rss.reader.di.scopes.ActivityScope import dev.sasikanth.rss.reader.home.HomePresenter import dev.sasikanth.rss.reader.refresh.LastUpdatedAt import dev.sasikanth.rss.reader.repository.RssRepository -import dev.sasikanth.rss.reader.repository.SettingsRepository import dev.sasikanth.rss.reader.search.SearchPresenter import dev.sasikanth.rss.reader.settings.SettingsPresenter import dev.sasikanth.rss.reader.utils.DispatchersProvider import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import me.tatarka.inject.annotations.Inject @@ -77,7 +69,6 @@ private typealias SettingsPresenterFactory = class AppPresenter( componentContext: ComponentContext, dispatchersProvider: DispatchersProvider, - settingsRepository: SettingsRepository, private val homePresenter: HomePresenterFactory, private val searchPresenter: SearchPresentFactory, private val bookmarksPresenter: BookmarkPresenterFactory, @@ -90,7 +81,6 @@ class AppPresenter( instanceKeeper.getOrCreate { PresenterInstance( dispatchersProvider = dispatchersProvider, - settingsRepository = settingsRepository, lastUpdatedAt = lastUpdatedAt, rssRepository = rssRepository ) @@ -98,7 +88,6 @@ class AppPresenter( private val navigation = StackNavigation() - internal val state = presenterInstance.state internal val screenStack: Value> = childStack( source = navigation, @@ -141,27 +130,12 @@ class AppPresenter( private class PresenterInstance( dispatchersProvider: DispatchersProvider, - settingsRepository: SettingsRepository, private val lastUpdatedAt: LastUpdatedAt, private val rssRepository: RssRepository ) : InstanceKeeper.Instance { private val coroutineScope = CoroutineScope(SupervisorJob() + dispatchersProvider.main) - private val _state = MutableStateFlow(AppState.DEFAULT) - val state: StateFlow = - _state.stateIn( - scope = coroutineScope, - started = SharingStarted.WhileSubscribed(5000), - initialValue = AppState.DEFAULT - ) - - init { - settingsRepository.browserType - .onEach { browserType -> _state.update { it.copy(browserType = browserType) } } - .launchIn(coroutineScope) - } - fun refreshFeedsIfExpired() { coroutineScope.launch { if (lastUpdatedAt.hasExpired()) { diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppState.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppState.kt deleted file mode 100644 index 48ef10e31..000000000 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppState.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2023 Sasikanth Miriyampalli - * - * 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 dev.sasikanth.rss.reader.app - -import androidx.compose.runtime.Immutable -import dev.sasikanth.rss.reader.repository.BrowserType - -@Immutable -internal data class AppState(val browserType: BrowserType) { - - companion object { - - val DEFAULT = AppState(browserType = BrowserType.Default) - } -} diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/bookmarks/ui/BookmarksScreen.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/bookmarks/ui/BookmarksScreen.kt index f2820e1f2..058c47cf1 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/bookmarks/ui/BookmarksScreen.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/bookmarks/ui/BookmarksScreen.kt @@ -37,6 +37,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -47,20 +48,23 @@ import dev.sasikanth.rss.reader.bookmarks.BookmarksEvent import dev.sasikanth.rss.reader.bookmarks.BookmarksPresenter import dev.sasikanth.rss.reader.components.ScrollToTopButton import dev.sasikanth.rss.reader.home.ui.PostListItem +import dev.sasikanth.rss.reader.platform.LocalLinkHandler import dev.sasikanth.rss.reader.resources.strings.LocalStrings import dev.sasikanth.rss.reader.ui.AppTheme +import kotlinx.coroutines.launch @Composable internal fun BookmarksScreen( bookmarksPresenter: BookmarksPresenter, - openLink: (String) -> Unit, modifier: Modifier = Modifier ) { val state by bookmarksPresenter.state.collectAsState() val bookmarks = state.bookmarks.collectAsLazyPagingItems() val listState = rememberLazyListState() + val coroutineScope = rememberCoroutineScope() val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } } val layoutDirection = LocalLayoutDirection.current + val linkHandler = LocalLinkHandler.current Scaffold( modifier = modifier, @@ -104,11 +108,13 @@ internal fun BookmarksScreen( PostListItem( item = post, enablePostSource = false, - onClick = { openLink(post.link) }, + onClick = { coroutineScope.launch { linkHandler.openLink(post.link) } }, onPostBookmarkClick = { bookmarksPresenter.dispatch(BookmarksEvent.OnPostBookmarkClick(post)) }, - onPostCommentsClick = { openLink(post.commentsLink!!) }, + onPostCommentsClick = { + post.commentsLink?.let { coroutineScope.launch { linkHandler.openLink(it) } } + }, onPostSourceClick = { // no-op } diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt index 3c42442a6..6d6ec181b 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt @@ -88,6 +88,7 @@ import dev.sasikanth.rss.reader.home.HomeEvent import dev.sasikanth.rss.reader.home.HomePresenter import dev.sasikanth.rss.reader.home.HomeState import dev.sasikanth.rss.reader.models.local.PostWithMetadata +import dev.sasikanth.rss.reader.platform.LocalLinkHandler import dev.sasikanth.rss.reader.resources.strings.LocalStrings import dev.sasikanth.rss.reader.resources.strings.TwineStrings import dev.sasikanth.rss.reader.ui.AppTheme @@ -99,11 +100,7 @@ private val BOTTOM_SHEET_CORNER_SIZE = 32.dp @OptIn(ExperimentalFoundationApi::class) @Composable -internal fun HomeScreen( - homePresenter: HomePresenter, - openLink: (String) -> Unit, - modifier: Modifier = Modifier -) { +internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modifier) { val coroutineScope = rememberCoroutineScope() val state by homePresenter.state.collectAsState() @@ -130,12 +127,13 @@ internal fun HomeScreen( bottomSheetSwipeTransition.animateDp { BOTTOM_SHEET_CORNER_SIZE * it.inverseProgress() } val strings = LocalStrings.current + val linkHandler = LocalLinkHandler.current LaunchedEffect(Unit) { homePresenter.effects.collect { effect -> when (effect) { is HomeEffect.OpenPost -> { - openLink(effect.post.link) + linkHandler.openLink(effect.post.link) } HomeEffect.MinimizeSheet -> { bottomSheetState.collapse() @@ -177,7 +175,9 @@ internal fun HomeScreen( onSwipeToRefresh = { homePresenter.dispatch(HomeEvent.OnSwipeToRefresh) }, onPostClicked = { homePresenter.dispatch(HomeEvent.OnPostClicked(it)) }, onPostBookmarkClick = { homePresenter.dispatch(HomeEvent.OnPostBookmarkClick(it)) }, - onPostCommentsClick = { commentsLink -> openLink(commentsLink) }, + onPostCommentsClick = { commentsLink -> + coroutineScope.launch { linkHandler.openLink(commentsLink) } + }, onPostSourceClick = { feedLink -> homePresenter.dispatch(HomeEvent.OnPostSourceClicked(feedLink)) }, diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/search/ui/SearchScreen.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/search/ui/SearchScreen.kt index 6ce6e0420..dcacd07e3 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/search/ui/SearchScreen.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/search/ui/SearchScreen.kt @@ -54,6 +54,7 @@ import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -72,6 +73,7 @@ import dev.sasikanth.rss.reader.components.DropdownMenu import dev.sasikanth.rss.reader.components.DropdownMenuItem import dev.sasikanth.rss.reader.components.ScrollToTopButton import dev.sasikanth.rss.reader.home.ui.PostListItem +import dev.sasikanth.rss.reader.platform.LocalLinkHandler import dev.sasikanth.rss.reader.resources.icons.Sort import dev.sasikanth.rss.reader.resources.icons.TwineIcons import dev.sasikanth.rss.reader.resources.strings.LocalStrings @@ -82,18 +84,17 @@ import dev.sasikanth.rss.reader.search.SearchSortOrder.* import dev.sasikanth.rss.reader.ui.AppTheme import dev.sasikanth.rss.reader.utils.KeyboardState import dev.sasikanth.rss.reader.utils.keyboardVisibilityAsState +import kotlinx.coroutines.launch @Composable -internal fun SearchScreen( - searchPresenter: SearchPresenter, - openLink: (String) -> Unit, - modifier: Modifier = Modifier -) { +internal fun SearchScreen(searchPresenter: SearchPresenter, modifier: Modifier = Modifier) { val state by searchPresenter.state.collectAsState() val listState = rememberLazyListState() + val coroutineScope = rememberCoroutineScope() val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } } - val layoutDirection = LocalLayoutDirection.current val searchResults = state.searchResults.collectAsLazyPagingItems() + val layoutDirection = LocalLayoutDirection.current + val linkHandler = LocalLinkHandler.current Scaffold( modifier = modifier, @@ -125,11 +126,13 @@ internal fun SearchScreen( PostListItem( item = post, enablePostSource = false, - onClick = { openLink(post.link) }, + onClick = { coroutineScope.launch { linkHandler.openLink(post.link) } }, onPostBookmarkClick = { searchPresenter.dispatch(SearchEvent.OnPostBookmarkClick(post)) }, - onPostCommentsClick = { openLink(post.commentsLink!!) }, + onPostCommentsClick = { + post.commentsLink?.let { coroutineScope.launch { linkHandler.openLink(it) } } + }, onPostSourceClick = { // no-op }, diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/settings/ui/SettingsScreen.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/settings/ui/SettingsScreen.kt index e77ff0b8f..ddcd56a45 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/settings/ui/SettingsScreen.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/settings/ui/SettingsScreen.kt @@ -45,6 +45,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -52,21 +53,25 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.dp import dev.sasikanth.rss.reader.app.AppInfo +import dev.sasikanth.rss.reader.platform.LocalLinkHandler import dev.sasikanth.rss.reader.repository.BrowserType import dev.sasikanth.rss.reader.resources.strings.LocalStrings import dev.sasikanth.rss.reader.settings.SettingsEvent import dev.sasikanth.rss.reader.settings.SettingsPresenter import dev.sasikanth.rss.reader.ui.AppTheme +import dev.sasikanth.rss.reader.utils.Constants import dev.sasikanth.rss.reader.utils.canBlurImage +import kotlinx.coroutines.launch @Composable internal fun SettingsScreen( settingsPresenter: SettingsPresenter, modifier: Modifier = Modifier, - openReportIssuePage: () -> Unit ) { + val coroutineScope = rememberCoroutineScope() val state by settingsPresenter.state.collectAsState() val layoutDirection = LocalLayoutDirection.current + val linkHandler = LocalLinkHandler.current Scaffold( modifier = modifier, @@ -143,7 +148,14 @@ internal fun SettingsScreen( ) } - item { ReportIssueItem(appInfo = state.appInfo, onClick = openReportIssuePage) } + item { + ReportIssueItem( + appInfo = state.appInfo, + onClick = { + coroutineScope.launch { linkHandler.openLink(Constants.REPORT_ISSUE_LINK) } + } + ) + } } } }, diff --git a/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/HomeViewController.kt b/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/HomeViewController.kt index 216eb9dc6..9e68bc034 100644 --- a/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/HomeViewController.kt +++ b/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/HomeViewController.kt @@ -17,21 +17,15 @@ package dev.sasikanth.rss.reader import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier -import androidx.compose.ui.interop.LocalUIViewController import androidx.compose.ui.uikit.OnFocusBehavior import androidx.compose.ui.window.ComposeUIViewController import com.arkivanov.decompose.ExperimentalDecomposeApi import com.arkivanov.decompose.extensions.compose.jetbrains.PredictiveBackGestureOverlay import com.arkivanov.essenty.backhandler.BackDispatcher import dev.sasikanth.rss.reader.app.App -import dev.sasikanth.rss.reader.repository.BrowserType import dev.sasikanth.rss.reader.repository.BrowserType.* import me.tatarka.inject.annotations.Assisted import me.tatarka.inject.annotations.Inject -import platform.Foundation.NSURL -import platform.SafariServices.SFSafariViewController -import platform.UIKit.UIApplication -import platform.UIKit.UIModalPresentationPageSheet import platform.UIKit.UIViewController typealias HomeViewController = (backDispatcher: BackDispatcher) -> UIViewController @@ -40,30 +34,11 @@ typealias HomeViewController = (backDispatcher: BackDispatcher) -> UIViewControl @Inject fun HomeViewController(app: App, @Assisted backDispatcher: BackDispatcher) = ComposeUIViewController(configure = { onFocusBehavior = OnFocusBehavior.DoNothing }) { - val uiViewController = LocalUIViewController.current - PredictiveBackGestureOverlay( backDispatcher = backDispatcher, backIcon = null, modifier = Modifier.fillMaxSize() ) { - app( - { link, browserType -> openLink(link, browserType, uiViewController) }, - { reportIssueLink -> openLink(reportIssueLink, Default, uiViewController) } - ) - } - } - -private fun openLink(link: String, browserType: BrowserType, uiViewController: UIViewController) { - when (browserType) { - Default -> { - UIApplication.sharedApplication().openURL(NSURL(string = link)) - } - InApp -> { - val safari = SFSafariViewController(NSURL(string = link)) - safari.modalPresentationStyle = UIModalPresentationPageSheet - - uiViewController.presentViewController(safari, animated = true, completion = null) + app() } } -}