Skip to content

Commit

Permalink
Merge pull request #19 from Mohamed02Emad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Mohamed02Emad committed Jun 26, 2023
2 parents cac000c + a1fbcbc commit 4c594c8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
71 changes: 39 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {

```gradle
dependencies {
implementation 'com.github.Mohamed02Emad:Mo_Horizonta_Stepper:1.1.0'
implementation 'com.github.Mohamed02Emad:Mo_Horizonta_Stepper:1.2.0'
}
```

Expand All @@ -33,7 +33,7 @@ default mode is `SELECT_CURRENT`

`setStepperMode(MoHorizontalStepper.MoStepperMode.SELECT_CURRENT)`

available modes (can only chance them from code)
available modes (can only change them from code)

| Modes | Usage |
| ------------------------------------------------ | --------------------------------------------------------------|
Expand All @@ -60,32 +60,34 @@ each color name is in this image
![colornames](https://github.com/Mohamed02Emad/Mo_Horizonta_Stepper/assets/81470639/c2662f99-68a1-443a-8fa0-5461876ea74d)

* an example of changing selected text color to red
`setSelectedTextColor(R.color.red)`
`setSelectedTextColor(R.colors.red)`

methods from code :

## table of public methods to use
| Methods | Return Type | Parameters | Default | description |
| --------------------------------- | --------------------- | --------------------- | ----------------- | ------------------------------------------------ |
| `moveToPreviousStep` | Any | -- | -- | moves the stepper to the previous step |
| `moveToNextStep` | Any | -- | -- | moves the stepper to the next step |
| `setStepperMode` | Any | MoStepperMode | SELECT_CURRENT | change stepper mode to one of the above |
| `setCurrentStep` | Any | Integer | 4 | move stepper to this exact step |
| `setSelectedTextColor` | Any | Integer | white | takes `R.colors.color` to set mentioned color |
| `setSelectedBackgroundColor` | Any | Integer | red | takes `R.colors.color` to set mentioned color |
| `setNotSelectedBackgroundColor` | Any | Integer | white | takes `R.colors.color` to set mentioned color |
| `setNotSelectedTextColor` | Any | Integer | black | takes `R.colors.color` to set mentioned color |
| `setNotSelectedRingColor` | Any | Integer | red | takes `R.colors.color` to set mentioned color |
| `setCurrentSelectedRingColor` | Any | Integer | teal | takes `R.colors.color` to set mentioned color |
| `setSelectedSpacerColor` | Any | Integer | red | takes `R.colors.color` to set mentioned color |
| `setNotSelectedSpacerColor` | Any | Integer | black | takes `R.colors.color` to set mentioned color |
| `getPreviousFragment` | Integer | -- | -- | return id of previous fragment, null if no prev |
| `getNextFragment` | Integer | -- | -- | return id of next fragment, null if no next |
| `getCurrentStepIndex` | Integer | -- | -- | return the index of current step |
| `setNumberOfSteps` | Integer | Integer | 4 | set number of steps in the stepper |
| `getNumberOfSteps` | integer | -- | 4 | return total number of steps in the stepper |
| `isLastStep` | Boalean | -- | -- | return true if last step is selected else false |
| `isFirstStep` | Boalean | -- | -- | return true if first step is selected else false |
| Methods | Return Type | Parameters | Default | description |
|---------------------------------|-------------|---------------|----------------|-------------------------------------------------------|
| `moveToPreviousStep` | Any | -- | -- | moves the stepper to the previous step |
| `moveToNextStep` | Any | -- | -- | moves the stepper to the next step |
| `setStepperMode` | Any | MoStepperMode | SELECT_CURRENT | change stepper mode to one of the above |
| `setCurrentStep` | Any | Integer | 4 | move stepper to this exact step |
| `setSelectedTextColor` | Any | Integer | white | takes `R.colors.color` to set mentioned color |
| `setSelectedBackgroundColor` | Any | Integer | red | takes `R.colors.color` to set mentioned color |
| `setNotSelectedBackgroundColor` | Any | Integer | white | takes `R.colors.color` to set mentioned color |
| `setNotSelectedTextColor` | Any | Integer | black | takes `R.colors.color` to set mentioned color |
| `setNotSelectedRingColor` | Any | Integer | red | takes `R.colors.color` to set mentioned color |
| `setCurrentSelectedRingColor` | Any | Integer | teal | takes `R.colors.color` to set mentioned color |
| `setSelectedSpacerColor` | Any | Integer | red | takes `R.colors.color` to set mentioned color |
| `setNotSelectedSpacerColor` | Any | Integer | black | takes `R.colors.color` to set mentioned color |
| `getPreviousFragment` | Integer | -- | -- | return id of previous fragment, null if no prev |
| `getNextFragment` | Integer | -- | -- | return id of next fragment, null if no next |
| `getCurrentStepIndex` | Integer | -- | -- | return the index of current step |
| `setNumberOfSteps` | Integer | Integer | 4 | set number of steps in the stepper |
| `getNumberOfSteps` | integer | -- | 4 | return total number of steps in the stepper |
| `isLastStep` | Boolean | -- | -- | return true if last step is selected else false |
| `isFirstStep` | Boolean | -- | -- | return true if first step is selected else false |
| `isStepClickable` | Boolean | -- | true | return true if steps are clickable else false |
| `setIsStepClickable` | -- | Boolean | true | decide if steps can be clicked or not |

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand All @@ -108,7 +110,7 @@ now you need to access this stepper from your code and set it's attributes
setStepperMode(MoHorizontalStepper.MoStepperMode.SELECT_PREVIOUS_AND_CURRENT)
setNumberOfSteps(5)
//make sure not to call setBackgroundColor() but setSelectedBackgroundColor
setSelectedBackgroundColor(R.color.red)
setSelectedBackgroundColor(R.colors.red)

//rest of you initialization
}
Expand All @@ -121,6 +123,8 @@ or you can access some attributes from your xml ( here are attributes that can b
android:id="@+id/stepper"
android:layout_width="match_parent"
android:layout_height="wrap_content"


app:selectedTextColor=""
app:selectedBackgroundColor=""
app:notSelectedBackgroundColor=""
Expand All @@ -134,7 +138,7 @@ or you can access some attributes from your xml ( here are attributes that can b

## use it to navigate

1- create navhost fragment with navGraph
1- create navHost fragment with navGraph

```xml
<androidx.fragment.app.FragmentContainerView
Expand All @@ -145,8 +149,8 @@ or you can access some attributes from your xml ( here are attributes that can b
app:navGraph="@navigation/stepper_navigation" />
```

2- in your code pass a menu and make sure that menu has sasme size as number of steps,
if number of elements are diffrent that number of steps you will get null as a result from the stepper
2- in your code pass a menu and make sure that menu has same size as number of steps,
if number of elements are different that number of steps you will get null as a result from the stepper

```kotlin
val stepper = findViewById<MoHorizontalStepper>(R.id.stepper)
Expand All @@ -155,7 +159,7 @@ if number of elements are diffrent that number of steps you will get null as a r
menuInflater.inflate(R.menu.menu, myMenu)
stepper.apply {
setStepperMode(MoHorizontalStepper.MoStepperMode.SELECT_PREVIOUS_AND_CURRENT)
setNumberOfSteps(make sure they are same number as your menu items)
setNumberOfSteps(myMenu.size)
setNavigationMenu(myMenu)
}
```
Expand All @@ -166,20 +170,23 @@ if number of elements are diffrent that number of steps you will get null as a r
stepper.stepClickListener={stepIndex ->
val fragmentId = stepper.getFragmentByIndex(stepIndex-1)
fragmentId?.let {destination ->

// you have the destination navigate with any way you like
//here is an example

val navController = navHostFragment.findNavController()
navController.navigate(destination, null, null, null)
stepper.setCurrentStep(stepIndex)

}
}
```

# Notes

1- if you used `moveToNextStep` or `moveToPreviousStep` you have to navigate manualy after that
1- if you used `moveToNextStep` or `moveToPreviousStep` you have to navigate manually after them

2- if you are using the `MoStepperMode.SELECT_PREVIOUS` mode , there is an additional color called `currentSelected` which indicates the current step color
and you can change it using `setCurrentSelectedRingColor(R.colors.color)`

3- currently steps have fixed size , I'll fix it in the next release

# have fun
6 changes: 3 additions & 3 deletions mohorizontalstepper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'maven-publish'
}
group = 'Mohamed02Emad'
version = "1.1.0"
version = "1.2.0"

android {
namespace 'com.mo_stepper.mohorizontalstepper'
Expand All @@ -14,7 +14,7 @@ android {
minSdk 21
targetSdk 33
versionCode 1
versionName "1.1.0"
versionName "1.2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -51,7 +51,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.Mohamed02Emad'
artifactId = 'mo-horizontal-stepper'
version = '1.1.0'
version = '1.2.0'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MoHorizontalStepper @JvmOverloads constructor(
var stepClickListener: ((stepIndex: Int) -> Unit)? = null
private var stepperMode: MoStepperMode = MoStepperMode.SELECT_CURRENT
private var menu: Menu? = null
private var isClickable = true

private var selectedTextColor: Int = 0
private var selectedBackgroundColor: Int = 0
Expand Down Expand Up @@ -233,6 +234,13 @@ class MoHorizontalStepper @JvmOverloads constructor(
return currentStepIndex
}

fun setIsStepClickable(isClickable: Boolean) {
this.isClickable = isClickable
}

fun isStepClickable(): Boolean = isClickable


/*
methods for shaping and coloring
*/
Expand Down Expand Up @@ -333,8 +341,10 @@ class MoHorizontalStepper @JvmOverloads constructor(
val txt = stepView.findViewById<TextView>(R.id.tv_number)
txt.text = stepNumber.toString()
stepView.setOnClickListener {
setCurrentStep(stepNumber)
stepClickListener?.invoke(stepNumber)
if (isClickable) {
setCurrentStep(stepNumber)
stepClickListener?.invoke(stepNumber)
}
}
return stepView
}
Expand Down

0 comments on commit 4c594c8

Please sign in to comment.