Skip to content

Commit

Permalink
Merge pull request #31 from snuhcs-course/design_pattern
Browse files Browse the repository at this point in the history
design pattern
  • Loading branch information
ozeeeno authored Dec 5, 2023
2 parents 5cce3eb + 3d360d1 commit 67c32ec
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sealed class BottomNavItem( // Bottom Navigation Bar에 들어갈 아이템들
)
object Social: BottomNavItem(
title = "Social",
icon = FooriendIcon.Social,
icon = Icons.Default.Search,
route = "social"
)
object MyPage: BottomNavItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ import androidx.compose.material.icons.filled.Store
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -117,6 +113,11 @@ fun PostingScreen(

var contentState by remember { mutableStateOf(TextFieldValue("")) }

val reviewCountManager = ReviewCountManager()
val toastObserver = ToastObserver(context)

reviewCountManager.addObserver(toastObserver)

Column(
modifier = Modifier
.verticalScroll(state)
Expand Down Expand Up @@ -341,6 +342,7 @@ fun PostingScreen(
coroutineScope.launch {
Log.d("PostingScreen", "restaurantPlaceId: $restaurantPlaceId")
val response = placesApi.getPlaceDetails(placeId = restaurantPlaceId, apiKey = "AIzaSyDV4YwwZmJp1PHNO4DSp_BdgY4qCDQzKH0")
var myReviewCount = apiService.getMyReviews().reviewList.size
Log.d("PostingScreen", "restaurant: $response")
val restaurant = RestaurantInfo(
googleMapPlaceId = restaurantPlaceId,
Expand Down Expand Up @@ -391,8 +393,11 @@ fun PostingScreen(
restaurant = restaurant
)
)
Toast.makeText(context, "리뷰가 등록되었습니다.", Toast.LENGTH_SHORT).show()
onPostClick()
Toast.makeText(context, "리뷰가 등록되었습니다.", Toast.LENGTH_SHORT).show()
reviewCountManager.updateReviewCount(myReviewCount+1)
}
},
}
},
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.team13.fooriend.ui.screen

import android.content.Context
import android.widget.Toast

interface ReviewCountSubject {
fun addObserver(observer: ReviewCountObserver)
fun removeObserver(observer: ReviewCountObserver)
fun notifyObservers()
}

class ReviewCountManager : ReviewCountSubject {
private val observers: MutableList<ReviewCountObserver> = ArrayList()
private var myReviewCount: Int = 0

fun updateReviewCount(count: Int) {
myReviewCount = count
if (myReviewCount % 3 == 0 && myReviewCount > 0) {
notifyObservers()
}
}

override fun addObserver(observer: ReviewCountObserver) {
observers.add(observer)
}

override fun removeObserver(observer: ReviewCountObserver) {
observers.remove(observer)
}

override fun notifyObservers() {
for (observer in observers) {
observer.update(myReviewCount)
}
}
}

interface ReviewCountObserver {
fun update(reviewCount: Int)
}

class ToastObserver(private val context: Context) : ReviewCountObserver {
override fun update(reviewCount: Int) {
Toast.makeText(context, "리뷰가 $reviewCount 개 등록되었습니다. 축하드립니다", Toast.LENGTH_SHORT).show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fun SocialSearchBar(
active = it
},
placeholder = {
Text(text = "Search User", fontSize = 15.sp)
Text(text = "친구를 이름으로 검색", fontSize = 15.sp)
},
leadingIcon = {
Icon(imageVector = Icons.Default.Search, contentDescription = "Search Icon")
Expand Down

0 comments on commit 67c32ec

Please sign in to comment.