Add profile and profile picture selection
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c53f9e8b91
commit
bcc735f713
@ -0,0 +1,52 @@
|
||||
package fr.iut.alldev.allin.ui.profile.components
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import fr.iut.alldev.allin.theme.AllInTheme
|
||||
|
||||
@Composable
|
||||
fun ProfileScreenContent(
|
||||
username: String,
|
||||
image: String?,
|
||||
totalBets: Int,
|
||||
bestWin: Int,
|
||||
friends: Int,
|
||||
selectNewProfilePicture: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(vertical = 18.dp, horizontal = 21.dp)
|
||||
) {
|
||||
ProfileScreenHeader(
|
||||
image = image,
|
||||
username = username,
|
||||
totalBets = totalBets,
|
||||
bestWin = bestWin,
|
||||
friends = friends,
|
||||
selectNewProfilePicture = selectNewProfilePicture
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Composable
|
||||
private fun ProfileScreenContentPreview() {
|
||||
AllInTheme {
|
||||
ProfileScreenContent(
|
||||
username = "User 1",
|
||||
image = null,
|
||||
totalBets = 12,
|
||||
bestWin = 365,
|
||||
friends = 5,
|
||||
selectNewProfilePicture = { }
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package fr.iut.alldev.allin.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.core.content.FileProvider
|
||||
import fr.iut.alldev.allin.R
|
||||
import java.io.File
|
||||
|
||||
class AskPicture : ActivityResultContract<AskPictureParams, AskPictureResult?>() {
|
||||
private var uri: Uri? = null
|
||||
|
||||
override fun createIntent(context: Context, input: AskPictureParams): Intent {
|
||||
val pickerIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
|
||||
.also { intent ->
|
||||
input.cameraFile.also { file ->
|
||||
val photoUri: Uri = FileProvider.getUriForFile(
|
||||
context,
|
||||
"${context.packageName}.fileprovider",
|
||||
file
|
||||
).also { uri = it }
|
||||
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri)
|
||||
}
|
||||
}
|
||||
|
||||
return Intent.createChooser(cameraIntent, context.getText(R.string.profile_pick_profile_picture))
|
||||
.also { intent ->
|
||||
intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(pickerIntent))
|
||||
}
|
||||
}
|
||||
|
||||
override fun parseResult(resultCode: Int, intent: Intent?): AskPictureResult? {
|
||||
return if (resultCode != Activity.RESULT_OK) {
|
||||
null
|
||||
} else {
|
||||
(intent?.data ?: uri)?.let {
|
||||
AskPictureResult.PictureResult(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class AskPictureParams(val cameraFile: File)
|
||||
|
||||
sealed class AskPictureResult {
|
||||
data class PictureResult(val pickedFile: Uri?) : AskPictureResult()
|
||||
}
|
||||
|
||||
fun createImageFile(context: Context): File {
|
||||
val directory = File(context.cacheDir, ".").apply {
|
||||
mkdirs()
|
||||
}
|
||||
return File.createTempFile("picture_", ".jpg", directory)
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<cache-path
|
||||
name="allin"
|
||||
path="." />
|
||||
</paths>
|
Loading…
Reference in new issue