-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat/#166] report 기능 구현
- Loading branch information
Showing
47 changed files
with
793 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
common-ui/src/main/java/org/swm/att/common_ui/adapter/SduiReportAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.swm.att.common_ui.adapter | ||
|
||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import org.swm.att.common_ui.util.ItemDiffCallback | ||
import org.swm.att.common_ui.viewholder.BaseSduiViewHolder | ||
import org.swm.att.common_ui.viewholder.getSduiViewHolder | ||
import org.swm.att.domain.entity.response.SduiReportItemVO | ||
import org.swm.att.domain.sever_driven_ui.SduiViewType | ||
|
||
class SduiReportAdapter: ListAdapter<SduiReportItemVO, BaseSduiViewHolder>( | ||
ItemDiffCallback<SduiReportItemVO>( | ||
onContentTheSame = { old, new -> old == new }, | ||
onItemsTheSame = { old, new -> old.content == new.content } | ||
) | ||
) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseSduiViewHolder { | ||
return getSduiViewHolder(parent, SduiViewType.getViewTypeByOrdinal(viewType)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: BaseSduiViewHolder, position: Int) { | ||
val item = getItem(position) | ||
holder.bind(item.content) | ||
} | ||
|
||
override fun getItemViewType(position: Int): Int { | ||
return getItem(position).viewType.ordinal | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
common-ui/src/main/java/org/swm/att/common_ui/richtext/RichTextSpannable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.swm.att.common_ui.richtext | ||
|
||
import android.graphics.Color | ||
import android.text.SpannableString | ||
import android.text.style.ForegroundColorSpan | ||
import android.text.style.RelativeSizeSpan | ||
import org.swm.att.domain.sever_driven_ui.response.text.ReportTextItemVO | ||
|
||
class RichTextSpannable(richText: ReportTextItemVO): SpannableString(richText.text) { | ||
class Builder(private val richText: ReportTextItemVO) { | ||
private val spannableString = SpannableString(richText.text) | ||
|
||
fun setTextColor(color: String?): Builder { | ||
color?.let { | ||
Color.parseColor(it).let { | ||
spannableString.setSpan( | ||
ForegroundColorSpan(it), | ||
0, | ||
richText.text?.length ?: 0, | ||
SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
} | ||
return this | ||
} | ||
|
||
fun setFontSize(size: Float?): Builder { | ||
size?.let { | ||
spannableString.setSpan( | ||
RelativeSizeSpan(it), | ||
0, | ||
richText.text?.length ?: 0, | ||
SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
return this | ||
} | ||
|
||
fun build() = spannableString | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
common-ui/src/main/java/org/swm/att/common_ui/viewholder/BaseSduiViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.swm.att.common_ui.viewholder | ||
|
||
import androidx.databinding.ViewDataBinding | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.swm.att.domain.sever_driven_ui.response.SduiReportContent | ||
|
||
sealed class BaseSduiViewHolder( | ||
binding: ViewDataBinding | ||
): RecyclerView.ViewHolder(binding.root) { | ||
abstract fun bind(reportContent: SduiReportContent) | ||
} |
97 changes: 97 additions & 0 deletions
97
common-ui/src/main/java/org/swm/att/common_ui/viewholder/SduiGraphViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.swm.att.common_ui.viewholder | ||
|
||
import android.annotation.SuppressLint | ||
import android.graphics.Color | ||
import android.graphics.DashPathEffect | ||
import com.github.mikephil.charting.animation.Easing | ||
import com.github.mikephil.charting.components.Legend | ||
import com.github.mikephil.charting.components.XAxis | ||
import com.github.mikephil.charting.components.YAxis | ||
import com.github.mikephil.charting.data.Entry | ||
import com.github.mikephil.charting.data.LineData | ||
import com.github.mikephil.charting.data.LineDataSet | ||
import org.swm.att.common_ui.databinding.ItemSduiGraphBinding | ||
import org.swm.att.domain.sever_driven_ui.response.SduiReportContent | ||
import org.swm.att.domain.sever_driven_ui.response.graph.ReportGraphVO | ||
|
||
|
||
class SduiGraphViewHolder( | ||
private val binding: ItemSduiGraphBinding | ||
): BaseSduiViewHolder(binding) { | ||
override fun bind(reportContent: SduiReportContent) { | ||
initGraph() | ||
setGraph(reportContent as ReportGraphVO) | ||
} | ||
|
||
@SuppressLint("ResourceAsColor") | ||
private fun initGraph() { | ||
with(binding.reportLineChart) { | ||
setGridBackgroundColor(Color.parseColor("#F5F5F5")) | ||
animateX(1200, Easing.EaseInSine) | ||
description.isEnabled = false | ||
|
||
val xAxis: XAxis = binding.reportLineChart.getXAxis() | ||
xAxis.setDrawAxisLine(false) | ||
xAxis.setDrawGridLines(false) | ||
xAxis.position = XAxis.XAxisPosition.BOTTOM // x축 데이터 표시 위치 | ||
xAxis.granularity = 1f | ||
xAxis.textSize = 14f | ||
xAxis.textColor = Color.rgb(118, 118, 118) | ||
xAxis.spaceMin = 0.1f | ||
xAxis.spaceMax = 0.1f | ||
|
||
val yAxisLeft: YAxis = binding.reportLineChart.getAxisLeft() | ||
yAxisLeft.textSize = 14f | ||
yAxisLeft.textColor = Color.rgb(163, 163, 163) | ||
yAxisLeft.setDrawAxisLine(false) | ||
yAxisLeft.axisLineWidth = 2f | ||
yAxisLeft.axisMinimum = 0f | ||
|
||
val yAxis: YAxis = binding.reportLineChart.getAxisRight() | ||
yAxis.setDrawLabels(false) | ||
yAxis.textColor = Color.rgb(163, 163, 163) | ||
yAxis.setDrawAxisLine(false) | ||
yAxis.axisLineWidth = 2f | ||
yAxis.axisMinimum = 0f | ||
|
||
legend.orientation = Legend.LegendOrientation.VERTICAL | ||
legend.verticalAlignment = Legend.LegendVerticalAlignment.TOP | ||
legend.horizontalAlignment = Legend.LegendHorizontalAlignment.CENTER | ||
legend.textSize = 15F | ||
legend.form = Legend.LegendForm.LINE | ||
} | ||
} | ||
|
||
private fun setGraph(reportGraphData: ReportGraphVO) { | ||
binding.chartTitle = reportGraphData.graphTitle | ||
|
||
// entries 구하기 | ||
val entries = ArrayList<Entry>() | ||
reportGraphData.graphItems.map { reportGraphItemVO -> | ||
entries.add(Entry(reportGraphItemVO.graphKey.toFloat(), reportGraphItemVO.graphValue.toFloat())) | ||
} | ||
|
||
// lineDataSet 설정 | ||
val lineDataSet = LineDataSet(entries, null) | ||
lineDataSet.apply { | ||
valueTextSize = 15f | ||
mode = LineDataSet.Mode.CUBIC_BEZIER | ||
color = Color.parseColor(reportGraphData.graphColor) | ||
setCircleColor(Color.parseColor(reportGraphData.graphColor)) | ||
setDrawCircleHole(true) | ||
circleRadius = 5f | ||
setFormLineDashEffect(DashPathEffect(floatArrayOf(10f, 5f), 0f)) | ||
valueTextColor = Color.BLACK | ||
} | ||
|
||
// lineData 설정 | ||
val dataSet: List<LineDataSet> = arrayListOf(lineDataSet, lineDataSet) | ||
val lineData = LineData(dataSet) | ||
binding.reportLineChart.apply { | ||
setDrawGridBackground(true) | ||
data = lineData | ||
} | ||
|
||
binding.reportLineChart.invalidate() | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
common-ui/src/main/java/org/swm/att/common_ui/viewholder/SduiPieChartViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.swm.att.common_ui.viewholder | ||
|
||
import android.graphics.Color | ||
import com.github.mikephil.charting.animation.Easing | ||
import com.github.mikephil.charting.components.Legend | ||
import com.github.mikephil.charting.data.PieData | ||
import com.github.mikephil.charting.data.PieDataSet | ||
import com.github.mikephil.charting.data.PieEntry | ||
import org.swm.att.common_ui.databinding.ItemSduiPiechartBinding | ||
import org.swm.att.domain.sever_driven_ui.response.SduiReportContent | ||
import org.swm.att.domain.sever_driven_ui.response.piechart.ReportPieChartVO | ||
|
||
|
||
class SduiPieChartViewHolder( | ||
private val binding: ItemSduiPiechartBinding | ||
): BaseSduiViewHolder(binding) { | ||
override fun bind(reportContent: SduiReportContent) { | ||
setPieChart(reportContent as ReportPieChartVO) | ||
} | ||
|
||
private fun setPieChart(reportPieChartData: ReportPieChartVO) { | ||
binding.chartTitle = reportPieChartData.pieChartTitle | ||
val dataList = mutableListOf<PieEntry>() | ||
val colorList = mutableListOf<Int>() | ||
for (item in (reportPieChartData).pieChartItems) { | ||
dataList.add(PieEntry(item.categoryCount.toFloat(), item.categoryName)) | ||
colorList.add(Color.parseColor(item.chartColor)) | ||
} | ||
val dataSet = PieDataSet(dataList, null) | ||
dataSet.colors = colorList | ||
val pieData = PieData(dataSet) | ||
|
||
binding.reportPieChart.apply { | ||
data = pieData | ||
description.isEnabled = false | ||
isRotationEnabled = false | ||
isDrawHoleEnabled = true | ||
holeRadius = 60f | ||
setEntryLabelTextSize(10f) | ||
setEntryLabelColor(Color.BLACK) | ||
animateY(1400, Easing.EaseInOutQuad) | ||
animate() | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
common-ui/src/main/java/org/swm/att/common_ui/viewholder/SduiTextViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.swm.att.common_ui.viewholder | ||
|
||
import android.text.SpannableStringBuilder | ||
import android.view.Gravity | ||
import org.swm.att.common_ui.databinding.ItemSduiTextBinding | ||
import org.swm.att.common_ui.richtext.RichTextSpannable | ||
import org.swm.att.domain.sever_driven_ui.response.SduiReportContent | ||
import org.swm.att.domain.sever_driven_ui.response.text.ReportTextVO | ||
|
||
class SduiTextViewHolder( | ||
private val binding: ItemSduiTextBinding | ||
): BaseSduiViewHolder(binding) { | ||
private var spanTextList = SpannableStringBuilder() | ||
|
||
override fun bind(reportContent: SduiReportContent) { | ||
reportContent as ReportTextVO | ||
|
||
reportContent.textItems.forEach { | ||
val spannableString = RichTextSpannable.Builder(it) | ||
.setTextColor(it.color) | ||
.setFontSize(it.size) | ||
.build() | ||
|
||
spanTextList.append(spannableString) | ||
} | ||
|
||
binding.tvSdui.text = spanTextList | ||
when(reportContent.align) { | ||
"LEFT" -> binding.tvSdui.setGravity(Gravity.START) | ||
"RIGHT" -> binding.tvSdui.setGravity(Gravity.END) | ||
"CENTER" -> binding.tvSdui.setGravity(Gravity.CENTER) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
common-ui/src/main/java/org/swm/att/common_ui/viewholder/SduiUnknownViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.swm.att.common_ui.viewholder | ||
|
||
import android.util.Log | ||
import org.swm.att.common_ui.databinding.ItemSduiUnknownBinding | ||
import org.swm.att.domain.sever_driven_ui.response.SduiReportContent | ||
|
||
class SduiUnknownViewHolder( | ||
private val binding: ItemSduiUnknownBinding | ||
): BaseSduiViewHolder(binding) { | ||
override fun bind(reportContent: SduiReportContent) { | ||
Log.d("SduiUnknownViewHolder", "bind: $reportContent") | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
common-ui/src/main/java/org/swm/att/common_ui/viewholder/SduiViewHolderFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.swm.att.common_ui.viewholder | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
import org.swm.att.common_ui.R | ||
import org.swm.att.common_ui.databinding.ItemSduiGraphBinding | ||
import org.swm.att.common_ui.databinding.ItemSduiPiechartBinding | ||
import org.swm.att.common_ui.databinding.ItemSduiTextBinding | ||
import org.swm.att.common_ui.databinding.ItemSduiUnknownBinding | ||
import org.swm.att.domain.sever_driven_ui.SduiViewType | ||
|
||
fun getSduiViewHolder(parent: ViewGroup, viewType: SduiViewType): BaseSduiViewHolder { | ||
val layout = getLayoutByViewType(viewType) | ||
val binding: ViewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.context), layout, parent, false) | ||
|
||
//수정해야 함. | ||
return when(viewType) { | ||
SduiViewType.PIECHART -> SduiPieChartViewHolder(binding as ItemSduiPiechartBinding) | ||
SduiViewType.GRAPH -> SduiGraphViewHolder(binding as ItemSduiGraphBinding) | ||
SduiViewType.TEXT -> SduiTextViewHolder(binding as ItemSduiTextBinding) | ||
SduiViewType.UNKNOWN -> SduiUnknownViewHolder(binding as ItemSduiUnknownBinding) | ||
} | ||
} | ||
|
||
fun getLayoutByViewType(viewType: SduiViewType): Int { | ||
return when(viewType) { | ||
SduiViewType.PIECHART -> R.layout.item_sdui_piechart | ||
SduiViewType.GRAPH -> R.layout.item_sdui_graph | ||
SduiViewType.TEXT -> R.layout.item_sdui_text | ||
SduiViewType.UNKNOWN -> R.layout.item_sdui_unknown | ||
} | ||
} |
Oops, something went wrong.