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

Segundo entregable #32

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
115 changes: 115 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
id 'kotlin-android-extensions'

}

android {
compileSdk 32

defaultConfig {
applicationId "com.wizeline.criptocurrency"
minSdk 21
targetSdk 33
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'
}

viewBinding{
enabled=true
}

testOptions{
unitTests{
includeAndroidResources= true
}
}

kapt {
correctErrorTypes = true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.fragment:fragment-ktx:1.3.2'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'

// RETROFIT
implementation 'com.squareup.retrofit2:retrofit:2.9.0'

// GSON
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

//Hilt
implementation("com.google.dagger:hilt-android:2.44")
testImplementation 'junit:junit:4.12'
kapt("com.google.dagger:hilt-android-compiler:2.44")

//TEST
// To use the androidx.test.core APIs
androidTestImplementation("androidx.test:core:1.4.0")
// Kotlin extensions for androidx.test.core
androidTestImplementation("androidx.test:core-ktx:1.4.0")

// To use the androidx.test.espresso
androidTestImplementation("androidx.test:espresso:espresso-core:3.4.0")

// To use the JUnit Extension APIs
androidTestImplementation("androidx.test.ext:junit:1.1.3")
// Kotlin extensions for androidx.test.ext.junit
androidTestImplementation("androidx.test.ext:junit-ktx:1.1.3")

// To use the Truth Extension APIs
androidTestImplementation("androidx.test.ext:truth:1.4.0")

// To use the androidx.test.runner APIs
androidTestImplementation("androidx.test:runner:1.4.0")

// To use android test orchestrator
androidTestUtil("androidx.test:orchestrator:1.4.1")

//ROOM
implementation("androidx.room:room-runtime:2.4.3")
annotationProcessor("androidx.room:room-compiler:2.4.3")

// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:2.4.3")

// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:2.4.3")

// optional - RxJava2 support for Room
implementation("androidx.room:room-rxjava2:2.4.3")

// optional - RxJava3 support for Room
implementation("androidx.room:room-rxjava3:2.4.3")


//HTTP Logging Interceptor
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.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.wizeline.criptocurrency

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext
assertEquals("com.wizeline.criptomonedas", appContext.packageName)
}
}
27 changes: 27 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wizeline.criptocurrency">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.WizelineChallenge">
<activity
android:name="com.wizeline.criptocurrency.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
28 changes: 28 additions & 0 deletions app/src/main/java/com/wizeline/criptocurrency/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.wizeline.criptocurrency

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.wizeline.criptocurrency.common.adapters.utilities.toast
import com.wizeline.criptocurrency.ui.AvailableBooksFragment
import dagger.hilt.android.AndroidEntryPoint

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
loadFragment(AvailableBooksFragment())
}

fun loadFragment(fragment: Fragment){
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.add(R.id.fragment_container_view, fragment)
fragmentTransaction.commit()
}


}



Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wizeline.criptocurrency.common.adapters

sealed class RequestState<T>(val data: T? = null, val message: String? = null) {
class Success<T>(data: T) : RequestState<T>(data)
class Error<T>(message: String, data: T? = null) : RequestState<T>(data, message)
class Loading<T>(data: T? = null) : RequestState<T>(data)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.wizeline.criptocurrency.common.adapters

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.wizeline.criptocurrency.data.remote.dto.BitsoApi
import okhttp3.OkHttpClient
import okhttp3.Request
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import okhttp3.logging.HttpLoggingInterceptor

object RetrofitClient {

private const val BASE_URL = "https://api.bitso.com/v3/"

val gson: Gson = GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.setLenient()
.create()

private val okHttpClient: OkHttpClient =
OkHttpClient.Builder()
.addInterceptor { chain ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este código puede mejorar y ser más limpio. Logging interceptor y User-Agent interceptor son distintos y se pueden agregar al OkHttpClient.Builder en diferentes métodos de addInterceptor { ... }.
Así tampoco se requeriría agregar otro OkHttpClient.Builder dentro de addInterceptor.

val client: OkHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(HttpLoggingInterceptor().also {
it.setLevel(HttpLoggingInterceptor.Level.BODY)
}
).build()
val original = chain.request()
val request: Request = original.newBuilder()
.header("User-Agent", original.url.host)
.method(original.method, original.body)
.build()
client.newCall(request).execute()
}.build()

private fun getRetrofit(): Retrofit =
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient)
.build()

fun repository(): BitsoApi = getRetrofit().create(BitsoApi::class.java)

}
16 changes: 16 additions & 0 deletions app/src/main/java/com/wizeline/criptocurrency/common/VMFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wizeline.criptocurrency.common.adapters

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.wizeline.criptocurrency.domain.model.use_case.AvailableBooksUseCase
import com.wizeline.criptocurrency.domain.model.use_case.OrderBookUseCase
import com.wizeline.criptocurrency.domain.model.use_case.TickerUseCase
import com.wizeline.criptocurrency.ui.CriptoCurrencyViewModel

class ViewModelFactory(val availableBooksUseCase: AvailableBooksUseCase,
val tickerUseCase: TickerUseCase,
val orderBookUseCase: OrderBookUseCase
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T =
CriptoCurrencyViewModel(availableBooksUseCase,tickerUseCase,orderBookUseCase) as T
}
Loading