Skip to content

Commit

Permalink
Merge pull request #16 from TelePigeon/feat-calender-view
Browse files Browse the repository at this point in the history
[feat] Main 캘린더 뷰 구현
  • Loading branch information
jihyunniiii authored Jun 2, 2024
2 parents 767527f + 9197543 commit 5431a45
Show file tree
Hide file tree
Showing 17 changed files with 699 additions and 41 deletions.
17 changes: 17 additions & 0 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<string name="button_delete_room">삭제하기</string>
<string name="button_complete">완료하기</string>
<string name="button_apply">적용</string>
<string name="button_check">확인하기</string>

<!-- home -->
<string name="home_title">홈</string>
Expand Down Expand Up @@ -146,5 +147,21 @@
<string name="time_22">22시</string>
<string name="time_23">23시</string>
<string name="time_24">24시</string>

<!-- calendar -->
<string name="calendar_content">원하는 날짜를 선택해 답변을 확인해보세요</string>
<string name="calendar_monthly_report">월간 보고</string>
<string name="calendar_today_answer_empty">아직 답변이 없어요\n오늘의 질문에 답변해주세요</string>
<string name="calendar_future_answer_empty">답변이 존재하지 않아요</string>

<!-- monthly report -->
<string name="monthly_report_title">%d월 보고서</string>
<string name="monthly_report_content">질문을 생성한 키워드의 순위를 확인해보세요</string>
<string name="monthly_report_positive_keyword">긍정 키워드 순위</string>
<string name="monthly_report_negative_keyword">부정 키워드 순위</string>
<string name="monthly_report_rank_1">1위</string>
<string name="monthly_report_rank_2">2위</string>
<string name="monthly_report_rank_3">3위</string>
<string name="monthly_report_empty">아직 보고서가 생성되지 않았어요\n한 달이 마무리되어야 보고서가 생성돼요</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.dongguk.telepigeon.domain.model

data class QuestionAnswerModel(
val questionerName: String,
val respondentName: String,
val answerName: String,
val questionContent: String,
val answerContent: String,
val answerImage: String,
Expand Down
2 changes: 1 addition & 1 deletion feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
implementation(libs.coil)
implementation(libs.activity)

// navigation
// Navigation
implementation(libs.androidx.navigation.fragment)
implementation(libs.androidx.navigation.ui)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dongguk.telepigeon.feature.calendar.calendar

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import com.dongguk.telepigeon.domain.model.QuestionAnswerModel
import com.dongguk.telepigeon.feature.databinding.ItemCalendarAnswerBinding
import com.dongguk.telpigeon.core.ui.util.view.ItemDiffCallback

class CalendarAnswerAdapter : ListAdapter<QuestionAnswerModel, CalendarAnswerViewHolder>(
ItemDiffCallback<QuestionAnswerModel>(
onItemsTheSame = { old, new -> old.answerImage == new.answerImage },
onContentsTheSame = { old, new -> old == new },
),
) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): CalendarAnswerViewHolder = CalendarAnswerViewHolder(binding = ItemCalendarAnswerBinding.inflate(LayoutInflater.from(parent.context), parent, false))

override fun onBindViewHolder(
holder: CalendarAnswerViewHolder,
position: Int,
) {
holder.onBind(questionAnswerModel = currentList[position])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.dongguk.telepigeon.feature.calendar.calendar

import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.dongguk.telepigeon.domain.model.QuestionAnswerModel
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)
tvCalendarAnswerQuestionName.text = questionAnswerModel.questionerName
tvCalendarAnswerQuestionContent.text = questionAnswerModel.questionContent
tvCalendarAnswerAnswerName.text = questionAnswerModel.answerName
tvCalendarAnswerAnswerContent.text = questionAnswerModel.answerContent
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.dongguk.telepigeon.feature.calendar.calendar

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.dongguk.telepigeon.core.design.system.R
import com.dongguk.telepigeon.feature.databinding.FragmentCalendarBinding
import com.dongguk.telpigeon.core.ui.base.BindingFragment
import com.dongguk.telpigeon.core.ui.util.fragment.stringOf
import java.time.LocalDate

class CalendarFragment : BindingFragment<FragmentCalendarBinding>({ FragmentCalendarBinding.inflate(it) }) {
private val calendarViewModel by viewModels<CalendarViewModel>()
private lateinit var calendarAnswerAdapter: CalendarAnswerAdapter

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

initAdapter()
setCvCalendarDateChangeListener()
setBtnCalendarMonthlyReportClickListener()
}

private fun initAdapter() {
calendarAnswerAdapter = CalendarAnswerAdapter()
binding.rvCalendarAnswer.adapter = calendarAnswerAdapter

// TODO 서버통신 구현 후 collectData 함수로 해당 로직 이동
calendarAnswerAdapter.submitList(calendarViewModel.dummyQuestionAnswerModels)

(calendarViewModel.dummyQuestionAnswerModels.isEmpty()).let { isEmpty ->
with(binding) {
ivCalendarEmpty.visibility = if (isEmpty) View.VISIBLE else View.INVISIBLE
tvCalendarEmpty.visibility = if (isEmpty) View.VISIBLE else View.INVISIBLE
}
}
}

private fun setCvCalendarDateChangeListener() {
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)
}
}

private fun setBtnCalendarMonthlyReportClickListener() {
binding.btnCalendarMonthlyReport.setOnClickListener {
navigateToMonthlyReport()
}
}

private fun navigateToMonthlyReport() {
findNavController().navigate(com.dongguk.telepigeon.feature.R.id.action_all_navi_calender_to_monthly_report)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.dongguk.telepigeon.feature.calendar.calendar

import androidx.lifecycle.ViewModel
import com.dongguk.telepigeon.domain.model.QuestionAnswerModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class CalendarViewModel
@Inject
constructor() : ViewModel() {
val dummyQuestionAnswerModels =
listOf(
QuestionAnswerModel(
questionerName = "김둘기",
answerName = "둘기맘",
questionContent = "오늘 점심은 무슨 음식을 먹었나요?",
answerContent = "분식을 먹었어요! 맛있었어요!",
answerImage = "https://avatars.githubusercontent.com/u/103172971?v=4",
),
QuestionAnswerModel(
questionerName = "둘기맘",
answerName = "김둘기",
questionContent = "영양제는 잘 챙겨먹고 있나요?",
answerContent = "어제는 까먹었어요.. 오늘은 꼭 먹을게요!",
answerImage = "https://avatars.githubusercontent.com/u/103172971?v=4",
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.dongguk.telepigeon.feature.calendar.monthlyreport

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.dongguk.telepigeon.design.system.type.AppBarType
import com.dongguk.telepigeon.feature.databinding.FragmentMonthlyReportBinding
import com.dongguk.telpigeon.core.ui.base.BindingFragment

class MonthlyReportFragment : BindingFragment<FragmentMonthlyReportBinding>({ FragmentMonthlyReportBinding.inflate(it) }) {
private val monthlyReportViewModel by viewModels<MonthlyReportViewModel>()

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

initAppBar()
initLayout()
setBtnMonthlyReportCheckClickListener()
}

private fun initAppBar() {
binding.appbarMonthlyReport.initLayout(appBarType = AppBarType.X)
binding.appbarMonthlyReport.binding.ivAppBarTelepigeonX.setOnClickListener {
findNavController().popBackStack()
}
}

private fun initLayout() {
with(binding) {
layoutMonthlyReportNegativeKeyword.visibility = View.INVISIBLE
layoutMonthlyReportPositiveKeyword.visibility = View.INVISIBLE
tvMonthlyReportPositiveKeyword.visibility = View.INVISIBLE
tvMonthlyReportNegativeKeyword.visibility = View.INVISIBLE
}
}

private fun setBtnMonthlyReportCheckClickListener() {
binding.btnMonthlyReportCheck.setOnClickListener {
findNavController().popBackStack()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dongguk.telepigeon.feature.calendar.monthlyreport

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MonthlyReportViewModel
@Inject
constructor() : ViewModel()

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class QnaViewModel
val dummyQuestionAnswerModel =
QuestionAnswerModel(
questionerName = "김둘기",
respondentName = "둘기맘",
answerName = "둘기맘",
questionContent = "오늘 점심은 무슨 음식을 먹었나요?",
answerContent = "분식을 먹었어요! 맛있었어요!",
answerImage = "https://avatars.githubusercontent.com/u/103172971?v=4",
Expand Down
99 changes: 99 additions & 0 deletions feature/src/main/res/layout/fragment_calendar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".calendar.calendar.CalendarFragment">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/gl_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/horizontal_margin" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/gl_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="@dimen/horizontal_margin" />

<TextView
android:id="@+id/tv_calendar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/all_navi_calender"
android:textAppearance="@style/TextAppearance.TelePigeon.Title.Extra.40"
app:layout_constraintStart_toStartOf="@id/gl_start"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_calendar_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/calendar_content"
android:textAppearance="@style/TextAppearance.TelePigeon.Sub.Semi.16"
android:textColor="@color/g_06"
app:layout_constraintEnd_toStartOf="@+id/gl_end"
app:layout_constraintStart_toStartOf="@+id/gl_start"
app:layout_constraintTop_toBottomOf="@+id/tv_calendar_title" />

<CalendarView
android:id="@+id/cv_calendar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
app:layout_constraintEnd_toEndOf="@id/gl_end"
app:layout_constraintStart_toStartOf="@id/gl_start"
app:layout_constraintTop_toBottomOf="@id/tv_calendar_content" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_calendar_monthly_report"
style="@style/Theme.TelePigeon.Button.Small"
android:layout_width="wrap_content"
android:text="@string/calendar_monthly_report"
app:layout_constraintEnd_toStartOf="@+id/gl_end"
app:layout_constraintTop_toBottomOf="@+id/cv_calendar" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_calendar_answer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="22dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/gl_end"
app:layout_constraintStart_toStartOf="@id/gl_start"
app:layout_constraintTop_toBottomOf="@id/btn_calendar_monthly_report"
tools:itemCount="2"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_calendar_answer" />

<ImageView
android:id="@+id/iv_calendar_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_character_sad"
app:layout_constraintBottom_toTopOf="@id/tv_calendar_empty"
app:layout_constraintEnd_toStartOf="@id/gl_end"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintStart_toStartOf="@id/gl_start"
app:layout_constraintTop_toBottomOf="@id/btn_calendar_monthly_report" />

<TextView
android:id="@+id/tv_calendar_empty"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="@style/TextAppearance.TelePigeon.Sub.Semi.16"
android:textColor="@color/g_07"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/gl_end"
app:layout_constraintStart_toStartOf="@+id/gl_start"
app:layout_constraintTop_toBottomOf="@+id/iv_calendar_empty"
android:text="@string/calendar_today_answer_empty" />

</androidx.constraintlayout.widget.ConstraintLayout>
19 changes: 0 additions & 19 deletions feature/src/main/res/layout/fragment_calender.xml

This file was deleted.

Loading

0 comments on commit 5431a45

Please sign in to comment.