Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 8b38e9f

Browse files
authored
Merge pull request #75 from android/yaraki/Motion-update
Motion: Update dependencies
2 parents 088fa35 + 8d2b7d3 commit 8b38e9f

File tree

11 files changed

+71
-73
lines changed

11 files changed

+71
-73
lines changed

.github/workflows/android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828

2929
steps:
3030
- uses: actions/checkout@v1
31-
- name: set up JDK 1.8
31+
- name: set up JDK 11
3232
uses: actions/setup-java@v1
3333
with:
34-
java-version: 1.8
34+
java-version: 11
3535
- name: Build project
3636
run: .github/scripts/gradlew_recursive.sh assembleDebug
3737
- name: Zip artifacts

Motion/.idea/codeStyles/Project.xml

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Motion/.idea/codeStyles/codeStyleConfig.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Motion/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Motion/app/build.gradle

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,33 @@ android {
5151
dependencies {
5252
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
5353

54-
implementation 'androidx.core:core-ktx:1.3.2'
55-
implementation 'androidx.fragment:fragment-ktx:1.2.5'
56-
implementation 'androidx.appcompat:appcompat:1.2.0'
57-
implementation 'androidx.transition:transition:1.3.1'
54+
implementation 'androidx.core:core-ktx:1.6.0'
55+
implementation 'androidx.fragment:fragment-ktx:1.3.6'
56+
implementation 'androidx.appcompat:appcompat:1.3.1'
57+
implementation 'androidx.transition:transition:1.4.1'
5858
implementation 'androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03'
59-
implementation 'androidx.recyclerview:recyclerview:1.1.0'
59+
implementation 'androidx.recyclerview:recyclerview:1.2.1'
6060

61-
implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
61+
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
6262

63-
def lifecycle_version = '2.2.0'
63+
def lifecycle_version = '2.3.1'
6464
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
6565
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
6666

67-
def paging_version = '2.1.2'
68-
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
67+
implementation 'androidx.paging:paging-runtime-ktx:3.0.1'
6968

70-
implementation 'com.google.android.material:material:1.2.1'
69+
implementation 'com.google.android.material:material:1.4.0'
7170

7271
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
7372
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
7473

7574
implementation 'com.github.bumptech.glide:glide:4.9.0'
7675

77-
testImplementation 'junit:junit:4.13.1'
78-
testImplementation 'com.google.truth:truth:1.0.1'
76+
testImplementation 'junit:junit:4.13.2'
77+
testImplementation 'com.google.truth:truth:1.1.3'
7978

80-
testImplementation 'androidx.test:core:1.3.0'
81-
androidTestImplementation 'androidx.test.ext:truth:1.3.0'
82-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
83-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
79+
testImplementation 'androidx.test:core:1.4.0'
80+
androidTestImplementation 'androidx.test.ext:truth:1.4.0'
81+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
82+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
8483
}

Motion/app/src/main/java/com/example/android/motion/demo/loading/CheeseAdapter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import android.view.ViewGroup
2424
import android.widget.ImageView
2525
import android.widget.TextView
2626
import androidx.core.animation.doOnEnd
27-
import androidx.paging.PagedListAdapter
27+
import androidx.paging.PagingDataAdapter
2828
import androidx.recyclerview.widget.RecyclerView
2929
import com.bumptech.glide.Glide
3030
import com.bumptech.glide.load.resource.bitmap.CircleCrop
3131
import com.example.android.motion.R
3232
import com.example.android.motion.model.Cheese
3333

34-
internal class CheeseAdapter : PagedListAdapter<Cheese, CheeseViewHolder>(Cheese.DIFF_CALLBACK) {
34+
internal class CheeseAdapter : PagingDataAdapter<Cheese, CheeseViewHolder>(Cheese.DIFF_CALLBACK) {
3535

3636
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheeseViewHolder {
3737
return CheeseViewHolder(parent)
@@ -90,7 +90,7 @@ internal class CheeseViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder(
9090
// Shift the timing of fade-in/out for each item by its adapter position. We use the
9191
// elapsed real time to make this independent from the timing of method call.
9292
animation.currentPlayTime =
93-
(SystemClock.elapsedRealtime() - adapterPosition * 30L) % FADE_DURATION
93+
(SystemClock.elapsedRealtime() - bindingAdapterPosition * 30L) % FADE_DURATION
9494
animation.start()
9595
// Show the placeholder UI.
9696
image.setImageResource(R.drawable.image_placeholder)

Motion/app/src/main/java/com/example/android/motion/demo/loading/CheeseDataSource.kt

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,45 @@
1616

1717
package com.example.android.motion.demo.loading
1818

19-
import android.os.SystemClock
20-
import androidx.paging.DataSource
21-
import androidx.paging.PositionalDataSource
19+
import androidx.paging.PagingSource
20+
import androidx.paging.PagingState
2221
import com.example.android.motion.model.Cheese
22+
import kotlinx.coroutines.delay
2323

24-
class CheeseDataSource : PositionalDataSource<Cheese>() {
24+
class CheeseDataSource : PagingSource<Int, Cheese>() {
2525

26-
companion object Factory : DataSource.Factory<Int, Cheese>() {
27-
override fun create(): DataSource<Int, Cheese> = CheeseDataSource()
26+
override fun getRefreshKey(state: PagingState<Int, Cheese>): Int? {
27+
return state.anchorPosition
2828
}
2929

30-
override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback<Cheese>) {
31-
// Simulate a slow network.
32-
SystemClock.sleep(3000L)
33-
callback.onResult(
34-
Cheese.ALL.subList(
35-
params.requestedStartPosition,
36-
params.requestedStartPosition + params.requestedLoadSize
37-
),
38-
params.requestedStartPosition,
39-
Cheese.ALL.size
40-
)
30+
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Cheese> {
31+
return params.key.let { position ->
32+
if (position == null) {
33+
LoadResult.Page(
34+
emptyList(),
35+
prevKey = null,
36+
nextKey = 0,
37+
itemsBefore = 0,
38+
itemsAfter = Cheese.ALL.size
39+
)
40+
} else {
41+
// Simulate slow network.
42+
delay(3000)
43+
LoadResult.Page(
44+
Cheese.ALL.subList(
45+
position,
46+
(position + params.loadSize).coerceAtMost(Cheese.ALL.size)
47+
),
48+
prevKey = (position - params.loadSize).orNullIf { it < 0 },
49+
nextKey = (position + params.loadSize).orNullIf { it >= Cheese.ALL.size },
50+
itemsBefore = position,
51+
itemsAfter = Cheese.ALL.size - position
52+
)
53+
}
54+
}
4155
}
56+
}
4257

43-
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Cheese>) {
44-
// Simulate a slow network.
45-
SystemClock.sleep(3000L)
46-
callback.onResult(
47-
Cheese.ALL.subList(
48-
params.startPosition, params.startPosition + params.loadSize
49-
)
50-
)
51-
}
58+
private fun Int.orNullIf(condition: (Int) -> Boolean): Int? {
59+
return if (condition(this)) null else this
5260
}

Motion/app/src/main/java/com/example/android/motion/demo/loading/LoadingActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class LoadingActivity : AppCompatActivity() {
8282
list.itemAnimator = null
8383
TransitionManager.beginDelayedTransition(list, fade)
8484
}
85-
cheeseAdapter.submitList(cheeses)
85+
cheeseAdapter.submitData(lifecycle, cheeses)
8686
}
8787
}
8888

Motion/app/src/main/java/com/example/android/motion/demo/loading/LoadingViewModel.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ package com.example.android.motion.demo.loading
1919
import androidx.lifecycle.LiveData
2020
import androidx.lifecycle.MediatorLiveData
2121
import androidx.lifecycle.ViewModel
22-
import androidx.paging.PagedList
23-
import androidx.paging.toLiveData
22+
import androidx.paging.Pager
23+
import androidx.paging.PagingConfig
24+
import androidx.paging.PagingData
25+
import androidx.paging.liveData
2426
import com.example.android.motion.model.Cheese
2527

2628
class LoadingViewModel : ViewModel() {
2729

28-
private var source: LiveData<PagedList<Cheese>>? = null
29-
private val _cheeses = MediatorLiveData<PagedList<Cheese>>()
30-
val cheeses: LiveData<PagedList<Cheese>> = _cheeses
30+
private var source: LiveData<PagingData<Cheese>>? = null
31+
private val _cheeses = MediatorLiveData<PagingData<Cheese>>()
32+
val cheeses: LiveData<PagingData<Cheese>> = _cheeses
3133

3234
init {
3335
refresh()
3436
}
3537

3638
fun refresh() {
3739
source?.let { _cheeses.removeSource(it) }
38-
val s = CheeseDataSource.toLiveData(pageSize = 15)
40+
val s = Pager(PagingConfig(pageSize = 15)) {
41+
CheeseDataSource()
42+
}.liveData
3943
source = s
4044
_cheeses.addSource(s) { _cheeses.postValue(it) }
4145
}

Motion/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616

1717
buildscript {
18-
ext.kotlin_version = '1.4.10'
19-
ext.navigation_version = '2.3.1'
18+
ext.kotlin_version = '1.5.30'
19+
ext.navigation_version = '2.3.5'
2020
repositories {
2121
google()
2222
mavenCentral()
2323
}
2424
dependencies {
25-
classpath 'com.android.tools.build:gradle:4.2.2'
25+
classpath 'com.android.tools.build:gradle:7.0.2'
2626
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2727
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
2828
}

0 commit comments

Comments
 (0)