Skip to content

Commit

Permalink
Merge pull request openedx#183 from touchapp/fix/nav_issues
Browse files Browse the repository at this point in the history
Fix: Minor navigational issues
  • Loading branch information
dixidroid authored Jan 19, 2024
2 parents d1fc2c7 + 396b09d commit 4d97d4f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/org/openedx/core/ui/ComposeCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ fun TextIcon(
painter: Painter,
color: Color,
textStyle: TextStyle = MaterialTheme.appTypography.bodySmall,
iconModifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
) {
val modifier = if (onClick == null) {
Expand All @@ -996,7 +997,8 @@ fun TextIcon(
) {
Text(text = text, color = color, style = textStyle)
Icon(
modifier = Modifier.size((textStyle.fontSize.value + 4).dp),
modifier = iconModifier
.size((textStyle.fontSize.value + 4).dp),
painter = painter,
contentDescription = null,
tint = color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,15 @@ import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
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.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.ViewCompositionStrategy
Expand Down Expand Up @@ -78,6 +66,9 @@ class ChapterEndFragmentDialog : DialogFragment() {
ChapterEndDialogScreen(
sectionName = requireArguments().getString(ARG_SECTION_NAME) ?: "",
nextSectionName = requireArguments().getString(ARG_NEXT_SECTION_NAME) ?: "",
isVerticalNavigation = requireArguments().getBoolean(
ARG_IS_VERTICAL_NAVIGATION
),
onBackButtonClick = {
dismiss()
listener?.onDismiss()
Expand Down Expand Up @@ -122,14 +113,17 @@ class ChapterEndFragmentDialog : DialogFragment() {
companion object {
private const val ARG_SECTION_NAME = "sectionName"
private const val ARG_NEXT_SECTION_NAME = "nexSectionName"
private const val ARG_IS_VERTICAL_NAVIGATION = "isVerticalNavigation"
fun newInstance(
sectionName: String,
nextSectionName: String
nextSectionName: String,
isVerticalNavigation: Boolean
): ChapterEndFragmentDialog {
val dialog = ChapterEndFragmentDialog()
dialog.arguments = bundleOf(
ARG_SECTION_NAME to sectionName,
ARG_NEXT_SECTION_NAME to nextSectionName
ARG_NEXT_SECTION_NAME to nextSectionName,
ARG_IS_VERTICAL_NAVIGATION to isVerticalNavigation
)
return dialog
}
Expand All @@ -145,6 +139,7 @@ interface DialogListener {
private fun ChapterEndDialogScreen(
sectionName: String,
nextSectionName: String,
isVerticalNavigation: Boolean,
onBackButtonClick: () -> Unit,
onProceedButtonClick: () -> Unit,
onCancelButtonClick: () -> Unit
Expand Down Expand Up @@ -206,7 +201,8 @@ private fun ChapterEndDialogScreen(
text = stringResource(id = R.string.course_next_section),
painter = painterResource(org.openedx.core.R.drawable.core_ic_forward),
color = MaterialTheme.appColors.buttonText,
textStyle = MaterialTheme.appTypography.labelLarge
textStyle = MaterialTheme.appTypography.labelLarge,
iconModifier = Modifier.rotate(if (isVerticalNavigation) 90f else 0f)
)
},
onClick = onProceedButtonClick
Expand Down Expand Up @@ -366,6 +362,7 @@ fun ChapterEndDialogScreenPreview() {
ChapterEndDialogScreen(
sectionName = "Section",
nextSectionName = "Section2",
isVerticalNavigation = true,
onBackButtonClick = {},
onProceedButtonClick = {},
onCancelButtonClick = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ fun NavigationUnitsButtons(
nextButtonText: String,
hasPrevBlock: Boolean,
hasNextBlock: Boolean,
isVerticalNavigation: Boolean,
onPrevClick: () -> Unit,
onNextClick: () -> Unit
) {
Expand Down Expand Up @@ -362,6 +363,7 @@ fun NavigationUnitsButtons(
)
Spacer(Modifier.width(8.dp))
Icon(
modifier = Modifier.rotate(if (isVerticalNavigation) 0f else -90f),
painter = painterResource(id = org.openedx.core.R.drawable.core_ic_up),
contentDescription = null,
tint = MaterialTheme.appColors.primary
Expand Down Expand Up @@ -391,6 +393,7 @@ fun NavigationUnitsButtons(
)
Spacer(Modifier.width(8.dp))
Icon(
modifier = Modifier.rotate(if (isVerticalNavigation || !hasNextBlock) 0f else -90f),
painter = nextButtonIcon,
contentDescription = null,
tint = MaterialTheme.appColors.buttonText
Expand Down Expand Up @@ -921,6 +924,7 @@ private fun NavigationUnitsButtonsOnlyNextButtonPreview() {
windowSize = WindowSize(WindowType.Compact, WindowType.Compact),
hasPrevBlock = true,
hasNextBlock = true,
isVerticalNavigation = true,
nextButtonText = "Next",
onPrevClick = {}) {}
}
Expand All @@ -935,6 +939,7 @@ private fun NavigationUnitsButtonsOnlyFinishButtonPreview() {
windowSize = WindowSize(WindowType.Compact, WindowType.Compact),
hasPrevBlock = true,
hasNextBlock = false,
isVerticalNavigation = true,
nextButtonText = "Finish",
onPrevClick = {}) {}
}
Expand All @@ -949,6 +954,7 @@ private fun NavigationUnitsButtonsWithFinishPreview() {
windowSize = WindowSize(WindowType.Compact, WindowType.Compact),
hasPrevBlock = true,
hasNextBlock = false,
isVerticalNavigation = true,
nextButtonText = "Finish",
onPrevClick = {}) {}
}
Expand All @@ -963,6 +969,7 @@ private fun NavigationUnitsButtonsWithNextPreview() {
windowSize = WindowSize(WindowType.Compact, WindowType.Compact),
hasPrevBlock = true,
hasNextBlock = true,
isVerticalNavigation = true,
nextButtonText = "Next",
onPrevClick = {}) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ class CourseUnitContainerFragment : Fragment(R.layout.fragment_course_unit_conta
}

private fun initViewPager() {
binding.viewPager.orientation = ViewPager2.ORIENTATION_VERTICAL
if (!viewModel.isCourseUnitProgressEnabled) {
binding.viewPager.orientation = ViewPager2.ORIENTATION_VERTICAL
}
binding.viewPager.offscreenPageLimit = 1
adapter = CourseUnitContainerAdapter(this, viewModel.getUnitBlocks(), viewModel)
binding.viewPager.adapter = adapter
Expand Down Expand Up @@ -301,7 +303,8 @@ class CourseUnitContainerFragment : Fragment(R.layout.fragment_course_unit_conta
val nextVerticalBlock = viewModel.getNextVerticalBlock()
val dialog = ChapterEndFragmentDialog.newInstance(
currentVerticalBlock?.displayName ?: "",
nextVerticalBlock?.displayName ?: ""
nextVerticalBlock?.displayName ?: "",
!viewModel.isCourseUnitProgressEnabled
)
currentVerticalBlock?.let {
viewModel.finishVerticalClickedEvent(
Expand Down Expand Up @@ -379,6 +382,7 @@ class CourseUnitContainerFragment : Fragment(R.layout.fragment_course_unit_conta
hasPrevBlock = hasPrevBlock,
nextButtonText = nextButtonText,
hasNextBlock = hasNextBlock,
isVerticalNavigation = !viewModel.isCourseUnitProgressEnabled,
onPrevClick = {
handlePrevClick { next, hasPrev, hasNext ->
nextButtonText = next
Expand Down

0 comments on commit 4d97d4f

Please sign in to comment.