This file contains hidden or 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
// RX Java | |
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' | |
implementation 'io.reactivex.rxjava2:rxjava:2.2.2' | |
// Networking | |
implementation "com.squareup.retrofit2:retrofit:2.4.0" | |
implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0" | |
implementation "com.squareup.retrofit2:converter-gson:2.4.0" | |
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0' |
This file contains hidden or 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
open class Repository( | |
baseUrl: String, | |
isDebugEnabled: Boolean, | |
apiKey: String | |
) { | |
private val apiKeyHeader: String = "x-api-key" | |
val retrofit: Retrofit | |
init { |
This file contains hidden or 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
class CatsDataSource(retrofit: Retrofit) { | |
private val api: CatsApi = retrofit.create(CatsApi::class.java) | |
fun getNumberOfRandomCats(limit: Int, category_ids: Int?) = | |
api.getNumberOfRandomCats(limit, category_ids) | |
interface CatsApi { | |
@GET("images/search") |
This file contains hidden or 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
/** | |
* The class representing the Json response. Use http://www.jsonschema2pojo.org/ to get this. | |
* Or you can add this plugin for AS here https://plugins.jetbrains.com/plugin/9960-json-to-kotlin-class-jsontokotlinclass- | |
* It will create your data class from JSON to kotlin. | |
*/ | |
data class NetCat( | |
@SerializedName("id") val id: String, | |
@SerializedName("url") val url: String, | |
@SerializedName("breeds") val breeds: List<Any>, |
This file contains hidden or 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 guy extends Repository class so the retrofit variable will be available to use as it's instantiated in the init! | |
*/ | |
class CatsRepository( | |
baseUrl: String, | |
isDebugEnabled: Boolean, | |
apiKey: String | |
) : Repository(baseUrl, isDebugEnabled, apiKey) { | |
private val catsDataSource: CatsDataSource = CatsDataSource(retrofit) |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
// Read the docs with detailed instructions to get your API key and endpoint! | |
// https://docs.thecatapi.com/ | |
// the server url endpoint | |
private val serverUrl = "https://api.thecatapi.com/v1/" | |
// this is where you declare your api key | |
private val apiKey = "yourApiKeyHere" |
This file contains hidden or 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
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
// need this plugin to make this work | |
apply plugin: 'kotlin-kapt' | |
android { | |
// your android stuff goes here | |
} |
This file contains hidden or 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
@GlideModule | |
class GlideAppModule : AppGlideModule() |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<ImageView | |
android:id="@+id/imageView" |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:dist="http://schemas.android.com/apk/distribution" | |
package="com.yourpackagenamehere"> | |
<dist:module dist:instant="true" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<application | |
android:allowBackup="true" |
OlderNewer