├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── attrs.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ └── view_movie.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── antonioleiva │ │ │ │ └── flowworkshop │ │ │ │ ├── ui │ │ │ │ ├── common │ │ │ │ │ ├── Executors.kt │ │ │ │ │ ├── AspectRatioImageView.kt │ │ │ │ │ └── extensions.kt │ │ │ │ ├── MainViewModel.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ └── MoviesAdapter.kt │ │ │ │ ├── data │ │ │ │ ├── domain │ │ │ │ │ ├── Movie.kt │ │ │ │ │ └── MoviesRepository.kt │ │ │ │ ├── db │ │ │ │ │ ├── MovieDatabase.kt │ │ │ │ │ ├── Movie.kt │ │ │ │ │ ├── MovieDao.kt │ │ │ │ │ └── RoomDataSource.kt │ │ │ │ ├── server │ │ │ │ │ ├── TheMovieDbService.kt │ │ │ │ │ ├── TheMovieDbDataSource.kt │ │ │ │ │ ├── TheMovieDb.kt │ │ │ │ │ └── MovieDbResult.kt │ │ │ │ └── datamappers.kt │ │ │ │ └── MoviesApp.kt │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── antonioleiva │ │ └── flowworkshop │ │ └── ui │ │ ├── MainViewModelTest.kt │ │ ├── MoviesRepositoryTest.kt │ │ ├── CoroutinesTestRule.kt │ │ └── Fakes.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "My Application" -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Movies 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antoniolg/flow-workshop/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/ui/common/Executors.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui.common 2 | 3 | import java.util.concurrent.Executors 4 | 5 | val BACKGROUND = Executors.newFixedThreadPool(2) -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/domain/Movie.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.domain 2 | 3 | data class Movie( 4 | val id: Int, 5 | val title: String, 6 | val posterPath: String, 7 | val voteAverage: Double, 8 | ) -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Sep 24 16:44:53 CEST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated files 2 | bin/ 3 | gen/ 4 | 5 | # Gradle files 6 | .gradle/ 7 | build/ 8 | 9 | # Local configuration file (sdk path, etc) 10 | local.properties 11 | 12 | # Intellij project files 13 | *.iws 14 | .idea/tasks.xml 15 | .idea 16 | *.iml 17 | 18 | # OS 19 | .DS_Store 20 | 21 | # Api key 22 | app/src/main/res/values/api_key.xml -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/db/MovieDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.db 2 | 3 | import androidx.room.Database 4 | import androidx.room.RoomDatabase 5 | 6 | @Database(entities = [Movie::class], version = 1) 7 | abstract class MovieDatabase : RoomDatabase() { 8 | 9 | abstract fun movieDao(): MovieDao 10 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/db/Movie.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.db 2 | 3 | import androidx.room.Entity 4 | import androidx.room.PrimaryKey 5 | 6 | @Entity 7 | data class Movie( 8 | @PrimaryKey(autoGenerate = true) val id: Int, 9 | val title: String, 10 | val posterPath: String, 11 | val voteAverage: Double 12 | ) -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/server/TheMovieDbService.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.server 2 | 3 | import retrofit2.Call 4 | import retrofit2.http.GET 5 | import retrofit2.http.Query 6 | 7 | interface TheMovieDbService { 8 | @GET("discover/movie?sort_by=popularity.desc") 9 | suspend fun listPopularMoviesAsync( 10 | @Query("api_key") apiKey: String, 11 | @Query("page") page: Int 12 | ): MovieDbResult 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/MoviesApp.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop 2 | 3 | import android.app.Application 4 | import androidx.room.Room 5 | import com.antonioleiva.flowworkshop.data.db.MovieDatabase 6 | 7 | class MoviesApp : Application() { 8 | 9 | lateinit var db: MovieDatabase 10 | private set 11 | 12 | override fun onCreate() { 13 | super.onCreate() 14 | 15 | db = Room.databaseBuilder( 16 | this, 17 | MovieDatabase::class.java, "movie-db" 18 | ).build() 19 | } 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/db/MovieDao.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.db 2 | 3 | import androidx.room.Dao 4 | import androidx.room.Insert 5 | import androidx.room.OnConflictStrategy 6 | import androidx.room.Query 7 | import kotlinx.coroutines.flow.Flow 8 | 9 | @Dao 10 | interface MovieDao { 11 | 12 | @Query("SELECT * FROM Movie") 13 | fun getAll(): Flow> 14 | 15 | @Query("SELECT COUNT(id) FROM Movie") 16 | suspend fun movieCount(): Int 17 | 18 | @Insert(onConflict = OnConflictStrategy.IGNORE) 19 | suspend fun insertMovies(movies: List) 20 | 21 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/server/TheMovieDbDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.server 2 | 3 | import com.antonioleiva.flowworkshop.data.domain.Movie 4 | import com.antonioleiva.flowworkshop.data.domain.RemoteDataSource 5 | import com.antonioleiva.flowworkshop.data.toDomainMovie 6 | 7 | class TheMovieDbDataSource(private val apiKey: String) : RemoteDataSource { 8 | 9 | override suspend fun getMovies(page: Int): List = 10 | TheMovieDb.service 11 | .listPopularMoviesAsync(apiKey, page) 12 | .results 13 | .map { it.toDomainMovie() } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/datamappers.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data 2 | 3 | 4 | import com.antonioleiva.flowworkshop.data.domain.Movie 5 | import com.antonioleiva.flowworkshop.data.db.Movie as RoomMovie 6 | import com.antonioleiva.flowworkshop.data.server.Movie as ServerMovie 7 | 8 | fun ServerMovie.toDomainMovie(): Movie = 9 | Movie( 10 | 0, 11 | title, 12 | posterPath, 13 | voteAverage, 14 | ) 15 | 16 | fun Movie.toRoomMovie(): RoomMovie = 17 | RoomMovie( 18 | id, 19 | title, 20 | posterPath, 21 | voteAverage, 22 | ) 23 | 24 | fun RoomMovie.toDomainMovie(): Movie = Movie( 25 | id, 26 | title, 27 | posterPath, 28 | voteAverage, 29 | ) -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/server/TheMovieDb.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.server 2 | 3 | import okhttp3.OkHttpClient 4 | import okhttp3.logging.HttpLoggingInterceptor 5 | import retrofit2.Retrofit 6 | import retrofit2.converter.gson.GsonConverterFactory 7 | 8 | object TheMovieDb { 9 | 10 | private val okHttpClient = HttpLoggingInterceptor().run { 11 | level = HttpLoggingInterceptor.Level.BODY 12 | OkHttpClient.Builder().addInterceptor(this).build() 13 | } 14 | 15 | val service: TheMovieDbService = Retrofit.Builder() 16 | .baseUrl("https://api.themoviedb.org/3/") 17 | .client(okHttpClient) 18 | .addConverterFactory(GsonConverterFactory.create()) 19 | .build() 20 | .run { 21 | create(TheMovieDbService::class.java) 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/test/java/com/antonioleiva/flowworkshop/ui/MainViewModelTest.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import com.antonioleiva.flowworkshop.data.domain.MoviesRepository 4 | import kotlinx.coroutines.ExperimentalCoroutinesApi 5 | import kotlinx.coroutines.flow.collect 6 | import kotlinx.coroutines.test.runBlockingTest 7 | import org.junit.Assert 8 | import org.junit.Rule 9 | import org.junit.Test 10 | 11 | @ExperimentalCoroutinesApi 12 | class MainViewModelTest { 13 | 14 | @get:Rule 15 | val coroutinesTestRule = CoroutinesTestRule() 16 | 17 | @Test 18 | fun `Listening to movies Flow emits the list of movies from the server`() = runBlockingTest { 19 | val repository = MoviesRepository(FakeLocalDataSource(), FakeRemoteDataSource(fakeMovies)) 20 | val vm = MainViewModel(repository) 21 | 22 | vm.movies.collect { 23 | Assert.assertEquals(fakeMovies, it) 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/test/java/com/antonioleiva/flowworkshop/ui/MoviesRepositoryTest.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import com.antonioleiva.flowworkshop.data.domain.MoviesRepository 4 | import kotlinx.coroutines.ExperimentalCoroutinesApi 5 | import kotlinx.coroutines.TimeoutCancellationException 6 | import kotlinx.coroutines.test.runBlockingTest 7 | import org.junit.Rule 8 | import org.junit.Test 9 | 10 | @ExperimentalCoroutinesApi 11 | class MoviesRepositoryTest { 12 | 13 | @get:Rule 14 | val coroutinesTestRule = CoroutinesTestRule() 15 | 16 | @Test(expected = TimeoutCancellationException::class) 17 | fun `After timeout, an exception is thrown`() = runBlockingTest { 18 | val repository = MoviesRepository( 19 | FakeLocalDataSource(), 20 | FakeRemoteDataSource(delay = 6_000) 21 | ) 22 | 23 | repository.checkRequireNewPage(0) 24 | 25 | advanceTimeBy(5_000) 26 | } 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/db/RoomDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.db 2 | 3 | import com.antonioleiva.flowworkshop.data.domain.LocalDataSource 4 | import com.antonioleiva.flowworkshop.data.domain.Movie 5 | import com.antonioleiva.flowworkshop.data.toDomainMovie 6 | import com.antonioleiva.flowworkshop.data.toRoomMovie 7 | import kotlinx.coroutines.flow.Flow 8 | import kotlinx.coroutines.flow.map 9 | 10 | class RoomDataSource(db: MovieDatabase) : LocalDataSource { 11 | 12 | private val movieDao = db.movieDao() 13 | 14 | override suspend fun size(): Int = movieDao.movieCount() 15 | 16 | override suspend fun saveMovies(movies: List) { 17 | movieDao.insertMovies(movies.map { it.toRoomMovie() }) 18 | } 19 | 20 | override fun getMovies(): Flow> = 21 | movieDao 22 | .getAll() 23 | .map { movies -> movies.map { it.toDomainMovie() } } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/test/java/com/antonioleiva/flowworkshop/ui/CoroutinesTestRule.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import kotlinx.coroutines.Dispatchers 4 | import kotlinx.coroutines.ExperimentalCoroutinesApi 5 | import kotlinx.coroutines.test.TestCoroutineDispatcher 6 | import kotlinx.coroutines.test.resetMain 7 | import kotlinx.coroutines.test.setMain 8 | import org.junit.rules.TestWatcher 9 | import org.junit.runner.Description 10 | 11 | @ExperimentalCoroutinesApi 12 | class CoroutinesTestRule( 13 | private val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() 14 | ) : TestWatcher() { 15 | 16 | override fun starting(description: Description?) { 17 | super.starting(description) 18 | Dispatchers.setMain(testDispatcher) 19 | } 20 | 21 | override fun finished(description: Description?) { 22 | super.finished(description) 23 | Dispatchers.resetMain() 24 | testDispatcher.cleanupTestCoroutines() 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/ui/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import androidx.lifecycle.ViewModel 4 | import androidx.lifecycle.viewModelScope 5 | import com.antonioleiva.flowworkshop.data.domain.Movie 6 | import com.antonioleiva.flowworkshop.data.domain.MoviesRepository 7 | import com.antonioleiva.flowworkshop.ui.common.collectFlow 8 | import kotlinx.coroutines.flow.Flow 9 | import kotlinx.coroutines.flow.MutableStateFlow 10 | import kotlinx.coroutines.flow.StateFlow 11 | import kotlinx.coroutines.launch 12 | 13 | class MainViewModel(private val repository: MoviesRepository) : ViewModel() { 14 | 15 | private val _spinner = MutableStateFlow(true) 16 | val spinner: StateFlow get() = _spinner 17 | 18 | val movies: Flow> get() = repository.getMovies() 19 | 20 | init { 21 | viewModelScope.launch { notifyLastVisible(0) } 22 | } 23 | 24 | suspend fun notifyLastVisible(lastVisible: Int) { 25 | repository.checkRequireNewPage(lastVisible) 26 | _spinner.value = false 27 | } 28 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/server/MovieDbResult.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.server 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | data class MovieDbResult( 6 | val page: Int, 7 | val results: List, 8 | @SerializedName("total_pages") val totalPages: Int, 9 | @SerializedName("total_results") val totalResults: Int 10 | ) 11 | 12 | data class Movie( 13 | val adult: Boolean, 14 | @SerializedName("backdrop_path") val backdropPath: String?, 15 | @SerializedName("genre_ids") val genreIds: List, 16 | val id: Int, 17 | @SerializedName("original_language") val originalLanguage: String, 18 | @SerializedName("original_title") val originalTitle: String, 19 | val overview: String, 20 | val popularity: Double, 21 | @SerializedName("poster_path") val posterPath: String, 22 | @SerializedName("release_date") val releaseDate: String, 23 | val title: String, 24 | val video: Boolean, 25 | @SerializedName("vote_average") val voteAverage: Double, 26 | @SerializedName("vote_count") val voteCount: Int 27 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/data/domain/MoviesRepository.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.data.domain 2 | 3 | import kotlinx.coroutines.flow.Flow 4 | import kotlinx.coroutines.withTimeout 5 | 6 | private const val PAGE_SIZE = 20 7 | private const val PAGE_THRESHOLD = 10 8 | 9 | class MoviesRepository( 10 | private val localDataSource: LocalDataSource, 11 | private val remoteDataSource: RemoteDataSource, 12 | ) { 13 | fun getMovies(): Flow> = localDataSource.getMovies() 14 | 15 | suspend fun checkRequireNewPage(lastVisible: Int) { 16 | val size = localDataSource.size() 17 | if (lastVisible >= size - PAGE_THRESHOLD) { 18 | val page = size / PAGE_SIZE + 1 19 | val newMovies = withTimeout(5_000) { remoteDataSource.getMovies(page) } 20 | localDataSource.saveMovies(newMovies) 21 | } 22 | } 23 | } 24 | 25 | interface RemoteDataSource { 26 | suspend fun getMovies(page: Int): List 27 | } 28 | 29 | interface LocalDataSource { 30 | suspend fun size(): Int 31 | suspend fun saveMovies(movies: List) 32 | fun getMovies(): Flow> 33 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/test/java/com/antonioleiva/flowworkshop/ui/Fakes.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import com.antonioleiva.flowworkshop.data.domain.LocalDataSource 4 | import com.antonioleiva.flowworkshop.data.domain.Movie 5 | import com.antonioleiva.flowworkshop.data.domain.RemoteDataSource 6 | import kotlinx.coroutines.delay 7 | import kotlinx.coroutines.flow.Flow 8 | import kotlinx.coroutines.flow.flowOf 9 | 10 | val fakeMovies = listOf( 11 | Movie(1, "Title 1", "poster1", 7.0), 12 | Movie(2, "Title 2", "poster2", 7.0), 13 | Movie(3, "Title 3", "poster3", 7.0), 14 | Movie(4, "Title 4", "poster4", 7.0), 15 | ) 16 | 17 | class FakeLocalDataSource : LocalDataSource { 18 | 19 | private val movies = mutableListOf() 20 | 21 | override suspend fun size(): Int = movies.size 22 | 23 | override suspend fun saveMovies(movies: List) { 24 | this.movies += movies 25 | } 26 | 27 | override fun getMovies(): Flow> = flowOf(movies) 28 | 29 | } 30 | 31 | class FakeRemoteDataSource( 32 | private val movies: List = emptyList(), 33 | private val delay: Long = 0 34 | ) : RemoteDataSource { 35 | 36 | override suspend fun getMovies(page: Int): List { 37 | delay(delay) 38 | return movies 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_movie.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/ui/common/AspectRatioImageView.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui.common 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import androidx.appcompat.widget.AppCompatImageView 6 | import com.antonioleiva.flowworkshop.R 7 | 8 | class AspectRatioImageView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : AppCompatImageView(context, attrs, defStyleAttr) { 13 | 14 | private var ratio: Float = DEFAULT_RATIO 15 | 16 | init { 17 | attrs?.let { 18 | val a = context.obtainStyledAttributes(attrs, R.styleable.AspectRatioImageView) 19 | with(a) { 20 | ratio = getFloat(R.styleable.AspectRatioImageView_ratio, DEFAULT_RATIO) 21 | recycle() 22 | } 23 | } 24 | } 25 | 26 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 27 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) 28 | var width = measuredWidth 29 | var height = measuredHeight 30 | 31 | if (width == 0 && height == 0) { 32 | return 33 | } 34 | 35 | if (width > 0) { 36 | height = (width * ratio).toInt() 37 | } else { 38 | width = (height / ratio).toInt() 39 | } 40 | 41 | setMeasuredDimension(width, height) 42 | } 43 | 44 | companion object { 45 | const val DEFAULT_RATIO = 1F 46 | } 47 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/ui/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.lifecycle.lifecycleScope 6 | import com.antonioleiva.flowworkshop.R 7 | import com.antonioleiva.flowworkshop.data.db.RoomDataSource 8 | import com.antonioleiva.flowworkshop.data.domain.MoviesRepository 9 | import com.antonioleiva.flowworkshop.data.server.TheMovieDbDataSource 10 | import com.antonioleiva.flowworkshop.databinding.ActivityMainBinding 11 | import com.antonioleiva.flowworkshop.ui.common.* 12 | import kotlinx.coroutines.ExperimentalCoroutinesApi 13 | 14 | @ExperimentalCoroutinesApi 15 | class MainActivity : AppCompatActivity() { 16 | 17 | private lateinit var viewModel: MainViewModel 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | 22 | ActivityMainBinding.inflate(layoutInflater).apply { 23 | setContentView(root) 24 | 25 | viewModel = getViewModel(::buildViewModel) 26 | 27 | val moviesAdapter = MoviesAdapter(lifecycleScope) 28 | 29 | lifecycleScope.collectFlow(viewModel.spinner) { progress.visible = it } 30 | lifecycleScope.collectFlow(viewModel.movies) { moviesAdapter.submitList(it) } 31 | 32 | lifecycleScope.collectFlow(recycler.lastVisibleEvents) { 33 | viewModel.notifyLastVisible(it) 34 | } 35 | 36 | recycler.adapter = moviesAdapter 37 | } 38 | } 39 | 40 | private fun buildViewModel() = MainViewModel( 41 | MoviesRepository( 42 | RoomDataSource(app.db), 43 | TheMovieDbDataSource(getString(R.string.api_key)) 44 | ) 45 | ) 46 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-android-extensions' 5 | id 'kotlin-kapt' 6 | } 7 | 8 | android { 9 | compileSdkVersion 30 10 | buildToolsVersion "30.0.2" 11 | 12 | defaultConfig { 13 | applicationId "com.antonioleiva.flowworkshop" 14 | minSdkVersion 23 15 | targetSdkVersion 30 16 | versionCode 1 17 | versionName "1.0" 18 | 19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 20 | } 21 | 22 | buildFeatures { 23 | viewBinding = true 24 | } 25 | 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | 33 | compileOptions { 34 | sourceCompatibility JavaVersion.VERSION_1_8 35 | targetCompatibility JavaVersion.VERSION_1_8 36 | } 37 | kotlinOptions { 38 | jvmTarget = JavaVersion.VERSION_1_8 39 | } 40 | } 41 | 42 | dependencies { 43 | implementation fileTree(dir: "libs", include: ["*.jar"]) 44 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 45 | implementation 'androidx.core:core-ktx:1.3.2' 46 | implementation 'androidx.appcompat:appcompat:1.2.0' 47 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 48 | implementation 'androidx.recyclerview:recyclerview:1.1.0' 49 | 50 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0' 51 | implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0' 52 | implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' 53 | 54 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1' 55 | 56 | implementation 'com.github.bumptech.glide:glide:4.11.0' 57 | kapt 'com.github.bumptech.glide:compiler:4.11.0' 58 | 59 | implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0' 60 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 61 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 62 | 63 | implementation 'androidx.room:room-ktx:2.2.5' 64 | kapt 'androidx.room:room-compiler:2.2.5' 65 | 66 | testImplementation 'junit:junit:4.13.1' 67 | testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.1' 68 | 69 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/ui/MoviesAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import androidx.recyclerview.widget.DiffUtil 7 | import androidx.recyclerview.widget.ListAdapter 8 | import androidx.recyclerview.widget.RecyclerView 9 | import com.antonioleiva.flowworkshop.R 10 | import com.antonioleiva.flowworkshop.data.domain.Movie 11 | import com.antonioleiva.flowworkshop.databinding.ViewMovieBinding 12 | import com.antonioleiva.flowworkshop.ui.common.collectFlow 13 | import com.antonioleiva.flowworkshop.ui.common.onClickEvents 14 | import com.antonioleiva.flowworkshop.ui.common.toast 15 | import com.bumptech.glide.Glide 16 | import kotlinx.coroutines.CoroutineScope 17 | import kotlinx.coroutines.ExperimentalCoroutinesApi 18 | 19 | @ExperimentalCoroutinesApi 20 | class MoviesAdapter(private val scope: CoroutineScope) : 21 | ListAdapter(DiffCallback()) { 22 | 23 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewholder { 24 | return ItemViewholder( 25 | LayoutInflater.from(parent.context) 26 | .inflate(R.layout.view_movie, parent, false) 27 | ) 28 | } 29 | 30 | override fun onBindViewHolder(holder: ItemViewholder, position: Int) = with(holder) { 31 | val item = getItem(position) 32 | bind(item) 33 | scope.collectFlow(itemView.onClickEvents) { 34 | itemView.context.toast(item.title) 35 | } 36 | } 37 | 38 | class ItemViewholder(itemView: View) : RecyclerView.ViewHolder(itemView) { 39 | 40 | private val binding = ViewMovieBinding.bind(itemView) 41 | 42 | fun bind(item: Movie) = with(binding) { 43 | movieTitle.text = item.title 44 | Glide 45 | .with(movieCover.context) 46 | .load("https://image.tmdb.org/t/p/w185/${item.posterPath}") 47 | .into(movieCover) 48 | } 49 | } 50 | } 51 | 52 | class DiffCallback : DiffUtil.ItemCallback() { 53 | override fun areItemsTheSame(oldItem: Movie, newItem: Movie): Boolean { 54 | return oldItem.id == newItem.id 55 | } 56 | 57 | override fun areContentsTheSame(oldItem: Movie, newItem: Movie): Boolean { 58 | return oldItem == newItem 59 | } 60 | } -------------------------------------------------------------------------------- /app/src/main/java/com/antonioleiva/flowworkshop/ui/common/extensions.kt: -------------------------------------------------------------------------------- 1 | package com.antonioleiva.flowworkshop.ui.common 2 | 3 | import android.content.Context 4 | import android.view.View 5 | import android.widget.Toast 6 | import androidx.fragment.app.FragmentActivity 7 | import androidx.lifecycle.ViewModel 8 | import androidx.lifecycle.ViewModelProvider 9 | import androidx.lifecycle.get 10 | import androidx.recyclerview.widget.GridLayoutManager 11 | import androidx.recyclerview.widget.RecyclerView 12 | import com.antonioleiva.flowworkshop.MoviesApp 13 | import kotlinx.coroutines.CoroutineScope 14 | import kotlinx.coroutines.ExperimentalCoroutinesApi 15 | import kotlinx.coroutines.channels.awaitClose 16 | import kotlinx.coroutines.flow.* 17 | 18 | @Suppress("UNCHECKED_CAST") 19 | inline fun FragmentActivity.getViewModel(crossinline factory: () -> T): T { 20 | 21 | val vmFactory = object : ViewModelProvider.Factory { 22 | override fun create(modelClass: Class): U = factory() as U 23 | } 24 | 25 | return ViewModelProvider(this, vmFactory).get() 26 | } 27 | 28 | var View.visible: Boolean 29 | get() = visibility == View.VISIBLE 30 | set(value) { 31 | visibility = if (value) View.VISIBLE else View.GONE 32 | } 33 | 34 | val Context.app: MoviesApp 35 | get() = applicationContext as MoviesApp 36 | 37 | fun CoroutineScope.collectFlow(flow: Flow, body: suspend (T) -> Unit) { 38 | flow.onEach { body(it) } 39 | .launchIn(this) 40 | } 41 | 42 | @ExperimentalCoroutinesApi 43 | val View.onClickEvents: Flow 44 | get() = callbackFlow { 45 | val onClickListener = View.OnClickListener { offer(it) } 46 | setOnClickListener(onClickListener) 47 | awaitClose { setOnClickListener(null) } 48 | }.conflate() 49 | 50 | fun Context.toast(message: String) { 51 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show() 52 | } 53 | 54 | @ExperimentalCoroutinesApi 55 | val RecyclerView.lastVisibleEvents: Flow 56 | get() = callbackFlow { 57 | val lm = layoutManager as GridLayoutManager 58 | 59 | val listener = object : RecyclerView.OnScrollListener() { 60 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { 61 | offer(lm.findLastVisibleItemPosition()) 62 | } 63 | } 64 | addOnScrollListener(listener) 65 | awaitClose { removeOnScrollListener(listener) } 66 | }.conflate() -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | --------------------------------------------------------------------------------