-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from yuyakaido/feature/kotlin
Kotlinize sample app
- Loading branch information
Showing
10 changed files
with
358 additions
and
446 deletions.
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
75 changes: 0 additions & 75 deletions
75
sample/src/main/java/com/yuyakaido/android/cardstackview/sample/CardStackAdapter.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
sample/src/main/java/com/yuyakaido/android/cardstackview/sample/CardStackAdapter.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,51 @@ | ||
package com.yuyakaido.android.cardstackview.sample | ||
|
||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import com.bumptech.glide.Glide | ||
|
||
class CardStackAdapter( | ||
private var spots: List<Spot> = emptyList() | ||
) : RecyclerView.Adapter<CardStackAdapter.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return ViewHolder(inflater.inflate(R.layout.item_spot, parent, false)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val spot = spots[position] | ||
holder.name.text = spot.name | ||
holder.city.text = spot.city | ||
Glide.with(holder.image) | ||
.load(spot.url) | ||
.into(holder.image) | ||
holder.itemView.setOnClickListener { v -> | ||
Toast.makeText(v.context, spot.name, Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return spots.size | ||
} | ||
|
||
fun setSpots(spots: List<Spot>) { | ||
this.spots = spots | ||
} | ||
|
||
fun getSpots(): List<Spot> { | ||
return spots | ||
} | ||
|
||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { | ||
val name: TextView = view.findViewById(R.id.item_name) | ||
var city: TextView = view.findViewById(R.id.item_city) | ||
var image: ImageView = view.findViewById(R.id.item_image) | ||
} | ||
|
||
} |
Oops, something went wrong.