Skip to content

Commit

Permalink
integrated autosubscription and new deletefromcollection method
Browse files Browse the repository at this point in the history
  • Loading branch information
victordigio committed Nov 7, 2017
1 parent 16ad009 commit 1f6711d
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 86 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=1.0.9
VERSION_CODE=10
VERSION_NAME=1.1.0
VERSION_CODE=11
GROUP=com.github.vicpinm

POM_DESCRIPTION=Kotlin Presenter Adapter
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 23 20:33:49 CET 2016
#Tue Nov 07 12:54:24 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile "com.github.vicpinm:autosubscription:1.0.2"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ abstract class PresenterAdapter<T : Any>() : RecyclerView.Adapter<ViewHolder<T>>

override fun onBindViewHolder(holder: ViewHolder<T>, position: Int) {
if(isNormalPosition(position)) {
holder.onBind(data, getPositionWithoutHeaders(position))
holder.onBind(data, getPositionWithoutHeaders(position), deleteListener = {
removeItem(it)
})
appendListeners(holder)
}
else if(isHeaderPosition(position)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ abstract class ViewHolder<T: Any> : RecyclerView.ViewHolder {
context = itemView.context
}

fun onBind(data: List<T>, position: Int){
setupPresenter(data)
fun onBind(data: List<T>, position: Int, deleteListener: (T) -> Unit){
setupPresenter(data, deleteListener)
presenter?.data = data[position]
presenter?.position = position
presenter?.onCreate()
Expand All @@ -35,13 +35,14 @@ abstract class ViewHolder<T: Any> : RecyclerView.ViewHolder {
}


private fun setupPresenter(data: List<T>){
private fun setupPresenter(data: List<T>, listener: ((T) -> Unit)? = null){
presenter?.setPresenterView(this)
presenter?.dataCollection = data
presenter?.setDeleteListener = listener
}


fun onDestroy(){
presenter?.onDestroy()
presenter?.onPreDestroy()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vicpin.kpresenteradapter

import com.vicpinm.autosubscription.Unsubscriber
import java.util.concurrent.atomic.AtomicInteger

/**
Expand All @@ -15,9 +16,9 @@ abstract class ViewHolderPresenter<Data : Any, PresenterView: Any> {
lateinit var data: Data
var position = 0
lateinit var dataCollection: List<Data>
var setDeleteListener: ((Data) -> Unit)? = null
val presenterId: Int by lazy { presenterIdsGenerator.andIncrement }


fun setPresenterView(view: Any){
this.view = view as? PresenterView
}
Expand All @@ -26,8 +27,18 @@ abstract class ViewHolderPresenter<Data : Any, PresenterView: Any> {
*/
abstract fun onCreate()

fun onPreDestroy(){
Unsubscriber.unlink(this)
onDestroy()
}

/**
* Called when the view is recycled and is no more visible in the adapter
*/
open fun onDestroy(){}

fun deleteItemFromCollection() {
setDeleteListener?.invoke(data)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CountryPresenter : ViewHolderPresenter<Country, CountryPresenter.View>() {
}

fun onDeleteItem() {
deleteItemFromCollection()
view?.deleteItem(data)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class MainFragment : Fragment(), ItemRecycledListener, ItemDeletedListener<Count
}

override fun onItemDeleted(item: Country) {
adapter.removeItem(item)
adapter.updateHeaders()
}

Expand Down

0 comments on commit 1f6711d

Please sign in to comment.