-
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
week3 commit 이승철 #13
base: main
Are you sure you want to change the base?
week3 commit 이승철 #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="kr.co.landvibe.summer_coding_android"> | ||
|
||
<!-- 승철 --> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
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. 퍼미션 관련 부분에는 굳이 주석을 넣지 않아도 되요~! |
||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,71 @@ package kr.co.landvibe.summer_coding_android.leesc0893 | |
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.LinearLayout | ||
import android.widget.Toast | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.google.android.material.snackbar.Snackbar | ||
import kr.co.landvibe.summer_coding_android.R | ||
import kr.co.landvibe.summer_coding_android.databinding.ActivityLeesc0893Binding | ||
import kr.co.landvibe.summer_coding_android.leesc0893.adapter.BookAdapter | ||
import kr.co.landvibe.summer_coding_android.leesc0893.api.BookService | ||
import kr.co.landvibe.summer_coding_android.leesc0893.model.BestSellerDto | ||
import retrofit2.* | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
class Leesc0893Activity : AppCompatActivity() { | ||
private lateinit var binding: ActivityLeesc0893Binding | ||
private lateinit var adapter: BookAdapter | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_leesc0893) | ||
binding = ActivityLeesc0893Binding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
initRecyclerView() | ||
|
||
|
||
|
||
val retrofit = Retrofit.Builder() | ||
.baseUrl("https://book.interpark.com") // http 는 x , https 는 허용 | ||
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. 요런 상수들은 따로 상수화를 진행합니다. companion object 에 |
||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
|
||
val bookService = retrofit.create(BookService::class.java) | ||
|
||
bookService.getBestSellerBooks("2513DC43FA0D012F7E9EF24437004EC8AAFD621E944D018691E66C2874B46AF0") | ||
.enqueue(object : Callback<BestSellerDto> { | ||
override fun onResponse( // 성공 | ||
call: Call<BestSellerDto>, | ||
response: Response<BestSellerDto> | ||
) { | ||
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<BestSellerDto>, 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" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Book, BookAdapter.BookItemViewHolder>(diffUtil) { | ||
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. 굳 |
||
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<Book>() { | ||
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean { | ||
return oldItem.id == newItem.id | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SearchBookDto> | ||
|
||
@GET("/api/bestSeller.api?output=json&categoryId=100") // json 으로 받아오는 것 고정 | ||
fun getBestSellerBooks( | ||
@Query("key") apiKey: String, | ||
):Call<BestSellerDto> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Book> | ||
|
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Book> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="16dp"> | ||
|
||
<androidx.appcompat.widget.AppCompatImageView | ||
android:id="@+id/bookImageView" | ||
android:layout_width="100dp" | ||
android:layout_height="100dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:background="@color/black" /> | ||
|
||
<TextView | ||
android:id="@+id/titleTextView" | ||
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.
|
||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="12dp" | ||
android:ellipsize="end" | ||
android:fontFamily="@font/bmhannaprooft" | ||
android:lines="1" | ||
android:textColor="@color/black" | ||
android:textSize="16sp" | ||
android:textStyle="bold" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toEndOf="@+id/bookImageView" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:text="제목 예시" /> | ||
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.
|
||
|
||
<TextView | ||
android:id="@+id/contentTextView" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:layout_marginTop="12dp" | ||
android:ellipsize="end" | ||
android:fontFamily="@font/bmhannaprooft" | ||
android:lines="1" | ||
android:maxLines="3" | ||
android:textSize="12sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="@+id/titleTextView" | ||
app:layout_constraintStart_toStartOf="@+id/titleTextView" | ||
app:layout_constraintTop_toBottomOf="@+id/titleTextView" | ||
tools:text="내용 예시" /> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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.
해당 파일도 git ignore 에 추가시켜도 됩니다~