Skip to content

Commit

Permalink
Code improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
furkanaskin authored and Furkan committed Sep 16, 2020
1 parent 14d3af0 commit ffdca43
Showing 1 changed file with 29 additions and 50 deletions.
79 changes: 29 additions & 50 deletions app/src/main/java/com/faskn/clickablepiechart/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faskn.clickablepiechart

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.faskn.lib.PieChart
import com.faskn.lib.Slice
Expand All @@ -16,67 +15,47 @@ class MainActivity : AppCompatActivity() {

// Kotlin DSL example
val pieChartDSL = buildChart {
slices {
arrayListOf(
Slice(
Random.nextInt(1000, 3000).toFloat(),
R.color.colorPrimary,
"Google"
),
Slice(
Random.nextInt(1000, 2000).toFloat(),
R.color.colorPrimaryDark,
"Facebook"
),
Slice(
Random.nextInt(1000, 5000).toFloat(),
R.color.materialIndigo600,
"Twitter"
),
Slice(
Random.nextInt(1000, 10000).toFloat(),
R.color.colorAccent,
"Other"
)
)
}
slices { provideSlices() }
sliceWidth { 80f }
sliceStartPoint { 0f }
clickListener { s, fl ->
Log.d("ses", "s " + s)
Log.d("ses", "f " + fl.toString())
clickListener { angle, value ->
// ...
}
}

chart.setPieChart(pieChartDSL)
chart.showLegend(legendLayout)

val pieChart = PieChart(
arrayListOf(
Slice(
Random.nextInt(1000, 3000).toFloat(),
R.color.colorPrimary,
"Google"
),
Slice(
Random.nextInt(1000, 2000).toFloat(),
R.color.colorPrimaryDark,
"Facebook"
),
Slice(
Random.nextInt(1000, 5000).toFloat(),
R.color.materialIndigo600,
"Twitter"
),
Slice(
Random.nextInt(1000, 10000).toFloat(),
R.color.colorAccent,
"Other"
)
), clickListener = null, sliceStartPoint = 0f, sliceWidth = 80f
slices = provideSlices(), clickListener = null, sliceStartPoint = 0f, sliceWidth = 80f
).build()

chart.setPieChart(pieChart)
chart.showLegend(legendLayout)
}

private fun provideSlices(): ArrayList<Slice> {
return arrayListOf(
Slice(
Random.nextInt(1000, 3000).toFloat(),
R.color.colorPrimary,
"Google"
),
Slice(
Random.nextInt(1000, 2000).toFloat(),
R.color.colorPrimaryDark,
"Facebook"
),
Slice(
Random.nextInt(1000, 5000).toFloat(),
R.color.materialIndigo600,
"Twitter"
),
Slice(
Random.nextInt(1000, 10000).toFloat(),
R.color.colorAccent,
"Other"
)
)
}
}

0 comments on commit ffdca43

Please sign in to comment.