Skip to content

Commit

Permalink
Merge pull request #35 from TelePigeon/init-api-connection
Browse files Browse the repository at this point in the history
[init] 서버 통신 기초 세팅 및 API 연동 확인
  • Loading branch information
jihyunniiii authored Jun 7, 2024
2 parents 0ad4066 + 3599d47 commit cb894c6
Show file tree
Hide file tree
Showing 30 changed files with 154 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class BottomSheetWithSelectionAdapter : ListAdapter<String, BottomSheetWithSelec
onContentsTheSame = { old, new -> old == new },
),
) {
private var selectedItemPosition: Int = DEFAULT_OLD_POSITION
private var _selectedItemPosition: Int = DEFAULT_OLD_POSITION
val selectedItemPosition get() = _selectedItemPosition

override fun onCreateViewHolder(
parent: ViewGroup,
Expand All @@ -26,16 +27,16 @@ class BottomSheetWithSelectionAdapter : ListAdapter<String, BottomSheetWithSelec
holder: BottomSheetWithSelectionViewHolder,
position: Int,
) {
if (position == selectedItemPosition) {
if (position == _selectedItemPosition) {
holder.onSelectedItemBind(title = currentList[position])
} else {
holder.onUnselectedItemBind(title = currentList[position])
}

holder.itemView.setOnClickListener {
notifyItemChanged(selectedItemPosition)
selectedItemPosition = holder.adapterPosition
notifyItemChanged(selectedItemPosition)
notifyItemChanged(_selectedItemPosition)
_selectedItemPosition = holder.adapterPosition
notifyItemChanged(_selectedItemPosition)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BottomSheetWithSelectionDialogFragment(
private val selectionList: List<String>,
private val bottomSheetWithSelectionAdapter: BottomSheetWithSelectionAdapter,
private val clickBtn: () -> Unit = {},
private val onDialogClosed: () -> Unit = {},
private val onDialogClosed: (String) -> Unit = {},
) : BindingBottomSheetDialogFragment<DialogBottomSheetWithSelectionBinding>({ DialogBottomSheetWithSelectionBinding.inflate(it) }) {
override fun onViewCreated(
view: View,
Expand All @@ -27,7 +27,7 @@ class BottomSheetWithSelectionDialogFragment(

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
onDialogClosed()
onDialogClosed(bottomSheetWithSelectionAdapter.currentList[bottomSheetWithSelectionAdapter.selectedItemPosition])
}

private fun initLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.dongguk.telepigeon.design.system.component
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.TypedArray
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -44,4 +46,30 @@ class TelePigeonQnaEditText
) {
binding.ivEditTextQnaTelepigeon.setImageResource(qnaEditTextType.icon)
}

fun setOnTextChangedListener(listener: (String) -> Unit) {
editText.addTextChangedListener(
object : TextWatcher {
override fun beforeTextChanged(
s: CharSequence?,
start: Int,
count: Int,
after: Int,
) {
}

override fun onTextChanged(
s: CharSequence?,
start: Int,
before: Int,
count: Int,
) {
listener(s.toString())
}

override fun afterTextChanged(s: Editable) {
}
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ enum class MainType(
@DrawableRes val character: Int,
@StringRes val btnText: Int?,
) {
WAITING(
speechBubbleText = R.string.main_speech_bubble_text_waiting,
character = R.drawable.ic_character,
btnText = null,
),
COMPLETED(
speechBubbleText = R.string.main_speech_bubble_text_completed,
character = R.drawable.ic_character,
btnText = null,
),
SENT_HURRY(
speechBubbleText = R.string.main_speech_bubble_text_sent_hurry,
character = R.drawable.ic_character,
Expand Down
4 changes: 3 additions & 1 deletion core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@
<string name="main_btn_text_hurry"><u>재촉하기</u></string>
<string name="main_btn_text_check_answer"><u>답변 확인하기</u></string>
<string name="main_btn_text_answer_question">질문 답변하기</string>
<string name="main_speech_bubble_text_waiting">상대를 기다리는 중이에요</string>
<string name="main_speech_bubble_text_completed">오늘의 생존신고를\n완료했어요!</string>
<string name="main_speech_bubble_text_sent_hurry">상대에게 재촉하기를\n보냈어요</string>
<string name="main_speech_bubble_text_arrive_survival">상대의 생존신고가\n도착했어요</string>
<string name="main_speech_bubble_text_wait_survival">상대의 생존신고를\n기다리고 있어요</string>
<string name="main_speech_bubble_text_got_survival">상대가 재촉하기를 보냈어요</string>
<string name="main_speech_bubble_text_got_question">오늘의 질문이 도착했어요</string>
<string name="main_speech_bubble_text_got_question">오늘의 질문이 도착했어요!</string>
<string name="main_speech_bubble_text_not_send_survival">%d일 동안 생존신고를 보내지 않았어요</string>

<!-- qna -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface WorryRemoteDataSource {
requestPostWorryDto: RequestPostWorryDto,
): NullableBaseResponseDto<Unit>

suspend fun deleteWorry(worryId: Int): NullableBaseResponseDto<Unit>
suspend fun deleteWorry(worryId: Int): Unit?
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ class WorryRemoteDataSourceImpl
requestPostWorryDto: RequestPostWorryDto,
): NullableBaseResponseDto<Unit> = worryService.postWorry(roomId = roomId, requestPostWorryDto = requestPostWorryDto)

override suspend fun deleteWorry(worryId: Int): NullableBaseResponseDto<Unit> = worryService.deleteWorry(worryId = worryId)
override suspend fun deleteWorry(worryId: Int) = worryService.deleteWorry(worryId = worryId).body()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ResponseGetRoomsDto(
) {
@Serializable
class ResponseGetRoomDto(
@SerialName("id")
@SerialName("roomId")
val id: Int,
@SerialName("name")
val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class BaseResponseDto<T>(
@SerialName("code")
val code: Int,
val code: String,
@SerialName("data")
val data: T,
@SerialName("message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ProfileService {
@Path("${ROOM_ID}") roomId: Int,
): BaseResponseDto<ResponseGetRoomExtraDto>

@PUT("$ROOMS/${ROOM_ID}")
@PUT("$ROOMS/{$ROOM_ID}")
suspend fun putRoomKeywordsExtra(
@Path("${ROOM_ID}") roomId: Int,
@Body requestPutRoomKeywordsExtraDto: RequestPutRoomKeywordsExtraDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.dongguk.telepigeon.data.remote.model.response.base.NullableBaseRespon
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
Expand All @@ -25,6 +26,7 @@ interface QuestionAnswerService {
@Path("$ROOM_ID") roomId: Int,
): BaseResponseDto<ResponseGetQuestionDto>

@Multipart
@POST("$ROOMS/{$ROOM_ID}/$QUESTIONS/{$QUESTIONS_ID}/$ANSWERS")
suspend fun postAnswer(
@Path("$ROOM_ID") roomId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.dongguk.telepigeon.data.remote.model.request.RequestPostWorryDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetWorriesDto
import com.dongguk.telepigeon.data.remote.model.response.base.BaseResponseDto
import com.dongguk.telepigeon.data.remote.model.response.base.NullableBaseResponseDto
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
Expand All @@ -25,7 +26,7 @@ interface WorryService {
@DELETE("$WORRIES/{$WORRY_ID}")
suspend fun deleteWorry(
@Path("${WORRY_ID}") worryId: Int,
): NullableBaseResponseDto<Unit>
): Response<Unit?>

companion object {
const val ROOMS = "rooms"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import com.dongguk.telepigeon.domain.model.RoomKeywordsModel

fun ResponseGetRoomKeywordsDto.toRoomKeywordModel() =
RoomKeywordsModel(
keywords = this.keywords.joinToString { ", " },
keywords = this.keywords.joinToString(", ") { it.trim() },
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class QuestionAnswerRepositoryImpl
content: String,
): Result<Unit> =
runCatching {
questionAnswerRemoteDataSource.postAnswer(roomId = roomId, questionId = questionId, image = ContentUriRequestBody(contentResolver = contentResolver, uri = Uri.parse(image)).toFormData(), content = content.toRequestBody("text/plain".toMediaType()))
questionAnswerRemoteDataSource.postAnswer(roomId = roomId, questionId = questionId, image = if (image != null) ContentUriRequestBody(contentResolver = contentResolver, uri = Uri.parse(image)).toFormData() else null, content = content.toRequestBody("text/plain".toMediaType()))
}

override suspend fun getQuestionAnswer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.dongguk.telepigeon.feature.databinding.ItemCalendarAnswerBinding
class CalendarAnswerViewHolder(private val binding: ItemCalendarAnswerBinding) : RecyclerView.ViewHolder(binding.root) {
fun onBind(questionAnswerModel: QuestionAnswerModel) {
with(binding) {
ivCalendarAnswerImage.load(questionAnswerModel.answerImage)
if (questionAnswerModel.answerImage != null) ivCalendarAnswerImage.load(questionAnswerModel.answerImage)
tvCalendarAnswerQuestionName.text = questionAnswerModel.questionName
tvCalendarAnswerQuestionContent.text = questionAnswerModel.questionContent
tvCalendarAnswerAnswerName.text = questionAnswerModel.answerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class CalendarFragment : BindingFragment<FragmentCalendarBinding>({ FragmentCale
) {
super.onViewCreated(view, savedInstanceState)

calendarViewModel.getQuestionAnswer(LocalDate.now().year.toString() + "-" + LocalDate.now().monthValue)
calendarViewModel.getQuestionAnswer(LocalDate.now().year.toString() + "-" + String.format("%02d", LocalDate.now().monthValue) + "-" + String.format("%02d", LocalDate.now().dayOfMonth))
initAdapter()
collectGetQuestionAnswerState()
setCvCalendarDateChangeListener()
setBtnCalendarMonthlyReportClickListener(LocalDate.now().year.toString() + "-" + LocalDate.now().monthValue)
setBtnCalendarMonthlyReportClickListener(LocalDate.now().year.toString() + "-" + String.format("%02d", LocalDate.now().monthValue))
}

private fun initAdapter() {
Expand All @@ -55,6 +55,7 @@ class CalendarFragment : BindingFragment<FragmentCalendarBinding>({ FragmentCale
}
}
}

else -> Unit
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
Expand All @@ -64,8 +65,8 @@ class CalendarFragment : BindingFragment<FragmentCalendarBinding>({ FragmentCale
binding.cvCalendar.setOnDateChangeListener { _, year, month, dayOfMonth ->
binding.tvCalendarEmpty.text = if (LocalDate.now() == LocalDate.of(year, month + 1, dayOfMonth)) stringOf(R.string.calendar_today_answer_empty) else stringOf(R.string.calendar_future_answer_empty)

calendarViewModel.getQuestionAnswer(year.toString() + "-" + (month + 1))
setBtnCalendarMonthlyReportClickListener(year.toString() + "-" + (month + 1))
calendarViewModel.getQuestionAnswer(year.toString() + "-" + String.format("%02d", month + 1) + "-" + String.format("%02d", dayOfMonth))
setBtnCalendarMonthlyReportClickListener(year.toString() + "-" + String.format("%02d", month + 1))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MonthlyReportFragment : BindingFragment<FragmentMonthlyReportBinding>({ Fr
requireArguments().getString(DATE)?.let { monthlyReportViewModel.getMonthlyReport(it) }
initAppBar()
initLayout()
collectGetMonthlyReportState()
setBtnMonthlyReportCheckClickListener()
}

Expand All @@ -44,7 +45,7 @@ class MonthlyReportFragment : BindingFragment<FragmentMonthlyReportBinding>({ Fr
}
}

private fun collectState() {
private fun collectGetMonthlyReportState() {
monthlyReportViewModel.getMonthlyReportState.flowWithLifecycle(viewLifecycleOwner.lifecycle).onEach { getMonthlyReportState ->
when (getMonthlyReportState) {
is UiState.Success -> {
Expand All @@ -57,8 +58,8 @@ class MonthlyReportFragment : BindingFragment<FragmentMonthlyReportBinding>({ Fr
binding.tvMonthlyReportPositiveKeywordRank2.text = positiveKeywords[1]
binding.tvMonthlyReportPositiveKeywordRank3.text = positiveKeywords[2]
binding.tvMonthlyReportNegativeKeywordRank1.text = negativeKeywords[0]
binding.tvMonthlyReportNegativeKeywordRank2.text = positiveKeywords[1]
binding.tvMonthlyReportNegativeKeywordRank3.text = positiveKeywords[2]
binding.tvMonthlyReportNegativeKeywordRank2.text = negativeKeywords[1]
binding.tvMonthlyReportNegativeKeywordRank3.text = negativeKeywords[2]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.dongguk.telepigeon.feature.home.home

import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -40,7 +39,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
}

private fun initAdapter() {
homeRoomAdapter = HomeRoomAdapter(navigateToMain = ::navigateToMain)
homeRoomAdapter = HomeRoomAdapter(navigateToMain = ::navigateToMain, setRoomId = ::setRoomId)
binding.rvHomeRoom.adapter = homeRoomAdapter
}

Expand Down Expand Up @@ -80,8 +79,8 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
}
}

private fun navigateToMain(roomId: Int) {
findNavController().navigate(R.id.action_home_to_main, bundleOf(ROOM_ID to roomId))
private fun navigateToMain() {
findNavController().navigate(R.id.action_home_to_main)
}

private fun navigateToHomeSetting() {
Expand All @@ -96,7 +95,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
findNavController().navigate(R.id.action_home_to_home_modify_room)
}

companion object {
const val ROOM_ID = "roomId"
private fun setRoomId(roomId: Int) {
homeViewModel.setRoomId(roomId = roomId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import com.dongguk.telepigeon.feature.databinding.ItemHomeRoomBinding
import com.dongguk.telpigeon.core.ui.util.view.ItemDiffCallback

class HomeRoomAdapter(
private val navigateToMain: (Int) -> Unit,
private val navigateToMain: () -> Unit,
private val setRoomId: (Int) -> Unit,
) : ListAdapter<HomeRoomModel, HomeRoomViewHolder>(
ItemDiffCallback<HomeRoomModel>(
onItemsTheSame = { old, new -> old.id == new.id },
Expand All @@ -23,6 +24,7 @@ class HomeRoomAdapter(
binding = ItemHomeRoomBinding.inflate(LayoutInflater.from(parent.context), parent, false),
context = parent.context,
navigateToMain = navigateToMain,
setRoomId = setRoomId,
)

override fun onBindViewHolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import androidx.recyclerview.widget.RecyclerView
import com.dongguk.telepigeon.domain.model.HomeRoomModel
import com.dongguk.telepigeon.feature.databinding.ItemHomeRoomBinding

class HomeRoomViewHolder(private val binding: ItemHomeRoomBinding, private val context: Context, private val navigateToMain: (Int) -> Unit) : RecyclerView.ViewHolder(binding.root) {
class HomeRoomViewHolder(private val binding: ItemHomeRoomBinding, private val context: Context, private val navigateToMain: () -> Unit, private val setRoomId: (Int) -> Unit) : RecyclerView.ViewHolder(binding.root) {
private lateinit var homeRoomModel: HomeRoomModel

init {
binding.root.setOnClickListener {
navigateToMain(homeRoomModel.id)
setRoomId(homeRoomModel.id)
navigateToMain()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.dongguk.telepigeon.domain.model.HomeRoomModel
import com.dongguk.telepigeon.domain.usecase.GetRoomsUseCase
import com.dongguk.telepigeon.domain.usecase.SetRoomIdUseCase
import com.dongguk.telpigeon.core.ui.util.view.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -15,6 +16,7 @@ import javax.inject.Inject
class HomeViewModel
@Inject
constructor(
private val setRoomIdUseCase: SetRoomIdUseCase,
private val getRoomsUseCase: GetRoomsUseCase,
) : ViewModel() {
private val _getRoomsState = MutableStateFlow<UiState<List<HomeRoomModel>>>(UiState.Empty)
Expand All @@ -30,4 +32,8 @@ class HomeViewModel
}
}
}

fun setRoomId(roomId: Int) {
setRoomIdUseCase(roomId = roomId)
}
}
Loading

0 comments on commit cb894c6

Please sign in to comment.