Skip to content

Commit

Permalink
update dependencies; add one more example
Browse files Browse the repository at this point in the history
  • Loading branch information
D00mch committed Jun 21, 2019
1 parent d9e37ed commit b529b8f
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 50 deletions.
17 changes: 14 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Now you can use DiffUtilCompositeAdapter just like the base RecyclerView.Adapter

![example](https://github.com/Liverm0r/DelegateAdapters/blob/master/feed_example.jpg)


## Example of usage in Java

Write a Model:
Expand Down
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.10'
ext.kotlin_version = '1.3.40'
repositories {
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

ext {
minSdk = "14"
compileSdk = 28
targetSdk = 28
supportLib = "28.0.0"
buildTool = "27.0.3"
compileSdk = 29
targetSdk = 29
buildTool = "29.0.0"
androidX = "1.0.2"
recycler = "1.0.0"
}

allprojects {
Expand Down
12 changes: 7 additions & 5 deletions delegateadapter/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

group='com.github.Liverm0r'

Expand All @@ -14,7 +14,7 @@ android {
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

Expand All @@ -31,9 +31,11 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$supportLib"
implementation "com.android.support:recyclerview-v7:$supportLib"
implementation "androidx.appcompat:appcompat:$androidX"
implementation "androidx.recyclerview:recyclerview:$recycler"
testImplementation 'junit:junit:4.12'
implementation "androidx.core:core-ktx:$androidX"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.example.delegateadapter.delegate;

import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.example.delegateadapter.delegate;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
* @author dumchev on 04.11.17.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.example.delegateadapter.delegate;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.example.delegateadapter.delegate;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.example.delegateadapter.delegate.diff;

import android.support.annotation.NonNull;
import android.support.v7.util.DiffUtil;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.example.delegateadapter.delegate.diff;

import android.support.annotation.NonNull;
import android.support.v7.util.DiffUtil;
import android.util.SparseArray;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;

import com.example.delegateadapter.delegate.CompositeDelegateAdapter;
import com.example.delegateadapter.delegate.IDelegateAdapter;

Expand Down
13 changes: 9 additions & 4 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion compileSdk
Expand All @@ -11,7 +11,7 @@ android {
targetSdkVersion targetSdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -27,7 +27,12 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':delegateadapter')
implementation "com.android.support:recyclerview-v7:$supportLib"
implementation "com.android.support:appcompat-v7:$supportLib"
implementation "androidx.recyclerview:recyclerview:$recycler"
implementation "androidx.appcompat:appcompat:$androidX"
testImplementation 'junit:junit:4.12'
implementation "androidx.core:core-ktx:$androidX"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
5 changes: 5 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
android:label="@string/title_activity_base_example"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".base.KotlinBaseExampleActivity"
android:label="@string/title_activity_base_example"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.dumchev.delegateadapters.base.BaseExampleActivity;
import androidx.appcompat.app.AppCompatActivity;

import com.example.dumchev.delegateadapters.base.KotlinBaseExampleActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startActivity(new Intent(this, BaseExampleActivity.class));
startActivity(new Intent(this, KotlinBaseExampleActivity.class));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.dumchev.delegateadapters.base;

import android.support.annotation.NonNull;
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 androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.delegateadapter.delegate.diff.IComparableItem;
import com.example.dumchev.delegateadapters.R;
import com.example.dumchev.delegateadapters.base.model.ImageViewModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.dumchev.delegateadapters.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.delegateadapter.delegate.diff.DiffUtilCompositeAdapter;
import com.example.dumchev.delegateadapters.R;
import com.example.dumchev.delegateadapters.base.adapter.CheckDelegateAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.dumchev.delegateadapters.base

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.delegateadapter.delegate.diff.DiffUtilCompositeAdapter
import com.example.dumchev.delegateadapters.base.adapter.CheckDelegateAdapter
import com.example.dumchev.delegateadapters.base.adapter.GenerateItemsDelegateAdapter
import com.example.dumchev.delegateadapters.base.adapter.TextDelegateAdapter
import kotlinx.android.synthetic.main.activity_base_example.*

class KotlinBaseExampleActivity : AppCompatActivity() {

private val diffAdapter by lazy {
DiffUtilCompositeAdapter.Builder()
.add(GenerateItemsDelegateAdapter { generateNewData() })
.add(TextDelegateAdapter())
.add(CheckDelegateAdapter())
.build()
}

private fun generateNewData() {
diffAdapter.swapData(MockDataFactory.prepareData())
rv.scrollToPosition(0)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(com.example.dumchev.delegateadapters.R.layout.activity_base_example)
rv.run {
layoutManager = LinearLayoutManager(this@KotlinBaseExampleActivity)
adapter = diffAdapter
generateNewData()
}
}

fun onGenerateButtonClicked(view: View) {
diffAdapter.swapData(MockDataFactory.prepareData())
rv.scrollToPosition(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.delegateadapter.delegate.diff.IComparableItem;
import com.example.dumchev.delegateadapters.R;
import com.example.dumchev.delegateadapters.base.model.CheckViewModel;
import com.example.dumchev.delegateadapters.base.model.IViewModel;
import com.example.dumchev.delegateadapters.base.model.ImageViewModel;
import com.example.dumchev.delegateadapters.base.model.TextViewModel;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.dumchev.delegateadapters.base.adapter

import com.example.delegateadapter.delegate.KDelegateAdapter
import com.example.dumchev.delegateadapters.R
import com.example.dumchev.delegateadapters.base.model.ImageViewModel
import kotlinx.android.synthetic.main.image_item.*

class GenerateItemsDelegateAdapter(private val generateNewItems: () -> Unit) :
KDelegateAdapter<ImageViewModel>() {

override fun onBind(item: ImageViewModel, viewHolder: KViewHolder) = with(viewHolder) {
tv_title.text = item.title
img_bg.setImageResource(item.imageRes)
itemView.setOnClickListener { generateNewItems() }
}

override fun getLayoutId(): Int = R.layout.image_item

override fun isForViewType(items: List<*>, position: Int) = items[position] is ImageViewModel
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.dumchev.delegateadapters.base.adapter;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;

import com.example.delegateadapter.delegate.BaseDelegateAdapter;
import com.example.delegateadapter.delegate.BaseViewHolder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.dumchev.delegateadapters.base.model

import android.support.annotation.DrawableRes

import androidx.annotation.DrawableRes
import com.example.delegateadapter.delegate.diff.IComparableItem

/**
Expand Down
Loading

0 comments on commit b529b8f

Please sign in to comment.