-
Notifications
You must be signed in to change notification settings - Fork 0
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
MVC - API, ViewBinding적용 #2
Open
Leesin0222
wants to merge
18
commits into
develop
Choose a base branch
from
feature/mvc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
370532b
api통신을 위한 의존성 추가 및 buildConfig, viewBinding사용설정
Leesin0222 a92ef14
viewBinding적용으로 인한 view id수정
Leesin0222 faadea2
api통신을 사용하며 기존 인 메모리에서 사용되던 RecentReadCardListManager및 Card data class제거
Leesin0222 d82e06b
api통신 실패 시 보여줄 에러 메시지 정의
Leesin0222 17664cf
Manifest에 인터넷 권한 명시 및 cleartextTraffic사용하도록 설정
Leesin0222 aa342b1
CardResponse 구현
Leesin0222 26fabe3
cardApi 및 RetrofitBuilder구현
Leesin0222 702797e
토스트 확장 함수 구현
Leesin0222 24b2e1e
LifeCycle 코루틴 처리 확장함수 구현
Leesin0222 d907d09
MainActivity에 viewBinding적용
Leesin0222 0f56f12
AllCardListAdapter에 viewBinding적용 및 updateAllCard함수 구현
Leesin0222 bc88ce5
CardViewHolder에 viewBinding적용
Leesin0222 bb14c63
RecentReadCardListAdapter에 viewBinding적용 및 첫 번째 아이템 제거 함수 구현
Leesin0222 c0bc3a5
AllCardListFragment에 뷰바인딩 적용 및 모든 카드를 api 호출하여 받아오도록 구현
Leesin0222 180b637
RecentReadCardListFragment에 viewBinding적용 및 api호출 로직 구현
Leesin0222 86f6c2a
CardDetailActivity에 viewBinding적용 및 api호출 로직 구현
Leesin0222 d930bbe
Glide의존성 추가 및 imageUrl불러와 image띄워주는 로직 구현
Leesin0222 110c96d
getExtra type수정
Leesin0222 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/yongjincompany/android_assignment/core/util/LifeCycle.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,31 @@ | ||
package com.yongjincompany.android_assignment.core.util | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
|
||
fun Fragment.repeatOnLifecycleState( | ||
state: Lifecycle.State = Lifecycle.State.STARTED, | ||
block: suspend CoroutineScope.() -> Unit | ||
) = | ||
viewLifecycleOwner.launchRepeatOnLifecycleState(state, block) | ||
|
||
fun AppCompatActivity.repeatOnLifecycleState( | ||
state: Lifecycle.State = Lifecycle.State.STARTED, | ||
block: suspend CoroutineScope.() -> Unit | ||
): Job = | ||
launchRepeatOnLifecycleState(state, block) | ||
|
||
private fun LifecycleOwner.launchRepeatOnLifecycleState( | ||
state: Lifecycle.State = Lifecycle.State.STARTED, | ||
block: suspend CoroutineScope.() -> Unit | ||
) = | ||
lifecycleScope.launch { | ||
lifecycle.repeatOnLifecycle(state, block) | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/yongjincompany/android_assignment/core/util/Toast.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.yongjincompany.android_assignment.core.util | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
|
||
fun Context.toast(message: String, duration: Int = Toast.LENGTH_SHORT) { | ||
Toast.makeText(this, message, duration).show() | ||
} |
19 changes: 0 additions & 19 deletions
19
app/src/main/java/com/yongjincompany/android_assignment/data/Card.kt
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
app/src/main/java/com/yongjincompany/android_assignment/data/RecentReadCardListManager.kt
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/yongjincompany/android_assignment/data/RetrofitBuilder.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,39 @@ | ||
package com.yongjincompany.android_assignment.data | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import com.yongjincompany.android_assignment.BuildConfig | ||
import com.yongjincompany.android_assignment.data.api.CardApi | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
|
||
object RetrofitBuilder { | ||
private const val BASE_URL = "http://10.0.2.2:8080/api/" | ||
|
||
private val json = Json { | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
} | ||
|
||
private val httpLoggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = if (BuildConfig.DEBUG) { | ||
HttpLoggingInterceptor.Level.BODY | ||
} else { | ||
HttpLoggingInterceptor.Level.NONE | ||
} | ||
} | ||
|
||
private val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(httpLoggingInterceptor) | ||
.build() | ||
|
||
private val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
val cardApi: CardApi = retrofit.create(CardApi::class.java) | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/yongjincompany/android_assignment/data/api/CardApi.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,21 @@ | ||
package com.yongjincompany.android_assignment.data.api | ||
|
||
import com.yongjincompany.android_assignment.data.model.response.Card | ||
import retrofit2.http.GET | ||
import retrofit2.http.PATCH | ||
import retrofit2.http.Path | ||
import retrofit2.http.Query | ||
|
||
interface CardApi { | ||
@GET("card") | ||
suspend fun fetchAllCardList(): List<Card> | ||
|
||
@GET("card/read") | ||
suspend fun fetchRecentReadCardList(): List<Card> | ||
|
||
@PATCH("card/read/{id}") | ||
suspend fun changeCardReadStatus( | ||
@Path("id") id: Long, | ||
@Query("isRead") isRead: Boolean | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/yongjincompany/android_assignment/data/model/response/Card.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,22 @@ | ||
package com.yongjincompany.android_assignment.data.model.response | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Card( | ||
val description: String, | ||
val grade: CardGradeType, | ||
val id: Long, | ||
val imageUrl: String, | ||
val isRead: Boolean, | ||
val name: String, | ||
) | ||
|
||
@Serializable | ||
enum class CardGradeType { | ||
S, | ||
A, | ||
B, | ||
C, | ||
D, | ||
} |
52 changes: 38 additions & 14 deletions
52
app/src/main/java/com/yongjincompany/android_assignment/feature/home/AllCardListFragment.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 |
---|---|---|
@@ -1,31 +1,55 @@ | ||
package com.yongjincompany.android_assignment.feature.home | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.yongjincompany.android_assignment.data.Card | ||
import com.yongjincompany.android_assignment.data.Grade | ||
import com.yongjincompany.android_assignment.R | ||
import com.yongjincompany.android_assignment.core.util.SpacingItemDecoration | ||
import com.yongjincompany.android_assignment.core.util.repeatOnLifecycleState | ||
import com.yongjincompany.android_assignment.core.util.toast | ||
import com.yongjincompany.android_assignment.data.RetrofitBuilder | ||
import com.yongjincompany.android_assignment.databinding.FragmentAllCardListBinding | ||
import com.yongjincompany.android_assignment.feature.home.adapter.AllCardListAdapter | ||
|
||
class AllCardListFragment : Fragment(R.layout.fragment_all_card_list) { | ||
private var _binding: FragmentAllCardListBinding? = null | ||
private val binding get() = _binding!! | ||
private lateinit var allCardListAdapter: AllCardListAdapter | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentAllCardListBinding.inflate(inflater, container, false) | ||
val view = binding.root | ||
return view | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. View = Fragment.inflate().also {
_binding = it
}.root
View = Fragment.inflate().apply {
_binding = this
}.root |
||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val allCardListRecyclerView: RecyclerView = view.findViewById(R.id.rv_all_card_list) | ||
val allCardList = listOf( | ||
Card(id = 0, grade = Grade.D, name = "사죄 용진", img = R.drawable.sorry_yongjin_card_img, description = "왜 이 사람은 책상 위에 올라가 사죄하고 있을까요? 전 알아요 그는 세미콜론이라는 동아리를 나가서 새 길을 개척하겠다는 포부를 가지고 있다는 것을"), | ||
Card(id = 1, grade = Grade.C, name = "민달팽이 정민", img = R.drawable.snail_jeongmin_card_img, description = "문정민, 그는 프랭키 그 자체입니다. 그의 얼굴을 보고 절대 속으면 안됩니다. 끔찍하게도 그의 얼굴과 달리 그의 몸은 민달팽이와 같은 구조로 되어있습니다."), | ||
Card(id = 2, grade = Grade.B, name = "이별 영준", img = R.drawable.brakeup_youngjun_card_img, description = "만약 저런 표정으로 누워있는 그를 발견한다면 그를 절대로 건드리지 않는 것이 좋을겁니다. 그는 안좋은 일을 겪었거든요…"), | ||
Card(id = 3, grade = Grade.A, name = "마스터이 경수", img = R.drawable.masteryi_gyeongsu_card_img, description = "그는 잠자리일까요? 사람일까요? 그의 정체를 아는 사람은 없을겁니다… 아마도요.."), | ||
Card(id = 4, grade = Grade.A, name = "앙큼한 진성", img = R.drawable.cute_jinsung_card_img, description = "오우 그를 보셨나요? 그는 참 상큼발랄한 친구입니다. 그의 이름이요? 황진성입니다. 그는 웹개발자이죠.") | ||
) | ||
|
||
allCardListRecyclerView.adapter = AllCardListAdapter(allCardList) | ||
allCardListRecyclerView.addItemDecoration(SpacingItemDecoration(30)) | ||
allCardListAdapter = AllCardListAdapter() | ||
binding.rvAllCardList.adapter = allCardListAdapter | ||
binding.rvAllCardList.addItemDecoration(SpacingItemDecoration(30)) | ||
|
||
repeatOnLifecycleState { | ||
runCatching { | ||
RetrofitBuilder.cardApi.fetchAllCardList() | ||
}.onSuccess { | ||
allCardListAdapter.updateAllCard(it) | ||
}.onFailure { | ||
it.printStackTrace() | ||
requireContext().toast(getString(R.string.cant_all_card_read)) | ||
} | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-builder/coerce-input-values.html