Skip to content

Commit e4fbb2a

Browse files
committed
Updated to kotlin 1.2
1 parent 2dd1d3d commit e4fbb2a

12 files changed

Lines changed: 42 additions & 50 deletions

File tree

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ dependencies {
7171
implementation "com.android.support.constraint:constraint-layout:1.0.2"
7272

7373
//Database
74-
implementation "android.arch.persistence.room:runtime:1.0.0-beta1"
75-
implementation "android.arch.persistence.room:rxjava2:1.0.0-beta1"
76-
kapt "android.arch.persistence.room:compiler:1.0.0-beta1"
74+
implementation "android.arch.persistence.room:runtime:1.0.0-beta2"
75+
implementation "android.arch.persistence.room:rxjava2:1.0.0-beta2"
76+
kapt "android.arch.persistence.room:compiler:1.0.0-beta2"
7777

7878
//RX
7979
implementation "io.reactivex.rxjava2:rxjava:${rxJavaVersion}"

app/src/main/kotlin/io/armcha/ribble/domain/entity/Image.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@ import kotlinx.android.parcel.Parcelize
1313
@Parcelize
1414
data class Image(val small: String = emptyString,
1515
val normal: String = emptyString,
16-
val big: String = emptyString) : Parcelable {
17-
18-
constructor(parcel: Parcel) : this(
19-
parcel.readString(),
20-
parcel.readString(),
21-
parcel.readString())
22-
}
16+
val big: String = emptyString) : Parcelable

app/src/main/kotlin/io/armcha/ribble/domain/entity/Shot.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,4 @@ data class Shot constructor(val title: String?,
1717
var description: String? = null,
1818
var likesCount: Int? = null,
1919
var viewsCount: Int? = null,
20-
var bucketCount: Int? = null) : Parcelable {
21-
22-
constructor(parcel: Parcel) : this(
23-
parcel.readString(),
24-
parcel.readString(),
25-
parcel.readParcelable(Image::class.java.classLoader),
26-
parcel.readParcelable(User::class.java.classLoader),
27-
parcel.readString(),
28-
parcel.readValue(Int::class.java.classLoader) as? Int,
29-
parcel.readValue(Int::class.java.classLoader) as? Int,
30-
parcel.readValue(Int::class.java.classLoader) as? Int)
31-
}
20+
var bucketCount: Int? = null) : Parcelable

app/src/main/kotlin/io/armcha/ribble/domain/entity/User.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,4 @@ import kotlinx.android.parcel.Parcelize
1414
data class User constructor(val name: String?,
1515
val avatarUrl: String = emptyString,
1616
val username: String?,
17-
val location: String?) : Parcelable {
18-
19-
constructor(parcel: Parcel) : this(
20-
parcel.readString(),
21-
parcel.readString(),
22-
parcel.readString(),
23-
parcel.readString())
24-
}
17+
val location: String?) : Parcelable

app/src/main/kotlin/io/armcha/ribble/presentation/adapter/AbstractAdapter.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import android.support.v7.widget.RecyclerView
44
import android.view.View
55
import android.view.ViewGroup
66
import io.armcha.ribble.presentation.utils.extensions.inflate
7+
import io.reactivex.annotations.Experimental
8+
import kotlin.system.measureNanoTime
79

810
/**
911
* Created by Chatikyan on 14.08.2017.
@@ -12,9 +14,7 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
1214
private val layoutResId: Int)
1315
: RecyclerView.Adapter<AbstractAdapter.Holder>() {
1416

15-
override fun getItemCount(): Int {
16-
return itemList.size
17-
}
17+
override fun getItemCount() = itemList.size
1818

1919
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
2020
val view = parent inflate layoutResId
@@ -34,12 +34,23 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
3434
holder.itemView.bind(item)
3535
}
3636

37-
fun update(itemList: List<ITEM>) {
38-
this.itemList = itemList
39-
notifyDataSetChanged()//TODO
37+
fun addAll(itemList: List<ITEM>) {
38+
val startPosition = this.itemList.size
39+
this.itemList.toMutableList().addAll(itemList)
40+
notifyItemRangeInserted(startPosition, this.itemList.size)
41+
}
42+
43+
fun add(item: ITEM) {
44+
itemList.toMutableList().add(item)
45+
notifyItemInserted(itemList.size)
46+
}
47+
48+
fun remove(position: Int) {
49+
itemList.toMutableList().removeAt(position)
50+
notifyItemRemoved(position)
4051
}
4152

42-
final override fun onViewRecycled(holder: AbstractAdapter.Holder) {
53+
final override fun onViewRecycled(holder: Holder) {
4354
super.onViewRecycled(holder)
4455
onViewRecycled(holder.itemView)
4556
}
@@ -50,8 +61,7 @@ abstract class AbstractAdapter<ITEM> constructor(protected var itemList: List<IT
5061
protected open fun onItemClick(itemView: View, position: Int) {
5162
}
5263

53-
open fun View.bind(item: ITEM){
54-
//NO-OP
64+
protected open fun View.bind(item: ITEM) {
5565
}
5666

5767
class Holder(itemView: View) : RecyclerView.ViewHolder(itemView)

app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot/ShotFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ShotFragment : BaseFragment<ShotContract.View, ShotContract.Presenter>(),
4646
override fun getShotType() = extraWithKey<String>(SHOT_TYPE)
4747

4848
private fun updateAdapter(shotList: List<Shot>) {
49-
recyclerAdapter?.update(shotList) ?: this setUpRecyclerView shotList
49+
recyclerAdapter?.addAll(shotList) ?: this setUpRecyclerView shotList
5050
}
5151

5252
private infix fun setUpRecyclerView(shotList: List<Shot>) {

app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot/ShotPresenter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.arch.lifecycle.OnLifecycleEvent
55
import io.armcha.ribble.domain.entity.Shot
66
import io.armcha.ribble.domain.interactor.ShotListInteractor
77
import io.armcha.ribble.presentation.base_mvp.api.ApiPresenter
8+
import io.armcha.ribble.presentation.utils.extensions.log
89
import javax.inject.Inject
910

1011
/**
@@ -13,10 +14,9 @@ import javax.inject.Inject
1314
class ShotPresenter @Inject constructor(private val shotListInteractor: ShotListInteractor)
1415
: ApiPresenter<ShotContract.View>(), ShotContract.Presenter {
1516

16-
private val isPopularType = view?.getShotType() == TYPE_POPULAR
17-
1817
@OnLifecycleEvent(value = Lifecycle.Event.ON_START)
1918
fun onStart() {
19+
val isPopularType = view?.getShotType() == TYPE_POPULAR
2020
val requestType = if (isPopularType) POPULAR_SHOTS else RECENT_SHOTS
2121

2222
when (requestType.status) {
@@ -42,7 +42,7 @@ class ShotPresenter @Inject constructor(private val shotListInteractor: ShotList
4242
view?.showNoShots() ?: Unit
4343
}
4444
}
45-
45+
val isPopularType = view?.getShotType() == TYPE_POPULAR
4646
if (isPopularType)
4747
fetch(shotListInteractor.popularShotList(100), POPULAR_SHOTS, success)
4848
else

app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ShotDetailFragment : BaseFragment<ShotDetailContract.View, ShotDetailContr
118118
}
119119

120120
private fun updateAdapter(commentList: List<Comment>) {
121-
recyclerAdapter?.update(commentList) ?: this setUpRecyclerView commentList
121+
recyclerAdapter?.addAll(commentList) ?: this setUpRecyclerView commentList
122122
}
123123

124124
private infix fun setUpRecyclerView(commentList: List<Comment>) {

app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_following/UserFollowingFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class UserFollowingFragment : BaseFragment<UserFollowingContract.View, UserFollo
6666
}
6767

6868
private fun updateAdapter(shotList: List<Shot>) {
69-
recyclerAdapter?.update(shotList) ?: setUpRecyclerView(shotList)
69+
recyclerAdapter?.addAll(shotList) ?: setUpRecyclerView(shotList)
7070
}
7171

7272
private fun setUpRecyclerView(shotList: List<Shot>) {

app/src/main/kotlin/io/armcha/ribble/presentation/screen/user_likes/UserLikesFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.armcha.ribble.domain.entity.Like
88
import io.armcha.ribble.presentation.adapter.RibbleAdapter
99
import io.armcha.ribble.presentation.base_mvp.base.BaseFragment
1010
import io.armcha.ribble.presentation.screen.shot_detail.ShotDetailFragment
11+
import io.armcha.ribble.presentation.utils.C
1112
import io.armcha.ribble.presentation.utils.L
1213
import io.armcha.ribble.presentation.utils.S
1314
import io.armcha.ribble.presentation.utils.extensions.takeColor
@@ -28,7 +29,7 @@ class UserLikesFragment : BaseFragment<UserLikeContract.View, UserLikeContract.P
2829

2930
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
3031
super.onViewCreated(view, savedInstanceState)
31-
progressBar.backgroundCircleColor = takeColor(io.armcha.ribble.R.color.colorPrimary)
32+
progressBar.backgroundCircleColor = takeColor(C.colorPrimary)
3233
}
3334

3435
override fun injectDependencies() {
@@ -60,7 +61,7 @@ class UserLikesFragment : BaseFragment<UserLikeContract.View, UserLikeContract.P
6061
}
6162

6263
private fun updateAdapter(likeList: List<Like>) {
63-
recyclerAdapter?.update(likeList) ?: this setUpRecyclerView likeList
64+
recyclerAdapter?.addAll(likeList) ?: this setUpRecyclerView likeList
6465
}
6566

6667
private infix fun setUpRecyclerView(likeList: List<Like>) {

0 commit comments

Comments
 (0)