-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5b3c72
commit 7723fb5
Showing
14 changed files
with
152 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/androidTest/java/com/karumi/jetpack/superheroes/ui/view/waitFor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.karumi.jetpack.superheroes.ui.view | ||
|
||
import android.view.View | ||
import androidx.test.espresso.UiController | ||
import androidx.test.espresso.ViewAction | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import org.hamcrest.Matcher | ||
|
||
fun waitFor(millis: Long): ViewAction { | ||
return object : ViewAction { | ||
override fun getConstraints(): Matcher<View> { | ||
return ViewMatchers.isRoot() | ||
} | ||
|
||
override fun getDescription(): String { | ||
return "Wait for $millis milliseconds." | ||
} | ||
|
||
override fun perform(uiController: UiController, view: View) { | ||
uiController.loopMainThreadForAtLeast(millis) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...c/main/java/com/karumi/jetpack/superheroes/data/repository/SuperHeroesBoundaryCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.karumi.jetpack.superheroes.data.repository | ||
|
||
import androidx.lifecycle.Observer | ||
import androidx.paging.PagedList | ||
import com.karumi.jetpack.superheroes.domain.model.SuperHero | ||
|
||
|
||
class SuperHeroesBoundaryCallback( | ||
private val local: LocalSuperHeroDataSource, | ||
private val remote: RemoteSuperHeroDataSource | ||
) : PagedList.BoundaryCallback<SuperHero>() { | ||
|
||
private var pageIndexAboutToLoad = 0 | ||
|
||
override fun onZeroItemsLoaded() { | ||
loadNextPage() | ||
} | ||
|
||
override fun onItemAtEndLoaded(itemAtEnd: SuperHero) { | ||
loadNextPage() | ||
} | ||
|
||
private fun loadNextPage() { | ||
val remoteSuperHeroesPage = | ||
remote.getSuperHeroesPage(pageIndexAboutToLoad, SuperHeroRepository.PAGE_SIZE) | ||
|
||
remoteSuperHeroesPage.observeForever(object : Observer<List<SuperHero>> { | ||
override fun onChanged(superHeroes: List<SuperHero>) { | ||
local.saveAll(superHeroes) | ||
remoteSuperHeroesPage.removeObserver(this) | ||
pageIndexAboutToLoad++ | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
app/src/main/java/com/karumi/jetpack/superheroes/domain/usecase/GetSuperHeroes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.karumi.jetpack.superheroes.domain.usecase | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.paging.PagedList | ||
import com.karumi.jetpack.superheroes.data.repository.SuperHeroRepository | ||
import com.karumi.jetpack.superheroes.domain.model.SuperHero | ||
|
||
class GetSuperHeroes(private val superHeroesRepository: SuperHeroRepository) { | ||
operator fun invoke(): LiveData<List<SuperHero>> = superHeroesRepository.getAllSuperHeroes() | ||
operator fun invoke(): LiveData<PagedList<SuperHero>> = | ||
superHeroesRepository.getAllSuperHeroes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters