Skip to content

Commit

Permalink
Merge pull request #168 from AII-the-time/feat/#166-report-server-driven
Browse files Browse the repository at this point in the history
[Feat/#166] report 기능 구현
  • Loading branch information
915dbfl authored Nov 21, 2023
2 parents 8ff9b97 + 9c3e2c8 commit 9a774f4
Show file tree
Hide file tree
Showing 47 changed files with 793 additions and 74 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/org/swm/att/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.swm.att.BuildConfig
import org.swm.att.data.json_adapter.JsonAdapter
import org.swm.att.data.remote.datasource.AttEncryptedPrefDataSource
import org.swm.att.data.remote.datasource.AttEncryptedPrefDataSource.Companion.PreferenceKey.ACCESS_TOKEN
import retrofit2.Retrofit
Expand Down Expand Up @@ -55,10 +56,10 @@ object NetworkModule {
@Singleton
fun providePingRetrofit(okHttpClient: OkHttpClient): Retrofit {
return Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create())
.addConverterFactory(MoshiConverterFactory.create(JsonAdapter.moshi))
.client(okHttpClient)
.baseUrl(BuildConfig.ATT_BASE_URL)
.build()
}
}

}
1 change: 1 addition & 0 deletions common-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ dependencies {
implementation(libs.material)
testImplementation(libs.bundles.basic.test)
implementation(libs.hilt)
implementation(libs.mpandroidchart)
kapt(libs.hilt.kapt)
}
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
}
}
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
}
}
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)
}
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()
}
}
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()
}
}
}
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)
}
}
}
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")
}
}
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
}
}
Loading

0 comments on commit 9a774f4

Please sign in to comment.