-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
835 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/chunbae/narchive/data/data/GroupColorData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/chunbae/narchive/data/remote/api/TodoService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/chunbae/narchive/data/remote/repository/TodoGroupRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseTodoGroupData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/chunbae/narchive/data/remote/source/TodoGroupRemoteSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/chunbae/narchive/domain/repository/TodoGroupRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>> | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/chunbae/narchive/domain/source/TodoGroupSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/src/main/java/com/chunbae/narchive/presentation/ui/main/dialog/AddTodoGroupDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...java/com/chunbae/narchive/presentation/ui/main/dialog/adapter/AddTodoGroupColorAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.