Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: remove viewpagerdotsindicator module #3936

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ kotlin {

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(project(":viewpagerdotsindicator"))
implementation(project(":dhis_android_analytics"))
implementation(project(":form"))
implementation(project(":commons"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.outlined.LockReset
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand All @@ -22,6 +23,7 @@ import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
import com.google.android.material.shape.CornerFamily
Expand All @@ -44,6 +46,7 @@ import org.dhis2.commons.extensions.closeKeyboard
import org.dhis2.commons.matomo.Labels.Companion.CLICK
import org.dhis2.commons.sync.OnDismissListener
import org.dhis2.commons.sync.SyncContext
import org.dhis2.commons.ui.PagerIndicator
import org.dhis2.databinding.ActivityDatasetTableBinding
import org.dhis2.usescases.datasets.dataSetTable.dataSetDetail.DataSetDetailFragment.Companion.create
import org.dhis2.usescases.datasets.dataSetTable.dataSetSection.DataSetSection
Expand Down Expand Up @@ -325,7 +328,24 @@ class DataSetTableActivity : ActivityGlobalAbstract(), DataSetTableContract.View
resources.getQuantityText(R.plurals.error_message, violations.size)
binding.BSLayout.violationsViewPager.adapter =
ValidationResultViolationsAdapter(this, violations)
binding.BSLayout.dotsIndicator.setViewPager(binding.BSLayout.violationsViewPager)
binding.BSLayout.dotsIndicator.setContent {
var currentPage by remember { mutableIntStateOf(0) }
binding.BSLayout.violationsViewPager.registerOnPageChangeCallback(
object : OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
currentPage = position
}
},
)
if (violations.isNotEmpty()) {
PagerIndicator(
pageCount = violations.size,
currentPage = currentPage,
dotIndicatorColor = SurfaceColor.Error,
)
}
}
behavior = BottomSheetBehavior.from(binding.BSLayout.bottomSheetLayout)
behavior!!.addBottomSheetCallback(object : BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/violation_rules_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@
app:layout_constraintTop_toTopOf="@id/title"
app:srcCompat="@drawable/ic_arrow_up" />

<com.tbuonomo.viewpagerdotsindicator.WormDotsIndicator
<androidx.compose.ui.platform.ComposeView
android:id="@+id/dotsIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
app:dotsColor="@color/dots_error_selected"
app:dotsSize="12dp"
app:layout_constraintEnd_toEndOf="@id/endGuideline"
app:layout_constraintStart_toStartOf="@id/startGuideline"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
119 changes: 119 additions & 0 deletions commons/src/main/java/org/dhis2/commons/ui/PagerIndicator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package org.dhis2.commons.ui

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlin.math.max

@OptIn(ExperimentalFoundationApi::class)
@Preview(showBackground = true, backgroundColor = 0xFFFFFFFF)
@Composable
fun PagerIndicatorScreen() {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
val pageCount = 2
val pagerState = rememberPagerState(
pageCount = { pageCount },
)
HorizontalPager(
state = pagerState,
modifier = Modifier
.fillMaxSize()
.weight(1f),
) {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
Text(text = "Page $it")
}
}
PagerIndicator(
pageCount = pageCount,
currentPage = pagerState.currentPage,
)
}
}

@Composable
fun PagerIndicator(
indicatorScrollState: LazyListState = rememberLazyListState(),
pageCount: Int,
currentPage: Int,
dotIndicatorColor: Color = Color.DarkGray,
) {
LaunchedEffect(key1 = currentPage) {
val size = indicatorScrollState.layoutInfo.visibleItemsInfo.size
val lastVisibleIndex =
indicatorScrollState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0
val firstVisibleItemIndex = indicatorScrollState.firstVisibleItemIndex

if (currentPage > lastVisibleIndex - 1) {
indicatorScrollState.animateScrollToItem(currentPage - size + 2)
} else if (currentPage <= firstVisibleItemIndex + 1) {
indicatorScrollState.animateScrollToItem(max(currentPage - 1, 0))
}
}

LazyRow(
state = indicatorScrollState,
modifier = Modifier
.height(50.dp)
.width(((6 + 16) * 2 + 3 * (10 + 16)).dp), // I'm hard computing it to simplify
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
repeat(pageCount) { iteration ->
val color = if (currentPage == iteration) dotIndicatorColor else Color.LightGray
item(key = "item$iteration") {
val firstVisibleIndex by remember { derivedStateOf { indicatorScrollState.firstVisibleItemIndex } }
val lastVisibleIndex =
indicatorScrollState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0
val size by animateDpAsState(
targetValue = when (iteration) {
currentPage -> 10.dp
in firstVisibleIndex + 1..<lastVisibleIndex -> 10.dp
else -> 6.dp
},
label = "PagerIndicatorDotSizeAnimation",
)
Box(
modifier = Modifier
.padding(all = 8.dp)
.background(color = color, CircleShape)
.size(
size,
),
)
}
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include(
":app", ":viewpagerdotsindicator",
":app",
":dhis_android_analytics", ":form", ":commons",
":dhis2_android_maps", ":compose-table", ":ui-components",
":stock-usecase"
Expand Down
39 changes: 0 additions & 39 deletions viewpagerdotsindicator/.gitignore

This file was deleted.

32 changes: 0 additions & 32 deletions viewpagerdotsindicator/build.gradle.kts

This file was deleted.

17 changes: 0 additions & 17 deletions viewpagerdotsindicator/proguard-rules.pro

This file was deleted.

5 changes: 0 additions & 5 deletions viewpagerdotsindicator/src/main/AndroidManifest.xml

This file was deleted.

Loading
Loading