Skip to content

Commit

Permalink
Implement platform-specific openUrl for all platforms
Browse files Browse the repository at this point in the history
- Implemented `openUrl` function for every platform.
- Used `Intent` for Android to handle URL opening.
- Added platform-specific implementations for Native, Desktop, and wasmJs.
  • Loading branch information
HekmatullahAmin committed Feb 7, 2025
1 parent 07b6c44 commit d9c013a
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 127 deletions.
18 changes: 18 additions & 0 deletions feature/about/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2025 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".AndroidApp">

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/
package org.mifos.mobile.feature.about

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import android.app.Application

@Composable
actual fun MyWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
modifier: Modifier,
) {
class AndroidApp : Application() {
override fun onCreate() {
super.onCreate()
instance = this
}

companion object {
lateinit var instance: AndroidApp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView

@Composable
actual fun MyWebView(
actual fun MifosWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ package org.mifos.mobile.feature.about
import android.content.Intent
import android.net.Uri

actual fun openUrl(url: String?) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
internal actual fun openUrl(url: String?) {
val uri = url?.let { Uri.parse(url) } ?: return
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = uri
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
AndroidApp.instance.startActivity(intent)
}

internal actual fun openOssLicenses() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
expect fun MyWebView(
expect fun MifosWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
*/
package org.mifos.mobile.feature.about

expect fun openUrl(url: String?)
internal expect fun openUrl(url: String?)

internal expect fun openOssLicenses()
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import mifos_mobile.feature.about.generated.resources.feature_about_privacy_poli
import org.jetbrains.compose.resources.stringResource
import org.mifos.mobile.core.designsystem.component.MifosScaffold
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
import org.mifos.mobile.feature.about.MyWebView
import org.mifos.mobile.feature.about.MifosWebView
import org.mifos.mobile.feature.about.openUrl

@Composable
Expand Down Expand Up @@ -56,7 +56,7 @@ private fun WebView(

Column(modifier) {
Spacer(modifier = Modifier.height(20.dp))
MyWebView(
MifosWebView(
htmlContent = url,
isLoading = { isLoading = it },
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.about

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign

@Composable
actual fun MifosWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
modifier: Modifier,
) {
Box(modifier = modifier.fillMaxSize()) {
Text(
text = "Implement platform specific WebView for Desktop",
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import java.awt.Desktop
import java.net.URI

actual fun openUrl(url: String?) {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(URI(url))
}
val uri = url?.let { URI.create(it) } ?: return
Desktop.getDesktop().browse(uri)
}

internal actual fun openOssLicenses() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
actual fun MyWebView(
actual fun MifosWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
*/
package org.mifos.mobile.feature.about

import kotlinx.browser.window

actual fun openUrl(url: String?) {
// window.open(url, "_blank") // Opens in a new tab"
if (url != null) {
window.open(url, "_blank") // Opens in a new tab
}
}

internal actual fun openOssLicenses() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@
*/
package org.mifos.mobile.feature.about

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign

@Composable
actual fun MyWebView(
actual fun MifosWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
modifier: Modifier,
) {
Box(modifier = modifier.fillMaxSize()) {
Text(
text = "Implement platform specific WebView for IOS",
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center),
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
*/
package org.mifos.mobile.feature.about

actual fun openUrl(url: String?) {
// val nsUrl = NSURL.URLWithString(url)
// if (nsUrl != null) {
// UIApplication.sharedApplication.openURL(nsUrl)
// }
import platform.Foundation.NSURL
import platform.UIKit.UIApplication

internal actual fun openUrl(url: String?) {
val nsUrl = url?.let { NSURL.URLWithString(it) } ?: return
UIApplication.sharedApplication.openURL(nsUrl, options = emptyMap<Any?, Any>()) { success ->
if (!success) {
println("Failed to open URL: $url")
}
}
}

internal actual fun openOssLicenses() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.about

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign

@Composable
actual fun MifosWebView(
htmlContent: String,
isLoading: (isLoading: Boolean) -> Unit,
onUrlClicked: (url: String) -> Unit,
modifier: Modifier,
) {
Box(modifier = modifier.fillMaxSize()) {
Text(
text = "Implement platform specific WebView for WasmJs",
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
*/
package org.mifos.mobile.feature.about

import kotlinx.browser.window

actual fun openUrl(url: String?) {
// window.open(url, "_blank") // Opens in a new tab
if (url != null) {
window.open(url, "_blank") // Opens in a new tab
}
}

internal actual fun openOssLicenses() {
}

0 comments on commit d9c013a

Please sign in to comment.