Skip to content

Commit d9c013a

Browse files
Implement platform-specific openUrl for all platforms
- Implemented `openUrl` function for every platform. - Used `Intent` for Android to handle URL opening. - Added platform-specific implementations for Native, Desktop, and wasmJs.
1 parent 07b6c44 commit d9c013a

File tree

16 files changed

+162
-127
lines changed

16 files changed

+162
-127
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 Mifos Initiative
4+
5+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
6+
If a copy of the MPL was not distributed with this file,
7+
You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
10+
-->
11+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
12+
13+
<application
14+
android:name=".AndroidApp">
15+
16+
</application>
17+
18+
</manifest>
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
*/
1010
package org.mifos.mobile.feature.about
1111

12-
import androidx.compose.runtime.Composable
13-
import androidx.compose.ui.Modifier
12+
import android.app.Application
1413

15-
@Composable
16-
actual fun MyWebView(
17-
htmlContent: String,
18-
isLoading: (isLoading: Boolean) -> Unit,
19-
onUrlClicked: (url: String) -> Unit,
20-
modifier: Modifier,
21-
) {
14+
class AndroidApp : Application() {
15+
override fun onCreate() {
16+
super.onCreate()
17+
instance = this
18+
}
19+
20+
companion object {
21+
lateinit var instance: AndroidApp
22+
}
2223
}

feature/about/src/androidMain/kotlin/org/mifos/mobile/feature/about/MyWebView.android.kt renamed to feature/about/src/androidMain/kotlin/org/mifos/mobile/feature/about/MifosWebView.android.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import androidx.compose.ui.Modifier
1818
import androidx.compose.ui.viewinterop.AndroidView
1919

2020
@Composable
21-
actual fun MyWebView(
21+
actual fun MifosWebView(
2222
htmlContent: String,
2323
isLoading: (isLoading: Boolean) -> Unit,
2424
onUrlClicked: (url: String) -> Unit,

feature/about/src/androidMain/kotlin/org/mifos/mobile/feature/about/OpenUrl.android.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ package org.mifos.mobile.feature.about
1212
import android.content.Intent
1313
import android.net.Uri
1414

15-
actual fun openUrl(url: String?) {
16-
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
15+
internal actual fun openUrl(url: String?) {
16+
val uri = url?.let { Uri.parse(url) } ?: return
17+
val intent = Intent().apply {
18+
action = Intent.ACTION_VIEW
19+
data = uri
20+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
21+
}
22+
AndroidApp.instance.startActivity(intent)
23+
}
24+
25+
internal actual fun openOssLicenses() {
1726
}

feature/about/src/commonMain/kotlin/org/mifos/mobile/feature/about/MyWebView.kt renamed to feature/about/src/commonMain/kotlin/org/mifos/mobile/feature/about/MifosWebView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import androidx.compose.runtime.Composable
1313
import androidx.compose.ui.Modifier
1414

1515
@Composable
16-
expect fun MyWebView(
16+
expect fun MifosWebView(
1717
htmlContent: String,
1818
isLoading: (isLoading: Boolean) -> Unit,
1919
onUrlClicked: (url: String) -> Unit,

feature/about/src/commonMain/kotlin/org/mifos/mobile/feature/about/OpenUrl.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
*/
1010
package org.mifos.mobile.feature.about
1111

12-
expect fun openUrl(url: String?)
12+
internal expect fun openUrl(url: String?)
13+
14+
internal expect fun openOssLicenses()

feature/about/src/commonMain/kotlin/org/mifos/mobile/feature/about/ui/PrivacyPolicyScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import mifos_mobile.feature.about.generated.resources.feature_about_privacy_poli
2626
import org.jetbrains.compose.resources.stringResource
2727
import org.mifos.mobile.core.designsystem.component.MifosScaffold
2828
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
29-
import org.mifos.mobile.feature.about.MyWebView
29+
import org.mifos.mobile.feature.about.MifosWebView
3030
import org.mifos.mobile.feature.about.openUrl
3131

3232
@Composable
@@ -56,7 +56,7 @@ private fun WebView(
5656

5757
Column(modifier) {
5858
Spacer(modifier = Modifier.height(20.dp))
59-
MyWebView(
59+
MifosWebView(
6060
htmlContent = url,
6161
isLoading = { isLoading = it },
6262
modifier = Modifier.fillMaxWidth(),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
package org.mifos.mobile.feature.about
11+
12+
import androidx.compose.foundation.layout.Box
13+
import androidx.compose.foundation.layout.fillMaxSize
14+
import androidx.compose.material3.Text
15+
import androidx.compose.runtime.Composable
16+
import androidx.compose.ui.Alignment
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.text.style.TextAlign
19+
20+
@Composable
21+
actual fun MifosWebView(
22+
htmlContent: String,
23+
isLoading: (isLoading: Boolean) -> Unit,
24+
onUrlClicked: (url: String) -> Unit,
25+
modifier: Modifier,
26+
) {
27+
Box(modifier = modifier.fillMaxSize()) {
28+
Text(
29+
text = "Implement platform specific WebView for Desktop",
30+
textAlign = TextAlign.Center,
31+
modifier = Modifier.align(Alignment.Center),
32+
)
33+
}
34+
}

feature/about/src/desktopMain/kotlin/org/mifos/mobile/feature/about/OpenUrl.desktop.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import java.awt.Desktop
1313
import java.net.URI
1414

1515
actual fun openUrl(url: String?) {
16-
if (Desktop.isDesktopSupported()) {
17-
Desktop.getDesktop().browse(URI(url))
18-
}
16+
val uri = url?.let { URI.create(it) } ?: return
17+
Desktop.getDesktop().browse(uri)
18+
}
19+
20+
internal actual fun openOssLicenses() {
1921
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import androidx.compose.runtime.Composable
1313
import androidx.compose.ui.Modifier
1414

1515
@Composable
16-
actual fun MyWebView(
16+
actual fun MifosWebView(
1717
htmlContent: String,
1818
isLoading: (isLoading: Boolean) -> Unit,
1919
onUrlClicked: (url: String) -> Unit,

0 commit comments

Comments
 (0)