-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from felipecastilhos/refact/concerns_division
Melhorando a divisão de responsabilidades
- Loading branch information
Showing
36 changed files
with
407 additions
and
167 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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
17 changes: 0 additions & 17 deletions
17
app/src/main/java/com/github/felipecastilhos/pokedexandroid/AppModule.kt
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/github/felipecastilhos/pokedexandroid/PokedexApolloClient.kt
This file was deleted.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
app/src/main/java/com/github/felipecastilhos/pokedexandroid/PokedexApplication.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...roid/coroutines/AppDispatchersProvider.kt → ...mmun/coroutines/AppDispatchersProvider.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...xandroid/coroutines/DispatcherProvider.kt → ...d/commun/coroutines/DispatcherProvider.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...oid/coroutines/ScopedContextDispatcher.kt → ...mun/coroutines/ScopedContextDispatcher.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...stilhos/pokedexandroid/logs/LogHandler.kt → .../pokedexandroid/commun/logs/LogHandler.kt
This file contains 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 file contains 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
20 changes: 20 additions & 0 deletions
20
...ain/java/com/github/felipecastilhos/pokedexandroid/commun/network/PokedexApolloBuilder.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.felipecastilhos.pokedexandroid.commun.network | ||
|
||
import com.apollographql.apollo.ApolloClient | ||
import okhttp3.OkHttpClient | ||
|
||
/** | ||
* Application builder for [ApolloClient] the abstraction of GraphQl Client | ||
*/ | ||
object PokedexApolloBuilder { | ||
/** | ||
* Builds an [ApolloClient] | ||
* @param okHttpClient to be used on [ApolloClient] for making network requests | ||
* @param apiUrl is the server url to be used on [ApolloClient] | ||
*/ | ||
fun buildApollo(okHttpClient: OkHttpClient, apiUrl: String): ApolloClient = | ||
ApolloClient.builder() | ||
.serverUrl(apiUrl) | ||
.okHttpClient(okHttpClient) | ||
.build() | ||
} |
23 changes: 23 additions & 0 deletions
23
...ain/java/com/github/felipecastilhos/pokedexandroid/commun/network/PokedexOkHttpBuilder.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.felipecastilhos.pokedexandroid.commun.network | ||
|
||
import com.github.felipecastilhos.pokedexandroid.commun.logs.LogHandler | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
|
||
/** | ||
* | ||
*/ | ||
object PokedexOkHttpBuilder { | ||
fun buildOkHttp(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.addInterceptor(buildLogInterceptor(HttpLoggingInterceptor.Level.BODY)) | ||
.build() | ||
} | ||
|
||
private fun buildLogInterceptor(level: HttpLoggingInterceptor.Level): HttpLoggingInterceptor { | ||
val logger = HttpLoggingInterceptor.Logger { message -> LogHandler.d(message) } | ||
val logging = HttpLoggingInterceptor(logger) | ||
logging.level = level | ||
return logging | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...astilhos/pokedexandroid/ui/theme/Color.kt → ...s/pokedexandroid/commun/ui/theme/Color.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.github.felipecastilhos.pokedexandroid.ui.theme | ||
package com.github.felipecastilhos.pokedexandroid.commun.ui.theme | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
val Purple200 = Color(0xFFBB86FC) | ||
val Purple500 = Color(0xFF6200EE) | ||
val Purple700 = Color(0xFF3700B3) | ||
val Teal200 = Color(0xFF03DAC5) | ||
val Teal200 = Color(0xFF03DAC5) |
This file contains 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 file contains 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 file contains 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
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/github/felipecastilhos/pokedexandroid/datasource/Resource.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.felipecastilhos.pokedexandroid.datasource | ||
|
||
import com.github.felipecastilhos.pokedexandroid.datasource.remote.DataSourceException | ||
|
||
/** | ||
* Resource is an abstraction for data fetch | ||
*/ | ||
sealed class Resource<out T> { | ||
/** | ||
* Resource data fetch was successful | ||
* @param data was the result of data fetch | ||
*/ | ||
data class Success<out T>(val data: T) : Resource<T>() | ||
|
||
/** | ||
* Resource data fetch didn't work | ||
* @param exception was the error that occurred fetching data | ||
*/ | ||
data class Error(val exception: DataSourceException) : Resource<Nothing>() | ||
|
||
/** | ||
* Resource is loading, none result was returned yet. | ||
*/ | ||
object Loading : Resource<Nothing>() | ||
} | ||
|
||
/** | ||
* Extension to handle resouce on success data fetch | ||
*/ | ||
inline fun <T : Any> Resource<T>.onSuccess(action: (T) -> Unit): Resource<T> { | ||
if (this is Resource.Success) action(data) | ||
return this | ||
} | ||
|
||
/** | ||
* Extension to handle resouce on error data fetch | ||
*/ | ||
inline fun <T : Any> Resource<T>.onError(action: (DataSourceException) -> Unit): Resource<T> { | ||
if (this is Resource.Error) action(exception) | ||
return this | ||
} | ||
|
||
/** | ||
* Extension to handle resouce when is loading | ||
*/ | ||
inline fun <T : Any> Resource<T>.onLoading(action: () -> Unit): Resource<T> { | ||
if (this is Resource.Loading) action() | ||
return this | ||
} |
23 changes: 23 additions & 0 deletions
23
...n/java/com/github/felipecastilhos/pokedexandroid/datasource/remote/DataSourceException.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.felipecastilhos.pokedexandroid.datasource.remote | ||
|
||
import com.apollographql.apollo.api.Error | ||
|
||
/** | ||
* Data source exception | ||
* @param messageResource message for the error | ||
*/ | ||
sealed class DataSourceException( | ||
val messageResource: Any? | ||
) : RuntimeException() { | ||
/** | ||
* Unexpected error | ||
* @param messageResource resource for the message | ||
*/ | ||
class Unexpected(messageResource: Int) : DataSourceException(messageResource) | ||
|
||
/** | ||
* Server error | ||
* @param error that occurred | ||
*/ | ||
class Server(error: Error?) : DataSourceException(error) | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/github/felipecastilhos/pokedexandroid/datasource/remote/Enviroment.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.felipecastilhos.pokedexandroid.datasource.remote | ||
|
||
/** | ||
* Configurations of enviroments of the data sources | ||
*/ | ||
sealed class Enviroment(val graphQlUrl: String) { | ||
object Production : Enviroment("https://graphqlpokemon.favware.tech/") | ||
} |
3 changes: 3 additions & 0 deletions
3
...main/java/com/github/felipecastilhos/pokedexandroid/datasource/remote/RemoteDataSource.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.github.felipecastilhos.pokedexandroid.datasource.remote | ||
|
||
interface RemoteDataSource |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/github/felipecastilhos/pokedexandroid/di/AppModule.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.felipecastilhos.pokedexandroid.di | ||
|
||
import com.github.felipecastilhos.pokedexandroid.commun.coroutines.AppDispatchersProvider | ||
import com.github.felipecastilhos.pokedexandroid.commun.coroutines.DispatcherProvider | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
/** | ||
* [AppModule] provides communs components for the architecture over the application | ||
*/ | ||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
class AppModule { | ||
@Provides | ||
fun providesDispatcherProvider(): DispatcherProvider { | ||
return AppDispatchersProvider | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...xandroid/viewmodels/CoroutineViewModel.kt → ...d/domain/viewmodels/CoroutineViewModel.kt
This file contains 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
Oops, something went wrong.