mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 23:47:02 +05:30
Add and implement UrlLauncher
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
34ba71e229
commit
1a1410eb1c
4 changed files with 39 additions and 2 deletions
|
@ -4,5 +4,4 @@ import android.app.Application
|
|||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
class Application : Application() {
|
||||
}
|
||||
class Application : Application()
|
||||
|
|
19
app/src/main/java/dev/msfjarvis/todo/di/UrlLauncherModule.kt
Normal file
19
app/src/main/java/dev/msfjarvis/todo/di/UrlLauncherModule.kt
Normal file
|
@ -0,0 +1,19 @@
|
|||
package dev.msfjarvis.todo.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityComponent
|
||||
import dagger.hilt.android.qualifiers.ActivityContext
|
||||
import dev.msfjarvis.todo.urllauncher.UrlLauncher
|
||||
import dev.msfjarvis.todo.urllauncher.UrlLauncherImpl
|
||||
|
||||
@InstallIn(ActivityComponent::class)
|
||||
@Module
|
||||
object UrlLauncherModule {
|
||||
@Provides
|
||||
fun provideUrlLauncher(@ActivityContext context: Context): UrlLauncher {
|
||||
return UrlLauncherImpl(context)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package dev.msfjarvis.todo.urllauncher
|
||||
|
||||
interface UrlLauncher {
|
||||
fun launch(url: String)
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package dev.msfjarvis.todo.urllauncher
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.ACTION_VIEW
|
||||
import android.net.Uri
|
||||
import android.util.Patterns
|
||||
|
||||
class UrlLauncherImpl(private val context: Context) : UrlLauncher {
|
||||
override fun launch(url: String) {
|
||||
if (!Patterns.WEB_URL.matcher(url).matches()) return
|
||||
context.startActivity(Intent(ACTION_VIEW).apply { data = Uri.parse(url) })
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue