Skip to content

Commit

Permalink
#58 feat: 일정 관리 스와이프 기능 테스트 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunBaee committed Jun 2, 2023
1 parent 3ff9060 commit 23af000
Show file tree
Hide file tree
Showing 31 changed files with 835 additions and 21 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
android:exported="false" />
<activity android:name=".presentation.ui.profile.view.ProfileActivity"
android:exported="false" />
<activity android:name=".presentation.ui.todogroup.TodoGroupManageActivity"
android:exported="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.chunbae.narchive.data.data

data class GroupColorData(
val color : String,
var isSelect : Boolean = false
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chunbae.narchive.data.data

data class GroupData(
val todoGroupIdx : Int?,
val groupTitle : String,
val groupColor : String
val groupColor : String,
val isDefault : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.chunbae.narchive.data.remote.api

import com.chunbae.narchive.data.remote.response.ResponseTodoGroupData
import retrofit2.Response
import retrofit2.http.GET

interface TodoService {

@GET("/todo/groups")
suspend fun getTodoGroupList() : Response<ResponseTodoGroupData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.chunbae.narchive.data.remote.repository

import com.chunbae.narchive.data.data.GroupData
import com.chunbae.narchive.domain.repository.TodoGroupRepository
import com.chunbae.narchive.domain.source.TodoGroupSource
import javax.inject.Inject

class TodoGroupRepositoryImpl @Inject constructor(private val todoGroupSource: TodoGroupSource): TodoGroupRepository {
override suspend fun getTodoGroupListData(): Result<List<GroupData>> {
return todoGroupSource.getTodoGroupListData()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.chunbae.narchive.data.remote.response

import com.chunbae.narchive.data.data.GroupData
import com.chunbae.narchive.presentation.util.BaseResponse

data class ResponseTodoGroupData(
val result : List<GroupData>
) : BaseResponse()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.chunbae.narchive.data.remote.source

import com.chunbae.narchive.data.data.GroupData
import com.chunbae.narchive.data.remote.api.TodoService
import com.chunbae.narchive.domain.source.TodoGroupSource
import javax.inject.Inject

class TodoGroupRemoteSource @Inject constructor(private val todoService : TodoService): TodoGroupSource{
override suspend fun getTodoGroupListData(): Result<List<GroupData>> {
val res = todoService.getTodoGroupList()
if (res.isSuccessful) {
return Result.success(res.body()!!.result)
}
return Result.failure(IllegalArgumentException(res.message()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.chunbae.narchive.domain.repository

import com.chunbae.narchive.data.data.GroupData

interface TodoGroupRepository {

suspend fun getTodoGroupListData() : Result<List<GroupData>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.chunbae.narchive.domain.source

import com.chunbae.narchive.data.data.GroupData

interface TodoGroupSource {

suspend fun getTodoGroupListData() : Result<List<GroupData>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.chunbae.narchive.data.remote.repository.KakaoBookSearchRepositoryImpl
import com.chunbae.narchive.data.remote.repository.KakaoLocationSearchRepositoryImpl
import com.chunbae.narchive.data.remote.repository.MovieSearchRepositoryImpl
import com.chunbae.narchive.data.remote.repository.ProfileRepositoryImpl
import com.chunbae.narchive.data.remote.repository.TodoGroupRepositoryImpl
import com.chunbae.narchive.domain.repository.AuthRepository
import com.chunbae.narchive.domain.repository.BookRepository
import com.chunbae.narchive.domain.repository.CommentRepository
Expand All @@ -22,6 +23,7 @@ import com.chunbae.narchive.domain.repository.KakaoBookSearchRepository
import com.chunbae.narchive.domain.repository.KakaoLocationSearchRepository
import com.chunbae.narchive.domain.repository.MovieSearchRepository
import com.chunbae.narchive.domain.repository.ProfileRepository
import com.chunbae.narchive.domain.repository.TodoGroupRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -63,4 +65,7 @@ abstract class RepositoryModule {

@Binds
abstract fun bindMovieSearchRepository(movieSearchRepositoryImpl: MovieSearchRepositoryImpl) : MovieSearchRepository

@Binds
abstract fun bindTodoGroupRepository(todoGroupRepositoryImpl: TodoGroupRepositoryImpl) : TodoGroupRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.chunbae.narchive.data.remote.api.KakaoAiService
import com.chunbae.narchive.data.remote.api.KakaoService
import com.chunbae.narchive.data.remote.api.ProfileService
import com.chunbae.narchive.data.remote.api.SearchMovieService
import com.chunbae.narchive.data.remote.api.TodoService
import com.chunbae.narchive.presentation.di.annotation.KakaoAIRetrofit
import com.chunbae.narchive.presentation.di.annotation.KakaoRetrofit
import com.chunbae.narchive.presentation.di.annotation.MovieRetrofit
Expand Down Expand Up @@ -60,4 +61,7 @@ class ServiceModule {
@Singleton
fun provideBookService(@NarchiveRetrofit retrofit: Retrofit) : BookService = retrofit.create(BookService::class.java)

@Provides
@Singleton
fun provideTodoService(@NarchiveRetrofit retrofit: Retrofit) : TodoService = retrofit.create(TodoService::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.chunbae.narchive.data.remote.source.KakaoBookSearchRemoteSource
import com.chunbae.narchive.data.remote.source.KakaoLocationSearchRemoteSource
import com.chunbae.narchive.data.remote.source.MovieSearchRemoteSource
import com.chunbae.narchive.data.remote.source.ProfileRemoteSource
import com.chunbae.narchive.data.remote.source.TodoGroupRemoteSource
import com.chunbae.narchive.domain.source.AuthSource
import com.chunbae.narchive.domain.source.BookSource
import com.chunbae.narchive.domain.source.CommentSource
Expand All @@ -22,6 +23,7 @@ import com.chunbae.narchive.domain.source.KakaoBookSearchSource
import com.chunbae.narchive.domain.source.KakaoLocationSearchSource
import com.chunbae.narchive.domain.source.MovieSearchSource
import com.chunbae.narchive.domain.source.ProfileSource
import com.chunbae.narchive.domain.source.TodoGroupSource
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -63,4 +65,7 @@ abstract class SourceModule {

@Binds
abstract fun bindMovieSearchRemoteSource(movieSearchRemoteSource: MovieSearchRemoteSource) : MovieSearchSource

@Binds
abstract fun bindTodoGroupSource (todoGroupRemoteSource: TodoGroupRemoteSource) : TodoGroupSource
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.chunbae.narchive.presentation.ui.main.dialog

import android.content.Context
import android.content.DialogInterface
import android.graphics.Point
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.constraintlayout.widget.Group
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import com.chunbae.narchive.R
import com.chunbae.narchive.data.data.GroupColorData
import com.chunbae.narchive.databinding.DialogAddTodoGroupBinding
import com.chunbae.narchive.presentation.ui.main.dialog.adapter.AddTodoGroupColorAdapter
import com.chunbae.narchive.presentation.ui.main.todo.viewmodel.WriteTodoViewModel

class AddTodoGroupDialog : DialogFragment() {
private lateinit var binding : DialogAddTodoGroupBinding
private val viewModel : WriteTodoViewModel by activityViewModels()
private val colorAdapter by lazy {
AddTodoGroupColorAdapter(::selectColor, colorList)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_add_todo_group, container, false)

initBinding()
setColorRV()

return binding.root
}

override fun onResume() {
super.onResume()
val windowManager = requireActivity().getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = windowManager.defaultDisplay
val size = Point()
display.getSize(size)
val params: ViewGroup.LayoutParams? = dialog?.window?.attributes
val deviceWidth = size.x
params?.width = (deviceWidth * 0.9).toInt()
params?.height = WindowManager.LayoutParams.WRAP_CONTENT
dialog?.window?.attributes = params as WindowManager.LayoutParams
}

private fun initBinding() {
binding.viewModel = viewModel
binding.dialog = this
}

private fun setColorRV() {
binding.dialogAddTodoGroupRvColors.adapter = colorAdapter
binding.dialogAddTodoGroupRvColors.itemAnimator = null
}

private fun selectColor(color : String) {
viewModel.setNewAddColor(color)
}

fun onSaveGroup() {
viewModel.addNewGroup()
dismissDialog()
}

fun dismissDialog() {
dismiss()
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
viewModel.initAddNew()
}

/** Dummy */
private var colorList : MutableList<GroupColorData> = mutableListOf("RED", "ORANGE", "YELLOW", "GREEN", "BLUE", "NAVY", "PURPLE", "BLACK", "PINK", "GRAY").map { GroupColorData(it) } as MutableList

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class WriteTodoGroupDialog : BottomSheetDialogFragment() {
}

private fun onClick(position : Int) {
viewModel.setGroupSelect(position)
if(position == groupAdapter.itemCount - 1) {
AddTodoGroupDialog().show(requireActivity().supportFragmentManager, "ADD_GROUP")
} else {
viewModel.setGroupSelect(position)
}
dismiss()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.chunbae.narchive.presentation.ui.main.dialog.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chunbae.narchive.data.data.GroupColorData
import com.chunbae.narchive.data.data.GroupData
import com.chunbae.narchive.databinding.ItemDialogAddTodoGroupColorsBinding
import com.chunbae.narchive.presentation.util.TodoColor

class AddTodoGroupColorAdapter(private val selectColor : (String) -> Unit, private var colorList : MutableList<GroupColorData>) : RecyclerView.Adapter<AddTodoGroupColorAdapter.AddTodoGroupColorViewHolder>() {
inner class AddTodoGroupColorViewHolder(private val binding : ItemDialogAddTodoGroupColorsBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item : GroupColorData) {
binding.color = item
binding.root.setOnClickListener {
selectColor.invoke(item.color)
initSelect()
item.isSelect = true
notifyItemRangeChanged(0, colorList.size)
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AddTodoGroupColorViewHolder {
return AddTodoGroupColorViewHolder(ItemDialogAddTodoGroupColorsBinding.inflate(
LayoutInflater.from(parent.context), parent, false))
}

override fun getItemCount(): Int = colorList.size

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

private fun initSelect() {
for(i in colorList) {
i.isSelect = false
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chunbae.narchive.presentation.ui.main.todo.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chunbae.narchive.data.data.GroupData
Expand All @@ -14,7 +15,7 @@ class TodoWriteGroupAdapter (private val onClicked : (Int) -> Unit): RecyclerVie
inner class TodoWriteGroupViewHolder(private val binding : ItemDialogWriteTodoGroupFormBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item : GroupData) {
binding.groupData = item
//:TODO 추후 todo index로 변경해야함
binding.fgWriteTodoCardGroupColor.visibility = if (item.todoGroupIdx == 0) View.GONE else View.VISIBLE
binding.root.setOnClickListener { onClicked.invoke(absoluteAdapterPosition) }
}
}
Expand Down
Loading

0 comments on commit 23af000

Please sign in to comment.