Skip to content

Commit

Permalink
Merge pull request #181 from team-xquare/feature/153_post_bug_image
Browse files Browse the repository at this point in the history
🔀 :: (#180) Feature/152 post bug image
  • Loading branch information
rladmsdh authored Jul 3, 2023
2 parents ac321cf + d113946 commit 9abf687
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -25,11 +26,11 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.DropdownMenu
import androidx.compose.material.Icon
import androidx.compose.material.Scaffold
Expand Down Expand Up @@ -68,7 +69,6 @@ import com.xquare.xquare_android.util.DevicePaddings
import com.xquare.xquare_android.util.toFile
import java.io.File

// TODO Body4
internal object MenuItem {
const val HOME = ""
const val SCHEDULE = "일정"
Expand All @@ -93,25 +93,25 @@ fun BugReportScreen(
) {
val bugViewModel: BugViewModel = hiltViewModel()
val context = LocalContext.current
var image by remember { mutableStateOf(ArrayList<String>()) }
var photo by remember { mutableStateOf("") }
val photos by remember { mutableStateOf(ArrayList<String>()) }
var image by remember { mutableStateOf("") }

LaunchedEffect(Unit){
bugViewModel.eventFlow.collect{
when (it){
is BugViewModel.Event.Success -> {
Toast.makeText(context,"버그 제보 성공",Toast.LENGTH_SHORT).show()
photo = ""
photos.clear()
}
is BugViewModel.Event.Failure -> Toast.makeText(context,"버그 제보 실패",Toast.LENGTH_SHORT).show()
is BugViewModel.Event.UploadFileSuccess -> {
image = it.data as ArrayList<String>
photo = it.data[0]
image = it.data[0]
}
}
}
}

if (image != "") photos.add(image)
image = ""
BugreportContent(
onIconClick = { navController.popBackStack() },
onBtnClick = {
Expand All @@ -120,8 +120,7 @@ fun BugReportScreen(
sendImage = {
bugViewModel.uploadFile(it)
},
image = image,
photo = photo
photos = photos,
)


Expand All @@ -133,8 +132,7 @@ private fun BugreportContent(
onIconClick: () -> Unit,
onBtnClick: (BugEntity) -> Unit,
sendImage: (File) -> Unit,
image: ArrayList<String>,
photo:String
photos: ArrayList<String>,
) {
var where by remember { mutableStateOf("") }
var explanationText by remember { mutableStateOf("") }
Expand All @@ -146,9 +144,12 @@ private fun BugreportContent(
ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode == Activity.RESULT_OK) {
result.data!!.data?.run {
sendImage(toFile(context,this))
Toast.makeText(context,"사진 추가 성공",Toast.LENGTH_SHORT).show()
result.data!!.clipData?.run {
for (i in 0 until itemCount) {
val listItem = getItemAt(i).uri
sendImage(toFile(context, listItem))
}
Toast.makeText(context, "사진 추가 성공", Toast.LENGTH_SHORT).show()
}
}
galleryState = false
Expand All @@ -157,7 +158,7 @@ private fun BugreportContent(
val openGalleryLauncher =
Intent(Intent.ACTION_PICK).apply {
this.type = "image/*"
this.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
this.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
}
if (galleryState) {
openWebViewGallery.launch(openGalleryLauncher)
Expand All @@ -175,7 +176,8 @@ private fun BugreportContent(
btnEnabled = headerBtnEnabled,
onIconClick = onIconClick,
onBtnClick = {
onBtnClick(BugEntity(explanationText, where.toEntityWhere(), image_urls = image))
onBtnClick(BugEntity(explanationText, where.toEntityWhere(), image_urls = photos))
photos.clear()
explanationText = ""
},
)
Expand All @@ -193,18 +195,41 @@ private fun BugreportContent(
Spacer(modifier = Modifier.size(30.dp))
Text(text = "사진을 첨부해 주세요")
Spacer(modifier = Modifier.size(10.dp))
Column(
modifier = Modifier
.clickable { galleryState = true }
.size(150.dp)
.background(gray50),
) {
if (photo != ""){
Image(
modifier = Modifier.fillMaxSize(),
painter = rememberAsyncImagePainter(model = photo),
contentDescription = "bugPhoto",
)
Row {
if (photos.isEmpty()){
Column(
modifier = Modifier
.clickable { galleryState = true }
.size(150.dp)
.background(gray50),
) {
Image(
modifier = Modifier
.fillMaxSize()
.padding(20.dp),
painter = rememberAsyncImagePainter(model = R.drawable.ic_add_photo),
contentDescription = "insertBugPhoto",
)
}
} else {
LazyRow(
contentPadding = PaddingValues(horizontal = 12.dp),
) {
items(photos) {
Column(
modifier = Modifier
.size(150.dp)
.clickable { galleryState = true }
.padding(end = 4.dp),
) {
Image(
modifier = Modifier.fillMaxSize(),
painter = rememberAsyncImagePainter(model = it),
contentDescription = "bugPhoto",
)
}
}
}
}
}
Spacer(modifier = Modifier.size(16.dp))
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_add_photo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="86dp"
android:height="54dp"
android:viewportWidth="86"
android:viewportHeight="54">

<path android:pathData="M57 24.8889V3.11111C57 1.4 55.6 0 53.8889 0H32.1111C30.4 0 29 1.4 29 3.11111V24.8889C29 26.6 30.4 28 32.1111 28H53.8889C55.6 28 57 26.6 57 24.8889ZM38.1778 17.08L41.4444 21.0156L46.2667 14.8089C46.5778 14.4044 47.2 14.4044 47.5111 14.8244L52.9711 22.1044C53.0578 22.22 53.1106 22.3574 53.1235 22.5013C53.1365 22.6451 53.1092 22.7898 53.0446 22.9189C52.98 23.0481 52.8807 23.1568 52.7578 23.2327C52.6349 23.3087 52.4933 23.3489 52.3489 23.3489H33.6978C33.0444 23.3489 32.6867 22.6022 33.0911 22.0889L36.9644 17.1111C37.26 16.7067 37.8511 16.6911 38.1778 17.08Z"
android:fillColor="#98959E"/>
<path android:pathData="M1.848 40.592H8.832V41.396H1.848V40.592ZM8.184 40.592H9.156V41.432C9.156 42.332 9.156 43.4 8.844 44.828L7.86 44.72C8.184 43.316 8.184 42.32 8.184 41.432V40.592ZM8.46 42.428V43.136L1.704 43.436L1.572 42.644L8.46 42.428ZM0.6 44.528H10.392V45.32H0.6V44.528ZM1.74 46.352H9.24V48.884H2.748V50.348H1.764V48.14H8.256V47.12H1.74V46.352ZM1.764 50.012H9.612V50.792H1.764V50.012ZM19.5231 40.088H20.5311V46.724H19.5231V40.088ZM13.2831 47.312H20.5311V50.936H19.5231V48.128H13.2831V47.312ZM12.1911 45.296H13.0671C15.0351 45.296 16.4871 45.236 18.2271 44.96L18.3351 45.764C16.5471 46.064 15.0831 46.112 13.0671 46.112H12.1911V45.296ZM12.1671 40.724H17.0871V43.736H13.1631V45.692H12.1911V42.968H16.1151V41.54H12.1671V40.724ZM25.8657 41.324H34.5897V42.128H25.8657V41.324ZM25.3617 47.12H35.1897V47.936H25.3617V47.12ZM29.7537 47.78H30.7497V50.948H29.7537V47.78ZM30.2577 42.752C32.4657 42.752 33.7737 43.4 33.7737 44.564C33.7737 45.716 32.4657 46.376 30.2577 46.376C28.0377 46.376 26.7297 45.716 26.7297 44.564C26.7297 43.4 28.0377 42.752 30.2577 42.752ZM30.2577 43.52C28.6737 43.52 27.7617 43.892 27.7617 44.564C27.7617 45.236 28.6737 45.608 30.2577 45.608C31.8417 45.608 32.7537 45.236 32.7537 44.564C32.7537 43.892 31.8417 43.52 30.2577 43.52ZM29.7537 40.028H30.7497V41.864H29.7537V40.028ZM41.7364 41.024H42.5524V42.968C42.5524 45.368 41.2564 47.708 39.5404 48.62L38.9284 47.828C40.5004 47.036 41.7364 44.948 41.7364 42.968V41.024ZM41.9164 41.024H42.7204V42.968C42.7204 44.876 43.9324 46.856 45.4684 47.624L44.8564 48.416C43.1764 47.516 41.9164 45.296 41.9164 42.968V41.024ZM46.4164 40.088H47.4244V50.936H46.4164V40.088ZM47.1844 44.48H49.2004V45.32H47.1844V44.48ZM53.0034 41.276H53.8314V42.38C53.8314 44.372 52.6074 46.04 50.7834 46.7L50.2674 45.908C51.8994 45.332 53.0034 43.928 53.0034 42.38V41.276ZM53.1954 41.276H54.0234V42.38C54.0234 43.844 55.1514 45.164 56.7594 45.704L56.2434 46.484C54.4434 45.872 53.1954 44.288 53.1954 42.38V41.276ZM50.5314 40.988H56.4714V41.792H50.5314V40.988ZM58.0074 40.1H59.0154V48.032H58.0074V40.1ZM52.0434 49.88H59.3394V50.696H52.0434V49.88ZM52.0434 47.288H53.0274V50.24H52.0434V47.288ZM66.5461 41.912H67.3621V42.38C67.3621 44.24 66.1381 45.752 64.3261 46.34L63.8461 45.56C65.4541 45.068 66.5461 43.808 66.5461 42.38V41.912ZM66.7261 41.912H67.5421V42.38C67.5421 43.724 68.6581 44.888 70.2661 45.356L69.7981 46.148C67.9741 45.596 66.7261 44.168 66.7261 42.38V41.912ZM64.1461 41.36H69.9301V42.164H64.1461V41.36ZM66.5461 40.04H67.5421V41.684H66.5461V40.04ZM69.6301 43.112H72.0421V43.94H69.6301V43.112ZM71.7661 40.088H72.7621V46.508H71.7661V40.088ZM65.7301 47.072H72.7621V50.792H65.7301V47.072ZM71.7901 47.864H66.7021V49.988H71.7901V47.864ZM74.8732 46.508H84.7132V47.324H74.8732V46.508ZM79.2652 46.892H80.2492V50.936H79.2652V46.892ZM76.1092 40.52H77.1052V42.008H82.4692V40.52H83.4532V45.212H76.1092V40.52ZM77.1052 42.812V44.408H82.4692V42.812H77.1052Z"
android:fillColor="#98959E"/>

</vector>

0 comments on commit 9abf687

Please sign in to comment.