Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Nov 24, 2024
1 parent 80b3a75 commit 7570781
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package org.michaelbel.movies.common.browser

import android.content.Intent
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.toArgb
import androidx.core.net.toUri

fun openUrl(
Expand All @@ -22,4 +27,20 @@ fun openUrl(
intent.data = url.toUri()
}
resultContract.launch(customTabsIntent.intent)
}

@Composable
actual fun navigateToUrl(url: String): () -> Unit {
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val toolbarColor = MaterialTheme.colorScheme.primary.toArgb()
val colorSchemeParams = CustomTabColorSchemeParams.Builder()
.setToolbarColor(toolbarColor)
.build()
val customTabsIntentBuilder = CustomTabsIntent.Builder().apply {
setDefaultColorSchemeParams(colorSchemeParams)
}
val customTabsIntent = customTabsIntentBuilder.build().apply {
intent.data = url.toUri()
}
return { resultContract.launch(customTabsIntent.intent) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.michaelbel.movies.common.browser

import androidx.compose.runtime.Composable

@Composable
expect fun navigateToUrl(url: String): () -> Unit
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.michaelbel.movies.common.browser

import androidx.compose.runtime.Composable
import platform.Foundation.NSURL
import platform.UIKit.UIApplication

fun openUrl(url: String) {
@Composable
actual fun navigateToUrl(url: String): () -> Unit {
val nsUrl = NSURL.URLWithString(url)
if (nsUrl != null) {
UIApplication.sharedApplication().openURL(nsUrl)
return {
if (nsUrl != null) {
UIApplication.sharedApplication().openURL(nsUrl)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.michaelbel.movies.common.browser

fun openUrl(url: String) {
import androidx.compose.runtime.Composable

@Composable
actual fun navigateToUrl(url: String): () -> Unit {
return {}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.michaelbel.movies.common.browser

import androidx.compose.runtime.Composable
import java.awt.Desktop
import java.net.URI

fun openUrl(url: String) {
@Composable
actual fun navigateToUrl(url: String): () -> Unit {
val desktop = if (Desktop.isDesktopSupported()) Desktop.getDesktop() else null
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(URI.create(url))
return {
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(URI.create(url))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.michaelbel.movies.common.browser

fun openUrl(url: String) {
import androidx.compose.runtime.Composable

@Composable
actual fun navigateToUrl(url: String): () -> Unit {
return {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.koin.compose.koinInject
import org.michaelbel.movies.auth.AuthViewModel
import org.michaelbel.movies.common.browser.openUrl

@Composable
fun AuthRoute(
Expand All @@ -21,7 +20,7 @@ fun AuthRoute(
onSignInClick = { username, password -> },
onLoginClick = {},
onResetRequestToken = {},
onUrlClick = { url -> openUrl(url) },
onUrlClick = {},
modifier = modifier
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.koin.compose.koinInject
import org.michaelbel.movies.auth.AuthViewModel
import org.michaelbel.movies.common.browser.openUrl

@Composable
fun AuthRoute(
Expand All @@ -21,7 +20,7 @@ fun AuthRoute(
onSignInClick = { username, password -> },
onLoginClick = {},
onResetRequestToken = {},
onUrlClick = { url -> openUrl(url) },
onUrlClick = {},
modifier = modifier
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.michaelbel.movies.settings.ui

import android.app.Activity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
Expand All @@ -14,13 +11,12 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.stringResource
import org.koin.androidx.compose.koinViewModel
import org.michaelbel.movies.common.MOVIES_GITHUB_URL
import org.michaelbel.movies.common.browser.openUrl
import org.michaelbel.movies.common.browser.navigateToUrl
import org.michaelbel.movies.common.gender.GrammaticalGender
import org.michaelbel.movies.interactor.entity.AppLanguage
import org.michaelbel.movies.notifications.ktx.rememberPostNotificationsPermissionHandler
Expand Down Expand Up @@ -75,10 +71,9 @@ fun SettingsRoute(
val appVersionData by viewModel.appVersionData.collectAsStateCommon()
var areNotificationsEnabled by remember { mutableStateOf(viewModel.areNotificationsEnabled) }
val openAppNotificationSettings = openAppNotificationSettings()
val navigateToUrl = navigateToUrl(MOVIES_GITHUB_URL)

val context = LocalContext.current
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val toolbarColor = MaterialTheme.colorScheme.primary.toArgb()

val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -204,7 +199,7 @@ fun SettingsRoute(
),
githubData = SettingsData.RequestedData(
isFeatureEnabled = isGithubFeatureEnabled,
onRequest = { openUrl(resultContract, toolbarColor, MOVIES_GITHUB_URL) }
onRequest = navigateToUrl
),
reviewAppData = SettingsData.RequestedData(
isFeatureEnabled = isReviewAppFeatureEnabled && viewModel.isReviewFeatureEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.koinInject
import org.michaelbel.movies.common.MOVIES_GITHUB_URL
import org.michaelbel.movies.common.browser.openUrl
import org.michaelbel.movies.common.browser.navigateToUrl
import org.michaelbel.movies.common.gender.GrammaticalGender
import org.michaelbel.movies.interactor.entity.AppLanguage
import org.michaelbel.movies.settings.SettingsViewModel
Expand Down Expand Up @@ -46,6 +46,7 @@ fun SettingsRoute(
val currentFeedView by viewModel.currentFeedView.collectAsStateCommon()
val currentMovieList by viewModel.currentMovieList.collectAsStateCommon()
val snackbarHostState = remember { SnackbarHostState() }
val navigateToUrl = navigateToUrl(MOVIES_GITHUB_URL)

SettingsScreenContent(
settingsData = SettingsData(
Expand Down Expand Up @@ -111,7 +112,7 @@ fun SettingsRoute(
),
githubData = SettingsData.RequestedData(
isFeatureEnabled = isGithubFeatureEnabled,
onRequest = { openUrl(MOVIES_GITHUB_URL) }
onRequest = navigateToUrl
),
reviewAppData = SettingsData.RequestedData(
isFeatureEnabled = isReviewAppFeatureEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.koinInject
import org.michaelbel.movies.common.MOVIES_GITHUB_URL
import org.michaelbel.movies.common.browser.openUrl
import org.michaelbel.movies.common.browser.navigateToUrl
import org.michaelbel.movies.common.gender.GrammaticalGender
import org.michaelbel.movies.interactor.entity.AppLanguage
import org.michaelbel.movies.settings.SettingsViewModel
Expand Down Expand Up @@ -46,6 +46,7 @@ fun SettingsRoute(
val currentFeedView by viewModel.currentFeedView.collectAsStateCommon()
val currentMovieList by viewModel.currentMovieList.collectAsStateCommon()
val snackbarHostState = remember { SnackbarHostState() }
val navigateToUrl = navigateToUrl(MOVIES_GITHUB_URL)

SettingsScreenContent(
settingsData = SettingsData(
Expand Down Expand Up @@ -111,7 +112,7 @@ fun SettingsRoute(
),
githubData = SettingsData.RequestedData(
isFeatureEnabled = isGithubFeatureEnabled,
onRequest = { openUrl(MOVIES_GITHUB_URL) }
onRequest = navigateToUrl
),
reviewAppData = SettingsData.RequestedData(
isFeatureEnabled = isReviewAppFeatureEnabled
Expand Down

0 comments on commit 7570781

Please sign in to comment.