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

[Team04] Stitch&스타크 - 네트워크 통신 및 드래그 앤 드롭, 스와이프 구현 - 최종 PR #210

Open
wants to merge 32 commits into
base: team-04
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5e669dd
feat: 팝업메뉴 리스트 아이템에 연결, task 삭제, 이동 구현-#35
taewooyo Apr 11, 2022
25ea26d
feat: Task 수정 구현-#35
taewooyo Apr 11, 2022
5d44ced
Merge pull request #43 from bn-tw2020/feature/popup_menu-#35
jminie-o8o Apr 12, 2022
e8af100
feat: 카드 저장 조회 기능 API 구현
jminie-o8o Apr 12, 2022
f1ed922
feat: 카드 수정 기능 API 구현
jminie-o8o Apr 13, 2022
0c6e127
fix: 실행오류제거-#39
jminie-o8o Apr 13, 2022
161060a
Merge pull request #56 from bn-tw2020/feature/retrofit_network_packag…
taewooyo Apr 13, 2022
50a3d75
feat: drag-drop-swipe-#40
taewooyo Apr 13, 2022
fd30c11
Merge pull request #57 from bn-tw2020/feature/drag-drop-#40
jminie-o8o Apr 13, 2022
4d297df
feat: ItemTouchCallback 책임 분리-#59
taewooyo Apr 14, 2022
09cf433
fix: setOnTouchListener 경고문고해결-#59
taewooyo Apr 14, 2022
2b86c38
chore: LoadTaskResponse.kt 불필요한 파일제거-#59
taewooyo Apr 14, 2022
aae4853
Merge pull request #60 from bn-tw2020/feature/feedback-week2-1-#59
jminie-o8o Apr 14, 2022
32fc36a
feat: todo, inProgress, done 활동 조회-#62
taewooyo Apr 14, 2022
573f0e8
feat: todo, inProgress, done 활동 조회-#62
taewooyo Apr 14, 2022
edf6f70
feat: 히스토리 네트워크 통신-#65
taewooyo Apr 14, 2022
a8d32cb
chore: 불필요한 로그삭제-#65
taewooyo Apr 14, 2022
0b0e3af
feat: delete-api-#66
taewooyo Apr 14, 2022
2635df0
feat: move-api-#67
taewooyo Apr 14, 2022
0ad17e2
feat: 리사이클러뷰간 데이터 이동(메모리 이동)-#42
taewooyo Apr 15, 2022
e3a2a90
Merge pull request #72 from bn-tw2020/feature/활동_조회-#62
jminie-o8o Apr 15, 2022
e9f5045
feat: 추가 수정 네트워크 통신 구현-#63
jminie-o8o Apr 15, 2022
01998b7
Merge pull request #74 from jminie-o8o/feature/add-delete-api-#63
taewooyo Apr 15, 2022
bffef65
feat: history 기능 + 추가,수정 동기화-#65
taewooyo Apr 15, 2022
1690d23
Merge pull request #76 from bn-tw2020/feature/history-api-#65
jminie-o8o Apr 15, 2022
9369a9d
chore: 동기화-#66
taewooyo Apr 15, 2022
fe8f161
Merge pull request #77 from bn-tw2020/feature/delete-api-#66
jminie-o8o Apr 15, 2022
8ea5fd3
feat: 이동하기 네트워크 통신 요청 객체 수정 및 동기화-#67
taewooyo Apr 15, 2022
78e4762
Merge pull request #79 from bn-tw2020/feature/task-move-api-#67
jminie-o8o Apr 15, 2022
20bb8ca
Merge branch 'test_android' of https://github.com/bn-tw2020/todo-list…
taewooyo Apr 15, 2022
ac8a775
feat: 드래그 앤 드롭 에러 수정(메모리 관리)-#42
taewooyo Apr 15, 2022
70169cf
Merge pull request #80 from bn-tw2020/feature/recyclerview-drag-drop-#42
jminie-o8o Apr 15, 2022
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
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.todolist">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.example.todolist.common

import android.os.Build
import android.text.Html
import android.text.Spanned
import androidx.core.text.HtmlCompat
import androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY


fun String.htmlToString() : String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY).toString()
} else {
Html.fromHtml(this).toString()
}
fun String.htmlToSpanned() : Spanned {
return HtmlCompat.fromHtml(this, FROM_HTML_MODE_LEGACY)
}
Comment on lines -7 to 10

Choose a reason for hiding this comment

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

오 버전 분기 코드를 개선했군요!
좋습니다~
xxxCompat 클래스들이 버전 분기 처리를 해주느니 기억해두면 좋겠네요~

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class History(
val title: String,
val nowStatus: String,
val beforeStatus: String?,
val createData: String,
val createDateTime: String,

Choose a reason for hiding this comment

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

네이밍 개선 좋습니다~

)

enum class ActionType(val action: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.example.todolist.model

data class Task(
val title: String,
val content: String,
val contents: String,
val status: Status,
val author: String = "Android"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.todolist.model.request

data class ModifyTaskRequest(
val id: Int,
val title: String,
val contents: String,
val author: String = "Android",
val status: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.todolist.model.request

import com.example.todolist.model.Status

data class MoveTaskRequest(
val beforeStatus: Status,
val nowStatus: Status
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.todolist.model.request

data class TaskRequest(
val title: String,
val contents: String,
val status: String,
val author: String
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package com.example.todolist.model
package com.example.todolist.model.response

import com.example.todolist.model.Status
import com.google.gson.annotations.SerializedName

data class TasksResponse(
@SerializedName("todoCollection")
val todo: MutableList<TaskDetailResponse>,
@SerializedName("inProgressCollection")
val inProgress: MutableList<TaskDetailResponse>,
@SerializedName("doneCollection")
val done: MutableList<TaskDetailResponse>,
)

data class CommonResponse(
val status: Int,
@SerializedName("resources")
val taskDetailResponse: TaskDetailResponse,
)

data class TaskDetailResponse(
val id: Int,
val title: String,
val content: String,
val contents: String,
val status: Status,
val author: String = "Android",
val updateDateTime: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.todolist.network

sealed class Result<out T : Any> {
data class Success<out T : Any>(val data: T) : Result<T>()
data class Error(val error: String) : Result<Nothing>()
}
Comment on lines +3 to +6

Choose a reason for hiding this comment

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

sealed class 를 사용했네요 ??
sealed class 를 사용했던 이유가 무엇인가요?

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.todolist.network

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitAPI {
private const val BASE_URL = "http://www.louie-03.com/"

Choose a reason for hiding this comment

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

https 를 사용하지 않고 http 를 사용했던 이유가 무엇인가요?


private val okHttpClient: OkHttpClient by lazy {
OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.build()
}

private val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
}

val service: Service by lazy {
retrofit.create(Service::class.java)
}
}
38 changes: 38 additions & 0 deletions android/app/src/main/java/com/example/todolist/network/Service.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.todolist.network

import com.example.todolist.model.History
import com.example.todolist.model.Task
import com.example.todolist.model.request.ModifyTaskRequest
import com.example.todolist.model.request.MoveTaskRequest
import com.example.todolist.model.response.CommonResponse
import com.example.todolist.model.response.TasksResponse
import retrofit2.Response
import retrofit2.http.*

interface Service {

@Headers("Content-Type: application/json")
@GET("cards")
suspend fun loadTasks(): Response<TasksResponse>

@Headers("Content-Type: application/json")
@POST("cards")
suspend fun saveTask(@Body cardInfo: Task): Response<CommonResponse>

@Headers("Content-Type: application/json")
@PATCH("cards/{id}")
suspend fun modifyTask(
@Path("id") id: Int,
@Body modifyTaskRequest: ModifyTaskRequest
): Response<CommonResponse>

@Headers("Content-Type: application/json")
@GET("activity-logs")
suspend fun loadHistory(): Response<List<History>>

@DELETE("cards/{id}")
suspend fun deleteTask(@Path("id") id: Int): Response<CommonResponse>

@PATCH("cards/{id}/move")
suspend fun moveTask(@Path("id") id: Int, @Body request: MoveTaskRequest): Response<CommonResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.todolist.repository

import com.example.todolist.model.History
import com.example.todolist.model.Status
import com.example.todolist.model.Task
import com.example.todolist.model.request.ModifyTaskRequest
import com.example.todolist.model.request.MoveTaskRequest
import com.example.todolist.model.response.CommonResponse
import com.example.todolist.model.response.TaskDetailResponse
import com.example.todolist.model.response.TasksResponse

interface TaskDataSource {

suspend fun loadTasks(): TasksResponse?

suspend fun addTask(cardData: Task): CommonResponse?

suspend fun modifyTask(modifyTaskRequest: ModifyTaskRequest): CommonResponse?

suspend fun loadHistory(): List<History>?

suspend fun deleteTask(id: Int): CommonResponse?

suspend fun moveTask(request: MoveTaskRequest, id: Int): CommonResponse?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.todolist.repository

import com.example.todolist.model.History
import com.example.todolist.model.Status
import com.example.todolist.model.Task
import com.example.todolist.model.request.ModifyTaskRequest
import com.example.todolist.model.request.MoveTaskRequest
import com.example.todolist.model.response.CommonResponse
import com.example.todolist.model.response.TaskDetailResponse
import com.example.todolist.model.response.TasksResponse
import com.example.todolist.network.RetrofitAPI

class TaskRemoteDataSource : TaskDataSource {

override suspend fun loadTasks(): TasksResponse? {
val response = RetrofitAPI.service.loadTasks()
return if (response.isSuccessful) response.body() else null
}

override suspend fun addTask(cardData: Task): CommonResponse? {
val response = RetrofitAPI.service.saveTask(cardData)
return if (response.isSuccessful) response.body() else null
}

override suspend fun modifyTask(modifyTaskRequest: ModifyTaskRequest): CommonResponse? {
val response = RetrofitAPI.service.modifyTask(modifyTaskRequest.id, modifyTaskRequest)
return if (response.isSuccessful) response.body() else null
}

override suspend fun loadHistory(): List<History>? {
val response = RetrofitAPI.service.loadHistory()
return if (response.isSuccessful) response.body() else null
}

override suspend fun deleteTask(id: Int): CommonResponse? {
val response = RetrofitAPI.service.deleteTask(id)
return if (response.isSuccessful) response.body() else null
}

override suspend fun moveTask(request: MoveTaskRequest, id: Int): CommonResponse? {
val response = RetrofitAPI.service.moveTask(id, request)
return if (response.isSuccessful) response.body() else null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.example.todolist.repository

import com.example.todolist.model.History
import com.example.todolist.model.Status
import com.example.todolist.network.Result
import com.example.todolist.model.Task
import com.example.todolist.model.request.ModifyTaskRequest
import com.example.todolist.model.request.MoveTaskRequest
import com.example.todolist.model.response.CommonResponse
import com.example.todolist.model.response.TaskDetailResponse
import com.example.todolist.model.response.TasksResponse

class TaskRemoteRepository(
private val taskRemoteDataSource: TaskRemoteDataSource,
) {

suspend fun loadTask(): Result<TasksResponse> {
val response = taskRemoteDataSource.loadTasks()
response?.let {
return Result.Success(it)
}
return Result.Error("error")
}

suspend fun addTask(cardData: Task): Result<CommonResponse> {
val response = taskRemoteDataSource.addTask(cardData)
response?.let {
return Result.Success(it)
}
return Result.Error("error")
}

suspend fun modifyTask(modifyTaskRequest: ModifyTaskRequest): Result<CommonResponse> {
val response = taskRemoteDataSource.modifyTask(modifyTaskRequest)
response?.let {
return Result.Success(it)
}
return Result.Error("error")
}

suspend fun loadHistory(): Result<List<History>> {
val response = taskRemoteDataSource.loadHistory()
response?.let {
return Result.Success(it)
}
return Result.Error("error")
}

suspend fun deleteTask(id: Int): Result<TaskDetailResponse> {
val response = taskRemoteDataSource.deleteTask(id)
response?.let {
return Result.Success(it.taskDetailResponse)
}
return Result.Error("error")
}

suspend fun moveTask(task: TaskDetailResponse, status: Status): Result<TaskDetailResponse> {
val response = taskRemoteDataSource.moveTask(MoveTaskRequest(task.status, status), task.id)
response?.let {
return Result.Success(it.taskDetailResponse)
}
return Result.Error("error")
}
}
Loading