Skip to content

Commit

Permalink
fix: Implement missing targets in link opener
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Dec 27, 2024
1 parent 741fb5a commit c30b5bb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private fun sendEmail(
) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]")
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
intent.putExtra(Intent.EXTRA_SUBJECT, "Menza problem report")
intent.putExtra(Intent.EXTRA_TEXT, text)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,50 @@ internal class AndroidLinkOpener(
}
}.mapLeft { CommonError.AppNotFound.Link }

override fun writeEmail(email: String): Outcome<Unit> =
override fun writeEmail(
emails: List<String>,
subject: String?,
content: String?,
): Outcome<Unit> =
runCatchingAppNotFound {
error("Not yet implemented")
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(Intent.EXTRA_EMAIL, emails.toTypedArray())
subject?.let {
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
}
content?.let {
intent.putExtra(Intent.EXTRA_TEXT, content)
}
context.startActivity(Intent.createChooser(intent, ""))
}.mapLeft { CommonError.AppNotFound.Email }

override fun callPhoneNumber(number: String): Outcome<Unit> =
runCatchingAppNotFound {
error("Not yet implemented")
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:$number")
context.startActivity(Intent.createChooser(intent, ""))
}.mapLeft { CommonError.AppNotFound.PhoneCall }

override fun openAddress(address: String): Outcome<Unit> =
runCatchingAppNotFound {
error("Not yet implemented")
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("geo:0,0?q=${Uri.encode(address)}")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
}.mapLeft { CommonError.AppNotFound.Map }

override fun openGeo(
lat: Float,
long: Float,
): Outcome<Unit> =
runCatchingAppNotFound {
error("Not yet implemented")
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("geo:${lat},${long}")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
}.mapLeft { CommonError.AppNotFound.Map }

override fun openTelegram(groupUrl: String): Outcome<Unit> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -31,13 +31,14 @@ import cz.lastaapps.core.domain.model.AppSocial.PLAY_STORE_APP
import cz.lastaapps.core.domain.model.AppSocial.PLAY_STORE_DEVELOPER
import cz.lastaapps.core.domain.model.AppSocial.TELEGRAM
import cz.lastaapps.core.util.providers.LinkOpener
import cz.lastaapps.core.util.providers.writeEmail

class OpenAppSocialUC internal constructor(
private val link: LinkOpener,
) {
operator fun invoke(social: AppSocial) =
when (social) {
EMAIL -> link.writeEmail("[email protected]")
EMAIL -> link.writeEmail("[email protected]", null, null)
FACEBOOK -> link.openFacebookPage("https://www.facebook.com/lastaapps/")
GITHUB_ISSUES -> link.openLink("https://github.com/Lastaapps/menza/issues")
GITHUB_DEVELOPER -> link.openLink("https://github.com/lastaapps/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import cz.lastaapps.core.domain.Outcome
interface LinkOpener {
fun openLink(url: String): Outcome<Unit>

fun writeEmail(email: String): Outcome<Unit>
fun writeEmail(emails: List<String>, subject: String?, content: String?): Outcome<Unit>

fun callPhoneNumber(number: String): Outcome<Unit>

Expand All @@ -39,3 +39,6 @@ interface LinkOpener {

fun openFacebookPage(pageUrl: String): Outcome<Unit>
}

fun LinkOpener.writeEmail(email: String, subject: String?, content: String?) =
writeEmail(listOf(email), subject, content)

0 comments on commit c30b5bb

Please sign in to comment.