Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecaulley committed Jun 11, 2019
0 parents commit dd07b24
Show file tree
Hide file tree
Showing 51 changed files with 1,175 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Built application files
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Pokedex Example Android App

This application was created to show a simple application using the following,

* Retrofit
* Kotlin Couroutines
* ReKotlin
* Butterknife
* Glide

As of version 2.6.0 of Retrofit, there is now native library support for Kotlin couroutines.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

androidExtensions {
experimental = true
features = ["parcelize"]
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.pokedex"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'org.rekotlin:rekotlin:1.0.4'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-M1"
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.jakewharton:butterknife:10.1.0'
kapt 'com.jakewharton:butterknife-compiler:10.1.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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://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,24 @@
package com.example.pokedex

import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.example.pokedex", appContext.packageName)
}
}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.example.pokedex">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/pokedex/PokedexGlideModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.pokedex

import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule

@GlideModule
class PokedexGlideModule : AppGlideModule() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.pokedex.action

import org.rekotlin.Action

data class DownloadPokemonListAction(val unit: Unit = Unit) : Action
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.pokedex.action

import com.example.pokedex.model.Pokemon
import org.rekotlin.Action

data class PokemonListUpdatedAction(val pokemon: List<Pokemon>) : Action
32 changes: 32 additions & 0 deletions app/src/main/java/com/example/pokedex/activity/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.pokedex.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.pokedex.R
import com.example.pokedex.fragment.PokemonFragment
import com.example.pokedex.fragment.PokemonListFragment
import com.example.pokedex.model.Pokemon

class MainActivity : AppCompatActivity(), PokemonListFragment.OnPokemonSelectedInteractionListener {
override fun onPokemonSelectedInteraction(pokemon: Pokemon?) {
val pokemonFragment = PokemonFragment.newInstance(pokemon)
pushFragment(pokemonFragment)
}

private fun pushFragment(newFragment: Fragment) {
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, newFragment)
transaction.addToBackStack(null)
transaction.commit()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// Set the starting fragment
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, PokemonListFragment.newInstance()).commit()
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/example/pokedex/api/ApiClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.pokedex.api

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ApiClient {

private const val BASE_URL = "https://pokeapi.co/api/v2/"
private var retrofit: Retrofit? = null

val client: Retrofit?
get() {
if (retrofit == null) {
retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
return retrofit
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/example/pokedex/api/PokemonApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.pokedex.api

import com.example.pokedex.model.Pokemon
import com.example.pokedex.model.PokemonListResult
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Url
import java.net.URI

interface PokemonApi {
@GET("pokemon")
suspend fun getAll(): PokemonListResult

@GET
suspend fun getPokemon(@Url url: URI): Pokemon
}
38 changes: 38 additions & 0 deletions app/src/main/java/com/example/pokedex/appReducer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.pokedex

import android.util.Log
import com.example.pokedex.action.DownloadPokemonListAction
import com.example.pokedex.action.PokemonListUpdatedAction
import com.example.pokedex.api.ApiClient
import com.example.pokedex.api.PokemonApi
import com.example.pokedex.model.Pokemon
import com.example.pokedex.model.PokemonListResult
import com.example.pokedex.state.AppState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.rekotlin.Action

fun appReducer(action: Action, providedState: AppState?): AppState {
// if no state has been provided, create the default state
var state = providedState ?: AppState()

when (action) {
is PokemonListUpdatedAction -> {
state = state.copy(pokemon = action.pokemon)
}
is DownloadPokemonListAction -> {
val apiService = ApiClient.client?.create(PokemonApi::class.java)
CoroutineScope(Dispatchers.IO).launch {
val pokemonList = apiService?.getAll()?.results ?: emptyList()
val pokemon = pokemonList.mapNotNull { apiService?.getPokemon(it.url) }
withContext(Dispatchers.Main) {
appStore.dispatch(PokemonListUpdatedAction(pokemon))
}
}
}
}

return state
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/pokedex/appStore.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.pokedex

import org.rekotlin.Store

val appStore = Store(
reducer = ::appReducer,
state = null
)
Loading

0 comments on commit dd07b24

Please sign in to comment.