Skip to content

Commit

Permalink
Added a Url Opener Helper for... opening urls on both platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Robiez committed Mar 11, 2024
1 parent 4e18f52 commit b469cca
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import android.os.Build
import fr.androidmakers.domain.interactor.GetAfterpartyVenueUseCase
import fr.androidmakers.domain.interactor.GetAgendaUseCase
import fr.androidmakers.domain.interactor.GetConferenceVenueUseCase
import fr.androidmakers.domain.interactor.OpenCocUseCase
import fr.androidmakers.domain.interactor.OpenFaqUseCase
import fr.androidmakers.domain.interactor.OpenYoutubeUseCase
import fr.androidmakers.domain.interactor.SyncBookmarksUseCase
import fr.androidmakers.domain.repo.BookmarksRepository
import fr.androidmakers.domain.repo.PartnersRepository
Expand All @@ -13,6 +16,7 @@ import fr.androidmakers.domain.repo.SessionsRepository
import fr.androidmakers.domain.repo.SpeakersRepository
import fr.androidmakers.domain.repo.UserRepository
import fr.androidmakers.store.firebase.FirebaseUserRepository
import fr.androidmakers.domain.utils.UrlOpener
import fr.androidmakers.store.graphql.ApolloClientBuilder
import fr.androidmakers.store.graphql.PartnersGraphQLRepository
import fr.androidmakers.store.graphql.RoomsGraphQLRepository
Expand All @@ -30,12 +34,16 @@ class AndroidMakersApplication : Application() {
lateinit var getConferenceVenueUseCase: GetConferenceVenueUseCase
lateinit var getAfterpartyVenueUseCase: GetAfterpartyVenueUseCase
lateinit var syncBookmarksUseCase: SyncBookmarksUseCase
lateinit var openFaqUseCase: OpenFaqUseCase
lateinit var openCocUseCase: OpenCocUseCase
lateinit var openYoutubeUseCase: OpenYoutubeUseCase

lateinit var partnersRepository: PartnersRepository
lateinit var roomsRepository: RoomsRepository
lateinit var sessionsRepository: SessionsRepository
lateinit var speakersRepository: SpeakersRepository
lateinit var userRepository: UserRepository
lateinit var urlOpener: UrlOpener

lateinit var bookmarksStore: BookmarksRepository

Expand Down Expand Up @@ -78,6 +86,11 @@ class AndroidMakersApplication : Application() {
sessionsRepository
)

urlOpener = UrlOpener(this)
openFaqUseCase = OpenFaqUseCase(urlOpener)
openCocUseCase = OpenCocUseCase(urlOpener)
openYoutubeUseCase = OpenYoutubeUseCase(urlOpener)

openFeedback = OpenFeedback(
context = this,
openFeedbackProjectId = "am2023",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import dev.gitlive.firebase.auth.GoogleAuthProvider
import dev.gitlive.firebase.auth.auth
import fr.androidmakers.domain.model.User
import fr.androidmakers.store.firebase.toUser
import fr.androidmakers.domain.utils.UrlOpener
import fr.paug.androidmakers.AndroidMakersApplication
import fr.paug.androidmakers.R
import fr.paug.androidmakers.ui.components.MainLayout
Expand Down Expand Up @@ -122,11 +123,11 @@ class MainActivity : AppCompatActivity() {
}

private fun onFaqClick() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://androidmakers.droidcon.com/faqs/")))
AndroidMakersApplication.instance().openFaqUseCase()
}

private fun onCodeOfConductClick() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://androidmakers.droidcon.com/code-of-conduct/")))
AndroidMakersApplication.instance().openCocUseCase()
}

private fun onXHashtagClick() {
Expand Down Expand Up @@ -215,7 +216,7 @@ class MainActivity : AppCompatActivity() {
}

private fun onYouTubeLogoClick() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.youtube_channel))))
AndroidMakersApplication.instance().openYoutubeUseCase()
}

private fun onSponsorClick(url: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package fr.paug.androidmakers.ui.theme

import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
Expand Down
1 change: 0 additions & 1 deletion androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<string name="x_hashtag" translatable="false">#AMxDC24</string>
<string name="x_hashtag_for_query" translatable="false">AMxDC24</string>
<string name="x_user_name" translatable="false">AndroidMakersFR</string>
<string name="youtube_channel" translatable="false">https://www.youtube.com/channel/UCkatLlah5weIpN23LqMgdTg</string>

<string name="sponsors">Sponsors</string>
<string name="gold_sponsor">Gold Sponsor</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.androidmakers.domain.utils

import android.content.Context
import android.content.Intent
import android.net.Uri

actual class UrlOpener(private val context: Context) {
actual fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.androidmakers.domain.interactor

import fr.androidmakers.domain.utils.Constants
import fr.androidmakers.domain.utils.UrlOpener

class OpenCocUseCase(
private val urlOpener: UrlOpener
) {
operator fun invoke() = urlOpener.openUrl(Constants.Urls.coc)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.androidmakers.domain.interactor

import fr.androidmakers.domain.utils.Constants
import fr.androidmakers.domain.utils.UrlOpener

class OpenFaqUseCase(
private val urlOpener: UrlOpener
) {
operator fun invoke() = urlOpener.openUrl(Constants.Urls.faq)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.androidmakers.domain.interactor

import fr.androidmakers.domain.utils.Constants
import fr.androidmakers.domain.utils.UrlOpener

class OpenYoutubeUseCase(
private val urlOpener: UrlOpener
) {
operator fun invoke() = urlOpener.openUrl(Constants.Urls.youtube)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fr.androidmakers.domain.utils

object Constants {
object Urls {
const val faq = "https://androidmakers.droidcon.com/faqs/"
const val coc = "https://androidmakers.droidcon.com/code-of-conduct/"
const val youtube = "https://www.youtube.com/channel/UCkatLlah5weIpN23LqMgdTg"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fr.androidmakers.domain.utils

expect class UrlOpener {
fun openUrl(url: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fr.androidmakers.domain.utils

import platform.Foundation.NSURL
import platform.UIKit.UIApplication

actual class UrlOpener {
actual fun openUrl(url: String) {
val urlObj = NSURL(string = url)
if (UIApplication.sharedApplication.canOpenURL(urlObj)) {
UIApplication.sharedApplication.openURL(urlObj)
}
}
}

0 comments on commit b469cca

Please sign in to comment.