diff --git a/local.properties b/local.properties new file mode 100644 index 0000000..5771c86 --- /dev/null +++ b/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Thu Aug 11 16:45:35 KST 2022 +sdk.dir=/Users/leeseungcheol/Library/Android/sdk diff --git a/summer_coding_android/app/build.gradle b/summer_coding_android/app/build.gradle index b107e81..6e1e9c3 100644 --- a/summer_coding_android/app/build.gradle +++ b/summer_coding_android/app/build.gradle @@ -40,7 +40,14 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.2' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation 'com.squareup.retrofit2:converter-gson:2.9.0' + implementation 'com.github.bumptech.glide:glide:4.13.2' + + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + } \ No newline at end of file diff --git a/summer_coding_android/app/src/main/AndroidManifest.xml b/summer_coding_android/app/src/main/AndroidManifest.xml index 46b301c..cc256d3 100644 --- a/summer_coding_android/app/src/main/AndroidManifest.xml +++ b/summer_coding_android/app/src/main/AndroidManifest.xml @@ -1,7 +1,11 @@ + + + + { + override fun onResponse( // 성공 + call: Call, + response: Response + ) { + if (response.isSuccessful.not()) { + Log.d(TAG, "response.isSuccessful.not()") + return + } + response.body()?.let { BestSellerDto -> + Log.d(TAG, BestSellerDto.toString()) + BestSellerDto.books.forEach { book -> + Log.d(TAG, book.toString()) + } + adapter.submitList(BestSellerDto.books) + } + } + + override fun onFailure(call: Call, t: Throwable) { // 실패 + Log.d(TAG, t.toString()) + } + + }) + /* bookService.getBooksByName()*/ + } + + private fun initRecyclerView(){ + adapter = BookAdapter() + binding.mainRecyclerView.layoutManager = LinearLayoutManager(this) + binding.mainRecyclerView.adapter = adapter + } + + companion object { + private const val TAG: String = "Leesc0893Activity" } } \ No newline at end of file diff --git a/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/adapter/BookAdapter.kt b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/adapter/BookAdapter.kt new file mode 100644 index 0000000..4bd022b --- /dev/null +++ b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/adapter/BookAdapter.kt @@ -0,0 +1,52 @@ +package kr.co.landvibe.summer_coding_android.leesc0893.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import kr.co.landvibe.summer_coding_android.databinding.ItemBookBinding +import kr.co.landvibe.summer_coding_android.leesc0893.model.Book + + +class BookAdapter : ListAdapter(diffUtil) { + inner class BookItemViewHolder(private val binding: ItemBookBinding) : + RecyclerView.ViewHolder(binding.root) { + fun bind(bookModel: Book) { + binding.titleTextView.text = bookModel.title + binding.contentTextView.text = bookModel.description + Glide.with(binding.bookImageView.context).load(bookModel.coverSmallUrl) + .into(binding.bookImageView) + } + + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookItemViewHolder { + return BookItemViewHolder( + ItemBookBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) + } + + override fun onBindViewHolder(holder: BookItemViewHolder, position: Int) { + holder.bind(currentList[position]) + } + + companion object { + val diffUtil = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean { + return oldItem == newItem + } + + override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean { + return oldItem.id == newItem.id + } + + } + } + +} \ No newline at end of file diff --git a/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/api/BookService.kt b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/api/BookService.kt new file mode 100644 index 0000000..39320a2 --- /dev/null +++ b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/api/BookService.kt @@ -0,0 +1,21 @@ +package kr.co.landvibe.summer_coding_android.leesc0893.api + +import kr.co.landvibe.summer_coding_android.leesc0893.model.BestSellerDto +import kr.co.landvibe.summer_coding_android.leesc0893.model.SearchBookDto +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Query + +interface BookService { + + @GET("/api/search.api?output=json") // json 으로 받아오는 것 고정 + fun getBooksByName( + @Query("key") apiKey: String, + @Query("query") keyword: String, + ):Call + + @GET("/api/bestSeller.api?output=json&categoryId=100") // json 으로 받아오는 것 고정 + fun getBestSellerBooks( + @Query("key") apiKey: String, + ):Call +} \ No newline at end of file diff --git a/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/BestSellerDto.kt b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/BestSellerDto.kt new file mode 100644 index 0000000..1a1f163 --- /dev/null +++ b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/BestSellerDto.kt @@ -0,0 +1,9 @@ +package kr.co.landvibe.summer_coding_android.leesc0893.model + +import com.google.gson.annotations.SerializedName + +data class BestSellerDto( // 이게 데이터를 한번에 가져오고 "Book" data class 의 정보들을 mapping 된 상태로 저장 + @SerializedName("title") val title: String, + @SerializedName("item") val books: List + +) diff --git a/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/Book.kt b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/Book.kt new file mode 100644 index 0000000..e2015ea --- /dev/null +++ b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/Book.kt @@ -0,0 +1,10 @@ +package kr.co.landvibe.summer_coding_android.leesc0893.model + +import com.google.gson.annotations.SerializedName + +data class Book( + @SerializedName("itemId") val id : Long, + @SerializedName("title") val title : String, + @SerializedName("description") val description : String, + @SerializedName("coverSmallUrl") val coverSmallUrl : String +) \ No newline at end of file diff --git a/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/SearchBookDto.kt b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/SearchBookDto.kt new file mode 100644 index 0000000..e2e096f --- /dev/null +++ b/summer_coding_android/app/src/main/java/kr/co/landvibe/summer_coding_android/leesc0893/model/SearchBookDto.kt @@ -0,0 +1,8 @@ +package kr.co.landvibe.summer_coding_android.leesc0893.model + +import com.google.gson.annotations.SerializedName + +data class SearchBookDto( + @SerializedName("title") val title: String, + @SerializedName("item") val books: List +) \ No newline at end of file diff --git a/summer_coding_android/app/src/main/res/font/bmhannaprooft.otf b/summer_coding_android/app/src/main/res/font/bmhannaprooft.otf new file mode 100644 index 0000000..372cf07 Binary files /dev/null and b/summer_coding_android/app/src/main/res/font/bmhannaprooft.otf differ diff --git a/summer_coding_android/app/src/main/res/layout/activity_leesc0893.xml b/summer_coding_android/app/src/main/res/layout/activity_leesc0893.xml index 8b46911..53e6633 100644 --- a/summer_coding_android/app/src/main/res/layout/activity_leesc0893.xml +++ b/summer_coding_android/app/src/main/res/layout/activity_leesc0893.xml @@ -6,4 +6,21 @@ android:layout_height="match_parent" tools:context=".leesc0893.Leesc0893Activity"> + + + + \ No newline at end of file diff --git a/summer_coding_android/app/src/main/res/layout/item_book.xml b/summer_coding_android/app/src/main/res/layout/item_book.xml new file mode 100644 index 0000000..cb6788b --- /dev/null +++ b/summer_coding_android/app/src/main/res/layout/item_book.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + \ No newline at end of file