Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose #3

Open
wants to merge 49 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
bade7dc
# splash screen on compose
Oct 11, 2021
84cefc2
# error screen on compose + flows in cache
Oct 11, 2021
3317975
# error screen on compose fixes
Oct 11, 2021
f238e33
# theme fix
Oct 11, 2021
2416e90
# pokemons screen on compose - done partially
Oct 11, 2021
2609594
# crash fixes
Oct 11, 2021
8aadcdd
# swipe refresh + fixes
Oct 12, 2021
d0aa4c9
# pagination
Oct 12, 2021
d12b2c7
# pagination
Oct 12, 2021
223ab30
# empty view
Oct 12, 2021
36e0192
# formatting
Oct 12, 2021
6639653
# trashHold fix
Oct 12, 2021
929b70b
# item click + crash fix
Oct 12, 2021
05804f8
# cleanup
Oct 12, 2021
1bb6015
# detail screen on compose + cleanup
Oct 12, 2021
45c92d9
# detail screen on compose done + cleanup
Oct 13, 2021
42628de
# gradle update
Oct 13, 2021
ad7ea59
# themes + smaller icons
Oct 13, 2021
4b6b55b
# unused libraries removed
Oct 13, 2021
3ca764a
# fucking hilt
Oct 13, 2021
e39da76
# cleanup
Oct 13, 2021
f054b6b
# cleanup
Oct 13, 2021
e028296
# todos
Oct 13, 2021
16720b4
# error handling while loading image
Oct 13, 2021
fe8c5e5
# mvi improvement
Nov 12, 2021
d9d7245
# mvi improvement
Nov 13, 2021
6bd93c0
# libs update
Nov 17, 2021
7d08878
Merge remote-tracking branch 'origin/compose' into compose
Nov 17, 2021
674a21c
# libs update
Dec 13, 2021
14f1606
# libs update
Dec 13, 2021
778998c
# libs update
Mar 22, 2022
ab17101
# migration fixes
Mar 22, 2022
17aa679
Merge remote-tracking branch 'origin/compose' into compose
Mar 22, 2022
bac456f
# merge fix
Mar 22, 2022
3bcc74c
# libs update
Apr 11, 2022
c68ea13
# mvi update (partial states)
Jun 16, 2022
c87b76e
# libs update
Jun 16, 2022
990f072
# cleanup
Jun 16, 2022
224f425
# libs update + room fixes
Nov 11, 2022
0d4aa1a
# mvi
Apr 21, 2023
c05bf82
# libs update
Apr 21, 2023
0d359a4
# agp migration
Apr 21, 2023
6898741
# agp migration to 8.0.0
Apr 21, 2023
1a2ca58
# agp migration fix
Apr 21, 2023
0d54991
# unit tests fixed
Apr 22, 2023
3e13b08
# duplication removed
Apr 22, 2023
ac675da
# migration
Apr 25, 2023
2f3ffdc
# review improvement
Sep 11, 2023
dbff4f1
# dsl migration
Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Pokemons
Exam task VMedia


TODO: animate screen changes
80 changes: 0 additions & 80 deletions app/build.gradle

This file was deleted.

98 changes: 98 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
plugins {
id("com.android.application")
kotlin("android")
id("com.google.devtools.ksp")
id("androidx.navigation.safeargs.kotlin")
id("dagger.hilt.android.plugin")
}

android {
namespace = "com.mdgd.pokemon"
compileSdk = rootProject.extra["compile"] as Int?

defaultConfig {
applicationId = "com.mdgd.pokemon"
minSdk = rootProject.extra["min"] as Int?

versionCode = 1
versionName = "1.0"
multiDexEnabled = true

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.6"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
implementation(project(":mvi"))
implementation(project(":models"))
implementation(project(":models_impl"))
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

// swipe-refresh
implementation("com.google.accompanist:accompanist-swiperefresh:0.19.0")

// navigation
implementation("androidx.navigation:navigation-fragment-ktx:${rootProject.extra["nav_version"]}")
implementation("androidx.navigation:navigation-ui-ktx:${rootProject.extra["nav_version"]}")

// image loading
implementation("io.coil-kt:coil-compose:1.3.0")

// json
implementation("com.google.code.gson:gson:${rootProject.extra["gson"]}")

// hilt
implementation("com.google.dagger:hilt-android:${rootProject.extra["hilt"]}")
ksp("com.google.dagger:hilt-android-compiler:${rootProject.extra["hilt"]}")

implementation("androidx.hilt:hilt-navigation-fragment:${rootProject.extra["hilt_jetpack"]}")
ksp("androidx.hilt:hilt-compiler:${rootProject.extra["hilt_jetpack"]}")
implementation("androidx.hilt:hilt-work:1.0.0")

// lifecycle
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${rootProject.extra["lifecycle_ktx"]}")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:${rootProject.extra["lifecycle_ktx"]}")

implementation("androidx.work:work-runtime-ktx:${rootProject.extra["work_version"]}")

testImplementation("junit:junit:${rootProject.extra["ver_junit"]}")
testImplementation("org.mockito:mockito-core:${rootProject.extra["mockito_core"]}")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:${rootProject.extra["mockito_kotlin"]}")
testImplementation("android.arch.core:core-testing:${rootProject.extra["testing_core"]}")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${rootProject.extra["testing_coroutine"]}")
testImplementation("com.google.code.gson:gson:${rootProject.extra["gson"]}")

androidTestImplementation("androidx.test.ext:junit:${rootProject.extra["junit_android"]}")
androidTestImplementation("androidx.test.espresso:espresso-core:${rootProject.extra["espresso"]}")
androidTestImplementation("com.android.support.test.espresso:espresso-contrib:3.3.0")

implementation("androidx.core:core-ktx:${rootProject.extra["ktx"]}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${rootProject.extra["coroutines"]}")
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.mdgd.pokemon;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

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

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mdgd.pokemon">
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:largeHeap="true"
android:name=".PokemonsApp"
android:allowBackup="true"
android:allowBackup="false"
android:icon="@drawable/ic_pokemon"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@drawable/ic_pokemon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/Theme.Pokemons">

<activity android:name=".ui.MainActivity">
<activity
android:name=".ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove" />

</application>

</manifest>
26 changes: 16 additions & 10 deletions app/src/main/java/com/mdgd/pokemon/PokemonsApp.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package com.mdgd.pokemon

import androidx.hilt.work.HiltWorkerFactory
import androidx.multidex.MultiDexApplication
import com.mdgd.pokemon.models.AppModule
import com.mdgd.pokemon.models_impl.DefaultAppModule
import androidx.work.Configuration
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject

class PokemonsApp : MultiDexApplication() {
@HiltAndroidApp
class PokemonsApp : MultiDexApplication(), Configuration.Provider {

var appComponent: AppModule? = null
private set
companion object {
var instance: PokemonsApp? = null
private set
}

@Inject
lateinit var workerFactory: HiltWorkerFactory

override fun onCreate() {
super.onCreate()
instance = this
appComponent = DefaultAppModule(this)
}

companion object {
var instance: PokemonsApp? = null
private set
}
override fun getWorkManagerConfiguration() = Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()
}
2 changes: 0 additions & 2 deletions app/src/main/java/com/mdgd/pokemon/bg/LoadPokemonsContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ package com.mdgd.pokemon.bg
interface ServiceModel {
fun load()
}

interface LoadPokemonContext
16 changes: 5 additions & 11 deletions app/src/main/java/com/mdgd/pokemon/bg/LoadPokemonsModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import kotlinx.coroutines.*
class LoadPokemonsModel(private val repo: PokemonsRepo, private val cache: Cache) : ServiceModel {
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val exceptionHandler = CoroutineExceptionHandler { _, e ->
coroutineScope.launch {
cache.putLoadingProgress(Result(e))
cancelScope()
}
cache.putLoadingProgress(Result(e))
coroutineScope.cancel()
}

override fun load() {
Expand All @@ -20,13 +18,9 @@ class LoadPokemonsModel(private val repo: PokemonsRepo, private val cache: Cache
repo.loadInitialPages(initialAmount)
cache.putLoadingProgress(Result(initialAmount))

cache.putLoadingProgress(Result(repo.loadPokemons(initialAmount)))
cancelScope()
val newAmount = repo.loadPokemons(initialAmount)
cache.putLoadingProgress(Result(newAmount))
coroutineScope.cancel()
}
}

private suspend fun cancelScope() {
delay(50)
coroutineScope.cancel()
}
}

This file was deleted.

14 changes: 11 additions & 3 deletions app/src/main/java/com/mdgd/pokemon/bg/UploadWorker.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.mdgd.pokemon.bg

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.mdgd.pokemon.PokemonsApp.Companion.instance
import com.mdgd.pokemon.models.cache.Cache
import com.mdgd.pokemon.models.repo.PokemonsRepo
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject

class UploadWorker(context: Context, params: WorkerParameters) : Worker(context, params) {
private val model: ServiceModel = PokemonsLoadingModelFactory(instance!!.appComponent!!).create()
@HiltWorker
class UploadWorker @AssistedInject constructor(
@Assisted context: Context, @Assisted params: WorkerParameters,
repo: PokemonsRepo, cache: Cache
) : Worker(context, params) {
private val model: ServiceModel = LoadPokemonsModel(repo, cache)

override fun doWork(): Result {
model.load()
Expand Down
Loading