Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
implementation(project(path = ":feature:authorization"))
implementation(project(path = ":feature:registration"))
implementation(project(path = ":feature:graph"))
implementation(project(path = ":feature:customview"))

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ class NavMainImpl @Inject constructor(
override fun goToGraphPage() {
navigatorDelegate.navigate(action = R.id.action_global_graph)
}

override fun goToCustomPage() {
navigatorDelegate.navigate(action = R.id.action_global_custom)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/navigation/graph_global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
android:id="@+id/action_global_graph"
app:destination="@id/nav_graph"/>
<include app:graph="@navigation/nav_graph" />

<action
android:id="@+id/action_global_custom"
app:destination="@id/nav_custom"/>
<include app:graph="@navigation/nav_custom" />
</navigation>
11 changes: 11 additions & 0 deletions core/base/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@

<string name="toast_data_source_cache">Данные получены из кэша</string>
<string name="toast_data_source_api">Данные получены из API</string>

<string name="pie_chart_title">Overlapping Pie Chart</string>
<string name="pie_chart_subtitle">Tap on sectors to select them</string>
<string name="three_sectors">3</string>
<string name="four_sectors">4</string>
<string name="five_sectors">5</string>
<string name="six_sectors">6</string>
<string name="clear_selection">Clear Selection</string>



</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface NavMain {
fun goToDetailsPage(recipeId: Int)

fun goToGraphPage()

fun goToCustomPage()
}
1 change: 1 addition & 0 deletions feature/customview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
64 changes: 64 additions & 0 deletions feature/customview/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
id("androidx.navigation.safeargs.kotlin")
}

android {
namespace = "com.example.androiddevelopment2.customview"
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
buildFeatures {
viewBinding = true
}
}

dependencies {

implementation(project(path = ":core:base"))
implementation(project(path = ":core:domain"))
implementation(project(path = ":core:utils"))
implementation(project(path = ":core:navigation"))

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

// Hilt
implementation(libs.hilt)
ksp(libs.hilt.compiler)

// VBPD
implementation(libs.viewbindingpropertydelegate.noreflection)

implementation(libs.navigation.fragment)
implementation(libs.navigation.ui)
}
Empty file.
21 changes: 21 additions & 0 deletions feature/customview/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.androiddevelopment2.customview

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.androiddevelopment2.customview.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/customview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.example.androiddevelopment2.customview

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import by.kirich1409.viewbindingdelegate.viewBinding
import com.example.androiddevelopment2.customview.PieChartView.Companion.NO_SELECTION
import com.example.androiddevelopment2.customview.databinding.FragmentPieChartBinding
import com.example.androiddevelopment2.customview.state.PieChartEvent
import com.example.androiddevelopment2.customview.state.PieChartState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch


@AndroidEntryPoint
class PieChartFragment : Fragment(R.layout.fragment_pie_chart) {
private val viewBinding: FragmentPieChartBinding by viewBinding(FragmentPieChartBinding::bind)

private val viewModel: PieChartViewModel by viewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setupPieChart()
setupClickListeners()
observeViewModel()
}

private fun setupPieChart() {
viewBinding.pieChartView.apply {
onSelectionChanged = { index ->
if (index == NO_SELECTION) {
viewModel.reduce(PieChartEvent.OnClearSelection)
} else {
viewModel.reduce(PieChartEvent.OnSectorSelected(index))
}
}
}
}

@SuppressLint("ClickableViewAccessibility")
private fun setupClickListeners() {
viewBinding.apply {
root.setOnClickListener {
viewModel.reduce(PieChartEvent.OnClearSelection)
}
btn3Sectors.setOnClickListener {
viewModel.reduce(PieChartEvent.OnSectorCountChanged(3))
}
btn4Sectors.setOnClickListener {
viewModel.reduce(PieChartEvent.OnSectorCountChanged(4))
}
btn5Sectors.setOnClickListener {
viewModel.reduce(PieChartEvent.OnSectorCountChanged(5))
}
btn6Sectors.setOnClickListener {
viewModel.reduce(PieChartEvent.OnSectorCountChanged(6))
}
btnClearSelection.setOnClickListener { viewModel.reduce(PieChartEvent.OnClearSelection) }
}
}

private fun observeViewModel() {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.state.collect { state ->
when (state) {
is PieChartState.Initial -> {
}
is PieChartState.Success -> {
viewBinding.pieChartView.updateData(
count = state.sectorCount,
colors = state.colors,
selectedIndex = state.selectedSector
)
}
}
}
}
}
}
Loading