-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into troubleshooting/paging_adapter_scrolling_bug
# Conflicts: # app/src/main/java/com/intive/tmdbandroid/home/ui/HomeFragment.kt # app/src/main/res/layout/item_screening.xml
- Loading branch information
Showing
35 changed files
with
1,102 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,40 +2,84 @@ name: TMDB CI | |
|
||
on: | ||
push: | ||
branches: [ master ] | ||
branches: [ master, feature/github_actions ] | ||
pull_request: | ||
branches: [ master ] | ||
branches: [ master, feature/github_actions ] | ||
|
||
jobs: | ||
test: | ||
name: Run Unit Tests | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-latest #Each job runs in a runner environment specified | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
- uses: actions/checkout@v2.3.3 | ||
- name: set up JDK 11 | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: 1.8 | ||
java-version: '11' | ||
distribution: 'adopt' | ||
cache: gradle | ||
- name: Unit tests | ||
run: bash ./gradlew test --stacktrace | ||
- name: Unit tests results | ||
uses: actions/upload-artifact@v1 | ||
uses: actions/upload-artifact@v2.2.3 | ||
with: | ||
name: unit-tests-results | ||
path: app/build/reports/tests/testDebugUnitTest/index.html | ||
|
||
lint: | ||
name: Lint Check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: set up JDK 11 | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
cache: gradle | ||
- name: Lint debug flavor | ||
run: bash ./gradlew lintDebug --stacktrace | ||
- name: Lint results | ||
uses: actions/[email protected] | ||
with: | ||
name: lint-result | ||
path: app/build/reports/lint-results-debug.html | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v2.3.3 | ||
- name: set up JDK 11 | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
cache: gradle | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Build with Gradle | ||
run: ./gradlew build | ||
run: bash ./gradlew assembleDebug --stacktrace | ||
|
||
- name: Upload APK | ||
uses: actions/[email protected] | ||
with: | ||
name: app | ||
path: app/build/outputs/apk/debug/*.apk | ||
|
||
- name: Send mail | ||
if: always() | ||
uses: dawidd6/action-send-mail@v2 | ||
with: | ||
# mail server settings | ||
server_address: smtp.gmail.com | ||
server_port: 465 | ||
# user credentials | ||
username: ${{ secrets.EMAIL_USERNAME }} | ||
password: ${{ secrets.EMAIL_PASSWORD }} | ||
# email subject | ||
subject: ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }} | ||
# email body as text | ||
body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }} | ||
# comma-separated string, send email to | ||
to: [email protected] | ||
# from email name | ||
from: TMDB Team! GitHub Actions! |
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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/intive/tmdbandroid/datasource/TVShowSearchSource.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,40 @@ | ||
package com.intive.tmdbandroid.datasource | ||
|
||
import androidx.paging.PagingSource | ||
import com.intive.tmdbandroid.entity.ResultTVShowsEntity | ||
import androidx.paging.PagingState | ||
import com.intive.tmdbandroid.datasource.network.Service | ||
import com.intive.tmdbandroid.model.TVShow | ||
import kotlinx.coroutines.flow.collect | ||
|
||
class TVShowSearchSource(private val service: Service, private val query: String) : PagingSource<Int, TVShow>() { | ||
companion object { | ||
const val DEFAULT_PAGE_INDEX = 1 | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, TVShow> { | ||
return try { | ||
val pageNumber = params.key ?: DEFAULT_PAGE_INDEX | ||
lateinit var response: ResultTVShowsEntity | ||
service.getTvShowByTitle(query, pageNumber).collect { response = it } | ||
|
||
val prevKey = if (pageNumber > DEFAULT_PAGE_INDEX) pageNumber - 1 else null | ||
val nextKey = if (response.TVShows.isNotEmpty()) pageNumber + 1 else null | ||
|
||
LoadResult.Page( | ||
data = response.toTVShowList(), | ||
prevKey = prevKey, | ||
nextKey = nextKey | ||
) | ||
} catch (e: Exception) { | ||
LoadResult.Error(e) | ||
} | ||
} | ||
|
||
override fun getRefreshKey(state: PagingState<Int, TVShow>): Int? { | ||
return state.anchorPosition?.let { | ||
state.closestPageToPosition(it)?.prevKey?.plus(1) | ||
?: state.closestPageToPosition(it)?.nextKey?.minus(1) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.