diff --git a/app/src/main/java/dev/msfjarvis/todo/Application.kt b/app/src/main/java/dev/msfjarvis/todo/Application.kt index e42a64c1..4ff3cad9 100644 --- a/app/src/main/java/dev/msfjarvis/todo/Application.kt +++ b/app/src/main/java/dev/msfjarvis/todo/Application.kt @@ -4,5 +4,4 @@ import android.app.Application import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp -class Application : Application() { -} +class Application : Application() diff --git a/app/src/main/java/dev/msfjarvis/todo/di/UrlLauncherModule.kt b/app/src/main/java/dev/msfjarvis/todo/di/UrlLauncherModule.kt new file mode 100644 index 00000000..806aba97 --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/todo/di/UrlLauncherModule.kt @@ -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) + } +} diff --git a/app/src/main/java/dev/msfjarvis/todo/urllauncher/UrlLauncher.kt b/app/src/main/java/dev/msfjarvis/todo/urllauncher/UrlLauncher.kt new file mode 100644 index 00000000..16002181 --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/todo/urllauncher/UrlLauncher.kt @@ -0,0 +1,5 @@ +package dev.msfjarvis.todo.urllauncher + +interface UrlLauncher { + fun launch(url: String) +} diff --git a/app/src/main/java/dev/msfjarvis/todo/urllauncher/UrlLauncherImpl.kt b/app/src/main/java/dev/msfjarvis/todo/urllauncher/UrlLauncherImpl.kt new file mode 100644 index 00000000..67c5b98c --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/todo/urllauncher/UrlLauncherImpl.kt @@ -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) }) + } +}