Skip to content

Commit

Permalink
Merge branch 'dev' into 35-custom_view_3
Browse files Browse the repository at this point in the history
  • Loading branch information
MajoritySky2496 authored Jan 21, 2024
2 parents d01c063 + 21d3fb8 commit 1347f54
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package app.cashadvisor.authorization.domain.api

import app.cashadvisor.authorization.domain.models.AccountInformation
import kotlinx.coroutines.flow.Flow

interface AccountInformationInteractor {
fun getAccountInformation(): Flow<AccountInformation>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.cashadvisor.authorization.presentation.ui.domain.impl
package app.cashadvisor.authorization.domain.impl

import app.cashadvisor.authorization.presentation.ui.domain.api.AccountInformationInteractor
import app.cashadvisor.authorization.presentation.ui.domain.models.AccountInformation
import app.cashadvisor.authorization.domain.api.AccountInformationInteractor
import app.cashadvisor.authorization.domain.models.AccountInformation
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import java.util.Date
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.cashadvisor.authorization.presentation.ui.domain.models
package app.cashadvisor.authorization.domain.models

import java.util.Date

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
package app.cashadvisor.authorization.presentation.ui.diagrams

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import app.cashadvisor.R
import android.widget.SeekBar
import androidx.fragment.app.Fragment
import app.cashadvisor.databinding.FragmentFourthDiagramBinding
import app.cashadvisor.databinding.FragmentThirdDiagramBinding
import kotlin.random.Random

class FourthDiagramFragment : Fragment() {

private var _binding: FragmentFourthDiagramBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
_binding = FragmentFourthDiagramBinding.inflate(layoutInflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.randomInt.setOnClickListener {
with(binding) {
customDiagramFourth.progress = Random.nextInt(-5, 105)
customM6.progress = Random.nextInt(-5, 105)
customM8.progress = Random.nextInt(-5, 105)
customM9.progress = Random.nextInt(-5, 105)
}
}

binding.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
with(binding) {
customDiagramFourth.progress = progress
customM6.progress = progress
customM8.progress = progress
customM9.progress = progress
}
}

override fun onStartTrackingTouch(seekBar: SeekBar?) {}

override fun onStopTrackingTouch(seekBar: SeekBar?) {}
})
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

}

This file was deleted.

80 changes: 76 additions & 4 deletions app/src/main/res/layout/fragment_fourth_diagram.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".authorization.presentation.ui.diagrams.FourthDiagramFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="4th diagram" />
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="4th diagram"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<app.cashadvisor.customView.CustomViewDiagramFourth
android:id="@+id/custom_diagram_fourth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text" />

<app.cashadvisor.customView.CustomViewDiagramFourth
android:id="@+id/custom_m6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:colorProgress="?attr/m6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/custom_diagram_fourth" />

<app.cashadvisor.customView.CustomViewDiagramFourth
android:id="@+id/custom_m8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:colorProgress="?attr/m8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/custom_m6" />

<app.cashadvisor.customView.CustomViewDiagramFourth
android:id="@+id/custom_m9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:colorProgress="?attr/m9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/custom_m8" />

<Button
android:id="@+id/random_int"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="Random_Int"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<SeekBar
android:id="@+id/seek_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="24dp"
android:max="100"
app:layout_constraintBottom_toTopOf="@+id/random_int"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package app.cashadvisor.customView

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.graphics.Typeface
import android.os.Build
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import app.cashadvisor.uikit.R
import kotlin.math.max


class CustomViewDiagramFourth @JvmOverloads constructor(
context: Context,
attributesSet: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.CustomViewDiagramFourthStyle
) : View(context, attributesSet, defStyleAttr, defStyleRes) {

private var barWidth: Float = 0f
private var barMaxWidth = 0f

private var backgroundProgressColor = Color.GRAY
private var progressColor = Color.GREEN
private var progressTextColor = Color.WHITE
private var progressTextSize = DEFAULT_TEXT_SIZE

private var progressPaddingBackground = PROGRESS_PADDING_BACKGROUND
private var progressTextPadding = PROGRESS_PADDING_TEXT
private var cornerRadius = DEFAULT_CORNER_RADIUS

private lateinit var paintRect: Paint
private lateinit var paintProgressRect: Paint
private lateinit var paintText: Paint
private lateinit var textFontProgress: Typeface

private val backgroundSizeField = RectF(0f, 0f, 0f, 0f)
private val progressSizeField = RectF(0f, 0f, 0f, 0f)

var progress: Int = 0
set(value) {
field = value.coerceIn(0, 100)
barWidth = barMaxWidth * (100 - field) / 100f
invalidate()
}

init {
initAttributes(attributesSet, defStyleAttr, defStyleRes)
initPaint()
}

private fun initAttributes(attributesSet: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) {

val typedArray = context.obtainStyledAttributes(
attributesSet, R.styleable.CustomViewDiagramFourth, defStyleAttr, defStyleRes
).apply {
backgroundProgressColor = getColor(
R.styleable.CustomViewDiagramFourth_colorBackground, Color.GRAY
)
progressColor = getColor(R.styleable.CustomViewDiagramFourth_colorProgress, Color.GREEN)
cornerRadius =
getDimension(R.styleable.CustomViewDiagramFourth_radiusView, DEFAULT_CORNER_RADIUS)
progressTextColor =
getColor(R.styleable.CustomViewDiagramFourth_textColorProgress, Color.WHITE)
progressTextSize = getDimension(
R.styleable.CustomViewDiagramFourth_textSizeProgress, DEFAULT_TEXT_SIZE
)
}
val textFontId =
typedArray.getResourceId(R.styleable.CustomViewDiagramFourth_textFontProgress, 0)
textFontProgress = if (textFontId != 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Typeface.create(resources.getFont(textFontId), Typeface.NORMAL)
} else {
Typeface.DEFAULT
}
} else {
Typeface.DEFAULT
}

progressPaddingBackground = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, PROGRESS_PADDING_BACKGROUND, resources.displayMetrics
)
progressTextPadding = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, PROGRESS_PADDING_TEXT, resources.displayMetrics
)
typedArray.recycle()
}

private fun initPaint() {
paintRect = Paint().apply {
isAntiAlias = true
color = backgroundProgressColor
}
paintProgressRect = Paint().apply {
isAntiAlias = true
color = progressColor
}
paintText = Paint().apply {
isAntiAlias = true
textAlign = Paint.Align.RIGHT
color = progressTextColor
textSize = progressTextSize
typeface = textFontProgress
}
}

override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {

backgroundSizeField.apply {
left = paddingLeft.toFloat()
top = paddingTop.toFloat()
right = width - paddingRight.toFloat()
bottom = height - paddingBottom.toFloat()
}
progressSizeField.apply {
left = paddingLeft.toFloat() + progressPaddingBackground
top = paddingTop.toFloat() + progressPaddingBackground
right = width - paddingRight - progressPaddingBackground
bottom = height - paddingBottom - progressPaddingBackground
}
barMaxWidth = width.toFloat() - progressSizeField.height()
progress = progress
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {

val minWidth = suggestedMinimumWidth + paddingLeft + paddingRight
val minHeight = suggestedMinimumHeight + paddingTop + paddingBottom

val desiredHeightSizeInPixels = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, DEFAULT_HEIGHT, resources.displayMetrics
).toInt()
val desiredWidthSizeInPixels = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, DEFAULT_WIDTH, resources.displayMetrics
).toInt()

val desiredWidth = max(minWidth, desiredWidthSizeInPixels + paddingLeft + paddingRight)
val desiredHeight = max(minHeight, desiredHeightSizeInPixels + paddingTop + paddingBottom)

setMeasuredDimension(
resolveSize(desiredWidth, widthMeasureSpec),
resolveSize(desiredHeight, heightMeasureSpec)
)
}

override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)

val xPos = progressSizeField.right - progressTextPadding - progressPaddingBackground
val yPos = height / 2f
val yPosText = (yPos - ((paintText.descent() + paintText.ascent()) / 2))
progressSizeField.left = paddingLeft.toFloat() + progressPaddingBackground + barWidth

canvas.drawRoundRect(
backgroundSizeField, cornerRadius, cornerRadius, paintRect
)

if (progress != 0) {
canvas.drawRoundRect(
progressSizeField, cornerRadius, cornerRadius, paintProgressRect
)
}

canvas.drawText(
progress.toString(), xPos, yPosText, paintText
)
}

companion object {
const val PROGRESS_PADDING_BACKGROUND = 1f
const val PROGRESS_PADDING_TEXT = 5f
const val DEFAULT_CORNER_RADIUS = 10f
const val DEFAULT_TEXT_SIZE = 11F
const val DEFAULT_HEIGHT = 15f
const val DEFAULT_WIDTH = 150f
}
}
Loading

0 comments on commit 1347f54

Please sign in to comment.