Skip to content

Commit

Permalink
adding challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
lgleasain committed Jun 14, 2021
1 parent bc56c80 commit 1aacd15
Show file tree
Hide file tree
Showing 71 changed files with 3,190 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
/.idea
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: "androidx.navigation.safeargs.kotlin"

android {
compileSdkVersion 30
defaultConfig {
applicationId "com.raywenderlich.codingcompanionfinder"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}

dependencies {
// android stuff
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

// Kotlin
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0" // use -ktx for Kotlin
implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0" // use -ktx for

// Glide
implementation("com.github.bumptech.glide:glide:4.12.0") {
exclude group: "com.android.support"
}
kapt 'com.github.bumptech.glide:compiler:4.12.0'

// carouselview library
implementation "com.synnapps:carouselview:0.1.5"

// retrofit
implementation "com.squareup.okhttp3:logging-interceptor:3.14.9"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

// eventbus
implementation 'org.greenrobot:eventbus:3.1.1'

// Architecture components
def lifecycle_version = "2.2.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

// Koin
implementation 'org.koin:koin-android-viewmodel:2.0.1'
androidTestImplementation 'org.koin:koin-test:2.0.1'

// testing dependencies
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.test:rules:1.3.0"
androidTestImplementation "androidx.test.ext:junit:1.1.2"
androidTestImplementation "androidx.navigation:navigation-testing:2.3.5"
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.12.0'
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.3.0"
}
Original file line number Diff line number Diff line change
@@ -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:https://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
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"animals": [
{
"id": 44543909,
"organization_id": "GA604",
"url": "https://www.petfinder.com/dog/joy-44543909/ga/loganville/five-freedoms-farm-ga604/?referrer_id=22998841-2049-4c0e-a9f4-cdc9f8aebd64",
"type": "Dog",
"species": "Dog",
"breeds": {
"primary": "Shih Tzu",
"secondary": null,
"mixed": false,
"unknown": false
},
"colors": {
"primary": "White / Cream",
"secondary": null,
"tertiary": null
},
"age": "Senior",
"gender": "Male",
"size": "Small",
"coat": "Medium",
"attributes": {
"spayed_neutered": true,
"house_trained": false,
"declawed": null,
"special_needs": true,
"shots_current": true
},
"environment": {
"children": true,
"dogs": true,
"cats": true
},
"tags": [
"loving",
"docile"
],
"name": "Joy",
"description": "Joy is a docile, quiet lapdog who just wants to be held and loved! She came from a neglect situation...",
"photos": [
],
"status": "adoptable",
"published_at": "2019-04-25T13:45:51+0000",
"contact": {
"email": "[email protected]",
"phone": null,
"address": {
"address1": "PO Box 303",
"address2": null,
"city": "Loganville",
"state": "GA",
"postcode": "30052",
"country": "US"
}
},
"_links": {
"self": {
"href": "/v2/animals/44543909"
},
"type": {
"href": "/v2/types/dog"
},
"organization": {
"href": "/v2/organizations/ga604"
}
}
},
{
"id": 44543882,
"organization_id": "GA913",
"url": "https://www.petfinder.com/cat/kevin-44543882/ga/rome/public-animal-welfare-services-ga913/?referrer_id=22998841-2049-4c0e-a9f4-cdc9f8aebd64",
"type": "Cat",
"species": "Cat",
"breeds": {
"primary": "Domestic Short Hair",
"secondary": null,
"mixed": false,
"unknown": false
},
"colors": {
"primary": null,
"secondary": null,
"tertiary": null
},
"age": "Young",
"gender": "Female",
"size": "Medium",
"coat": null,
"attributes": {
"spayed_neutered": false,
"house_trained": false,
"declawed": false,
"special_needs": false,
"shots_current": false
},
"environment": {
"children": null,
"dogs": null,
"cats": null
},
"tags": [],
"name": "KEVIN",
"description": null,
"photos": [],
"status": "adoptable",
"published_at": "2019-04-25T13:23:40+0000",
"contact": {
"email": "[email protected]",
"phone": "(706) 236-4537",
"address": {
"address1": "99 North Ave",
"address2": null,
"city": "Rome",
"state": "GA",
"postcode": "30161",
"country": "US"
}
},
"_links": {
"self": {
"href": "/v2/animals/44543882"
},
"type": {
"href": "/v2/types/cat"
},
"organization": {
"href": "/v2/organizations/ga913"
}
}
}
],
"pagination": {
"count_per_page": 20,
"total_count": 230898,
"current_page": 1,
"total_pages": 11545,
"_links": {
"next": {
"href": "/v2/animals?location=30318&page=2"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2021 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
* distribute, sublicense, create a derivative work, and/or sell copies of the
* Software in any work that is designed, intended, or marketed for pedagogical or
* instructional purposes related to programming, coding, application development,
* or information technology. Permission for such use, copying, modification,
* merger, publication, distribution, sublicensing, creation of derivative works,
* or sale is expressly withheld.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.raywenderlich.codingcompanionfinder

import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

object CommonTestDataUtil {

fun dispatch(request: RecordedRequest): MockResponse? {
return when (request.path) {
"/animals?limit=20&location=30318" -> {
MockResponse().setResponseCode(200).setBody(
readFile("search_30318.json")
)
}
"/animals?limit=20&location=90210" -> {
MockResponse().setResponseCode(200).setBody("{\"animals\": []}")
}
else -> {
MockResponse().setResponseCode(404).setBody("{}")
}
}
}

@Throws(IOException::class)
private fun readFile(jsonFileName: String): String {
val inputStream = this::class.java.getResourceAsStream("/assets/$jsonFileName")
?: throw NullPointerException(
"Have you added the local resource correctly?, "
+ "Hint: name it as: " + jsonFileName
)
val stringBuilder = StringBuilder()
var inputStreamReader: InputStreamReader? = null
try {
inputStreamReader = InputStreamReader(inputStream)
val bufferedReader = BufferedReader(inputStreamReader)
var character: Int = bufferedReader.read()
while (character != -1) {
stringBuilder.append(character.toChar())
character = bufferedReader.read()
}
} catch (exception: IOException) {
exception.printStackTrace()
} finally {
inputStream.close()
inputStreamReader?.close()
}
return stringBuilder.toString()
}
}
Loading

0 comments on commit 1aacd15

Please sign in to comment.