Skip to content

Commit

Permalink
[BUD-36] feat : Buddy 등록 화면 구현 완료 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDW03 committed Mar 23, 2023
1 parent 1fa4c53 commit 992771f
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 159 deletions.
8 changes: 4 additions & 4 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions buddy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ dependencies {
api project(path: ':common-ui')

implementation 'io.github.ParkSangGwon:tedimagepicker:1.2.8'

implementation 'de.hdodenhof:circleimageview:3.1.0'


// Navigation
api "androidx.navigation:navigation-fragment-ktx:$rootProject.nav_version"
api "androidx.navigation:navigation-ui-ktx:$rootProject.nav_version"

implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:4.13.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class BuddyViewModel @Inject constructor(
_newBuddy.value?.adoptDay = adoptDay
}

fun setNeutered(Neutered: String) {
_newBuddy.value?.isNeutered = (Neutered == "")
fun setNeutered(Neutered: Boolean) {
_newBuddy.value?.isNeutered = Neutered
}

fun setGender(gender: String) {
Expand All @@ -66,7 +66,6 @@ class BuddyViewModel @Inject constructor(
}

fun setSelectImgUri(uri: Uri?) {
_selectImgUri.value = null
_selectImgUri.value = uri
}

Expand All @@ -79,10 +78,14 @@ class BuddyViewModel @Inject constructor(

fun createBuddy() {
viewModelScope.launch {
val jwt = dataStoreUseCase.bearerJsonWebToken.first()!!
val buddyId = buddyUseCase.createBuddy(jwt, _newBuddy.value!!)
if (_selectImgUri.value != null) {
uploadBuddyImg(jwt, buddyId)
try {
val jwt = dataStoreUseCase.bearerJsonWebToken.first()!!
val buddyId = buddyUseCase.createBuddy(jwt, _newBuddy.value!!)
if (_selectImgUri.value != null) {
uploadBuddyImg(jwt, buddyId)
}
} catch (e: Exception) {
Log.d("createBuddy", e.message.toString())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ class CompleteRegistrationFragment : Fragment() {

private val buddyViewModel: BuddyViewModel by viewModels({ requireActivity() })


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
_binding = FragmentCompleteRegistrationBinding.inflate(inflater, container, false)
return binding.root
}

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

binding.apply {
this.viewModel = buddyViewModel
this.lifecycleOwner = viewLifecycleOwner
}

binding.next.setOnClickListener {
buddyViewModel.createBuddy()
LoginUtil.startMainActivity(requireActivity(), mainActivityClass)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nocapstone.buddyvet.buddy.ui

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
Expand All @@ -14,6 +15,8 @@ import com.nocapstone.common_ui.CalendarUtil
import com.nocapstone.common_ui.DialogForDatePicker
import com.nocapstone.common_ui.R.layout.list_item
import dagger.hilt.android.AndroidEntryPoint
import gun0912.tedimagepicker.builder.TedImagePicker
import java.lang.reflect.GenericArrayType


@AndroidEntryPoint
Expand All @@ -22,7 +25,8 @@ class InputBuddyInfoFragment : Fragment() {
private var _binding: FragmentInputBuddyInfoBinding? = null
private val binding get() = _binding!!
private val buddyViewModel: BuddyViewModel by viewModels({ requireActivity() })

private val neuteredItem = listOf("", "아니오")
private val genderListItem = listOf("남자", "여자")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -34,21 +38,24 @@ class InputBuddyInfoFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val breadAdapter = ArrayAdapter(
val neuteredAdapter = ArrayAdapter(
requireContext(),
list_item,
listOf("", "아니오")
neuteredItem
)


val genderAdapter = ArrayAdapter(
requireContext(),
list_item,
listOf("남자", "여자", "없음")
genderListItem
)

with(binding) {
viewModel = buddyViewModel
lifecycleOwner = viewLifecycleOwner
genderTv.setAdapter(genderAdapter)
isNeuteredTv.setAdapter(breadAdapter)
isNeuteredTv.setAdapter(neuteredAdapter)
birthDayTv.text = CalendarUtil.getTodayDate()
adoptDayTv.text = CalendarUtil.getTodayDate()
birthDayTv.setOnClickListener {
Expand All @@ -67,20 +74,35 @@ class InputBuddyInfoFragment : Fragment() {
}
.build().show()
}
imgSelect.setOnClickListener {
TedImagePicker.with(requireContext())
.start {
buddyViewModel.setSelectImgUri(it)
}
}
}

binding.next.setOnClickListener {
setData()
buddyViewModel
findNavController().navigate(R.id.next)
}
}

private fun setData(){
with(binding){
buddyViewModel.setName(nameEt.editText.toString())
buddyViewModel.setNeutered(isNeuteredTv.text.toString())
buddyViewModel.setGender(genderTv.text.toString())
private fun setData() {
with(binding) {
buddyViewModel.setName(nameTv.text.toString())
buddyViewModel.setNeutered(
when (isNeuteredTv.text.toString()) {
neuteredItem[0] -> true
else -> false
}
)
buddyViewModel.setGender(
when (genderTv.text.toString()) {
genderListItem[0] -> "M"
else -> "W"
}
)
buddyViewModel.setAdoptDay(adoptDayTv.text.toString())
buddyViewModel.setBirthDay(birthDayTv.text.toString())
}
Expand Down
95 changes: 92 additions & 3 deletions buddy/src/main/res/layout/fragment_complete_registration.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
<layout 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">

<data>

<variable
name="viewModel"
type="com.nocapstone.buddyvet.buddy.ui.BuddyViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="21dp"
tools:context="com.nocapstone.buddyvet.buddy.ui.CompleteRegistrationFragment">


<TextView
android:id="@+id/complete_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/cafe24_ssurround_air"
android:gravity="center"
android:text="이대로 등록 할까"
android:textColor="@color/black"
android:textSize="32sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" />


<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_iv"
uri="@{viewModel.selectImgUri}"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginTop="32dp"
app:civ_border_overlay="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/complete_tv" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/profile_iv">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/cafe24_ssurround"
android:text="@{viewModel.newBuddy.name}"
android:textColor="@color/black"
android:textSize="17sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/cafe24_ssurround"
android:text='@{viewModel.newBuddy.gender == "M" ? "남아" : "여아"}'
android:textColor="@color/black"
android:textSize="17sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/cafe24_ssurround"
android:text='@{"중성화 여부 : " + (viewModel.newBuddy.neutered ? "O" : "X")}'
android:textColor="@color/black"
android:textSize="17sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/cafe24_ssurround"
android:text='@{"태어난 날 : " + viewModel.newBuddy.birthDay}'
android:textColor="@color/black"
android:textSize="17sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/cafe24_ssurround"
android:text='@{"가족이 된 날 : " + viewModel.newBuddy.adoptDay}'
android:textColor="@color/black"
android:textSize="17sp" />

</LinearLayout>


<com.google.android.material.button.MaterialButton
android:id="@+id/next"
style="@style/basic_btn"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="@dimen/basic_bottom_btn_margin_non_padding"
android:text="다음"
android:text="등록하기"
android:textSize="@dimen/basic_btn_textSize"
app:backgroundTint="@color/butter"
app:layout_constraintBottom_toBottomOf="parent" />
Expand Down
Loading

0 comments on commit 992771f

Please sign in to comment.