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

[feat] Main 뷰 구현 #12

Merged
merged 14 commits into from
May 13, 2024
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
@@ -0,0 +1,47 @@
package com.dongguk.telepigeon.design.system.component

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.dongguk.telepigeon.core.design.system.R
import com.dongguk.telepigeon.core.design.system.databinding.EditTextQnaTelepigeonBinding
import com.dongguk.telepigeon.design.system.type.TelePigeonQnaEditTextType

@SuppressLint("CustomViewStyleable")
class TelePigeonQnaEditText
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val binding: EditTextQnaTelepigeonBinding
val editText get() = binding.etEditTextQnaTelepigeon

init {
binding = EditTextQnaTelepigeonBinding.inflate(LayoutInflater.from(context), this, true)
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TelePigeonQnaEditText)
try {
initView(typedArray)
} finally {
typedArray.recycle()
}
}

private fun initView(typedArray: TypedArray) {
typedArray.apply {
with(binding) {
etEditTextQnaTelepigeon.hint = getString(R.styleable.TelePigeonEditText_telePigeonEditTextHint)
}
}
}

fun initLayout(
qnaEditTextType: TelePigeonQnaEditTextType,
) {
binding.ivEditTextQnaTelepigeon.setImageResource(qnaEditTextType.icon)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dongguk.telepigeon.design.system.mapper

import com.dongguk.telepigeon.design.system.type.QnaType

fun String.toQnaType(): QnaType = QnaType.valueOf(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.dongguk.telepigeon.design.system.type

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.dongguk.telepigeon.core.design.system.R

enum class MainType(
@StringRes val speechBubbleText: Int,
@DrawableRes val character: Int,
@StringRes val btnText: Int?,
) {
SENT_HURRY(
speechBubbleText = R.string.main_speech_bubble_text_sent_hurry,
character = R.drawable.ic_character,
btnText = null,
),
ARRIVE_SURVIVAL(
speechBubbleText = R.string.main_speech_bubble_text_arrive_survival,
character = R.drawable.ic_character_letter,
btnText = R.string.main_btn_text_check_answer,
),
WAIT_SURVIVAL(
speechBubbleText = R.string.main_speech_bubble_text_wait_survival,
character = R.drawable.ic_character_oh,
btnText = R.string.main_btn_text_hurry,
),
GOT_SURVIVAL(
speechBubbleText = R.string.main_speech_bubble_text_got_survival,
character = R.drawable.ic_character_angry,
btnText = R.string.main_btn_text_answer_question,
),
GOT_QUESTION(
speechBubbleText = R.string.main_speech_bubble_text_got_question,
character = R.drawable.ic_character_letter,
btnText = R.string.main_btn_text_answer_question,
),
NOT_SEND_SURVIVAL(
speechBubbleText = R.string.main_speech_bubble_text_not_send_survival,
character = R.drawable.ic_character_letter,
btnText = R.string.main_btn_text_answer_question,
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dongguk.telepigeon.design.system.type

import androidx.annotation.StringRes
import com.dongguk.telepigeon.core.design.system.R

enum class QnaType(
@StringRes val title: Int,
@StringRes val description: Int,
@StringRes val btnText: Int,
) {
SURVIVAL(
title = R.string.qna_title_survival,
description = R.string.qna_description_survival,
btnText = R.string.qna_btn_text_survival,
),
CHECK_ANSWER(
title = R.string.qna_title_check_answer,
description = R.string.answer_description_check_answer,
btnText = R.string.qna_btn_text_check_answer,
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dongguk.telepigeon.design.system.type

import androidx.annotation.DrawableRes
import com.dongguk.telepigeon.core.design.system.R

enum class TelePigeonQnaEditTextType(
@DrawableRes val icon: Int,
) {
Q(
icon = R.drawable.ic_all_question_30,
),
A(
icon = R.drawable.ic_all_answer_30,
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="15dp" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="@color/key_lime"
android:dashWidth="2dp"
android:dashGap="2dp" />
</shape>
38 changes: 38 additions & 0 deletions core/designsystem/src/main/res/layout/edit_text_qna_telepigeon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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="wrap_content"
android:background="@drawable/shape_border_radius_10"
android:backgroundTint="@color/marble"
android:paddingHorizontal="18dp"
android:paddingVertical="22dp">

<ImageView
android:id="@+id/iv_edit_text_qna_telepigeon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_all_question_30" />

<EditText
android:id="@+id/et_edit_text_qna_telepigeon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="@null"
android:imeOptions="actionDone"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.TelePigeon.Body.Semi.14"
android:textColor="@color/g_10"
android:textColorHint="@color/g_04"
app:layout_constraintBottom_toBottomOf="@id/iv_edit_text_qna_telepigeon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_edit_text_qna_telepigeon"
app:layout_constraintTop_toTopOf="@id/iv_edit_text_qna_telepigeon"
tools:text="답변 입력하기" />

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions core/designsystem/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<attr name="telePigeonEditTextTitle" format="reference|string" />
<attr name="telePigeonEditTextHint" format="reference|string" />
</declare-styleable>

<declare-styleable name="TelePigeonQnaEditText">
<attr name="telePigeonQnaEditTextHint" format="reference|string" />
</declare-styleable>
</resources>
25 changes: 24 additions & 1 deletion core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,33 @@
<string name="answer_description_check_answer">상대의 답변을 확인하세요</string>
<string name="answer_description_done">답변을 완료했어요</string>
<string name="answer_description_not_yet">아직 답변을 하지 않았어요</string>

<!-- home setting -->
<string name="home_setting_title">앱 전체 설정</string>
<string name="home_setting_notification">알림 설정</string>
<string name="home_setting_logout">로그아웃</string>
<string name="home_setting_withdrawal">탈퇴하기</string>

<!-- main -->
<string name="main_description">오늘의 생존신고를 보내보세요</string>
<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_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_not_send_survival">%d일 동안 생존신고를 보내지 않았어요</string>

<!-- qna -->
<string name="qna_title_survival">오늘의 생존신고 보내기</string>
<string name="qna_title_check_answer">상대의 답변 확인하기</string>
<string name="qna_description_survival">아래 질문에 답변을 작성해주세요</string>
<string name="qna_description_check_answer">상대의 생존신고를 확인해보세요</string>
<string name="qna_btn_text_survival">전송하기</string>
<string name="qna_btn_text_check_answer">확인하기</string>
<string name="qna_answer_hint">답변 입력하기</string>
<string name="qna_add_picture">사진 추가하기</string>
<string name="qna_warning">패널티가 부과되었습니다. 필수로 사진을 추가해주세요.</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dongguk.telepigeon.domain.model

data class CheckQuestionEntity(
val id: Int,
val content: String,
val isPenalty: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.dongguk.telepigeon.domain.model

data class QuestionAnswerEntity(
val questionerName: String,
val respondentName: String,
val questionContent: String,
val answerContent: String,
val answerImage: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dongguk.telepigeon.domain.model

data class RoomEntity(
val name: String,
val number: Int,
val days: Int?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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.navigation.fragment.findNavController
import com.dongguk.telepigeon.feature.R
Expand Down Expand Up @@ -30,7 +31,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
}

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

// TODO 서버통신 구현 후 collectData 함수로 해당 로직 이동
Expand Down Expand Up @@ -61,6 +62,10 @@ 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 navigateToHomeSetting() {
findNavController().navigate(R.id.action_home_to_home_setting)
}
Expand All @@ -72,4 +77,8 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
private fun navigateToHomeModifyRoom() {
findNavController().navigate(R.id.action_home_to_home_modify_room)
}

companion object {
const val ROOM_ID = "roomId"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import com.dongguk.telepigeon.domain.model.HomeRoomEntity
import com.dongguk.telepigeon.feature.databinding.ItemHomeRoomBinding
import com.dongguk.telpigeon.core.ui.util.view.ItemDiffCallback

class HomeRoomAdapter : ListAdapter<HomeRoomEntity, HomeRoomViewHolder>(
ItemDiffCallback<HomeRoomEntity>(
onItemsTheSame = { old, new -> old.id == new.id },
onContentsTheSame = { old, new -> old == new },
),
) {
class HomeRoomAdapter(
private val navigateToMain: (Int) -> Unit,
) : ListAdapter<HomeRoomEntity, HomeRoomViewHolder>(
ItemDiffCallback<HomeRoomEntity>(
onItemsTheSame = { old, new -> old.id == new.id },
onContentsTheSame = { old, new -> old == new },
),
) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): HomeRoomViewHolder =
HomeRoomViewHolder(
binding = ItemHomeRoomBinding.inflate(LayoutInflater.from(parent.context), parent, false),
context = parent.context,
navigateToMain = navigateToMain,
)

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

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

init {
binding.root.setOnClickListener {
navigateToMain(homeRoomEntity.id)
}
}

fun onBind(homeRoomEntity: HomeRoomEntity) {
this.homeRoomEntity = homeRoomEntity
with(binding) {
ivHomeRoomEmotion.setImageDrawable(context.getDrawable(homeRoomEntity.emotion))
ivHomeRoomEmotion.setImageResource(homeRoomEntity.emotion)
tvHomeRoomName.text = homeRoomEntity.name
tvHomeRoomRelation.text = homeRoomEntity.relation
tvHomeRoomAnswerDescription.text = context.getString(homeRoomEntity.answerDescription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.dongguk.telpigeon.core.ui.util.view.setBackgroundTint
class HomeModifyRoomViewHolder(private val binding: ItemHomeRoomBinding, private val context: Context) : RecyclerView.ViewHolder(binding.root) {
fun onSelectedItemBind(homeRoomEntity: HomeRoomEntity) {
with(binding) {
ivHomeRoomEmotion.setImageDrawable(context.getDrawable(homeRoomEntity.emotion))
ivHomeRoomEmotion.setImageResource(homeRoomEntity.emotion)
tvHomeRoomName.text = homeRoomEntity.name
tvHomeRoomRelation.text = homeRoomEntity.relation
tvHomeRoomAnswerDescription.text = context.getString(homeRoomEntity.answerDescription)
Expand All @@ -24,7 +24,7 @@ class HomeModifyRoomViewHolder(private val binding: ItemHomeRoomBinding, private

fun onUnselectedItemBind(homeRoomEntity: HomeRoomEntity) {
with(binding) {
ivHomeRoomEmotion.setImageDrawable(context.getDrawable(homeRoomEntity.emotion))
ivHomeRoomEmotion.setImageResource(homeRoomEntity.emotion)
tvHomeRoomName.text = homeRoomEntity.name
tvHomeRoomRelation.text = homeRoomEntity.relation
tvHomeRoomAnswerDescription.text = context.getString(homeRoomEntity.answerDescription)
Expand Down

This file was deleted.

Loading
Loading