├── .gitignore ├── Bitlue_DarkTheme_FilterSettings.png ├── Bitlue_DarkTheme_HomeScreen.png ├── Bitlue_DemoVideo.mp4 ├── Bitlue_LightTheme_FilterSettings.png ├── Bitlue_LightTheme_HomeScreen.png ├── README.md ├── app-debug.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── carlosmesquita │ │ └── technicaltest │ │ └── n26 │ │ └── bitlue │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── carlosmesquita │ │ │ └── technicaltest │ │ │ └── n26 │ │ │ └── bitlue │ │ │ ├── BitlueApplication.kt │ │ │ ├── data_source │ │ │ ├── DataSource.kt │ │ │ └── remote │ │ │ │ ├── BlockchainRemoteDataSource.kt │ │ │ │ └── api │ │ │ │ └── blockchain │ │ │ │ ├── BlockchainAPI.kt │ │ │ │ ├── model │ │ │ │ ├── BitcoinValueDTO.kt │ │ │ │ ├── BlockchainResponseDTO.kt │ │ │ │ └── mapper │ │ │ │ │ ├── BitcoinValueDTOMapper.kt │ │ │ │ │ └── BlockchainResponseDTOMapper.kt │ │ │ │ └── utils │ │ │ │ ├── FilterRollingAverage.kt │ │ │ │ └── FilterTimeRange.kt │ │ │ ├── di │ │ │ ├── RemoteModule.kt │ │ │ └── RepositoryModule.kt │ │ │ ├── repository │ │ │ └── BitcoinRepository.kt │ │ │ ├── ui │ │ │ ├── MainActivity.kt │ │ │ ├── MainViewModel.kt │ │ │ ├── actions │ │ │ │ ├── MainEvents.kt │ │ │ │ └── MainStates.kt │ │ │ ├── bitcoin_value │ │ │ │ └── BitcoinValueFragment.kt │ │ │ ├── custom │ │ │ │ └── chart │ │ │ │ │ ├── BitcoinValuesChart.kt │ │ │ │ │ └── utils │ │ │ │ │ ├── DateAxisValueFormatter.kt │ │ │ │ │ ├── PriceAxisValueFormatter.kt │ │ │ │ │ └── PriceMarkerView.kt │ │ │ ├── model │ │ │ │ ├── BitcoinRecordInfo.kt │ │ │ │ └── BitcoinValue.kt │ │ │ └── settings │ │ │ │ └── filter │ │ │ │ └── FilterSettingsDialogFragment.kt │ │ │ └── utils │ │ │ ├── ModelsMapper.kt │ │ │ ├── Result.kt │ │ │ └── extensions │ │ │ ├── ContextX.kt │ │ │ └── LongX.kt │ └── res │ │ ├── anim │ │ ├── bottom_sheet_slide_in.xml │ │ └── bottom_sheet_slide_out.xml │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── dragger_bar.xml │ │ ├── gradient_primary_to_transparent.xml │ │ ├── ic_close.xml │ │ ├── ic_day_night.xml │ │ ├── ic_filter.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_bitcoin_value.xml │ │ ├── fragment_dialog_filter_settings.xml │ │ └── view_chart_marker.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── nav_graph.xml │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── motions.xml │ │ ├── shapes.xml │ │ ├── strings.xml │ │ ├── styles.xml │ │ ├── themes.xml │ │ └── types.xml │ └── test │ └── java │ └── com │ └── carlosmesquita │ └── technicaltest │ └── n26 │ └── bitlue │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | 15 | # Built application files 16 | *.abb 17 | 18 | # Files for the ART/Dalvik VM 19 | *.dex 20 | 21 | # Java class files 22 | *.class 23 | 24 | # Generated files 25 | bin/ 26 | gen/ 27 | out/ 28 | 29 | # Gradle files 30 | .gradle/ 31 | build/ 32 | 33 | # Local configuration file (sdk path, etc) 34 | local.properties 35 | 36 | # Proguard folder generated by Eclipse 37 | proguard/ 38 | 39 | # Log Files 40 | *.log 41 | 42 | # Android Studio Navigation editor temp files 43 | .navigation/ 44 | 45 | # Android Studio captures folder 46 | captures/ 47 | 48 | # Intellij 49 | /.idea 50 | 51 | # Keystore files 52 | *.jks 53 | 54 | # Others 55 | /keystore.properties 56 | /google-services.json 57 | -------------------------------------------------------------------------------- /Bitlue_DarkTheme_FilterSettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/Bitlue_DarkTheme_FilterSettings.png -------------------------------------------------------------------------------- /Bitlue_DarkTheme_HomeScreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/Bitlue_DarkTheme_HomeScreen.png -------------------------------------------------------------------------------- /Bitlue_DemoVideo.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/Bitlue_DemoVideo.mp4 -------------------------------------------------------------------------------- /Bitlue_LightTheme_FilterSettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/Bitlue_LightTheme_FilterSettings.png -------------------------------------------------------------------------------- /Bitlue_LightTheme_HomeScreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/Bitlue_LightTheme_HomeScreen.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bitlue 2 | 3 | 4 | 5 | > GIF Source: [Bitlue_DemoVideo](Bitlue_DemoVideo.mp4) 6 | 7 | Bitlue is an app where you can check the Bitcoin's current market price value (Bitcoin + value = Bitlue) and its records. 8 | 9 | The price values were requested from [Blockchain API](https://www.blockchain.com/charts). 10 | 11 | ## Getting Started 12 | 13 | In the last 3 days, I developed this nice app using the following tech stack: 14 | - Kotlin 15 | - MVVM architecture 16 | - Jetpack Architecture Components: ViewModel, Navigation... 17 | - Hilt - Dependency injection 18 | - Coroutines + Flow 19 | - Material Design Components 20 | - Retrofit 21 | - [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart) 22 | 23 | ## MVVM Architecture 24 | 25 | In this section I will explain the MVVM architecture followed and all its different parts: 26 | 27 | ### UI 28 | First of all, the UI is strongly supported by a solid design system supported by the **Material Design**. 29 | Thanks to that, create a consistent design and a **dark theme** in parallel were able to achieve. 30 | 31 | This project follows the *Single-Activity pattern*, where **`MainActivity.kt`** its the base Activity. 32 | From it we can differentiate 2 Fragments: 33 | * **`BitcoinValueFragment.kt`**: you can check the current price value of the Bitcoin and a chart of its records. 34 | 35 | 36 | 37 | * **`FilterSettingsDialogFragment.kt`**: filters the chart values between 2 filters: time 38 | range(`enum class FilterTimeRange`) and rolling average(`enum class FilterRollingAverage`). 39 | 40 | 41 | 42 | Both Fragments are consuming the same ViewModel: **`MainViewModel.kt`**. The `FilterSettingsDialogFragment` was highly dependent on the `BitcoinValueFragment` and vice-versa, so I thought it make sense to share the same *ViewModel*. 43 | 44 | Apart from the use of `LiveData` to display some reactive data, the other part of the communication between the Fragments and the ViewModel is made by the **unidirectional event-state data flow pattern**. This pattern allows to separate the UI events (of Fragments) from the UI states (requested by the `MainViewModel`). It highly achieves to decouple the UI logic and the business logic and it organizes them in a better way. 45 | 46 | The chart in the `BitcoinValueFragment` is powered by [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart). In addition, a custom view called **`BitcoinValueChart`** was created to wrap all needed setup code for the final chart. 47 | 48 | ### Repository + DataSource 49 | 50 | It was built a **`BitcoinRepository.kt`** which consumes from **`BlockchainRemoteDataSource.kt`** that provides with all Bitcoin information from **`BlockchainAPI.kt`** using **Retrofit**. 51 | 52 | A separate ***interface DataSource*** was created because it was planned to create a *LocalDataSource* to be able to save some values locally in a Room database. Unfortunately this was not possible to accomplish in the given time. 53 | 54 | ### Data Models 55 | In order to keep the UI model (domain model) separate from any DTO model, I created 2 different types of models: 56 | * **`BitcoinRecordInfo`** & **`BitcoinValue`** as domain models. `BitcoinRecordInfo` to display some general info in the `BitcoinValueFragment`, and `BitcoinValue` to display values in the chart. 57 | * **`BlockchainResponseDTO`** & **`BitcoinValueDTO`** as the remote source models. Used to retrieve data from the `BlockchainAPI`. 58 | 59 | Both of them make use of their own mappers which are used in the Repository layer to map the DTOs to the domain model when retrieving the Bitcoin info. 60 | 61 | ## Conclusion 62 | 63 | ### Resources 64 | Find attach to the project folder a [Debug APK](app-debug.apk). 65 | In addition, a few screenshots and a demo video can be found also in the project folder: 66 | - Bitlue_DemoVideo.mp4 67 | - Bitlue_LightTheme_HomeScreen.png 68 | - Bitlue_LightTheme_FilterSettings.png 69 | - Bitlue_DarkTheme_HomeScreen.png 70 | - Bitlue_DarkTheme_FilterSettings.png 71 | 72 | ### Final words 73 | I hope you could enjoy my work and could appreciate the effort in it. 74 | 75 | Don't hesitate to ask any question if you have. 76 | -------------------------------------------------------------------------------- /app-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app-debug.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | id 'dagger.hilt.android.plugin' 6 | } 7 | 8 | android { 9 | compileSdkVersion 30 10 | buildToolsVersion "30.0.3" 11 | 12 | defaultConfig { 13 | applicationId "com.carlosmesquita.technicaltest.n26.bitlue" 14 | minSdkVersion 21 15 | targetSdkVersion 30 16 | versionCode 1 17 | versionName "1.0" 18 | 19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 20 | } 21 | 22 | buildFeatures { 23 | viewBinding true 24 | dataBinding true 25 | } 26 | 27 | buildTypes { 28 | release { 29 | minifyEnabled false 30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 31 | } 32 | } 33 | compileOptions { 34 | sourceCompatibility JavaVersion.VERSION_1_8 35 | targetCompatibility JavaVersion.VERSION_1_8 36 | } 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | } 41 | 42 | dependencies { 43 | // Timber - Improved Logger 44 | implementation 'com.jakewharton.timber:timber:4.7.1' 45 | 46 | // Hilt - Dependency injection 47 | implementation "com.google.dagger:hilt-android:$hilt_version" 48 | kapt "com.google.dagger:hilt-compiler:$hilt_version" 49 | implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_androidx_version" 50 | 51 | // Kotlin Coroutines 52 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' 53 | 54 | // Navigation 55 | implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" 56 | implementation "androidx.navigation:navigation-ui-ktx:$nav_version" 57 | 58 | // Android X 59 | implementation 'androidx.core:core-ktx:1.3.2' 60 | implementation 'androidx.appcompat:appcompat:1.2.0' 61 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 62 | 63 | // Android Lifecycle KTX 64 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:$androidKtx_version" 65 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:$androidKtx_version" 66 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$androidKtx_version" 67 | 68 | // Google Material Design 69 | implementation 'com.google.android.material:material:1.3.0' 70 | 71 | // Retrofit 72 | implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" 73 | implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" 74 | 75 | // MPAndroidChart - Chart drawing library 76 | implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' 77 | 78 | // Testing 79 | testImplementation 'junit:junit:4.13.2' 80 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 81 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 82 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | 23 | # Fragment 24 | # Based on: https://dev4phones.wordpress.com/2020/04/23/error-unable-to-instantiate-fragment-androidx-navigation-fragment-navhostfragment-make-sure-class-name-exists/ 25 | -keep class * extends androidx.fragment.app.Fragment{} -------------------------------------------------------------------------------- /app/src/androidTest/java/com/carlosmesquita/technicaltest/n26/bitlue/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.carlosmesquita.technicaltest.n26.bitlue", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/BitlueApplication.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue 2 | 3 | import android.app.Application 4 | import androidx.appcompat.app.AppCompatDelegate 5 | import dagger.hilt.android.HiltAndroidApp 6 | import timber.log.Timber 7 | 8 | @HiltAndroidApp 9 | class BitlueApplication : Application() { 10 | 11 | override fun onCreate() { 12 | super.onCreate() 13 | 14 | if (BuildConfig.DEBUG) { 15 | Timber.plant(Timber.DebugTree()) 16 | } 17 | 18 | AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/DataSource.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 5 | import kotlinx.coroutines.flow.Flow 6 | 7 | interface DataSource { 8 | fun getBitcoinInfo(timeSpan: FilterTimeRange, rollingAverage: FilterRollingAverage): Flow 9 | } -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/BlockchainRemoteDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.DataSource 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.BlockchainAPI 5 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.BlockchainResponseDTO 6 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 7 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 8 | import kotlinx.coroutines.CoroutineDispatcher 9 | import kotlinx.coroutines.Dispatchers 10 | import kotlinx.coroutines.flow.Flow 11 | import kotlinx.coroutines.flow.flow 12 | import kotlinx.coroutines.flow.flowOn 13 | 14 | class BlockchainRemoteDataSource( 15 | private val blockchainAPI: BlockchainAPI, 16 | private val defaultDispatcher: CoroutineDispatcher = Dispatchers.IO 17 | ) : DataSource { 18 | 19 | override fun getBitcoinInfo( 20 | timeSpan: FilterTimeRange, 21 | rollingAverage: FilterRollingAverage 22 | ): Flow = flow { 23 | emit( 24 | blockchainAPI.getMarketPriceChart( 25 | timeSpan = timeSpan.queryText, 26 | rollingAverage = rollingAverage.queryText 27 | ) 28 | ) 29 | }.flowOn(defaultDispatcher) 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/BlockchainAPI.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.BlockchainResponseDTO 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 5 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 6 | import retrofit2.http.GET 7 | import retrofit2.http.Query 8 | 9 | interface BlockchainAPI { 10 | 11 | companion object { 12 | const val BASE_URL = "https://api.blockchain.info/" 13 | 14 | const val CHARTS_ENDPOINT = "charts" 15 | const val MARKET_PRICE_ENDPOINT = "market-price" 16 | 17 | const val TIME_SPAN_QUERY = "timespan" 18 | const val ROLLING_AVERAGE_QUERY = "rollingAverage" 19 | } 20 | 21 | @GET("$CHARTS_ENDPOINT/$MARKET_PRICE_ENDPOINT") 22 | suspend fun getMarketPriceChart( 23 | @Query(TIME_SPAN_QUERY) timeSpan: String = 24 | FilterTimeRange.ONE_YEAR.queryText, 25 | @Query(ROLLING_AVERAGE_QUERY) rollingAverage: String = 26 | FilterRollingAverage.RAW_VALUES.queryText, 27 | ): BlockchainResponseDTO 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/model/BitcoinValueDTO.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model 2 | 3 | data class BitcoinValueDTO( 4 | var x: Long, 5 | var y: Double 6 | ) 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/model/BlockchainResponseDTO.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model 2 | 3 | data class BlockchainResponseDTO( 4 | val status: String, 5 | val name: String, 6 | val unit: String, 7 | val period: String, 8 | val description: String, 9 | val values: List, 10 | ) 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/model/mapper/BitcoinValueDTOMapper.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.mapper 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.BitcoinValueDTO 4 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.model.BitcoinValue 5 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.DomainMapper 6 | 7 | class BitcoinValueDTOMapper : DomainMapper { 8 | 9 | override fun mapToDomainModel(dtoModel: BitcoinValueDTO): BitcoinValue { 10 | return BitcoinValue( 11 | dateMillis = dtoModel.x, 12 | price = dtoModel.y 13 | ) 14 | } 15 | 16 | override fun mapToDomainModelList(dtoModelList: List): List { 17 | return dtoModelList.map { mapToDomainModel(it) } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/model/mapper/BlockchainResponseDTOMapper.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.mapper 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.BlockchainResponseDTO 4 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.model.BitcoinRecordInfo 5 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.DomainMapper 6 | import java.util.* 7 | 8 | class BlockchainResponseDTOMapper : DomainMapper { 9 | 10 | override fun mapToDomainModel(dtoModel: BlockchainResponseDTO): BitcoinRecordInfo { 11 | return BitcoinRecordInfo( 12 | name = dtoModel.name, 13 | description = dtoModel.description, 14 | bitcoinValues = BitcoinValueDTOMapper().mapToDomainModelList(dtoModel.values).onEach { 15 | it.currency = Currency.getInstance(dtoModel.unit) 16 | } 17 | ) 18 | } 19 | 20 | override fun mapToDomainModelList(dtoModelList: List): List { 21 | return dtoModelList.map { mapToDomainModel(it) } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/utils/FilterRollingAverage.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils 2 | 3 | enum class FilterRollingAverage( 4 | val displayText: String, 5 | val queryText: String, 6 | val isDefault: Boolean 7 | ) { 8 | RAW_VALUES("8 Hours", "8hours", true), 9 | SEVEN_DAY_AVERAGE("7 Days", "7days", false), 10 | THIRTY_DAY_AVERAGE("30 Days", "30days", false) 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/data_source/remote/api/blockchain/utils/FilterTimeRange.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils 2 | 3 | enum class FilterTimeRange( 4 | val displayText: String, 5 | val queryText: String, 6 | val isDefault: Boolean 7 | ) { 8 | THIRTY_DAYS("30 Days", "30days", false), 9 | ONE_YEAR("1 Year", "1year", true), 10 | THREE_YEARS("3 Years", "3years", false), 11 | ALL("All", "100years", false) 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/di/RemoteModule.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.di 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.BlockchainRemoteDataSource 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.BlockchainAPI 5 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.mapper.BlockchainResponseDTOMapper 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.components.SingletonComponent 10 | import retrofit2.Retrofit 11 | import retrofit2.converter.gson.GsonConverterFactory 12 | import javax.inject.Singleton 13 | 14 | @Module 15 | @InstallIn(SingletonComponent::class) 16 | object RemoteModule { 17 | 18 | @Singleton 19 | @Provides 20 | fun provideBlockchainAPI(): BlockchainAPI = Retrofit.Builder() 21 | .baseUrl(BlockchainAPI.BASE_URL) 22 | .addConverterFactory(GsonConverterFactory.create()) 23 | .build() 24 | .create(BlockchainAPI::class.java) 25 | 26 | @Singleton 27 | @Provides 28 | fun provideBlockchainResponseDTOMapper() = BlockchainResponseDTOMapper() 29 | 30 | @Singleton 31 | @Provides 32 | fun provideBlockchainRemoteDataSource(blockchainAPI: BlockchainAPI) = 33 | BlockchainRemoteDataSource(blockchainAPI) 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/di/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.di 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.BlockchainRemoteDataSource 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.mapper.BlockchainResponseDTOMapper 5 | import com.carlosmesquita.technicaltest.n26.bitlue.repository.BitcoinRepository 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.components.SingletonComponent 10 | import javax.inject.Singleton 11 | 12 | @Module 13 | @InstallIn(SingletonComponent::class) 14 | object RepositoryModule { 15 | 16 | @Singleton 17 | @Provides 18 | fun provideRepository( 19 | blockchainRemoteDataSource: BlockchainRemoteDataSource, 20 | blockchainResponseDTOMapper: BlockchainResponseDTOMapper 21 | ) = 22 | BitcoinRepository(blockchainRemoteDataSource, blockchainResponseDTOMapper) 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/repository/BitcoinRepository.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.repository 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.BlockchainRemoteDataSource 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.model.mapper.BlockchainResponseDTOMapper 5 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 6 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 7 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.model.BitcoinRecordInfo 8 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.Result 9 | import kotlinx.coroutines.CoroutineDispatcher 10 | import kotlinx.coroutines.Dispatchers 11 | import kotlinx.coroutines.flow.Flow 12 | import kotlinx.coroutines.flow.flowOn 13 | import kotlinx.coroutines.flow.map 14 | 15 | class BitcoinRepository( 16 | private val blockchainRemoteDataSource: BlockchainRemoteDataSource, 17 | private val blockchainResponseDTOMapper: BlockchainResponseDTOMapper, 18 | private val defaultDispatcher: CoroutineDispatcher = Dispatchers.Default 19 | ) { 20 | 21 | fun getBitcoinInfo( 22 | timeSpan: FilterTimeRange, 23 | rollingAverage: FilterRollingAverage 24 | ): Flow> = 25 | blockchainRemoteDataSource.getBitcoinInfo(timeSpan, rollingAverage) 26 | .map { 27 | val mappedResponse = blockchainResponseDTOMapper.mapToDomainModel(it) 28 | 29 | Result.Success(mappedResponse) 30 | } 31 | .flowOn(defaultDispatcher) 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.carlosmesquita.technicaltest.n26.bitlue.databinding.ActivityMainBinding 6 | import dagger.hilt.android.AndroidEntryPoint 7 | 8 | @AndroidEntryPoint 9 | class MainActivity : AppCompatActivity() { 10 | 11 | private lateinit var binding: ActivityMainBinding 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | 16 | binding = ActivityMainBinding.inflate(layoutInflater) 17 | setContentView(binding.root) 18 | } 19 | } -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui 2 | 3 | import androidx.appcompat.app.AppCompatDelegate 4 | import androidx.lifecycle.* 5 | import com.carlosmesquita.technicaltest.n26.bitlue.BuildConfig 6 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 7 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 8 | import com.carlosmesquita.technicaltest.n26.bitlue.repository.BitcoinRepository 9 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainEvents 10 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainEvents.BitcoinValueEvents 11 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainEvents.FilterSettingsEvents 12 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainStates 13 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainStates.BitcoinValueStates 14 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.Result 15 | import dagger.hilt.android.lifecycle.HiltViewModel 16 | import kotlinx.coroutines.ExperimentalCoroutinesApi 17 | import kotlinx.coroutines.channels.Channel 18 | import kotlinx.coroutines.flow.* 19 | import kotlinx.coroutines.launch 20 | import timber.log.Timber 21 | import javax.inject.Inject 22 | 23 | @ExperimentalCoroutinesApi 24 | @HiltViewModel 25 | class MainViewModel @Inject constructor( 26 | repository: BitcoinRepository 27 | ) : ViewModel() { 28 | 29 | val eventsChannel = Channel(Channel.BUFFERED) 30 | private val events = eventsChannel.receiveAsFlow() 31 | 32 | private val _states = MutableSharedFlow() 33 | val states = _states.asSharedFlow() 34 | 35 | private val _selectedTimeRangeFilter = 36 | MutableLiveData(FilterTimeRange.values().first { it.isDefault }) 37 | val selectedTimeRangeFilter: LiveData = _selectedTimeRangeFilter 38 | 39 | private val _selectedRollingAverageFilter = 40 | MutableLiveData(FilterRollingAverage.values().first { it.isDefault }) 41 | val selectedRollingAverageFilter: LiveData = _selectedRollingAverageFilter 42 | 43 | private val bitcoinInfoFlow = combine( 44 | selectedTimeRangeFilter.asFlow(), 45 | selectedRollingAverageFilter.asFlow() 46 | ) { timeRangeFilter, rollingAverageFilter -> 47 | Pair(timeRangeFilter, rollingAverageFilter) 48 | }.flatMapLatest { (timeRangeFilter, rollingAverageFilter) -> 49 | repository.getBitcoinInfo(timeRangeFilter, rollingAverageFilter) 50 | }.onStart { 51 | resumeLoading() 52 | }.catch { 53 | emit(Result.Error(it)) 54 | }.onCompletion { 55 | stopLoading() 56 | } 57 | 58 | val errorMessage = bitcoinInfoFlow 59 | .filter { it is Result.Error } 60 | .map { (it as Result.Error).throwable.message } 61 | .asLiveData() 62 | 63 | val currentBitcoinValue = liveData { 64 | val firstSuccessResult = bitcoinInfoFlow 65 | .firstOrNull { it is Result.Success } as? Result.Success ?: return@liveData 66 | 67 | emit(firstSuccessResult.data.bitcoinValues.last().getPriceStringFormat()) 68 | } 69 | 70 | val infoTitle = bitcoinInfoFlow 71 | .filter { it is Result.Success } 72 | .map { (it as Result.Success).data.name } 73 | .asLiveData() 74 | 75 | val bitcoinValues = bitcoinInfoFlow 76 | .filter { it is Result.Success } 77 | .map { (it as Result.Success).data.bitcoinValues } 78 | .asLiveData() 79 | 80 | init { 81 | viewModelScope.launch { 82 | events.collect { 83 | Timber.i("Event triggered => ${it::class.java.name}") 84 | 85 | when (it) { 86 | is BitcoinValueEvents -> handleBitcoinValueEvent(it) 87 | is FilterSettingsEvents -> handleFilterSettingsEvent(it) 88 | } 89 | } 90 | } 91 | } 92 | 93 | private fun handleBitcoinValueEvent(event: BitcoinValueEvents) = viewModelScope.launch { 94 | when (event) { 95 | BitcoinValueEvents.OnFabClicked -> { 96 | sendStateToUI(BitcoinValueStates.OpenFilterSettings) 97 | } 98 | 99 | BitcoinValueEvents.OnThemeToggleClicked -> { 100 | if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) { 101 | AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) 102 | } else { 103 | AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) 104 | } 105 | } 106 | 107 | else -> { 108 | if (BuildConfig.DEBUG) { 109 | throw IllegalStateException( 110 | "Unknown BitcoinValueEvents instance: ${event::class.java.simpleName}" 111 | ) 112 | } 113 | } 114 | } 115 | } 116 | 117 | private fun handleFilterSettingsEvent(event: FilterSettingsEvents) = viewModelScope.launch { 118 | when (event) { 119 | is FilterSettingsEvents.OnFilterTimeRangeClicked -> { 120 | _selectedTimeRangeFilter.value = event.filterTimeRange 121 | } 122 | 123 | is FilterSettingsEvents.OnFilterRollingAverageClicked -> { 124 | _selectedRollingAverageFilter.value = event.filterRollingAverage 125 | } 126 | 127 | else -> { 128 | if (BuildConfig.DEBUG) { 129 | throw IllegalStateException( 130 | "Unknown FilterSettingsEvents instance: ${event::class.java.simpleName}" 131 | ) 132 | } 133 | } 134 | } 135 | } 136 | 137 | private fun resumeLoading() = viewModelScope.launch { 138 | sendStateToUI(BitcoinValueStates.HideFAB) 139 | sendStateToUI(BitcoinValueStates.ShowLoading) 140 | } 141 | 142 | private fun stopLoading() = viewModelScope.launch { 143 | sendStateToUI(BitcoinValueStates.HideLoading) 144 | sendStateToUI(BitcoinValueStates.ShowFAB) 145 | } 146 | 147 | private suspend fun sendStateToUI(states: MainStates) = viewModelScope.launch { 148 | _states.emit(states) 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/actions/MainEvents.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.actions 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 4 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 5 | 6 | sealed class MainEvents { 7 | 8 | sealed class BitcoinValueEvents : MainEvents() { 9 | object OnFabClicked : BitcoinValueEvents() 10 | object OnThemeToggleClicked : BitcoinValueEvents() 11 | } 12 | 13 | sealed class FilterSettingsEvents : MainEvents() { 14 | data class OnFilterTimeRangeClicked(val filterTimeRange: FilterTimeRange) : 15 | FilterSettingsEvents() 16 | 17 | data class OnFilterRollingAverageClicked(val filterRollingAverage: FilterRollingAverage) : 18 | FilterSettingsEvents() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/actions/MainStates.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.actions 2 | 3 | sealed class MainStates { 4 | 5 | sealed class BitcoinValueStates : MainStates() { 6 | object OpenFilterSettings : BitcoinValueStates() 7 | object ShowLoading : BitcoinValueStates() 8 | object HideLoading : BitcoinValueStates() 9 | object ShowFAB : BitcoinValueStates() 10 | object HideFAB : BitcoinValueStates() 11 | } 12 | 13 | sealed class FilterSettingsStates : MainStates() 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/bitcoin_value/BitcoinValueFragment.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.bitcoin_value 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.core.view.isVisible 6 | import androidx.fragment.app.Fragment 7 | import androidx.fragment.app.activityViewModels 8 | import androidx.lifecycle.lifecycleScope 9 | import androidx.navigation.fragment.findNavController 10 | import com.carlosmesquita.technicaltest.n26.bitlue.BuildConfig 11 | import com.carlosmesquita.technicaltest.n26.bitlue.R 12 | import com.carlosmesquita.technicaltest.n26.bitlue.databinding.FragmentBitcoinValueBinding 13 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.MainViewModel 14 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainEvents.BitcoinValueEvents 15 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainStates.BitcoinValueStates 16 | import com.google.android.material.dialog.MaterialAlertDialogBuilder 17 | import dagger.hilt.android.AndroidEntryPoint 18 | import kotlinx.coroutines.ExperimentalCoroutinesApi 19 | import kotlinx.coroutines.InternalCoroutinesApi 20 | import kotlinx.coroutines.flow.collect 21 | import kotlinx.coroutines.launch 22 | import timber.log.Timber 23 | 24 | @InternalCoroutinesApi 25 | @ExperimentalCoroutinesApi 26 | @AndroidEntryPoint 27 | class BitcoinValueFragment : Fragment(R.layout.fragment_bitcoin_value) { 28 | 29 | private val viewModel: MainViewModel by activityViewModels() 30 | 31 | private val binding: FragmentBitcoinValueBinding 32 | get() = _binding!! 33 | private var _binding: FragmentBitcoinValueBinding? = null 34 | 35 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 36 | super.onViewCreated(view, savedInstanceState) 37 | 38 | _binding = FragmentBitcoinValueBinding.bind(view).apply { 39 | lifecycleOwner = this@BitcoinValueFragment.viewLifecycleOwner 40 | viewModel = this@BitcoinValueFragment.viewModel 41 | } 42 | 43 | collectUIStates() 44 | 45 | viewModel.errorMessage.observe(viewLifecycleOwner) { 46 | showErrorDialog(it ?: return@observe) 47 | } 48 | 49 | viewModel.bitcoinValues.observe(viewLifecycleOwner) { 50 | binding.valuesChart.show(it) 51 | } 52 | 53 | binding.themeToggle.setOnClickListener { 54 | sendEvent(BitcoinValueEvents.OnThemeToggleClicked) 55 | } 56 | 57 | binding.fab.setOnClickListener { 58 | sendEvent(BitcoinValueEvents.OnFabClicked) 59 | } 60 | } 61 | 62 | override fun onDestroyView() { 63 | super.onDestroyView() 64 | 65 | _binding = null 66 | } 67 | 68 | private fun collectUIStates() = lifecycleScope.launchWhenStarted { 69 | viewModel.states.collect { 70 | Timber.i("State received => ${it::class.java.name}") 71 | 72 | if (it !is BitcoinValueStates) { 73 | return@collect 74 | } 75 | 76 | when (it) { 77 | BitcoinValueStates.OpenFilterSettings -> { 78 | findNavController().navigate(R.id.to_filterSettingsDialogFragment) 79 | } 80 | 81 | BitcoinValueStates.ShowLoading -> { 82 | binding.loadingBar.isVisible = true 83 | } 84 | 85 | BitcoinValueStates.HideLoading -> { 86 | binding.loadingBar.isVisible = false 87 | } 88 | 89 | BitcoinValueStates.ShowFAB -> { 90 | binding.fab.show() 91 | } 92 | 93 | BitcoinValueStates.HideFAB -> { 94 | binding.fab.hide() 95 | } 96 | 97 | else -> { 98 | if (BuildConfig.DEBUG) { 99 | throw IllegalStateException( 100 | "Unknown BitcoinValueStates instance: ${it::class.java.simpleName}" 101 | ) 102 | } 103 | } 104 | } 105 | } 106 | } 107 | 108 | private fun sendEvent(event: BitcoinValueEvents) = lifecycleScope.launch { 109 | viewModel.eventsChannel.send(event) 110 | } 111 | 112 | private fun showErrorDialog(detailsMessage: String) { 113 | MaterialAlertDialogBuilder(context ?: return) 114 | .setTitle(R.string.title_unexpected_error) 115 | .setMessage(getString(R.string.message_unexpected_error, detailsMessage)) 116 | .setPositiveButton(R.string.action_ok, null) 117 | .show() 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/custom/chart/BitcoinValuesChart.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import androidx.annotation.ColorInt 6 | import androidx.core.content.ContextCompat 7 | import com.carlosmesquita.technicaltest.n26.bitlue.R 8 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart.utils.DateAxisValueFormatter 9 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart.utils.PriceAxisValueFormatter 10 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart.utils.PriceMarkerView 11 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.model.BitcoinValue 12 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.extensions.getThemeColor 13 | import com.github.mikephil.charting.animation.Easing 14 | import com.github.mikephil.charting.charts.LineChart 15 | import com.github.mikephil.charting.data.Entry 16 | import com.github.mikephil.charting.data.LineData 17 | import com.github.mikephil.charting.data.LineDataSet 18 | import kotlinx.coroutines.* 19 | 20 | class BitcoinValuesChart @JvmOverloads constructor( 21 | context: Context, 22 | attrs: AttributeSet? = null, 23 | defStyle: Int = 0 24 | ) : LineChart(context, attrs, defStyle) { 25 | 26 | companion object { 27 | const val CHART_X_ANIMATION_DURATION = 2000 28 | val DEFAULT_ANIMATION_EASING: Easing.EasingFunction = Easing.EaseInOutQuad 29 | } 30 | 31 | private val xAxisValueFormatter = DateAxisValueFormatter() 32 | private val yAxisValueFormatter = PriceAxisValueFormatter() 33 | 34 | init { 35 | // No description or legend needed 36 | description.isEnabled = false 37 | legend.isEnabled = false 38 | 39 | // Disable any kind of zoom behaviour 40 | setScaleEnabled(false) 41 | isDoubleTapToZoomEnabled = false 42 | 43 | // Let user touch to highlight a selected value 44 | setTouchEnabled(true) 45 | 46 | setBorderColor(context.getThemeColor(R.attr.colorPrimary)) 47 | marker = PriceMarkerView(context, R.layout.view_chart_marker).apply { 48 | chartView = this@BitcoinValuesChart 49 | } 50 | 51 | setupNoDataText() 52 | setupXAxis() 53 | setupYAxis() 54 | } 55 | 56 | fun show(bitcoinValues: List) { 57 | // To show loading message 58 | data = null 59 | invalidate() 60 | 61 | CoroutineScope(Dispatchers.Default).launch { 62 | data = getData(bitcoinValues) 63 | 64 | withContext(Dispatchers.Main) { 65 | // To remove highlight value when new values are displayed 66 | highlightValue(null) 67 | animateX(CHART_X_ANIMATION_DURATION, DEFAULT_ANIMATION_EASING) 68 | } 69 | } 70 | } 71 | 72 | private fun setupXAxis() { 73 | xAxis.valueFormatter = xAxisValueFormatter 74 | xAxis.gridColor = ContextCompat.getColor(context, R.color.gray_light) 75 | xAxis.textColor = context.getThemeColor(R.attr.colorOnBackground) 76 | xAxis.setDrawAxisLine(false) 77 | } 78 | 79 | private fun setupYAxis() { 80 | axisLeft.valueFormatter = yAxisValueFormatter 81 | axisLeft.textColor = context.getThemeColor(R.attr.colorOnBackground) 82 | axisLeft.setDrawAxisLine(false) 83 | axisLeft.setDrawZeroLine(false) 84 | axisLeft.setDrawGridLines(false) 85 | 86 | axisRight.isEnabled = false 87 | } 88 | 89 | private fun setupNoDataText( 90 | text: String = context.getString(R.string.loading), 91 | @ColorInt textColor: Int = context.getThemeColor(R.attr.colorSecondary) 92 | ) { 93 | setNoDataText(text) 94 | setNoDataTextColor(textColor) 95 | } 96 | 97 | private fun getData(bitcoinValues: List): LineData { 98 | val entries = bitcoinValues.map { 99 | Entry(it.dateMillis.toFloat(), it.price.toFloat(), it.getPriceStringFormat()) 100 | } 101 | val lineDataSet = getLineDataSet(entries) 102 | 103 | return LineData(lineDataSet) 104 | } 105 | 106 | private fun getLineDataSet(entries: List) = LineDataSet(entries, "").apply { 107 | color = context.getThemeColor(R.attr.colorPrimary) 108 | fillDrawable = 109 | ContextCompat.getDrawable(context, R.drawable.gradient_primary_to_transparent) 110 | valueTextSize = 0f 111 | 112 | setDrawFilled(true) 113 | setDrawCircles(false) 114 | 115 | highLightColor = context.getThemeColor(R.attr.colorSecondary) 116 | setDrawHorizontalHighlightIndicator(false) 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/custom/chart/utils/DateAxisValueFormatter.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart.utils 2 | 3 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.extensions.toDateFormat 4 | import com.carlosmesquita.technicaltest.n26.bitlue.utils.extensions.unixToMillis 5 | import com.github.mikephil.charting.formatter.IndexAxisValueFormatter 6 | 7 | class DateAxisValueFormatter : IndexAxisValueFormatter() { 8 | 9 | companion object { 10 | const val DEFAULT_DATE_FORMAT = "MMM yy" 11 | } 12 | 13 | override fun getFormattedValue(value: Float): String { 14 | return value.toLong().unixToMillis().toDateFormat(DEFAULT_DATE_FORMAT) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/custom/chart/utils/PriceAxisValueFormatter.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart.utils 2 | 3 | import com.github.mikephil.charting.formatter.IndexAxisValueFormatter 4 | import kotlin.math.roundToInt 5 | 6 | class PriceAxisValueFormatter : IndexAxisValueFormatter() { 7 | 8 | override fun getFormattedValue(value: Float): String { 9 | return if (value > 1000f) { 10 | "${(value / 1000).roundToInt()}K" 11 | } else if (value <= 0f) { 12 | "" 13 | } else { 14 | value.toString() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/custom/chart/utils/PriceMarkerView.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.custom.chart.utils 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.view.LayoutInflater 6 | import androidx.annotation.LayoutRes 7 | import com.carlosmesquita.technicaltest.n26.bitlue.databinding.ViewChartMarkerBinding 8 | import com.github.mikephil.charting.components.MarkerView 9 | import com.github.mikephil.charting.data.Entry 10 | import com.github.mikephil.charting.highlight.Highlight 11 | import com.github.mikephil.charting.utils.MPPointF 12 | 13 | @SuppressLint("ViewConstructor") 14 | class PriceMarkerView( 15 | context: Context, 16 | @LayoutRes layoutResource: Int 17 | ) : MarkerView(context, layoutResource) { 18 | 19 | private val binding = ViewChartMarkerBinding.inflate(LayoutInflater.from(context), this, true) 20 | 21 | override fun refreshContent(entry: Entry?, highlight: Highlight?) { 22 | binding.markerTextLabel.text = entry?.data.toString() 23 | 24 | super.refreshContent(entry, highlight) 25 | } 26 | 27 | override fun getOffset(): MPPointF { 28 | return MPPointF(getXOffset(), getYOffset()) 29 | } 30 | 31 | private fun getXOffset(): Float { 32 | // this will center the marker-view horizontally 33 | return (-(width / 2)).toFloat() 34 | } 35 | 36 | private fun getYOffset(): Float { 37 | // this will cause the marker-view to be above the selected value 38 | return (-height).toFloat() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/model/BitcoinRecordInfo.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.model 2 | 3 | class BitcoinRecordInfo( 4 | val name: String, 5 | val description: String, 6 | val bitcoinValues: List, 7 | ) 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/model/BitcoinValue.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.model 2 | 3 | import java.text.NumberFormat 4 | import java.util.* 5 | 6 | data class BitcoinValue( 7 | val dateMillis: Long, 8 | val price: Double, 9 | ) { 10 | 11 | lateinit var currency: Currency 12 | 13 | companion object { 14 | const val MAX_FRACTION_DIGITS = 2 15 | } 16 | 17 | fun getPriceStringFormat(): String { 18 | val priceNumberFormat = NumberFormat.getCurrencyInstance(Locale.getDefault()) 19 | 20 | priceNumberFormat.maximumFractionDigits = MAX_FRACTION_DIGITS 21 | priceNumberFormat.currency = this.currency 22 | 23 | return priceNumberFormat.format(price) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/ui/settings/filter/FilterSettingsDialogFragment.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.ui.settings.filter 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.fragment.app.activityViewModels 8 | import androidx.lifecycle.lifecycleScope 9 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterRollingAverage 10 | import com.carlosmesquita.technicaltest.n26.bitlue.data_source.remote.api.blockchain.utils.FilterTimeRange 11 | import com.carlosmesquita.technicaltest.n26.bitlue.databinding.FragmentDialogFilterSettingsBinding 12 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.MainViewModel 13 | import com.carlosmesquita.technicaltest.n26.bitlue.ui.actions.MainEvents.FilterSettingsEvents 14 | import com.google.android.material.bottomsheet.BottomSheetDialogFragment 15 | import dagger.hilt.android.AndroidEntryPoint 16 | import kotlinx.coroutines.ExperimentalCoroutinesApi 17 | import kotlinx.coroutines.launch 18 | 19 | @ExperimentalCoroutinesApi 20 | @AndroidEntryPoint 21 | class FilterSettingsDialogFragment : BottomSheetDialogFragment() { 22 | 23 | private val viewModel: MainViewModel by activityViewModels() 24 | 25 | private val binding: FragmentDialogFilterSettingsBinding 26 | get() = _binding!! 27 | private var _binding: FragmentDialogFilterSettingsBinding? = null 28 | 29 | override fun onCreateView( 30 | inflater: LayoutInflater, 31 | container: ViewGroup?, 32 | savedInstanceState: Bundle? 33 | ): View { 34 | _binding = FragmentDialogFilterSettingsBinding.inflate(inflater, container, false) 35 | 36 | setupFilters() 37 | 38 | return binding.root 39 | } 40 | 41 | override fun onDestroyView() { 42 | super.onDestroyView() 43 | 44 | _binding = null 45 | } 46 | 47 | private fun setupFilters() { 48 | setupFilterTimeRange() 49 | setupFilterRollingAverage() 50 | } 51 | 52 | private fun setupFilterTimeRange() { 53 | with(binding) { 54 | FilterTimeRange.values().forEach { 55 | val button = when (it) { 56 | FilterTimeRange.ALL -> timeRangeFilterAllTimeButton 57 | FilterTimeRange.THIRTY_DAYS -> timeRangeFilter30daysButton 58 | FilterTimeRange.ONE_YEAR -> timeRangeFilter1yearButton 59 | FilterTimeRange.THREE_YEARS -> timeRangeFilter3yearsButton 60 | } 61 | 62 | button.apply { 63 | text = it.displayText 64 | isChecked = it == viewModel.selectedTimeRangeFilter.value 65 | setOnClickListener { _ -> 66 | sendEvent(FilterSettingsEvents.OnFilterTimeRangeClicked(it)) 67 | } 68 | } 69 | } 70 | } 71 | } 72 | 73 | private fun setupFilterRollingAverage() { 74 | with(binding) { 75 | FilterRollingAverage.values().forEach { 76 | val button = when (it) { 77 | FilterRollingAverage.RAW_VALUES -> rollingAverageFilterRawValuesButton 78 | FilterRollingAverage.SEVEN_DAY_AVERAGE -> rollingAverageFilter7dayAverageButton 79 | FilterRollingAverage.THIRTY_DAY_AVERAGE -> rollingAverageFilter30daysAverageButton 80 | } 81 | 82 | button.apply { 83 | text = it.displayText 84 | isChecked = it == viewModel.selectedRollingAverageFilter.value 85 | setOnClickListener { _ -> 86 | sendEvent(FilterSettingsEvents.OnFilterRollingAverageClicked(it)) 87 | } 88 | } 89 | } 90 | } 91 | } 92 | 93 | private fun sendEvent(event: FilterSettingsEvents) = lifecycleScope.launch { 94 | viewModel.eventsChannel.send(event) 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/utils/ModelsMapper.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.utils 2 | 3 | interface ModelsMapper : DomainMapper, 4 | DTOMapper 5 | 6 | interface DTOMapper { 7 | 8 | fun mapToDTOModel(domainModel: DomainModel): DTOModel 9 | 10 | fun mapToDTOModelList(domainModelList: List): List 11 | } 12 | 13 | interface DomainMapper { 14 | 15 | fun mapToDomainModel(dtoModel: DTOModel): DomainModel 16 | 17 | fun mapToDomainModelList(dtoModelList: List): List 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/utils/Result.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.utils 2 | 3 | sealed class Result { 4 | 5 | data class Success(val data: T) : Result() 6 | 7 | data class Loading(val loadingMessage: String? = null) : Result() 8 | 9 | data class Error(val throwable: Throwable) : Result() 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/utils/extensions/ContextX.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.utils.extensions 2 | 3 | import android.content.Context 4 | import android.util.TypedValue 5 | import androidx.annotation.AttrRes 6 | 7 | fun Context.getThemeColor(@AttrRes attrResId: Int): Int { 8 | val typedValue = TypedValue() 9 | theme.resolveAttribute(attrResId, typedValue, true) 10 | 11 | return typedValue.data 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlosmesquita/technicaltest/n26/bitlue/utils/extensions/LongX.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue.utils.extensions 2 | 3 | import java.text.SimpleDateFormat 4 | import java.util.* 5 | 6 | fun Long.unixToMillis(): Long { 7 | return this * 1000 8 | } 9 | 10 | fun Long.toDateFormat(dateFormat: String): String { 11 | return SimpleDateFormat(dateFormat, Locale.getDefault()).format(Date(this)) 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/anim/bottom_sheet_slide_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/anim/bottom_sheet_slide_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/dragger_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/gradient_primary_to_transparent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_day_night.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_filter.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_bitcoin_value.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 20 | 21 | 25 | 26 | 40 | 41 | 53 | 54 | 67 | 68 | 77 | 78 | 91 | 92 | 98 | 99 | 100 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_dialog_filter_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 28 | 29 | 39 | 40 | 47 | 48 | 55 | 56 | 63 | 64 | 71 | 72 | 73 | 82 | 83 | 95 | 96 | 103 | 104 | 111 | 112 | 119 | 120 | 121 | 127 | 128 | 134 | 135 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_chart_marker.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 21 | 22 | 28 | 29 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 17 | 18 | 19 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #ea9aae 6 | #ac485c 7 | #964357 8 | #6f3a4b 9 | 10 | #48ac98 11 | #2b6f5d 12 | 13 | #fc434c 14 | #d40021 15 | 16 | 17 | 18 | #ffffff 19 | 20 | #C8C8C8 21 | #7D7D7D 22 | #373737 23 | 24 | #121212 25 | 26 | 27 | #000000 28 | 29 | #00FFFFFF 30 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1dp 4 | 2dp 5 | 4dp 6 | 8dp 7 | 16dp 8 | 24dp 9 | 32dp 10 | 40dp 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/motions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/shapes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Bitlue 3 | 4 | Time Range 5 | Rolling Average 6 | Ups! 7 | 8 | Unexpected error happened. Please check details below.\n\nMore details: %s 9 | OK 10 | 11 | Loading… 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 22 | 23 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 57 | 58 | 69 | 70 | -------------------------------------------------------------------------------- /app/src/main/res/values/types.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 11 | 12 | 15 | 16 | 19 | 20 | 23 | 24 | 27 | 28 | 31 | 32 | 35 | 36 | 39 | 40 | 43 | 44 | 47 | 48 | 51 | 52 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/test/java/com/carlosmesquita/technicaltest/n26/bitlue/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.carlosmesquita.technicaltest.n26.bitlue 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext.kotlin_version = "1.4.21" 4 | ext.hilt_version = "2.31.2-alpha" 5 | ext.hilt_androidx_version = "1.0.0-alpha03" 6 | ext.nav_version = "2.3.4" 7 | ext.androidKtx_version = "2.3.0" 8 | ext.retrofitVersion = "2.9.0" 9 | 10 | repositories { 11 | google() 12 | jcenter() 13 | } 14 | dependencies { 15 | classpath "com.android.tools.build:gradle:4.1.2" 16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 17 | 18 | classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" 19 | 20 | // NOTE: Do not place your application dependencies here; they belong 21 | // in the individual module build.gradle files 22 | } 23 | } 24 | 25 | allprojects { 26 | repositories { 27 | google() 28 | jcenter() 29 | maven { url 'https://jitpack.io' } 30 | } 31 | } 32 | 33 | task clean(type: Delete) { 34 | delete rootProject.buildDir 35 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevnotesforks/Bitlue/41df721a93e28403dc6353cd2e4ed4ac0a7ca615/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 12 20:08:17 CET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "Bitlue" --------------------------------------------------------------------------------