Skip to content

Commit

Permalink
Merge branch 'feature/JP-Cache' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarwillymc committed Oct 4, 2023
2 parents 9d5655d + f9f1372 commit 69af447
Show file tree
Hide file tree
Showing 58 changed files with 251 additions and 334 deletions.
Binary file added .DS_Store
Binary file not shown.
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,71 @@
# JPMorganTest
Test
## CESAR CANAZA

Mobile developer willing to learn old and new technologies, I like the team work and communication.
Thank you for check this project.

## Architecture MVVM with clean

### data (Repositories - Framework)
- di: Contains the dependency injection with hilt
- settings: Contains all the settings local `(Convertes, SharedEncription)` and network `(Interceptor, Cookie, more)`
- sources: Contains all the content of each feature `For example: Search` like `framework database or retrofit` the connection is through repository
- di: Contains the dependency injection of the Feature like `Search`
- entities: Contains all the entities of the feature like `Search`
- mapper: Contains all the mapper of the feature
- local: Contains the framework with the local storage
- remote: Contains the framework to connect the data using `voley, retrofit or other`
- repository files: Contains the interface and the implementation of the connections with the local and remote data
### domain (Model - Use Case)
- usecase:
- entities: Contains all the entities in domain with the logic if they have
- usecase Files: Contains each use case of the app where we can sort, filter and others
### presentation (ViewModel - Screen UI)
- Main Activity: Contains the main activity in jetpack compose
- Screen Directory: Contains all the resources that manage a screen like **View Model, CustomComposable, State, Screen**
- delegate: Contains Singleton classes that work when we need to share contents between ViewModel where we **delegate the action to do something** or **save something light**
### Additional comments
- ui: Package that contains all the layers like **Permission, General Composables, NavigationComponent, Theme, Services**
- util: Contains global Constants and Extension Functions
## FILE WITH JAVA
- domain/base/SuspendNoParamsUseCase.java
- data/sources/search/mapper/SearchResultMapperImpl.java
- data/sources/search/local/SearchLocalDataSourceImpl.java
## Technology Stack
- Kotlin Programming language
- Java: Programming language
- MVVM: Architecture design that help us to decouple our code in layers
- Retrofit: Library that help us to consume ApiRest
- JUnit: Framework that help us to test code
- Kotlin Coroutines: Provides ways to manage threads very easily
- Flow: Library that help us to manage the asynchronous stream data
- Mockk: Library for Mock data in the unit test
- Jetpack Compose: Framework for UI using Kotlin where we developed the code like puzzles
- Hilt: Dependency Injection in Compile-Time
- Jetpack Navigation: library that simplify and streamline the navigation between composables or screens
- Jacoco: Generate Files of the coverage of the unit test
- KLint: Format the code for give my quality to the project
- Detekt: Code analysis tool that help us to follow rules in the code
- others like: Google accompanist, Turbine ....
## Configuration:
### Local.properties
Add this line
```
WEATHER_KEY=751d80f6c314139192ffcb62c107e654
SHARED_PREFERENCES_NAME=dbappjpmorgan
BASE_URL=https://api.openweathermap.org/
```
### Gradle Java

Go to **Gradle JDK** and change to **Java17**

![Java](image/gradle_j17.png)

### DOWNLOAD APP
## Download the app by Google Drive
- [GOOGLE DRIVE](https://drive.google.com/drive/folders/1DV46UTecrTV2EdjYL2M6HMVA0CiD7H0K?usp=sharing)
## Download the app by artifact github
Go to [Here](https://github.com/cesarwillymc/JPMorganTest/actions)
- ![APK](image/artifact.png)
Later select the first workflow and download the apk
- ![APK](image/app.png)
Binary file added app/.DS_Store
Binary file not shown.
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.cesarwillymc.jpmorgantest.data.di
import android.content.Context
import android.content.SharedPreferences
import com.cesarwillymc.jpmorgantest.BuildConfig
import com.cesarwillymc.jpmorgantest.data.sources.local.EncryptedSharedPreferencesFactory
import com.cesarwillymc.jpmorgantest.data.settings.local.EncryptedSharedPreferencesFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.cesarwillymc.jpmorgantest.data.di

import com.cesarwillymc.jpmorgantest.BuildConfig
import com.cesarwillymc.jpmorgantest.data.sources.network.WeatherInterceptor
import com.cesarwillymc.jpmorgantest.data.sources.network.util.DefaultClient
import com.cesarwillymc.jpmorgantest.data.settings.network.WeatherInterceptor
import com.cesarwillymc.jpmorgantest.data.settings.network.util.DefaultClient
import com.cesarwillymc.jpmorgantest.data.sources.search.service.SearchService
import com.google.gson.Gson
import dagger.Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cesarwillymc.jpmorgantest.data.sources.local
package com.cesarwillymc.jpmorgantest.data.settings.local

import android.content.Context
import android.content.SharedPreferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cesarwillymc.jpmorgantest.data.sources.network
package com.cesarwillymc.jpmorgantest.data.settings.network

import com.cesarwillymc.jpmorgantest.BuildConfig
import okhttp3.Interceptor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.cesarwillymc.jpmorgantest.data.sources.network.util
package com.cesarwillymc.jpmorgantest.data.settings.network.util

import com.cesarwillymc.jpmorgantest.data.sources.network.util.error.ErrorApi
import com.cesarwillymc.jpmorgantest.data.sources.network.util.error.ErrorHandler
import com.cesarwillymc.jpmorgantest.data.sources.network.util.error.ErrorSource
import com.cesarwillymc.jpmorgantest.data.settings.network.util.error.ErrorApi
import com.cesarwillymc.jpmorgantest.data.settings.network.util.error.ErrorHandler
import com.cesarwillymc.jpmorgantest.data.settings.network.util.error.ErrorSource
import com.cesarwillymc.jpmorgantest.util.state.Result
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import okhttp3.ResponseBody
import retrofit2.HttpException
import java.io.IOException

/**
* Created by Cesar Canaza on 10/3/23.
* cesarwilly.mc@gmail.com
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cesarwillymc.jpmorgantest.data.sources.network.util
package com.cesarwillymc.jpmorgantest.data.settings.network.util

import javax.inject.Qualifier

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cesarwillymc.jpmorgantest.data.sources.network.util.error
package com.cesarwillymc.jpmorgantest.data.settings.network.util.error

/**
* Created by Cesar Canaza on 10/3/23.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cesarwillymc.jpmorgantest.data.sources.network.util.error
package com.cesarwillymc.jpmorgantest.data.settings.network.util.error

/**
* Created by Cesar Canaza on 10/3/23.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cesarwillymc.jpmorgantest.data.sources.network.util.error
package com.cesarwillymc.jpmorgantest.data.settings.network.util.error

/**
* Created by Cesar Canaza on 10/3/23.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.cesarwillymc.jpmorgantest.data.sources.search.local;

import android.content.SharedPreferences;

import androidx.annotation.NonNull;

import com.cesarwillymc.jpmorgantest.util.constants.ConstantsKt;
import com.cesarwillymc.jpmorgantest.util.state.Result;

import javax.inject.Inject;

import kotlin.Unit;
import kotlin.jvm.JvmField;


/**
* Created by Cesar Canaza on 10/4/23.
* cesarwilly.mc@gmail.com
* <p>
* IOWA, United States.
*/
public class SearchLocalDataSourceImpl implements SearchLocalDataSource {
private final SharedPreferences sharedPreferences;

@Inject
public SearchLocalDataSourceImpl(SharedPreferences sharedPreferences) {
this.sharedPreferences = sharedPreferences;
}

@NonNull
@Override
public Result<Unit> saveQuery(@NonNull String value) {
try {
SharedPreferences.Editor editor = sharedPreferences.edit();
if (value.isEmpty()) {
editor.remove(RECENTLY_SEARCHED);
} else {
editor.putString(RECENTLY_SEARCHED, value);
}
editor.apply();
return new Result.Success<>(null);
} catch (Exception e) {
return new Result.Error(e);
}
}

@NonNull
@Override
public Result<String> recentlySearched() {
try {
String result = sharedPreferences.getString(
RECENTLY_SEARCHED,
ConstantsKt.EMPTY_STRING
);
if (result.isBlank()) {
return new Result.Error(new Exception());
} else {
return new Result.Success<>(result);
}
} catch (Exception e) {
return new Result.Error(e);
}
}

@JvmField
static String RECENTLY_SEARCHED = "recently_searched";
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.cesarwillymc.jpmorgantest.data.sources.search.mapper;

import androidx.annotation.NonNull;

import com.cesarwillymc.jpmorgantest.data.sources.search.entities.WeatherDetailResponse;
import com.cesarwillymc.jpmorgantest.domain.usecase.entities.WeatherDetail;
import com.cesarwillymc.jpmorgantest.util.constants.ConstantsKt;

import javax.inject.Inject;

/**
* Created by Cesar Canaza on 10/4/23.
* cesarwilly.mc@gmail.com
* <p>
* IOWA, United States.
*/
public class SearchResultMapperImpl implements SearchResultMapper {
@Inject
public SearchResultMapperImpl(){}

@NonNull
@Override
public WeatherDetail fromResponseToDomain(@NonNull WeatherDetailResponse info) {
return new WeatherDetail(
info.getName(),
info.getMain().getFeelsLike(),
info.getWeather().isEmpty() ? ConstantsKt.EMPTY_STRING : info.getWeather().get(ConstantsKt.ZERO).getDescription(),
info.getMain().getHumidity(),
info.getMain().getPressure(),
info.getWind().getSpeed(),
info.getSys().getSunrise(),
info.getSys().getSunset(),
info.getWeather().isEmpty() ? ConstantsKt.EMPTY_STRING : info.getWeather().get(ConstantsKt.ZERO).getIcon()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cesarwillymc.jpmorgantest.data.sources.search.remote

import com.cesarwillymc.jpmorgantest.data.sources.network.util.BaseRemoteDataSource
import com.cesarwillymc.jpmorgantest.data.settings.network.util.BaseRemoteDataSource
import com.cesarwillymc.jpmorgantest.data.sources.search.entities.WeatherDetailResponse
import com.cesarwillymc.jpmorgantest.data.sources.search.service.SearchService
import com.cesarwillymc.jpmorgantest.util.state.Result
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cesarwillymc.jpmorgantest.domain.base;

import static com.cesarwillymc.jpmorgantest.util.constants.ConstantsKt.LOG_DOMAIN;
import android.util.Log;
import com.cesarwillymc.jpmorgantest.util.state.Result;

/**
* Created by Cesar Canaza on 10/3/23.
* cesarwilly.mc@gmail.com
* <p>
* IOWA, United States.
* <p>
* It can be used for use cases that return Unit, Boolean, Int, etc.
* No mapper needed
*/
public abstract class SuspendNoParamsUseCase<Results> {

public Result<Results> invoke() {
try {
return execute();
} catch (Exception e) {
Log.e(LOG_DOMAIN, e.getMessage());
return new Result.Error.Error(e);
}
}

protected abstract Result<Results> execute() throws Exception;
}
Loading

0 comments on commit 69af447

Please sign in to comment.