Skip to content

Commit

Permalink
Add project files
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-melikian committed Oct 11, 2020
1 parent f7dcd12 commit 2a6b8c5
Show file tree
Hide file tree
Showing 49 changed files with 1,222 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
80 changes: 80 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
}

repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/sargunv/maven' }
maven { url "https://jitpack.io" }
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "fr.ozoneprojects.pokedexcompose"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.10'
}
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'

// Lifecycle
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-beta01'

// Tests
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

// Jetpack Compose
// Compose UI
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"

// Compose Runtime LiveData
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

// Coil Composable
implementation 'com.github.luca992:coil-composable:0.3.2'

// PokeApiClient
implementation 'me.sargunvohra.lib:pokekotlin:2.3.1'

}
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,22 @@
package fr.ozoneprojects.pokedexcompose

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

/**
* 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.getInstrumentation().targetContext
assertEquals("fr.ozoneprojects.pokedexcompose", appContext.packageName)
}
}
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.ozoneprojects.pokedexcompose">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PokedexCompose">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.PokedexCompose.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
31 changes: 31 additions & 0 deletions app/src/main/java/fr/ozoneprojects/pokedexcompose/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.ozoneprojects.pokedexcompose

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.setContent
import androidx.ui.tooling.preview.Preview
import fr.ozoneprojects.pokedexcompose.ui.PokedexComposeTheme
import fr.ozoneprojects.pokedexcompose.ui.pokedex.app.compose.PokedexScreen

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApp()
}
}
}

@Composable
fun MyApp() {
PokedexComposeTheme {
PokedexScreen()
}
}

@Preview
@Composable
private fun DefaultPreview() {
MyApp()
}
22 changes: 22 additions & 0 deletions app/src/main/java/fr/ozoneprojects/pokedexcompose/ui/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.ozoneprojects.pokedexcompose.ui

import androidx.compose.ui.graphics.Color

val purple200 = Color(0xFFBB86FC)
val purple500 = Color(0xFF6200EE)
val purple700 = Color(0xFF3700B3)
val teal200 = Color(0xFF03DAC5)

val pokeBlack = Color(0xFF303943)
val pokeBlue = Color(0xFF429BED)
val pokeBrown = Color(0xFFB1736C)
val pokeLightBlue = Color(0xFF58ABF6)
val pokeLightBrown = Color(0xFFCA8179)
val pokeLightPurple = Color(0xFF9F5BBA)
val pokeLightRed = Color(0xFFF7786B)
val pokeLightTeal = Color(0xFF2CDAB1)
val pokeLightYellow = Color(0xFFFFCE4B)
val pokePurple = Color(0xFF7C538C)
val pokeRed = Color(0xFFFA6555)
val pokeTeal = Color(0xFF4FC1A6)
val pokeYellow = Color(0xFFF6C747)
11 changes: 11 additions & 0 deletions app/src/main/java/fr/ozoneprojects/pokedexcompose/ui/Shape.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.ozoneprojects.pokedexcompose.ui

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp

val shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)
47 changes: 47 additions & 0 deletions app/src/main/java/fr/ozoneprojects/pokedexcompose/ui/Theme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fr.ozoneprojects.pokedexcompose.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable

private val DarkColorPalette = darkColors(
primary = purple200,
primaryVariant = purple700,
secondary = teal200
)

private val LightColorPalette = lightColors(
primary = purple500,
primaryVariant = purple700,
secondary = teal200

/* Other default colors to override
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black,
*/
)

@Composable
fun PokedexComposeTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable() () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}

MaterialTheme(
colors = colors,
typography = typography,
shapes = shapes,
content = content
)
}
28 changes: 28 additions & 0 deletions app/src/main/java/fr/ozoneprojects/pokedexcompose/ui/Type.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fr.ozoneprojects.pokedexcompose.ui

import androidx.compose.material.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp

// Set of Material typography styles to start with
val typography = Typography(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
)
/* Other default text styles to override
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp
)
*/
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.ozoneprojects.pokedexcompose.ui.pokedex.app

import androidx.lifecycle.*
import fr.ozoneprojects.pokedexcompose.ui.pokedex.domain.PokedexRepository
import fr.ozoneprojects.pokedexcompose.ui.pokedex.domain.PokemonUi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class PokedexViewModelFactory(private val pokedexRepository: PokedexRepository) :
ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T =
modelClass.getConstructor(PokedexRepository::class.java)
.newInstance(pokedexRepository)

}

class PokedexViewModel(private val pokedexRepository: PokedexRepository) : ViewModel() {
private val pokedexEntries = MutableLiveData<List<PokemonUi>>()
fun pokedexEntries(): LiveData<List<PokemonUi>> = pokedexEntries

fun getAll() = viewModelScope.launch {
withContext(Dispatchers.IO) {
val result = pokedexRepository.getAll()
withContext(Dispatchers.Main) {
pokedexEntries.value = result
}
}
}
}

Loading

0 comments on commit 2a6b8c5

Please sign in to comment.