Skip to content

Commit c5751cb

Browse files
author
Mazen Rashed
committed
Preparing to release 1.0
1 parent 5de74d1 commit c5751cb

File tree

7 files changed

+27
-63
lines changed

7 files changed

+27
-63
lines changed

RxPaginationLib/src/main/java/com/mazenrashed/rxpaginationlib/DataChanges.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

RxPaginationLib/src/main/java/com/mazenrashed/rxpaginationlib/PaginationListManagerImpl.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.jakewharton.rxrelay2.BehaviorRelay
44
import com.mazenrashed.rxpaginationlib.RxPagination.Companion.ALL_ITEMS_EFFECTED
55

66
class PaginationListManagerImpl<T>(
7-
private val dataChanges: BehaviorRelay<DataChanges<T>>,
7+
private val dataList: BehaviorRelay<ArrayList<T>>,
88
private var page: BehaviorRelay<Int>,
99
private val pageSize : Int,
1010
private var isLastPage: BehaviorRelay<Boolean>
@@ -13,24 +13,20 @@ class PaginationListManagerImpl<T>(
1313

1414
override fun addToList(newMembers: ArrayList<T>) {
1515
if (isLastPage.value == true) return
16-
dataChanges.accept(
17-
dataChanges.value.apply {
16+
dataList.accept(
17+
dataList.value.apply {
1818
if (page.value == 0)
19-
this?.list?.clear()
19+
this?.clear()
2020
if (newMembers.isEmpty()) {
2121
isLastPage.accept(true)
2222
return@apply
2323
}
2424

25-
this?.list?.addAll(newMembers.apply {
25+
this?.addAll(newMembers.apply {
2626
if (this.size < pageSize)
2727
isLastPage.accept(true)
2828
})
29-
} ?: DataChanges(
30-
ArrayList(),
31-
ALL_ITEMS_EFFECTED,
32-
RxPagination.TransactionTypes.REPLACE_ALL
33-
)
29+
} ?: ArrayList()
3430
)
3531
page.accept(page.value?.plus(1) ?: 0)
3632
}

RxPaginationLib/src/main/java/com/mazenrashed/rxpaginationlib/RxPagination.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ abstract class RxPagination<T>(
1616

1717
private val bag = CompositeDisposable()
1818

19-
val dataList = BehaviorRelay.createDefault(
20-
DataChanges<T>(
21-
ArrayList(),
22-
ALL_ITEMS_EFFECTED,
23-
TransactionTypes.REPLACE_ALL
24-
)
25-
)
26-
19+
val dataList = BehaviorRelay.createDefault(ArrayList<T>())
2720
var page = BehaviorRelay.createDefault(firstPage)
2821
var isLastPage = BehaviorRelay.createDefault(false)
2922

@@ -49,7 +42,7 @@ abstract class RxPagination<T>(
4942

5043
abstract fun onFetchDataListSubscribed()
5144

52-
abstract fun onFetchDataListSuccess(dataList: ArrayList<T>)
45+
abstract fun onFetchDataListSuccess(lastLoadedList: ArrayList<T>)
5346

5447
abstract fun onFetchDataListError(throwable: Throwable)
5548

app/src/main/java/com/mazenrashed/rxpagination/data/repository/GithubRepositoryRepository.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ class GithubRepositoryRepository : ListRepository<GithubRepository> {
1414
return endPoints.getRepositories(pageSize, page)
1515
}
1616

17-
1817
}

app/src/main/java/com/mazenrashed/rxpagination/ui/GithubRepositoriesViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class GithubRepositoriesViewModel :
1010

1111
val isLoading = BehaviorRelay.createDefault(false)
1212

13-
1413
init {
1514
loadDataList()
1615
}
@@ -21,9 +20,10 @@ class GithubRepositoriesViewModel :
2120

2221
override fun onFetchDataListError(throwable: Throwable) {
2322
isLoading.accept(false)
23+
throwable.printStackTrace()
2424
}
2525

26-
override fun onFetchDataListSuccess(dataList: ArrayList<GithubRepository>) {
26+
override fun onFetchDataListSuccess(lastLoadedList: ArrayList<GithubRepository>) {
2727
isLoading.accept(false)
2828
}
2929

app/src/main/java/com/mazenrashed/rxpagination/ui/MainActivity.kt

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.mazenrashed.rxpagination.ui
22

33
import android.os.Bundle
4-
import android.util.Log
4+
import android.view.View
55
import androidx.activity.viewModels
66
import androidx.appcompat.app.AppCompatActivity
7-
import com.google.gson.Gson
87
import com.mazenrashed.rxpagination.R
98
import com.mazenrashed.rxpagination.data.model.GithubRepository
10-
import com.mazenrashed.rxpaginationlib.RxPagination
119
import io.reactivex.android.schedulers.AndroidSchedulers
1210
import io.reactivex.disposables.CompositeDisposable
1311
import io.reactivex.rxkotlin.addTo
@@ -35,41 +33,15 @@ class MainActivity : AppCompatActivity() {
3533
.observeOn(AndroidSchedulers.mainThread())
3634
.subscribe {
3735
refresh_layout.isRefreshing = it
36+
progress_bar.visibility = if (it) View.VISIBLE else View.GONE
3837
}.addTo(bag)
39-
// Observable.interval(7, TimeUnit.SECONDS)
40-
// .subscribe({
41-
// if (viewModel.isLastPage.value == false)
42-
// viewModel.loadDataList()
43-
// }, {
44-
// it.printStackTrace()
45-
// })
46-
// .addTo(bag)
4738

4839
viewModel
4940
.dataList
5041
.observeOn(AndroidSchedulers.mainThread())
51-
.subscribe {
52-
it.effectedItem.let {
53-
Log.d(
54-
"Effected item",
55-
if (it == RxPagination.ALL_ITEMS_EFFECTED) "All Items" else it.toString()
56-
)
57-
}
58-
59-
Log.d(
60-
"Transaction type",
61-
when (it.transactionType) {
62-
RxPagination.TransactionTypes.ADD -> "Add"
63-
RxPagination.TransactionTypes.DELETE -> "Delete"
64-
RxPagination.TransactionTypes.MODIFY -> "Modify"
65-
RxPagination.TransactionTypes.REPLACE_ALL -> "Replace All"
66-
}
67-
)
68-
69-
Log.d("list", Gson().toJson(it.list.map { it.name }))
70-
71-
dataList.clear()
72-
dataList.addAll(it.list)
42+
.subscribe { dataList ->
43+
this.dataList.clear()
44+
this.dataList.addAll(dataList)
7345
adapter.notifyDataSetChanged()
7446
}
7547
.addTo(bag)

app/src/main/res/layout/activity_main.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
android:layout_height="match_parent"
77
tools:context=".ui.MainActivity">
88

9+
<ProgressBar
10+
android:id="@+id/progress_bar"
11+
style="?android:attr/progressBarStyle"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
app:layout_constraintStart_toStartOf="parent"
15+
app:layout_constraintEnd_toEndOf="parent"
16+
app:layout_constraintTop_toTopOf="parent"
17+
app:layout_constraintBottom_toBottomOf="parent"
18+
android:elevation="2dp"/>
19+
920
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1021
android:id="@+id/refresh_layout"
1122
android:layout_width="0dp"
@@ -21,6 +32,7 @@
2132
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
2233
tools:itemCount="4"
2334
tools:listitem="@layout/repo_item"/>
35+
2436
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
2537

2638
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)