diff options
author | Dan Nizri <dsn5ft@virginia.edu> | 2017-05-27 08:57:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-27 08:57:30 -0400 |
commit | c030f517847f4beaf5bdb0c35b40d72ae6908289 (patch) | |
tree | 049e5a1931a5e9917f4d929eee9bc83a088f5b3c | |
parent | f8c4cd393b08c6076f20078dbeda7dc638044d88 (diff) | |
parent | c12589bba48d84d7b54ab83b7e4109e584a40a52 (diff) | |
download | android-kotlin-demo-studio-master-dev.tar.gz |
Merge pull request #23 from americanexpress/use_databinding_with_stable_dependenciesstudio-3.2.1studio-master-devmirror-goog-studio-master-dev
Use data-binding for repository items
-rw-r--r-- | app/build.gradle | 27 | ||||
-rw-r--r-- | app/src/main/kotlin/com/yodle/android/kotlindemo/adapter/RepositoryAdapter.kt | 28 | ||||
-rw-r--r-- | app/src/main/res/layout/repository_item.xml | 150 | ||||
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.jar | bin | 54212 -> 54783 bytes | |||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.properties | 4 |
6 files changed, 116 insertions, 95 deletions
diff --git a/app/build.gradle b/app/build.gradle index 25dc1e8..176a880 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,16 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: "org.jetbrains.kotlin.kapt" android { - compileSdkVersion 23 + compileSdkVersion 25 buildToolsVersion "25.0.2" + dataBinding { + enabled = true + } + defaultConfig { applicationId "com.yodle.android.kotlindemo" minSdkVersion 16 @@ -27,22 +32,19 @@ android { } } -kapt { - generateStubs = true -} - dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // Kotlin compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + ext.supportLibVersion = "25.3.1" // Support Libraries - compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.android.support:design:23.4.0' - compile 'com.android.support:recyclerview-v7:23.4.0' - compile 'com.android.support:cardview-v7:23.4.0' - compile 'com.android.support:palette-v7:23.4.0' + compile "com.android.support:appcompat-v7:${supportLibVersion}" + compile "com.android.support:design:${supportLibVersion}" + compile "com.android.support:recyclerview-v7:${supportLibVersion}" + compile "com.android.support:cardview-v7:${supportLibVersion}" + compile "com.android.support:palette-v7:${supportLibVersion}" // Dagger 2 compile 'com.google.dagger:dagger:2.4' @@ -75,6 +77,9 @@ dependencies { compile 'com.github.grandstaish.paperparcel:paperparcel-kotlin:1.0.0' kapt 'com.github.grandstaish.paperparcel:compiler:1.0.0' + // Data Binding + kapt "com.android.databinding:compiler:2.3.2" + // Testing testCompile 'junit:junit:4.12' testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" @@ -92,7 +97,7 @@ dependencies { } buildscript { - ext.kotlin_version = '1.1.1' + ext.kotlin_version = '1.1.2-3' repositories { jcenter() } diff --git a/app/src/main/kotlin/com/yodle/android/kotlindemo/adapter/RepositoryAdapter.kt b/app/src/main/kotlin/com/yodle/android/kotlindemo/adapter/RepositoryAdapter.kt index c1c79be..e758487 100644 --- a/app/src/main/kotlin/com/yodle/android/kotlindemo/adapter/RepositoryAdapter.kt +++ b/app/src/main/kotlin/com/yodle/android/kotlindemo/adapter/RepositoryAdapter.kt @@ -2,18 +2,18 @@ package com.yodle.android.kotlindemo.adapter import android.content.Context import android.support.v7.widget.RecyclerView -import android.view.View +import android.view.LayoutInflater import android.view.ViewGroup import com.ocpsoft.pretty.time.PrettyTime -import com.yodle.android.kotlindemo.R +import com.yodle.android.kotlindemo.BR import com.yodle.android.kotlindemo.activity.RepositoryDetailActivity +import com.yodle.android.kotlindemo.databinding.RepositoryItemBinding import com.yodle.android.kotlindemo.extension.format -import com.yodle.android.kotlindemo.extension.formatted -import com.yodle.android.kotlindemo.extension.inflateLayout import com.yodle.android.kotlindemo.extension.loadUrl import com.yodle.android.kotlindemo.model.Repository -import kotlinx.android.synthetic.main.repository_item.view.* -import java.util.* +import kotlinx.android.synthetic.main.repository_item.view.repositoryItemImage +import kotlinx.android.synthetic.main.repository_item.view.repositoryItemRootLayout +import java.util.ArrayList class RepositoryAdapter(val context: Context) : RecyclerView.Adapter<RepositoryAdapter.RepositoryViewHolder>() { @@ -21,7 +21,10 @@ class RepositoryAdapter(val context: Context) : RecyclerView.Adapter<RepositoryA override fun getItemCount() = repositories.size - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = RepositoryViewHolder(context.inflateLayout(R.layout.repository_item, parent)) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepositoryViewHolder { + val layoutInflator: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + return RepositoryViewHolder(RepositoryItemBinding.inflate(layoutInflator, parent, false)) + } override fun onBindViewHolder(holder: RepositoryViewHolder, position: Int) = holder.bind(repositories.get(position)) @@ -30,16 +33,13 @@ class RepositoryAdapter(val context: Context) : RecyclerView.Adapter<RepositoryA notifyDataSetChanged() } - class RepositoryViewHolder(view: View) : RecyclerView.ViewHolder(view) { + class RepositoryViewHolder(val binding: RepositoryItemBinding) : RecyclerView.ViewHolder(binding.root) { - val context: Context = view.context - val prettyTime = PrettyTime() + val context: Context = binding.root.context fun bind(repository: Repository) { - itemView.repositoryItemTitle.text = repository.full_name - itemView.repositoryItemDescription.text = repository.description - itemView.repositoryItemLastUpdated.text = "Updated ${prettyTime.format(repository.pushed_at)}" - itemView.repositoryItemStarCount.text = repository.watchers_count.formatted() + binding.setVariable(BR.repo, repository) + binding.setVariable(BR.pushedDate, PrettyTime().format(repository.pushed_at)) itemView.repositoryItemImage.loadUrl(repository.owner.avatar_url) itemView.repositoryItemRootLayout.setOnClickListener { context.startActivity(RepositoryDetailActivity.getIntent(context, repository)) } } diff --git a/app/src/main/res/layout/repository_item.xml b/app/src/main/res/layout/repository_item.xml index c7afb3e..aac0935 100644 --- a/app/src/main/res/layout/repository_item.xml +++ b/app/src/main/res/layout/repository_item.xml @@ -1,82 +1,98 @@ <?xml version="1.0" encoding="utf-8"?> -<FrameLayout android:id="@+id/repositoryItemRootLayout" - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:background="?attr/selectableItemBackground" - android:clickable="true" - android:paddingTop="@dimen/material_padding"> +<layout> + <data> + <import type="java.text.NumberFormat"/> + <variable + name="repo" + type="com.yodle.android.kotlindemo.model.Repository"/> + <variable + name="pushedDate" + type="String"/> + </data> - <ImageView - android:id="@+id/repositoryItemImage" - android:layout_width="40dp" - android:layout_height="40dp" - android:layout_marginBottom="@dimen/material_padding" - android:layout_marginLeft="@dimen/material_padding" - tools:src="@mipmap/ic_launcher" /> - - <LinearLayout + <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/repositoryItemRootLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/material_padding" - android:layout_marginLeft="@dimen/material_list_padding_left" - android:layout_marginRight="@dimen/material_padding" - android:orientation="vertical"> + android:background="?attr/selectableItemBackground" + android:clickable="true" + android:paddingTop="@dimen/material_padding"> - <TextView - android:id="@+id/repositoryItemTitle" - style="@style/PrimaryTextStyle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/material_padding_quarter" - android:layout_marginRight="@dimen/material_padding_double" - android:ellipsize="end" - android:lines="1" - tools:text="JetBrains/kotlin" /> + <ImageView + android:id="@+id/repositoryItemImage" + android:layout_width="40dp" + android:layout_height="40dp" + android:layout_marginBottom="@dimen/material_padding" + android:layout_marginLeft="@dimen/material_padding" + tools:src="@mipmap/ic_launcher"/> - <TextView - android:id="@+id/repositoryItemDescription" - style="@style/SecondaryTextStyle" + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/material_padding_quarter" - tools:text="The Kotlin Programming Language" /> + android:layout_marginBottom="@dimen/material_padding" + android:layout_marginLeft="@dimen/material_list_padding_left" + android:layout_marginRight="@dimen/material_padding" + android:orientation="vertical"> - <TextView - android:id="@+id/repositoryItemLastUpdated" - style="@style/SecondaryTextStyle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - tools:text="Updated 6 hours ago" /> - </LinearLayout> + <TextView + android:id="@+id/repositoryItemTitle" + android:text="@{repo.full_name}" + style="@style/PrimaryTextStyle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/material_padding_quarter" + android:layout_marginRight="@dimen/material_padding_double" + android:ellipsize="end" + android:lines="1" + tools:text="JetBrains/kotlin"/> - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="right" - android:gravity="center_vertical" - android:orientation="horizontal" - android:paddingRight="@dimen/material_padding"> + <TextView + android:id="@+id/repositoryItemDescription" + android:text="@{repo.description}" + style="@style/SecondaryTextStyle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/material_padding_quarter" + tools:text="The Kotlin Programming Language"/> + + <TextView + android:id="@+id/repositoryItemLastUpdated" + android:text='@{"Updated" + pushedDate}' + style="@style/SecondaryTextStyle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:text="Updated 6 hours ago"/> + </LinearLayout> - <TextView - android:id="@+id/repositoryItemStarCount" - style="@style/SecondaryTextStyle" + <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="@dimen/material_padding_quarter" - android:textColor="@color/primary_text" - tools:text="532" /> + android:layout_gravity="right" + android:gravity="center_vertical" + android:orientation="horizontal" + android:paddingRight="@dimen/material_padding"> - <ImageView - android:layout_width="16dp" - android:layout_height="16dp" - android:adjustViewBounds="true" - android:src="@drawable/ic_star" /> - </LinearLayout> + <TextView + android:id="@+id/repositoryItemStarCount" + android:text='@{NumberFormat.getInstance().format(repo.watchers_count)}' + style="@style/SecondaryTextStyle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginRight="@dimen/material_padding_quarter" + android:textColor="@color/primary_text" + tools:text="532"/> + + <ImageView + android:layout_width="16dp" + android:layout_height="16dp" + android:adjustViewBounds="true" + android:src="@drawable/ic_star"/> + </LinearLayout> - <View - style="@style/HorizontalDividerStyle" - android:layout_gravity="bottom" - android:layout_marginLeft="@dimen/material_list_padding_left" /> -</FrameLayout>
\ No newline at end of file + <View + style="@style/HorizontalDividerStyle" + android:layout_gravity="bottom" + android:layout_marginLeft="@dimen/material_list_padding_left"/> + </FrameLayout> +</layout> diff --git a/build.gradle b/build.gradle index 1ea4bd0..d0aa704 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differindex e49c3ea..a685ce4 100644 --- a/gradle/wrapper/gradle-wrapper.jar +++ b/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6692436..240c8f2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Mar 15 14:27:04 MST 2017 +#Thu Apr 13 16:35:17 MST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip |