diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d743eb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.iml +.gradle +.idea +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e249340 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion + + defaultConfig { + applicationId "com.example.android.instantappsample.app" + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + versionCode rootProject.versionCode + versionName rootProject.versionName + } + + flavorDimensions "default" + + buildTypes { + debug + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation project(':character-details') + implementation project(':character-list') + implementation project(':base') +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d6f0bb6 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/base/.gitignore b/base/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/base/.gitignore @@ -0,0 +1 @@ +/build diff --git a/base/build.gradle b/base/build.gradle new file mode 100644 index 0000000..07f4463 --- /dev/null +++ b/base/build.gradle @@ -0,0 +1,50 @@ +apply plugin: 'com.android.feature' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion + + baseFeature true + defaultConfig { + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + versionCode rootProject.versionCode + versionName rootProject.versionName + } + buildTypes { + debug + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + flavorDimensions "default" +} + +dependencies { + api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + api "com.android.support:appcompat-v7:$support_version" + api 'com.android.support.constraint:constraint-layout:1.1.2' + api 'com.squareup.retrofit2:retrofit:2.4.0' + api 'com.squareup.retrofit2:converter-gson:2.4.0' + api 'com.google.code.gson:gson:2.8.5' + api 'com.squareup.okhttp3:okhttp:3.11.0' + api 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' + api 'com.squareup.okhttp3:logging-interceptor:3.9.1' + + api 'com.jakewharton.timber:timber:4.7.1' + + api 'io.reactivex.rxjava2:rxandroid:2.1.0' + api 'io.reactivex.rxjava2:rxkotlin:2.2.0' + + api "android.arch.lifecycle:extensions:1.1.1" + api 'com.github.bumptech.glide:glide:4.8.0' + + api 'com.android.support:appcompat-v7:28.0.0-rc01' + application project(':app') + feature project(':character-list') + feature project(":character-details") +} diff --git a/base/src/main/AndroidManifest.xml b/base/src/main/AndroidManifest.xml new file mode 100644 index 0000000..dc62152 --- /dev/null +++ b/base/src/main/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/ApiInterface.kt b/base/src/main/java/com/example/android/instantappsample/ApiInterface.kt new file mode 100644 index 0000000..10f2faa --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/ApiInterface.kt @@ -0,0 +1,13 @@ +package com.example.android.instantappsample + +import com.example.android.instantappsample.data.CharacterPage +import io.reactivex.Observable +import retrofit2.http.GET +import retrofit2.http.Query + +interface ApiInterface { + + @GET("character/") + fun getCharacterPage(@Query("page")pageNumber: Long): Observable + +} \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/MyObserver.kt b/base/src/main/java/com/example/android/instantappsample/MyObserver.kt new file mode 100644 index 0000000..47f68d7 --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/MyObserver.kt @@ -0,0 +1,23 @@ +package com.example.android.instantappsample + +import io.reactivex.Observer +import io.reactivex.disposables.Disposable + +open class MyObserver : Observer { + override fun onComplete() { + + } + + override fun onSubscribe(d: Disposable) { + + } + + override fun onNext(t: T) { + + } + + override fun onError(e: Throwable) { + + } + +} \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/RestClient.kt b/base/src/main/java/com/example/android/instantappsample/RestClient.kt new file mode 100644 index 0000000..800cbd4 --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/RestClient.kt @@ -0,0 +1,29 @@ +package com.example.android.instantappsample + +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory +import retrofit2.converter.gson.GsonConverterFactory +import timber.log.Timber + +object RestClient { + val apiInterface: ApiInterface by lazy { + val loginInterceptor = HttpLoggingInterceptor { + Timber.w(it) + }.apply { + level = HttpLoggingInterceptor.Level.BODY + } + val client = OkHttpClient.Builder() + .addInterceptor(loginInterceptor) + .build() + + Retrofit.Builder() + .client(client) + .baseUrl("https://rickandmortyapi.com/api/") + .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) + .build() + .create(ApiInterface::class.java) + } +} \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/Util.kt b/base/src/main/java/com/example/android/instantappsample/Util.kt new file mode 100644 index 0000000..e82be67 --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/Util.kt @@ -0,0 +1,5 @@ +package com.example.android.instantappsample + +fun String.something() { + this.length +} \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/data/Character.kt b/base/src/main/java/com/example/android/instantappsample/data/Character.kt new file mode 100644 index 0000000..e11c38a --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/data/Character.kt @@ -0,0 +1,16 @@ +package com.example.android.instantappsample.data + +data class Character( + val id: Int, + val name: String, + val status: String, + val species: String, + val type: String, + val gender: String, + val origin: Origin, + val location: Location, + val image: String, + val episode: List, + val url: String, + val created: String +) \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/data/CharacterPage.kt b/base/src/main/java/com/example/android/instantappsample/data/CharacterPage.kt new file mode 100644 index 0000000..dc3bab8 --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/data/CharacterPage.kt @@ -0,0 +1,6 @@ +package com.example.android.instantappsample.data + +data class CharacterPage( + val info: Info, + val results: List +) \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/data/Info.kt b/base/src/main/java/com/example/android/instantappsample/data/Info.kt new file mode 100644 index 0000000..47b365c --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/data/Info.kt @@ -0,0 +1,8 @@ +package com.example.android.instantappsample.data + +data class Info( + val count: Long, + val pages: Long, + val next: String, + val prev: String +) \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/data/Location.kt b/base/src/main/java/com/example/android/instantappsample/data/Location.kt new file mode 100644 index 0000000..44ca2c6 --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/data/Location.kt @@ -0,0 +1,6 @@ +package com.example.android.instantappsample.data + +data class Location( + val name: String, + val url: String +) \ No newline at end of file diff --git a/base/src/main/java/com/example/android/instantappsample/data/Origin.kt b/base/src/main/java/com/example/android/instantappsample/data/Origin.kt new file mode 100644 index 0000000..009b047 --- /dev/null +++ b/base/src/main/java/com/example/android/instantappsample/data/Origin.kt @@ -0,0 +1,6 @@ +package com.example.android.instantappsample.data + +data class Origin( + val name: String, + val url: String +) \ No newline at end of file diff --git a/base/src/main/res/drawable-v24/ic_launcher_foreground.xml b/base/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/base/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/base/src/main/res/drawable/ic_launcher_background.xml b/base/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/base/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/base/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/base/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/base/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/base/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/base/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/base/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/base/src/main/res/mipmap-hdpi/ic_launcher.png b/base/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..a2f5908 Binary files /dev/null and b/base/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/base/src/main/res/mipmap-hdpi/ic_launcher_round.png b/base/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..1b52399 Binary files /dev/null and b/base/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/base/src/main/res/mipmap-mdpi/ic_launcher.png b/base/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..ff10afd Binary files /dev/null and b/base/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/base/src/main/res/mipmap-mdpi/ic_launcher_round.png b/base/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..115a4c7 Binary files /dev/null and b/base/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/base/src/main/res/mipmap-xhdpi/ic_launcher.png b/base/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..dcd3cd8 Binary files /dev/null and b/base/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/base/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/base/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..459ca60 Binary files /dev/null and b/base/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/base/src/main/res/mipmap-xxhdpi/ic_launcher.png b/base/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..8ca12fe Binary files /dev/null and b/base/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/base/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/base/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..8e19b41 Binary files /dev/null and b/base/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/base/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/base/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..b824ebd Binary files /dev/null and b/base/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/base/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/base/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..4c19a13 Binary files /dev/null and b/base/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/base/src/main/res/values/colors.xml b/base/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/base/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/base/src/main/res/values/strings.xml b/base/src/main/res/values/strings.xml new file mode 100644 index 0000000..3bc65d6 --- /dev/null +++ b/base/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + InstantAppSample + diff --git a/base/src/main/res/values/styles.xml b/base/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/base/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e2bd97f --- /dev/null +++ b/build.gradle @@ -0,0 +1,38 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +ext { + support_version = '28.0.0-rc01' + compileSdkVersion = 28 + buildToolsVersion = "28.0.1" + minSdkVersion = 23 + targetSdkVersion = 28 + versionCode = 1 + versionName = "1.0" +} + +buildscript { + ext.kotlin_version = '1.2.60' + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.1.4' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/character-details/.gitignore b/character-details/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/character-details/.gitignore @@ -0,0 +1 @@ +/build diff --git a/character-details/build.gradle b/character-details/build.gradle new file mode 100644 index 0000000..c994fcd --- /dev/null +++ b/character-details/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.feature' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +android { + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion + + defaultConfig { + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + versionCode rootProject.versionCode + versionName rootProject.versionName + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + debug + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation project(':base') +} diff --git a/character-details/proguard-rules.pro b/character-details/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/character-details/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/character-details/src/main/AndroidManifest.xml b/character-details/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c3fcaee --- /dev/null +++ b/character-details/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/character-details/src/main/java/com/example/android/character_details/CharacterDetails.kt b/character-details/src/main/java/com/example/android/character_details/CharacterDetails.kt new file mode 100644 index 0000000..d8526e8 --- /dev/null +++ b/character-details/src/main/java/com/example/android/character_details/CharacterDetails.kt @@ -0,0 +1,12 @@ +package com.example.android.character_details + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle + +class CharacterDetails : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + } +} diff --git a/character-details/src/main/res/layout/activity_main.xml b/character-details/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..cc66c2c --- /dev/null +++ b/character-details/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/character-details/src/main/res/values/strings.xml b/character-details/src/main/res/values/strings.xml new file mode 100644 index 0000000..f11f745 --- /dev/null +++ b/character-details/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + + diff --git a/character-list/.gitignore b/character-list/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/character-list/.gitignore @@ -0,0 +1 @@ +/build diff --git a/character-list/build.gradle b/character-list/build.gradle new file mode 100644 index 0000000..5af6475 --- /dev/null +++ b/character-list/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.feature' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion + + defaultConfig { + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + versionCode rootProject.versionCode + versionName rootProject.versionName + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + debug + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + androidExtensions { + experimental = true + } +} + +dependencies { + implementation project(':base') + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "com.android.support:recyclerview-v7:$support_version" +} diff --git a/character-list/proguard-rules.pro b/character-list/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/character-list/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/character-list/src/main/AndroidManifest.xml b/character-list/src/main/AndroidManifest.xml new file mode 100644 index 0000000..02fff92 --- /dev/null +++ b/character-list/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterItemAdapter.kt b/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterItemAdapter.kt new file mode 100644 index 0000000..2fda5ff --- /dev/null +++ b/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterItemAdapter.kt @@ -0,0 +1,50 @@ +package com.example.android.instantappsample.character_list + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.bumptech.glide.Glide +import com.example.android.instantappsample.data.Character +import kotlinx.android.extensions.LayoutContainer +import kotlinx.android.synthetic.main.item_character.* + +class CharacterItemAdapter( + list: MutableList = mutableListOf(), + private val onCharacterClicked: (character: Character) -> Unit = {} +) : RecyclerView.Adapter() { + + var characterList: MutableList = list + set(value) { + field = value + notifyDataSetChanged() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.item_character, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { + viewHolder.bindView(characterList[position]) + } + + override fun getItemCount() = characterList.size + + + inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), LayoutContainer { + override val containerView: View? + get() = itemView + + fun bindView(character: Character) { + itemCharacterContainerCrl.setOnClickListener { + onCharacterClicked(character) + } + Glide.with(itemView.context) + .load(character.image) + .into(itemCharacterIv) + + itemCharacterNameTv.text = character.name + } + } +} \ No newline at end of file diff --git a/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterListActivity.kt b/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterListActivity.kt new file mode 100644 index 0000000..34bf7d1 --- /dev/null +++ b/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterListActivity.kt @@ -0,0 +1,34 @@ +package com.example.android.instantappsample.character_list + +import android.arch.lifecycle.Observer +import android.arch.lifecycle.ViewModelProviders +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import kotlinx.android.synthetic.main.activity_main.* +import timber.log.Timber + +class CharacterListActivity : AppCompatActivity() { + + private val viewModel: CharacterListViewModel by lazy { ViewModelProviders.of(this)[CharacterListViewModel::class.java] } + private lateinit var characterListAdapter: CharacterItemAdapter + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + if (Timber.treeCount() < 1) { + Timber.plant(Timber.DebugTree()) + } + viewModel.fetchPage(1) + viewModel.setupRecyclerViewPager(characterListRv) + + characterListAdapter = CharacterItemAdapter { + + } + + viewModel.pageData.observe(this, Observer { + it?.results?.let(characterListAdapter.characterList::addAll) + characterListAdapter.notifyDataSetChanged() + }) + characterListRv.adapter = characterListAdapter + } +} diff --git a/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterListViewModel.kt b/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterListViewModel.kt new file mode 100644 index 0000000..1ade402 --- /dev/null +++ b/character-list/src/main/java/com/example/android/instantappsample/character_list/CharacterListViewModel.kt @@ -0,0 +1,48 @@ +package com.example.android.instantappsample.character_list + +import android.arch.lifecycle.MutableLiveData +import android.arch.lifecycle.ViewModel +import android.net.Uri +import android.support.v7.widget.RecyclerView +import com.example.android.instantappsample.MyObserver +import com.example.android.instantappsample.RestClient +import com.example.android.instantappsample.data.CharacterPage +import io.reactivex.Observer +import io.reactivex.disposables.Disposable +import io.reactivex.schedulers.Schedulers +import timber.log.Timber + +class CharacterListViewModel : ViewModel() { + + private val apiInterface = RestClient.apiInterface + private var nextPage: Long? = 0 + + val pageData = MutableLiveData() + + fun fetchPage(page: Long) { + apiInterface.getCharacterPage(page) + .subscribeOn(Schedulers.io()) + .subscribe(object : MyObserver() { + override fun onNext(t: CharacterPage) { + pageData.postValue(t) + val uri = Uri.parse(t.info.next) + nextPage = uri.getQueryParameter("page")?.toLong() + } + + override fun onError(e: Throwable) { + Timber.e(e) + } + }) + } + + fun setupRecyclerViewPager(recyclerView: RecyclerView) { + recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + if (!recyclerView.canScrollVertically(1)) { + nextPage?.let(::fetchPage) + } + } + }) + } +} \ No newline at end of file diff --git a/character-list/src/main/res/layout/activity_main.xml b/character-list/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..5612211 --- /dev/null +++ b/character-list/src/main/res/layout/activity_main.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/character-list/src/main/res/layout/item_character.xml b/character-list/src/main/res/layout/item_character.xml new file mode 100644 index 0000000..4af5d9e --- /dev/null +++ b/character-list/src/main/res/layout/item_character.xml @@ -0,0 +1,33 @@ + + + + + + + + \ No newline at end of file diff --git a/character-list/src/main/res/values/strings.xml b/character-list/src/main/res/values/strings.xml new file mode 100644 index 0000000..7abc06d --- /dev/null +++ b/character-list/src/main/res/values/strings.xml @@ -0,0 +1 @@ + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..743d692 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,13 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7a3265e Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..7f4c43b --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Aug 21 13:41:04 CEST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/instantapp/.gitignore b/instantapp/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/instantapp/.gitignore @@ -0,0 +1 @@ +/build diff --git a/instantapp/build.gradle b/instantapp/build.gradle new file mode 100644 index 0000000..7291983 --- /dev/null +++ b/instantapp/build.gradle @@ -0,0 +1,7 @@ +apply plugin: 'com.android.instantapp' + +dependencies { + implementation project(':character-details') + implementation project(':character-list') + implementation project(':base') +} diff --git a/local.properties b/local.properties new file mode 100644 index 0000000..b0e44fc --- /dev/null +++ b/local.properties @@ -0,0 +1,9 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Tue Aug 21 15:11:39 CEST 2018 +ndk.dir=/Users/mariuszkarwowski/Library/Android/sdk/ndk-bundle +sdk.dir=/Users/mariuszkarwowski/Library/Android/sdk diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..ce7d61e --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':character-list', ':app', ':base', ':instantapp', ':character-details'