Skip to content

Commit

Permalink
Updated to kotlin 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
armcha committed Oct 16, 2017
1 parent 2dd1d3d commit e4fbb2a
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 50 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/kotlin/io/armcha/ribble/domain/entity/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
val big: String = emptyString) : Parcelable
13 changes: 1 addition & 12 deletions app/src/main/kotlin/io/armcha/ribble/domain/entity/Shot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
var bucketCount: Int? = null) : Parcelable
9 changes: 1 addition & 8 deletions app/src/main/kotlin/io/armcha/ribble/domain/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
val location: String?) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -12,9 +14,7 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
private val layoutResId: Int)
: RecyclerView.Adapter<AbstractAdapter.Holder>() {

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
Expand All @@ -34,12 +34,23 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
holder.itemView.bind(item)
}

fun update(itemList: List<ITEM>) {
this.itemList = itemList
notifyDataSetChanged()//TODO
fun addAll(itemList: List<ITEM>) {
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)
}
Expand All @@ -50,8 +61,7 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
protected open fun onItemClick(itemView: View, position: Int) {
}

open fun View.bind(item: ITEM){
//NO-OP
protected open fun View.bind(item: ITEM) {
}

class Holder(itemView: View) : RecyclerView.ViewHolder(itemView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ShotFragment : BaseFragment<ShotContract.View, ShotContract.Presenter>(),
override fun getShotType() = extraWithKey<String>(SHOT_TYPE)

private fun updateAdapter(shotList: List<Shot>) {
recyclerAdapter?.update(shotList) ?: this setUpRecyclerView shotList
recyclerAdapter?.addAll(shotList) ?: this setUpRecyclerView shotList
}

private infix fun setUpRecyclerView(shotList: List<Shot>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -13,10 +14,9 @@ import javax.inject.Inject
class ShotPresenter @Inject constructor(private val shotListInteractor: ShotListInteractor)
: ApiPresenter<ShotContract.View>(), 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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ShotDetailFragment : BaseFragment<ShotDetailContract.View, ShotDetailContr
}

private fun updateAdapter(commentList: List<Comment>) {
recyclerAdapter?.update(commentList) ?: this setUpRecyclerView commentList
recyclerAdapter?.addAll(commentList) ?: this setUpRecyclerView commentList
}

private infix fun setUpRecyclerView(commentList: List<Comment>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class UserFollowingFragment : BaseFragment<UserFollowingContract.View, UserFollo
}

private fun updateAdapter(shotList: List<Shot>) {
recyclerAdapter?.update(shotList) ?: setUpRecyclerView(shotList)
recyclerAdapter?.addAll(shotList) ?: setUpRecyclerView(shotList)
}

private fun setUpRecyclerView(shotList: List<Shot>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +29,7 @@ class UserLikesFragment : BaseFragment<UserLikeContract.View, UserLikeContract.P

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
progressBar.backgroundCircleColor = takeColor(io.armcha.ribble.R.color.colorPrimary)
progressBar.backgroundCircleColor = takeColor(C.colorPrimary)
}

override fun injectDependencies() {
Expand Down Expand Up @@ -60,7 +61,7 @@ class UserLikesFragment : BaseFragment<UserLikeContract.View, UserLikeContract.P
}

private fun updateAdapter(likeList: List<Like>) {
recyclerAdapter?.update(likeList) ?: this setUpRecyclerView likeList
recyclerAdapter?.addAll(likeList) ?: this setUpRecyclerView likeList
}

private infix fun setUpRecyclerView(likeList: List<Like>) {
Expand Down
2 changes: 1 addition & 1 deletion baseMVP/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand All @@ -14,6 +17,8 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2' }
}
}

Expand Down

0 comments on commit e4fbb2a

Please sign in to comment.