Skip to content

Commit

Permalink
#21 fix links and images
Browse files Browse the repository at this point in the history
  • Loading branch information
javadjafari1 committed Aug 11, 2023
1 parent 0196514 commit 9682cb3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ir.thatsmejavad.backgroundable.core

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.compose.ui.graphics.Color
import androidx.core.content.FileProvider
import ir.thatsmejavad.backgroundable.R
Expand Down Expand Up @@ -96,3 +99,40 @@ fun Bitmap.saveIn(
}
return tempFile
}

fun Context.openUrl(url: String) {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
} catch (e: ActivityNotFoundException) {
toast(R.string.label_no_app_found_to_handle_this_request)
}
}

fun Context.composeMail(
recipientMail: String,
subject: String = "",
message: String = "",
) {
try {
val selectorIntent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
}
val emailIntent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_EMAIL, arrayOf(recipientMail))
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_TEXT, message)
selector = selectorIntent
}
startActivity(emailIntent)
} catch (e: ActivityNotFoundException) {
toast(R.string.label_no_app_found_to_handle_this_request)
}
}

fun Context.toast(message: String, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, message, duration).show()
}

fun Context.toast(@StringRes stringRes: Int, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, stringRes, duration).show()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ir.thatsmejavad.backgroundable.screens.aboutus

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -29,6 +30,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
Expand All @@ -37,6 +39,8 @@ import ir.thatsmejavad.backgroundable.BuildConfig
import ir.thatsmejavad.backgroundable.R
import ir.thatsmejavad.backgroundable.common.ui.HexagonShape
import ir.thatsmejavad.backgroundable.common.ui.drawCustomHexagonPath
import ir.thatsmejavad.backgroundable.core.composeMail
import ir.thatsmejavad.backgroundable.core.openUrl
import ir.thatsmejavad.backgroundable.model.Contributor
import ir.thatsmejavad.backgroundable.model.ContributorLink

Expand All @@ -45,6 +49,8 @@ import ir.thatsmejavad.backgroundable.model.ContributorLink
fun AboutUsScreen(
onBackClicked: () -> Unit
) {
val context = LocalContext.current

Scaffold(
topBar = {
MediumTopAppBar(
Expand Down Expand Up @@ -76,9 +82,15 @@ fun AboutUsScreen(
BackgroundableAbout()

contributors.forEach { contributor ->
ContributorItem(contributor) {

}
ContributorItem(
contributor = contributor,
openEmail = { mail ->
context.composeMail(mail)
},
openUrl = { url ->
context.openUrl(url)
}
)
}
}
}
Expand All @@ -87,7 +99,8 @@ fun AboutUsScreen(
@Composable
private fun ContributorItem(
contributor: Contributor,
openUrl: (String) -> Unit
openUrl: (String) -> Unit,
openEmail: (String) -> Unit,
) {
Box(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -126,12 +139,19 @@ private fun ContributorItem(
) {
contributor.links.forEach { link ->
IconButton(
modifier = Modifier.size(32.dp),
onClick = { openUrl(link.url) },
modifier = Modifier
.size(54.dp),
onClick = {
if (link.name == "mail") {
openEmail(link.url)
} else {
openUrl(link.url)
}
},
) {
Icon(
painter = painterResource(link.icon),
contentDescription = link.name,
contentDescription = "${contributor.name}'s ${link.name}",
tint = MaterialTheme.colorScheme.surfaceTint
)

Expand All @@ -142,15 +162,14 @@ private fun ContributorItem(
Spacer(modifier = Modifier.size(40.dp))
}

Icon(
Image(
modifier = Modifier
.padding(top = 10.dp)
.size(100.dp)
.align(TopCenter)
.clip(CircleShape),
painter = painterResource(contributor.image),
contentDescription = "${contributor.name}'s image",
tint = MaterialTheme.colorScheme.primaryContainer
)
}
}
Expand Down Expand Up @@ -231,7 +250,7 @@ val contributors = listOf(
Contributor(
name = "Javad Jafari",
position = "Android Developer",
image = R.drawable.ic_grid,
image = R.drawable.jai_photo,
links = listOf(
ContributorLink(
icon = R.drawable.ic_linkedin,
Expand All @@ -246,14 +265,14 @@ val contributors = listOf(
ContributorLink(
icon = R.drawable.ic_mail,
url = "javad2147@yahoo.com",
name = "Mail"
name = "mail"
),
)
),
Contributor(
name = "Mohammad Ghasemi",
position = "UI/UX Designer",
image = R.drawable.ic_language,
image = R.drawable.mmd_photo,
links = listOf(
ContributorLink(
icon = R.drawable.ic_linkedin,
Expand All @@ -262,13 +281,13 @@ val contributors = listOf(
),
ContributorLink(
icon = R.drawable.ic_mail,
url = "github",
url = "Mohammadghasemi.de@gmail.com",
name = "mail"
),
ContributorLink(
icon = R.drawable.ic_dribble,
url = "github",
name = "mail"
url = "https://dribbble.com/MohammadGhasemi-de",
name = "dribble"
),
)
)
Expand Down
Binary file added app/src/main/res/drawable/jai_photo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/mmd_photo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
<string name="label_download_wallpaper">Download Wallpaper</string>
<string name="label_download_is_about_to_begin">Your image download is about to begin.</string>
<string name="label_pexels">Powered by Pexels Api</string>
<string name="label_no_app_found_to_handle_this_request">No App Found To Handle This Request!</string>
</resources>

0 comments on commit 9682cb3

Please sign in to comment.