Skip to content

Commit

Permalink
Merge pull request #168 from yuyakaido/feature/kotlin
Browse files Browse the repository at this point in the history
Kotlinize sample app
  • Loading branch information
yuyakaido authored Dec 20, 2018
2 parents 8b9a977 + 5362581 commit e800a80
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 446 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
13 changes: 11 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
Expand All @@ -15,11 +16,19 @@ android {
dependencies {
implementation project(':cardstackview')

// Kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// Image Loading
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

// Support Library
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'

// View
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

This file was deleted.

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)
}

}
Loading

0 comments on commit e800a80

Please sign in to comment.