mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 12:07:03 +05:30
common: make UrlLauncher use expect/actual
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
3021f96465
commit
f5c3a950bf
5 changed files with 15 additions and 11 deletions
|
@ -7,13 +7,12 @@ import dagger.hilt.InstallIn
|
|||
import dagger.hilt.android.components.ActivityComponent
|
||||
import dagger.hilt.android.qualifiers.ActivityContext
|
||||
import dev.msfjarvis.lobsters.ui.urllauncher.UrlLauncher
|
||||
import dev.msfjarvis.lobsters.ui.urllauncher.AndroidUrlLauncherImpl
|
||||
|
||||
@Module
|
||||
@InstallIn(ActivityComponent::class)
|
||||
object UrlLauncherModule {
|
||||
@Provides
|
||||
fun provideUrlLauncher(@ActivityContext context: Context): UrlLauncher {
|
||||
return AndroidUrlLauncherImpl(context)
|
||||
return UrlLauncher(context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@ package dev.msfjarvis.lobsters.ui.urllauncher
|
|||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import dev.msfjarvis.lobsters.ui.urllauncher.UrlLauncher
|
||||
|
||||
class AndroidUrlLauncherImpl(private val context: Context) : UrlLauncher {
|
||||
override fun launch(url: String) {
|
||||
actual class UrlLauncher(private val context: Context) {
|
||||
actual fun launch(url: String) {
|
||||
val customTabsIntent = CustomTabsIntent.Builder()
|
||||
.setShareState(CustomTabsIntent.SHARE_STATE_ON)
|
||||
.setShowTitle(true)
|
|
@ -1,5 +1,5 @@
|
|||
package dev.msfjarvis.lobsters.ui.urllauncher
|
||||
|
||||
fun interface UrlLauncher {
|
||||
expect class UrlLauncher {
|
||||
fun launch(url: String)
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package dev.msfjarvis.lobsters.ui.urllauncher
|
|||
import java.awt.Desktop
|
||||
import java.net.URI
|
||||
|
||||
class JVMUrlLauncherImpl() : UrlLauncher {
|
||||
override fun launch(url: String) {
|
||||
actual class UrlLauncher {
|
||||
actual fun launch(url: String) {
|
||||
val desktop = Desktop.getDesktop()
|
||||
|
||||
if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {
|
|
@ -11,6 +11,7 @@ import androidx.compose.foundation.rememberScrollState
|
|||
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
|
@ -21,6 +22,8 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.setValue
|
||||
import dev.msfjarvis.lobsters.data.ApiRepository
|
||||
import dev.msfjarvis.lobsters.model.LobstersPost
|
||||
import dev.msfjarvis.lobsters.ui.urllauncher.LocalUrlLauncher
|
||||
import dev.msfjarvis.lobsters.ui.urllauncher.UrlLauncher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@ -29,6 +32,7 @@ val repository = ApiRepository()
|
|||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun main() = Window(title = "Claw for lobste.rs") {
|
||||
val urlLauncher = UrlLauncher()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
var items by remember { mutableStateOf(emptyList<SavedPost>()) }
|
||||
coroutineScope.launch {
|
||||
|
@ -49,9 +53,11 @@ fun main() = Window(title = "Claw for lobste.rs") {
|
|||
if (items.isEmpty()) {
|
||||
Text("Loading...")
|
||||
} else {
|
||||
Column {
|
||||
items.forEach {
|
||||
LobstersItem(it)
|
||||
CompositionLocalProvider(LocalUrlLauncher provides urlLauncher) {
|
||||
Column {
|
||||
items.forEach {
|
||||
LobstersItem(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue