-
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
1 parent
2b8af6b
commit 6aaacf3
Showing
6 changed files
with
158 additions
and
21 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/seunggyu/stitch/adapter/BannerPagerAdapter.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,57 @@ | ||
package com.seunggyu.stitch.adapter | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import com.seunggyu.stitch.R | ||
import com.seunggyu.stitch.data.model.response.EventResponse | ||
|
||
class BannerPagerAdapter : RecyclerView.Adapter<BannerPagerAdapter.BannerViewHolder> { | ||
private var eventList: List<EventResponse> | ||
var context: Context? = null | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BannerViewHolder { | ||
val view: View = | ||
LayoutInflater.from(parent.context).inflate(R.layout.item_banner, parent, false) | ||
return BannerViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: BannerViewHolder, position: Int) { | ||
// infinite View Pager를 위한 position 변수 | ||
val actualPosition = holder.bindingAdapterPosition % eventList.size | ||
|
||
// 각 position에 해당하는 url을 리스트로부터 받아온다. | ||
val imageUrl: String = eventList[actualPosition].imageUrl.toString() | ||
val title: String = eventList[actualPosition].title.toString() | ||
Glide.with(holder.itemView.context).load(imageUrl).into(holder.ivBanner) | ||
holder.tvBanner.text = title | ||
// 클릭 리스너 .. | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return Int.MAX_VALUE | ||
} | ||
|
||
constructor(arrayList: List<EventResponse>) { | ||
eventList = arrayList | ||
} | ||
|
||
constructor(arrayList: List<EventResponse>, context: Context?) { | ||
eventList = arrayList | ||
this.context = context | ||
} | ||
|
||
inner class BannerViewHolder(view: View) : RecyclerView.ViewHolder(view) { | ||
var ivBanner: ImageView | ||
var tvBanner: TextView | ||
|
||
init { | ||
ivBanner = view.findViewById<ImageView>(R.id.iv_event) | ||
tvBanner = view.findViewById<TextView>(R.id.tv_event) | ||
} | ||
} | ||
} |
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
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