Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

design pattern #31

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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