Skip to content

Commit 97f2f8d

Browse files
committed
migrating to kotlin
1 parent 24fb645 commit 97f2f8d

File tree

13 files changed

+228
-154
lines changed

13 files changed

+228
-154
lines changed

.idea/copyright/Horácio_Flávio_Comé_Júnior.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/markdown-navigator.xml

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/markdown-navigator/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The next task is to add the dependecy to your _app_ `build.gradle` file.
2323
```gradle
2424
dependencies {
2525
...
26-
implementation 'com.github.horaciocome1:simple-recyclerview-adapter:0.1.0'
26+
implementation 'com.github.horaciocome1:simple-recyclerview-adapter:0.1.2'
2727
}
2828
```
2929
Now you ready to go. Except that you should _**sync your project**_ first.
@@ -33,58 +33,56 @@ As mention on IO18, android support libraries will not be updated anymore, thats
3333
I am wondering if it is necessary to do a separate lib for suppor appcompat. Email me if you thinking on that.
3434

3535
## How to use
36-
Intanciate a class `SimpleRecyclerViewAdapter` by using its own builder.
37-
```java
38-
SimpleRecyclerViewAdapter adapter = new SimpleRecyclerViewAdapter.Builder()
39-
.setItemLayout(R.layout.your_item_layout)
40-
.setList(yourList)
41-
.setOnBindViewHolder(new SimpleRecyclerViewAdapter.OnBindViewHolder() {
42-
@Override
43-
public void onBind(@NonNull SimpleRecyclerViewAdapter.ViewHolder holder, Object object) {
44-
// bind object data to the view
45-
}
46-
})
47-
.build();
48-
recyclerView.setAdapter(adapter);
36+
Call the default constructor passing as Datatype the class of your list objects.
37+
```kotlin
38+
recyclerView.adapter = SimpleRecyclerViewAdapter<DataType>().apply {
39+
itemLayout = R.layout.your_item_layout
40+
list = yourList
41+
setOnBindViewHolder { holder, dataType -> /* bind data here */ }
42+
}
4943
```
5044
### Examples
5145
Lets have a look at some common binding examples
52-
```java
53-
@Override
54-
public void onBind(@NonNull SimpleRecyclerViewAdapter.ViewHolder holder, Object object) {
55-
// binding a string to a textview
56-
((TextView) holder.getViewById(R.id.your_item_layout_textview_id)).setText((String) object)
57-
58-
// binding and image to an imageview using Picasso or Glide
59-
Picasso.with(context)
60-
.load(((Person) object).getProfilePic())
61-
.into((ImageView) holder.getViewById(R.id.your_item_layout_imageview_id))
46+
```kotlin
47+
recyclerView.adapter = SimpleRecyclerViewAdapter<User>().apply {
48+
itemLayout = R.layout.item_user
49+
list = users
50+
setOnBindViewHolder { holder, user ->
51+
holder.findViewById<Textview>(R.id.name).text = user.name
52+
holder.findViewById<Textview>(R.id.age).text = user.age
53+
ImageLoader.with(context)
54+
.load(user.photo)
55+
.into(holder.findViewById<ImageView>(R.id.photo))
56+
}
6257
}
6358
```
6459

65-
### Kotlin
66-
```kotlin
67-
val adapter = SimpleRecyclerViewAdapter.Builder()
68-
.setList(posts())
69-
.setItemLayout(R.layout.item_post)
70-
.setOnBindViewHolder { holder, `object` -> // bind your data here }
71-
.build()
72-
recyclerView.adapter = adapter
60+
### Java
61+
```java
62+
SimpleRecyclerViewAdapter<DataType> adapter = new SimpleRecyclerViewAdapter<>();
63+
adapter.setItemLayout(R.layout.your_item_layot);
64+
adapter.setList(yourList);
65+
adapter.setOnBindViewHolder(new Function2<SimpleRecyclerViewAdapter.ViewHolder, String, Unit>() {
66+
@Override
67+
public Unit invoke(SimpleRecyclerViewAdapter.ViewHolder viewHolder, DataType data) {
68+
// bind data here
69+
}
70+
});
71+
recyclerView.setAdapter(adapter);
7372
```
7473

7574
As you can see, casting is mandatory. Remember that this is a general porpose Adapter, althougth it is returning your own object, the class itself dont know it.
7675

7776
### Troubleshooting
78-
Notice that it is crucial to call `build( ... )` so that the listener could be initialized.
79-
It makes no sense only calling `build( ... )`.
77+
Naturally the adapter needs an item_layout, an list and an onBindViewHolder() implementation to display the list on screen.
78+
None of this is optional, so not setting them may lead to runtime app crash.
8079
```kotlin
81-
val adapter = SimpleRecyclerViewAdapter.Builder().build()
82-
recyclerView.adapter = adapter
80+
// this is what you need to a void
81+
recyclerView.adapter = SimpleRecyclerViewAdapter<DataType>()
8382
```
84-
This might lead to app crash.
8583

8684
### "Build or sinchronization failed!"
87-
Please reference to the part on the start where i talked about support libraries.
85+
This is might be a dependency matter. Please reference to the part on the start where i talked about support libraries.
8886

8987
## Licenses
9088
Copyright 2018 Horácio Flávio Comé Júnior
@@ -106,6 +104,6 @@ I am open to suggestions of any kind.
106104
Please be expressive, so others so we'all will be able to understand each other!
107105
Report any issues, please!
108106

109-
# Simple RecyclerView Utils
107+
## Simple RecyclerView Utils
110108
This is part of a serie of libraries that pretend to make recyclerview usage more easy.
111109
For a touch listener please see [Simple RecyclerView Touch Listener](https://github.com/horaciocome1/simple-recyclerview-touch-listener)

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
4+
ext.kotlin_version = '1.3.11'
5+
56
repositories {
67
google()
78
jcenter()
89
}
910
dependencies {
1011
classpath 'com.android.tools.build:gradle:3.2.1'
11-
12+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1213

1314
// NOTE: Do not place your application dependencies here; they belong
1415
// in the individual module build.gradle files

simplerecyclerviewadapter/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
23

34
android {
45
compileSdkVersion 28
@@ -8,8 +9,8 @@ android {
89
defaultConfig {
910
minSdkVersion 14
1011
targetSdkVersion 28
11-
versionCode 1
12-
versionName "0.1.0"
12+
versionCode 3
13+
versionName "0.1.2"
1314

1415
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1516

@@ -32,4 +33,8 @@ dependencies {
3233
testImplementation 'junit:junit:4.12'
3334
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3435
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
37+
}
38+
repositories {
39+
mavenCentral()
3540
}

simplerecyclerviewadapter/src/main/java/io/github/horaciocome1/simplerecyclerviewadapter/Constants.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)