Skip to content

Commit

Permalink
DPMS-14582 Upgrade gradle, targetSdk and abstract models (#22)
Browse files Browse the repository at this point in the history
## Description
This PR aims to refactor the ForecastChart to improve the chart setup as library.

### Major changes
- Create a new model in the core module to abstract the `MPAndroidChart` library models.
- update Gradle (5.1.1 -> 6.7.1)
- update Android Gradle Plugin (3.1.4 -> 4.0.1)
- update targetSdkVersion (28 -> 29) - **Must install Android SDK 10.0 (API 29)**
- Ktlint fixes.

![image](https://user-images.githubusercontent.com/13650290/125415337-5edfeb47-90ee-482a-9145-3aebadf442f8.png)
  • Loading branch information
rodiguif authored Jul 13, 2021
1 parent 725bda2 commit f5eb92d
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 114 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Step 2. Add the dependency

```gradle
dependencies {
implementation 'com.github.oxeanbits.forecast-chart:2.0.1'
implementation 'com.github.oxeanbits.forecast-chart:3.1.3'
}
```

Expand All @@ -30,9 +30,9 @@ dependencies {
## Basic usage

```kotlin
expectedDataArray = arrayListOf(Entry(1f, 1f), Entry(2f, 2f), Entry(3f, 3f)
actualDataArray = arrayListOf(Entry(1f, 1f), Entry(2f, 2f))
forecastedDataArray = arrayListOf(Entry(2f, 2f), Entry(3f, 3f))
expectedDataArray = listOf(ChartEntry(1f, 1f), ChartEntry(2f, 2f), ChartEntry(3f, 3f)
actualDataArray = listOf(ChartEntry(1f, 1f), ChartEntry(2f, 2f))
forecastedDataArray = listOf(ChartEntry(2f, 2f), ChartEntry(3f, 3f))

forecastChartComponent{
size(MATCH, 350)
Expand Down
17 changes: 10 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.oxeanbits.forecastchart"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
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
}
}

dependencies {
Expand All @@ -28,9 +33,7 @@ dependencies {

implementation 'co.trikita:anvil-sdk21:0.5.21'

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

implementation 'com.jakewharton.threetenabp:threetenabp:1.2.2'
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.4'

implementation project(path: ':core')
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MainExample : AppCompatActivity() {
actualLine.color, actualLine.forecasted)
forecastedLine(forecastedLine.values, forecastedLine.label,
forecastedLine.color, forecastedLine.forecasted)
endDateBar(endDateBar.x, endDateBar.y)
endDateBar(endDateBar.x, endDateBar.y, "End Date")
unit("")
zoomEnabled(true)
}
Expand All @@ -52,7 +52,7 @@ class MainExample : AppCompatActivity() {
actualLine.color, actualLine.forecasted)
forecastedLine(forecastedLine.values, forecastedLine.label,
forecastedLine.color, forecastedLine.forecasted)
endDateBar(endDateBar.x, endDateBar.y)
endDateBar(endDateBar.x, endDateBar.y, "End Date")
unit("")
dateFormat("MM/dd/yyyy")
decimalFormat(SetupChartExample.getDecimalFormat())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,55 @@
package com.oxeanbits.forecastchart.util

import android.graphics.Color
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.utils.ColorTemplate
import android.graphics.Color.CYAN
import android.graphics.Color.GRAY
import android.graphics.Color.GREEN
import com.oxeanbits.forecastchart.model.ChartEntry
import com.oxeanbits.forecastchart.model.Line
import java.text.DecimalFormat

object SetupChartExample{

val timestamp1 = DateFormatter.stringToTimestamp("2019-11-27")
val progress1 = 25f
val timestamp2 = DateFormatter.stringToTimestamp("2019-11-28")
val progress2 = 25f + progress1
val timestamp3 = DateFormatter.stringToTimestamp("2019-11-29")
val progress3 = 25f + progress2
val timestamp4 = DateFormatter.stringToTimestamp("2019-11-30")
val progress4 = 0f + progress3
val timestamp5 = DateFormatter.stringToTimestamp("2019-12-01")
val progress5 = 25f + progress4
val timestamp6 = DateFormatter.stringToTimestamp("2019-12-02")
val timestamp7 = DateFormatter.stringToTimestamp("2019-12-03")
val timestamp8 = DateFormatter.stringToTimestamp("2019-12-04")
val timestamp9 = DateFormatter.stringToTimestamp("2019-12-05")
val timestamp10 = DateFormatter.stringToTimestamp("2019-12-06")
object SetupChartExample {

private val timestamp1 = DateFormatter.stringToTimestamp("2019-11-27")
private const val PROGRESS_1 = 25f
private val timestamp2 = DateFormatter.stringToTimestamp("2019-11-28")
private const val PROGRESS_2 = 25f + PROGRESS_1
private val timestamp3 = DateFormatter.stringToTimestamp("2019-11-29")
private const val PROGRESS_3 = 25f + PROGRESS_2
private val timestamp4 = DateFormatter.stringToTimestamp("2019-11-30")
private const val PROGRESS_4 = 0f + PROGRESS_3
private val timestamp5 = DateFormatter.stringToTimestamp("2019-12-01")
private const val PROGRESS_5 = 25f + PROGRESS_4


fun getExpectedObj(): Line{
val expectedEntry = arrayListOf(Entry(timestamp1, progress1),
Entry(timestamp2, progress2), Entry(timestamp3,progress3),
Entry(timestamp4, progress4), Entry(timestamp5, progress5))
val expectedEntry = listOf(
ChartEntry(timestamp1, PROGRESS_1),
ChartEntry(timestamp2, PROGRESS_2), ChartEntry(timestamp3, PROGRESS_3),
ChartEntry(timestamp4, PROGRESS_4), ChartEntry(timestamp5, PROGRESS_5))

return Line(expectedEntry, "Production Target", ColorTemplate.getHoloBlue(), false)
return Line(expectedEntry, "Production Target", CYAN, false)
}

fun getActualObj(): Line{
val workedEntry= arrayListOf(Entry(timestamp1, 25f), Entry(timestamp2, 35f),
Entry(timestamp3, 50f)
fun getActualObj(): Line {
val workedEntry = listOf(ChartEntry(timestamp1, 25f), ChartEntry(timestamp2, 35f),
ChartEntry(timestamp3, 50f)
)

return Line(workedEntry, "Actual", Color.GREEN, false)
return Line(workedEntry, "Actual", GREEN, false)
}

fun getForecastedObj(): Line{
val forecastedEntry = arrayListOf(Entry(timestamp3,50f), Entry(timestamp4, 75f),
Entry(timestamp5, 100f))
fun getForecastedObj(): Line {
val forecastedEntry = listOf(ChartEntry(timestamp3,50f), ChartEntry(timestamp4, 75f),
ChartEntry(timestamp5, 100f))

return Line(forecastedEntry, "Forecasted", Color.GRAY, true)
return Line(forecastedEntry, "Forecasted", GRAY, true)
}

fun getEndDateObj(): BarEntry{
return BarEntry(timestamp5, 100f)
fun getEndDateObj(): ChartEntry {
return ChartEntry(timestamp5, 100f)
}

fun getDecimalFormat(): DecimalFormat{
fun getDecimalFormat(): DecimalFormat {
val decimalFormat = DecimalFormat()
decimalFormat.minimumFractionDigits = 2
decimalFormat.maximumFractionDigits = 2
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
19 changes: 13 additions & 6 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'

group = "com.github.oxeanbits"

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "29.0.2"

defaultConfig {
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

task javadoc(type: Javadoc) {
Expand All @@ -47,7 +52,7 @@ project.afterEvaluate {
group groupName
version android.defaultConfig.versionName
artifactId applicationName
artifact bundleRelease
artifact bundleReleaseAar
artifact sourcesJar
artifact javadocJar

Expand All @@ -74,5 +79,7 @@ dependencies {

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

implementation 'com.jakewharton.threetenabp:threetenabp:1.2.2'
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.4'

implementation 'androidx.core:core-ktx:1.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.oxeanbits.forecastchart.model
import com.github.mikephil.charting.data.BarEntry

data class Bar (
val values: ArrayList<BarEntry>,
val values: List<BarEntry>,
val label: String,
val color: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.oxeanbits.forecastchart.model

data class ChartEntry (
val x: Float,
val y: Float
)
6 changes: 4 additions & 2 deletions core/src/main/java/com/oxeanbits/forecastchart/model/Line.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.oxeanbits.forecastchart.model
import com.github.mikephil.charting.data.Entry

data class Line (
val values: ArrayList<Entry>,
val values: List<ChartEntry>,
val label: String,
val color: Int,
val forecasted: Boolean
)
) {
fun valuesToEntry() = values.map { Entry(it.x, it.y) }
}
Loading

0 comments on commit f5eb92d

Please sign in to comment.