From e4fbb2a6b6b5295957fc344bff1e75923764b228 Mon Sep 17 00:00:00 2001 From: Arman Chatikyan Date: Mon, 16 Oct 2017 13:36:48 +0400 Subject: [PATCH] Updated to kotlin 1.2 --- app/build.gradle | 6 ++-- .../io/armcha/ribble/domain/entity/Image.kt | 8 +----- .../io/armcha/ribble/domain/entity/Shot.kt | 13 +-------- .../io/armcha/ribble/domain/entity/User.kt | 9 +----- .../presentation/adapter/AbstractAdapter.kt | 28 +++++++++++++------ .../presentation/screen/shot/ShotFragment.kt | 2 +- .../presentation/screen/shot/ShotPresenter.kt | 6 ++-- .../screen/shot_detail/ShotDetailFragment.kt | 2 +- .../user_following/UserFollowingFragment.kt | 2 +- .../screen/user_likes/UserLikesFragment.kt | 5 ++-- baseMVP/build.gradle | 2 +- build.gradle | 9 ++++-- 12 files changed, 42 insertions(+), 50 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e764dcf..051fc4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -71,9 +71,9 @@ dependencies { implementation "com.android.support.constraint:constraint-layout:1.0.2" //Database - implementation "android.arch.persistence.room:runtime:1.0.0-beta1" - implementation "android.arch.persistence.room:rxjava2:1.0.0-beta1" - kapt "android.arch.persistence.room:compiler:1.0.0-beta1" + implementation "android.arch.persistence.room:runtime:1.0.0-beta2" + implementation "android.arch.persistence.room:rxjava2:1.0.0-beta2" + kapt "android.arch.persistence.room:compiler:1.0.0-beta2" //RX implementation "io.reactivex.rxjava2:rxjava:${rxJavaVersion}" diff --git a/app/src/main/kotlin/io/armcha/ribble/domain/entity/Image.kt b/app/src/main/kotlin/io/armcha/ribble/domain/entity/Image.kt index d041ef8..e963532 100644 --- a/app/src/main/kotlin/io/armcha/ribble/domain/entity/Image.kt +++ b/app/src/main/kotlin/io/armcha/ribble/domain/entity/Image.kt @@ -13,10 +13,4 @@ import kotlinx.android.parcel.Parcelize @Parcelize data class Image(val small: String = emptyString, val normal: String = emptyString, - val big: String = emptyString) : Parcelable { - - constructor(parcel: Parcel) : this( - parcel.readString(), - parcel.readString(), - parcel.readString()) -} \ No newline at end of file + val big: String = emptyString) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/io/armcha/ribble/domain/entity/Shot.kt b/app/src/main/kotlin/io/armcha/ribble/domain/entity/Shot.kt index 15bfa60..0d7367b 100644 --- a/app/src/main/kotlin/io/armcha/ribble/domain/entity/Shot.kt +++ b/app/src/main/kotlin/io/armcha/ribble/domain/entity/Shot.kt @@ -17,15 +17,4 @@ data class Shot constructor(val title: String?, var description: String? = null, var likesCount: Int? = null, var viewsCount: Int? = null, - var bucketCount: Int? = null) : Parcelable { - - constructor(parcel: Parcel) : this( - parcel.readString(), - parcel.readString(), - parcel.readParcelable(Image::class.java.classLoader), - parcel.readParcelable(User::class.java.classLoader), - parcel.readString(), - parcel.readValue(Int::class.java.classLoader) as? Int, - parcel.readValue(Int::class.java.classLoader) as? Int, - parcel.readValue(Int::class.java.classLoader) as? Int) -} \ No newline at end of file + var bucketCount: Int? = null) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/io/armcha/ribble/domain/entity/User.kt b/app/src/main/kotlin/io/armcha/ribble/domain/entity/User.kt index 3286351..0d0f4a7 100644 --- a/app/src/main/kotlin/io/armcha/ribble/domain/entity/User.kt +++ b/app/src/main/kotlin/io/armcha/ribble/domain/entity/User.kt @@ -14,11 +14,4 @@ import kotlinx.android.parcel.Parcelize data class User constructor(val name: String?, val avatarUrl: String = emptyString, val username: String?, - val location: String?) : Parcelable { - - constructor(parcel: Parcel) : this( - parcel.readString(), - parcel.readString(), - parcel.readString(), - parcel.readString()) -} \ No newline at end of file + val location: String?) : Parcelable \ No newline at end of file diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/adapter/AbstractAdapter.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/adapter/AbstractAdapter.kt index 3ba9cbb..30a962a 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/adapter/AbstractAdapter.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/adapter/AbstractAdapter.kt @@ -4,6 +4,8 @@ import android.support.v7.widget.RecyclerView import android.view.View import android.view.ViewGroup import io.armcha.ribble.presentation.utils.extensions.inflate +import io.reactivex.annotations.Experimental +import kotlin.system.measureNanoTime /** * Created by Chatikyan on 14.08.2017. @@ -12,9 +14,7 @@ abstract class AbstractAdapter constructor(protected var itemList: List() { - override fun getItemCount(): Int { - return itemList.size - } + override fun getItemCount() = itemList.size override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { val view = parent inflate layoutResId @@ -34,12 +34,23 @@ abstract class AbstractAdapter constructor(protected var itemList: List) { - this.itemList = itemList - notifyDataSetChanged()//TODO + fun addAll(itemList: List) { + val startPosition = this.itemList.size + this.itemList.toMutableList().addAll(itemList) + notifyItemRangeInserted(startPosition, this.itemList.size) + } + + fun add(item: ITEM) { + itemList.toMutableList().add(item) + notifyItemInserted(itemList.size) + } + + fun remove(position: Int) { + itemList.toMutableList().removeAt(position) + notifyItemRemoved(position) } - final override fun onViewRecycled(holder: AbstractAdapter.Holder) { + final override fun onViewRecycled(holder: Holder) { super.onViewRecycled(holder) onViewRecycled(holder.itemView) } @@ -50,8 +61,7 @@ abstract class AbstractAdapter constructor(protected var itemList: List(), override fun getShotType() = extraWithKey(SHOT_TYPE) private fun updateAdapter(shotList: List) { - recyclerAdapter?.update(shotList) ?: this setUpRecyclerView shotList + recyclerAdapter?.addAll(shotList) ?: this setUpRecyclerView shotList } private infix fun setUpRecyclerView(shotList: List) { diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot/ShotPresenter.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot/ShotPresenter.kt index 52836bc..f3e3c49 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot/ShotPresenter.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot/ShotPresenter.kt @@ -5,6 +5,7 @@ import android.arch.lifecycle.OnLifecycleEvent import io.armcha.ribble.domain.entity.Shot import io.armcha.ribble.domain.interactor.ShotListInteractor import io.armcha.ribble.presentation.base_mvp.api.ApiPresenter +import io.armcha.ribble.presentation.utils.extensions.log import javax.inject.Inject /** @@ -13,10 +14,9 @@ import javax.inject.Inject class ShotPresenter @Inject constructor(private val shotListInteractor: ShotListInteractor) : ApiPresenter(), ShotContract.Presenter { - private val isPopularType = view?.getShotType() == TYPE_POPULAR - @OnLifecycleEvent(value = Lifecycle.Event.ON_START) fun onStart() { + val isPopularType = view?.getShotType() == TYPE_POPULAR val requestType = if (isPopularType) POPULAR_SHOTS else RECENT_SHOTS when (requestType.status) { @@ -42,7 +42,7 @@ class ShotPresenter @Inject constructor(private val shotListInteractor: ShotList view?.showNoShots() ?: Unit } } - + val isPopularType = view?.getShotType() == TYPE_POPULAR if (isPopularType) fetch(shotListInteractor.popularShotList(100), POPULAR_SHOTS, success) else diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt index 49118df..7fed8cc 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt @@ -118,7 +118,7 @@ class ShotDetailFragment : BaseFragment) { - recyclerAdapter?.update(commentList) ?: this setUpRecyclerView commentList + recyclerAdapter?.addAll(commentList) ?: this setUpRecyclerView commentList } private infix fun setUpRecyclerView(commentList: List) { diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_following/UserFollowingFragment.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_following/UserFollowingFragment.kt index 28493cf..c655cfd 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_following/UserFollowingFragment.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_following/UserFollowingFragment.kt @@ -66,7 +66,7 @@ class UserFollowingFragment : BaseFragment) { - recyclerAdapter?.update(shotList) ?: setUpRecyclerView(shotList) + recyclerAdapter?.addAll(shotList) ?: setUpRecyclerView(shotList) } private fun setUpRecyclerView(shotList: List) { diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_likes/UserLikesFragment.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_likes/UserLikesFragment.kt index d688b56..e4d31f3 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_likes/UserLikesFragment.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_likes/UserLikesFragment.kt @@ -8,6 +8,7 @@ import io.armcha.ribble.domain.entity.Like import io.armcha.ribble.presentation.adapter.RibbleAdapter import io.armcha.ribble.presentation.base_mvp.base.BaseFragment import io.armcha.ribble.presentation.screen.shot_detail.ShotDetailFragment +import io.armcha.ribble.presentation.utils.C import io.armcha.ribble.presentation.utils.L import io.armcha.ribble.presentation.utils.S import io.armcha.ribble.presentation.utils.extensions.takeColor @@ -28,7 +29,7 @@ class UserLikesFragment : BaseFragment) { - recyclerAdapter?.update(likeList) ?: this setUpRecyclerView likeList + recyclerAdapter?.addAll(likeList) ?: this setUpRecyclerView likeList } private infix fun setUpRecyclerView(likeList: List) { diff --git a/baseMVP/build.gradle b/baseMVP/build.gradle index c5982aa..2189ed8 100644 --- a/baseMVP/build.gradle +++ b/baseMVP/build.gradle @@ -18,7 +18,7 @@ android { } } -ext.archVersion = '1.0.0-beta1' +ext.archVersion = '1.0.0-beta2' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' diff --git a/build.gradle b/build.gradle index b234098..f8abd1f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,14 @@ buildscript { - ext.kotlin_version = '1.1.51' + ext.kotlin_version = '1.2.0-beta-31' repositories { google() jcenter() + mavenCentral() + maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' } } + dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-beta7' + classpath 'com.android.tools.build:gradle:3.0.0-rc1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -14,6 +17,8 @@ allprojects { repositories { google() jcenter() + mavenCentral() + maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' } } }