Skip to content

Commit

Permalink
Merge branch 'develop' into feature/160_collect_as_state_with_lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
rladmsdh committed Jul 5, 2023
2 parents 2291be9 + de82760 commit 1b96d6b
Show file tree
Hide file tree
Showing 25 changed files with 348 additions and 230 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.work:work-runtime-ktx:2.7.1'

def nav_version = "2.4.2"
def nav_version = "2.5.3"
implementation("androidx.navigation:navigation-compose:$nav_version")

implementation "com.google.dagger:hilt-android:$hilt_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ package com.xquare.xquare_android.component
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.compose.currentBackStackEntryAsState
import com.semicolon.design.Body3
import com.semicolon.design.color.primary.gray.gray50
import com.semicolon.design.color.primary.gray.gray300
import com.semicolon.design.color.primary.gray.gray800
import com.semicolon.design.color.primary.gray.gray900
import com.semicolon.design.color.primary.white.white
import com.xquare.xquare_android.navigation.BottomNavigationItem
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@Composable
fun BottomNavigation(
Expand All @@ -41,13 +50,16 @@ fun BottomNavigation(
.weight(1f)
.background(color = white)
.clickable(
interactionSource = MutableInteractionSource(),
indication = rememberRipple(
radius = 28.dp
),
enabled = !selected
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(radius = 28.dp),
) {
navController.navigate(screen.route) { popUpTo(0) }
navController.navigate(screen.route) {
popUpTo(0) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.semicolon.design.color.primary.purple.purple400
import com.semicolon.design.color.primary.gray.gray300
import com.semicolon.design.color.primary.purple.purple300

@Composable
fun CustomSwitchButton(
Expand Down Expand Up @@ -65,7 +66,7 @@ fun CustomSwitchButton(
.width(buttonWidth)
.height(buttonHeight)
.clip(CircleShape)
.background(if (switchClicked) purple400 else Color.LightGray)
.background(if (switchClicked) purple300 else gray300)
.clickable(
interactionSource = interactionSource,
indication = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,12 @@ fun AlarmItem(
val tint = if (alarmList.is_read) black else purple300

val painter: Int = when (alarmList.topic) {
"APPLICATION_WEEKEND_MEAL",
"APPLICATION_STAY",
"APPLICATION_MOVE_CLASSROOM",
"APPLICATION_PICNIC",
"APPLICATION_PICNIC_PASS",
"APPLICATION_WEEKEND_PICNIC",
"APPLICATION_WEEKEND_PICNIC_RESERVATION" -> R.drawable.ic_apply
"ALL_BAD_POINT","ALL_PENALTY_LEVEL"->R.drawable.img_bad
"ALL_GOOD_POINT", "FEED_NOTICE_LIKE", "FEED_BAMBOO_LIKE" ->R.drawable.img_good
"FEED_NOTICE","FEED_NOTICE_COMMENT", "FEED_BAMBOO_COMMENT", -> R.drawable.ic_feed
"ALL_BAD_POINT","ALL_PENALTY_LEVEL"->R.drawable.ic_thums_down
"ALL_GOOD_POINT"->R.drawable.ic_thumbs_up
"FEED_NOTICE","FEED_NOTICE_COMMENT", "FEED_NOTICE_LIKE",
"FEED_BAMBOO_COMMENT", "FEED_BAMBOO_LIKE" -> R.drawable.ic_feed
"SCHEDULE_LOCAL","SCHEDULE_SOCIAL" -> R.drawable.ic_schedule
else -> R.drawable.ic_alarm
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.semicolon.design.Body1
import com.semicolon.design.Body2
import com.semicolon.design.Body3
import com.semicolon.design.color.primary.gray.gray50
import com.semicolon.design.color.primary.gray.gray700
import com.semicolon.design.color.primary.gray.gray800
Expand Down Expand Up @@ -59,7 +60,7 @@ fun MealDetail(
Row(verticalAlignment = Alignment.CenterVertically) {
Body1(text = "아침", color = gray800)
Spacer(Modifier.size(8.dp))
Body2(
Body3(
text = mealWithDateEntity.caloriesOfBreakfast,
color = gray700,
modifier = Modifier
Expand All @@ -74,7 +75,7 @@ fun MealDetail(
Spacer(Modifier.size(8.dp))
Row(verticalAlignment = Alignment.CenterVertically) {
Body1(text = "점심", color = gray800)
Body2(
Body3(
text = mealWithDateEntity.caloriesOfLunch,
color = gray700,
modifier = Modifier
Expand All @@ -89,13 +90,13 @@ fun MealDetail(
Spacer(Modifier.size(8.dp))
Row(verticalAlignment = Alignment.CenterVertically) {
Body1(text = "저녁", color = gray800)
Body2(
Body3(
text = mealWithDateEntity.caloriesOfDinner,
color = gray700,
modifier = Modifier
.fillMaxWidth()
.padding(3.dp)
.wrapContentWidth(align = Alignment.End)
.wrapContentWidth(align = Alignment.End),
)
}
Body2(text = dinner, color = gray900)
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ fun HomeScreen(navController: NavController) {
viewModel.run {
fetchPassTime()
fetchClassPosition()
fetchUserSimpleData()
fetchTodayMeal()
}
viewModel.eventFlow.collect {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class HomeViewModel @Inject constructor(
private val _userSimpleData = MutableStateFlow(HomeUserEntity("", "", 0, 0))
val userSimpleData: StateFlow<HomeUserEntity> = _userSimpleData

init {
fetchTodayMeal()
fetchUserSimpleData()
}
private val _todayMeal = MutableStateFlow(
MealEntity(
emptyList(),
Expand All @@ -36,15 +40,15 @@ class HomeViewModel @Inject constructor(
))
val todayMeal: StateFlow<MealEntity> = _todayMeal

fun fetchUserSimpleData() {
private fun fetchUserSimpleData() {
execute(
job = { fetchUserSimpleDataUseCase.execute(Unit) },
onSuccess = { it.collect { userSimpleData -> _userSimpleData.tryEmit(userSimpleData)} },
onFailure = { }
)
}

fun fetchTodayMeal() {
private fun fetchTodayMeal() {
execute(
job = {
fetchTodayMealUseCase.execute(Unit)
Expand Down
Loading

0 comments on commit 1b96d6b

Please sign in to comment.