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
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import android.view.View
import com.genius.multiprogressbar.MultiProgressBar

class MainActivity : AppCompatActivity(R.layout.activity_main), MultiProgressBar.ProgressStepChangeListener,
View.OnClickListener, MultiProgressBar.ProgressFinishListener {
View.OnClickListener {

private val progressBar: MultiProgressBar by lazy { findViewById(R.id.mpb_main) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

progressBar.setListener(this)
progressBar.setFinishListener(this)
}

override fun onClick(v: View?) {
Expand All @@ -34,7 +33,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), MultiProgressBar
Log.d("STEP", "Current step is $newStep")
}

override fun onProgressFinished() {
Log.d("PROGRESS", "Progress finished")
override fun onFinished() {
Log.d("FINISH", "We are finished stories")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class MultiProgressBar @JvmOverloads constructor(
private var singleDisplayedTime: Float = 1F

private var stepChangeListener: ProgressStepChangeListener? = null
private var finishListener: ProgressFinishListener? = null
private var progressPercents: Int

private var currentAbsoluteProgress = 0F
Expand Down Expand Up @@ -284,10 +283,6 @@ class MultiProgressBar @JvmOverloads constructor(
this.stepChangeListener = stepChangeListener
}

fun setFinishListener(finishListener: ProgressFinishListener?) {
this.finishListener = finishListener
}

fun setProgressStepsCount(progressSteps: Int) {
internalSetProgressStepsCount(progressSteps)
}
Expand Down Expand Up @@ -386,6 +381,19 @@ class MultiProgressBar @JvmOverloads constructor(
return singleDisplayedTime
}

fun nextTo(position: Int) {
if (isProgressIsRunning) {
pause()
currentAbsoluteProgress = position.toFloat().coerceAtMost(countOfProgressSteps.toFloat()) * progressPercents
animatedAbsoluteProgress = currentAbsoluteProgress
start()
} else {
currentAbsoluteProgress = position.toFloat().coerceAtMost(countOfProgressSteps.toFloat()) * progressPercents
animatedAbsoluteProgress = currentAbsoluteProgress
invalidate()
}
}

private fun internalStartProgress() {
val maxValue = countOfProgressSteps * progressPercents.toFloat()
activeAnimator = ValueAnimator.ofFloat(animatedAbsoluteProgress, maxValue).apply {
Expand All @@ -403,7 +411,7 @@ class MultiProgressBar @JvmOverloads constructor(
} else if (value == maxValue) {
currentAbsoluteProgress = maxValue
animatedAbsoluteProgress = maxValue
finishListener?.onProgressFinished()
stepChangeListener?.onFinished()
true
} else false

Expand Down Expand Up @@ -467,10 +475,8 @@ class MultiProgressBar @JvmOverloads constructor(

interface ProgressStepChangeListener {
fun onProgressStepChange(newStep: Int)
}

interface ProgressFinishListener {
fun onProgressFinished()
fun onFinished()
}

private companion object {
Expand Down