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: 집안일 담당자 정하고 생성 #85

Merged
merged 19 commits into from
Jun 25, 2022
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,42 @@
package com.depromeet.housekeeper.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.depromeet.housekeeper.databinding.ItemProfileBinding
import com.depromeet.housekeeper.model.Assignee

class AddAssigneeAdapter(private val assignees: ArrayList<Assignee>)
: RecyclerView.Adapter<AddAssigneeAdapter.ViewHolder>() {

@SuppressLint("NotifyDataSetChanged")
fun updateAssignees(assignee: ArrayList<Assignee>) {
assignees.clear()
assignees.addAll(assignee)
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding: ItemProfileBinding = ItemProfileBinding.inflate(
LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(assignees[position])
}

override fun getItemCount(): Int = assignees.size

inner class ViewHolder(val binding: ItemProfileBinding)
: RecyclerView.ViewHolder(binding.root){
fun bind(assignee: Assignee) {
binding.assignTemp = assignee
Glide.with(binding.root)
.load(assignee.profilePath)
.into(binding.ivIcon)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.depromeet.housekeeper.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.depromeet.housekeeper.databinding.ItemBottomSheetAssigneeBinding
import com.depromeet.housekeeper.model.Assignee
import timber.log.Timber

class BottomSheetAssigneeAdapter(private val assignees: ArrayList<Assignee>, private val curAssignees: ArrayList<Assignee>)
: RecyclerView.Adapter<BottomSheetAssigneeAdapter.ViewHolder>() {

private var selectedAssignees: ArrayList<Assignee> = arrayListOf() // 선택한 담당자들

init {
selectedAssignees.addAll(curAssignees)
Timber.d(curAssignees.toString())
Timber.d(selectedAssignees.toString())
}

fun getSelectedAssignees(): ArrayList<Assignee> {
return selectedAssignees
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding: ItemBottomSheetAssigneeBinding = ItemBottomSheetAssigneeBinding.inflate(
LayoutInflater.from(parent.context), parent, false)

binding.itemBottomSheetAssigneeCl.isSelected = false
return ViewHolder(binding)
}

@SuppressLint("NotifyDataSetChanged")
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(assignees[position])

holder.binding.itemBottomSheetAssigneeCl.apply {
setOnClickListener {
isSelected = !isSelected

when(isSelected) {
true -> selectedAssignees.add(assignees[position])
false -> selectedAssignees.remove(assignees[position])
}
}
}

}

override fun getItemCount(): Int = assignees.size

inner class ViewHolder(val binding: ItemBottomSheetAssigneeBinding)
: RecyclerView.ViewHolder(binding.root){

@SuppressLint("NotifyDataSetChanged")
fun bind(assignee: Assignee) {
// 초기 selected
if(selectedAssignees.contains(assignee)) {
binding.itemBottomSheetAssigneeCheckIv.isSelected = true
binding.itemBottomSheetAssigneeCl.isSelected = true
}

binding.itemBottomSheetAssigneeNameTv.text = assignee.memberName
binding.itemBottomSheetAssigneeCl.isSelected = binding.itemBottomSheetAssigneeCheckIv.isSelected
Glide.with(binding.root)
.load(assignee.profilePath)
.into(binding.itemBottomSheetAssigneeProfileIv)
}
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/depromeet/housekeeper/local/PrefsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ object PrefsManager {
private const val USER_NAME = "USER_NAME"
private const val HAS_TEAM = "HAS_TEAM"
private const val AUTH_CODE = "AUTH_CODE"
private const val MEMBER_ID = "MEMBER_ID"


fun init(context: Context) {
prefs = context.getSharedPreferences("house_keeper", Context.MODE_PRIVATE)
Expand Down Expand Up @@ -62,4 +64,22 @@ object PrefsManager {
putString(AUTH_CODE, authCode)
}?.apply()
}

// TODO : memberId 저장 시점
val memberId: Int
get() = prefs.getInt(MEMBER_ID, 10)

fun setMemberId(memberId: Int) {
prefs.edit()?.apply {
putInt(MEMBER_ID, memberId)
}?.apply()
}

fun deleteMemberInfo() {
prefs.edit()?.apply {
remove(MEMBER_ID)
setHasTeam(false)
}?.apply()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import kotlinx.parcelize.Parcelize
data class Assignee(
val memberId: Int,
val memberName: String,
val profilePath: String
val profilePath: String,
): Parcelable

2 changes: 1 addition & 1 deletion app/src/main/java/com/depromeet/housekeeper/model/Chore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class Chore(
var assignees: List<Int> = listOf(0),
var assignees: List<Int> = listOf(),
var houseWorkName: String = "",
var scheduledDate: String = "yyyy-MM-dd",
var scheduledTime: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ApiService {
): UpdateChoreResponse

@POST("/api/oauth/logout")
suspend fun logout(@Header("Authorization") auth: String)
suspend fun logout()

@POST("/api/teams")
suspend fun buildTeam(@Body buildTeam: BuildTeam): BuildTeamResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface RemoteDataSource {
updateChoreBody: UpdateChoreBody,
): Flow<UpdateChoreResponse>

suspend fun logout(auth: String): Flow<Unit>
suspend fun logout(): Flow<Unit>
suspend fun buildTeam(buildTeam: BuildTeam): Flow<BuildTeamResponse>
suspend fun getTeam(): Flow<Groups>
suspend fun getProfileImages(): Flow<ProfileImages>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class LoginResponse(
val hasTeam : Boolean,
val isNewMember: Boolean,
val memberName: String?,
val memberId: Int,
val refreshToken: String,
val refreshTokenExpireTime: String
):Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ object Repository : RemoteDataSource {
}

override suspend fun logout(
auth: String,
): Flow<Unit> = flow {
emit(apiService.logout(auth))
emit(apiService.logout())
}

override suspend fun buildTeam(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import okio.IOException
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.DELETE
import java.lang.Exception
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -48,12 +49,14 @@ object RetrofitBuilder {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()

return try {
chain.proceed(
request.newBuilder()
.addHeader("Authorization", PrefsManager.accessToken.ifEmpty { PrefsManager.authCode })
.addHeader("Authorization", PrefsManager.refreshToken.ifEmpty { PrefsManager.authCode })
.build()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다~~

)

} catch (e: Exception) {
Response.Builder()
.request(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.depromeet.housekeeper.R
import com.depromeet.housekeeper.adapter.AddAssigneeAdapter
import com.depromeet.housekeeper.adapter.DayRepeatAdapter
import com.depromeet.housekeeper.databinding.FragmentAddDirectTodoBinding
import com.depromeet.housekeeper.model.Assignee
import com.depromeet.housekeeper.model.Chore
import com.depromeet.housekeeper.model.enums.ViewType
import com.depromeet.housekeeper.ui.custom.dialog.AssigneeBottomSheetDialog
import com.depromeet.housekeeper.ui.custom.dialog.DialogType
import com.depromeet.housekeeper.ui.custom.dialog.FairerDialog
import com.depromeet.housekeeper.util.spaceNameMapper
Expand All @@ -32,6 +35,7 @@ class AddDirectTodoFragment : Fragment() {
lateinit var binding: FragmentAddDirectTodoBinding
lateinit var imm: InputMethodManager
lateinit var dayRepeatAdapter: DayRepeatAdapter
lateinit var addAssigneeAdapter: AddAssigneeAdapter
private val viewModel: AddDirectTodoViewModel by viewModels()
private val navArgs by navArgs<AddDirectTodoFragmentArgs>()

Expand Down Expand Up @@ -71,6 +75,13 @@ class AddDirectTodoFragment : Fragment() {
onEditView()
}
}

lifecycleScope.launchWhenCreated {
viewModel.curAssignees.collect {
addAssigneeAdapter.updateAssignees(it)
}
}

binding.space = spaceNameMapper(viewModel.chores.value[0].space)

lifecycleScope.launchWhenStarted {
Expand Down Expand Up @@ -117,6 +128,10 @@ class AddDirectTodoFragment : Fragment() {
}
}

binding.addAssigneeLayout.setOnClickListener {
createBottomSheet()
}

binding.addDirectTodoHeader.apply {
defaultHeaderBackBtn.setOnClickListener {
it.findNavController().navigateUp()
Expand Down Expand Up @@ -171,6 +186,20 @@ class AddDirectTodoFragment : Fragment() {
}
}

private fun createBottomSheet() {
val bottomSheet = AssigneeBottomSheetDialog(allGroup = viewModel.allGroupInfo.value, curAssignees = viewModel.curAssignees.value)
bottomSheet.show(childFragmentManager, bottomSheet.tag)
bottomSheet.setMyOkBtnClickListener(object: AssigneeBottomSheetDialog.MyOkBtnClickListener{
override fun onOkBtnClick() {
viewModel.setCurAssignees(bottomSheet.selectedAssignees)
addAssigneeAdapter.updateAssignees(viewModel.getCurAssignees())
viewModel.updateAssigneeId()
Timber.d(viewModel.chores.value.toString())
}
})
}


private fun createDatePickerDialog() {
val selectDate = navArgs.selectDate.date

Expand All @@ -195,14 +224,15 @@ class AddDirectTodoFragment : Fragment() {
private fun onEditView() {
// set arg
val houseWork = navArgs.houseWork
Timber.d("TAG $houseWork")
val assignees: List<Int> = arrayListOf()
houseWork.assignees.map {
assignees.plus(it.memberId)
}
val chore = Chore(assignees, houseWork.houseWorkName, houseWork.scheduledDate, houseWork.scheduledTime, houseWork.space)

// viewmodel update
viewModel.initEditChore(chore)
viewModel.initEditChore(chore, houseWork.assignees)
viewModel.setHouseWorkId(houseWork.houseWorkId)

// ui update
Expand Down Expand Up @@ -235,6 +265,10 @@ class AddDirectTodoFragment : Fragment() {
}

private fun setAdapter() {
// 집안일 담당자 adapter
addAssigneeAdapter = AddAssigneeAdapter(viewModel.curAssignees.value)
binding.addAssigneeRv.adapter = addAssigneeAdapter

// 요일 반복 rv adapter
val days: Array<String> = resources.getStringArray(R.array.day_array)
dayRepeatAdapter = DayRepeatAdapter(days)
Expand Down
Loading