Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
v2.1.1: Experimental support for skip button
Browse files Browse the repository at this point in the history
- Apply styling to the skip button using the miv.skipButtonStyling member lambda function
- Fix transparency not being applied on dot icon using dotIconColor
- Optimise MaterialIntroSequence (MIS)
- Now add MaterialIntroConfiguration to MIS directly using addConfig lambda function

Signed-off-by: Shripal Jain <shripal17@gmail.com>
  • Loading branch information
shripal17 committed Apr 29, 2020
1 parent 9dde967 commit 7cb0596
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 103 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ Create a new issue to add your app here
# License
--------


Copyright 2020 Shripal Jain

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.3.71'
repositories {
jcenter()
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package com.codertainment.materialintro

import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.view.Gravity
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import com.codertainment.materialintro.animation.MaterialIntroListener
import com.codertainment.materialintro.sequence.SkipLocation
import com.codertainment.materialintro.shape.Focus
import com.codertainment.materialintro.shape.FocusGravity
import com.codertainment.materialintro.shape.Shape
import com.codertainment.materialintro.shape.ShapeType
import com.codertainment.materialintro.utils.Constants
import com.google.android.material.button.MaterialButton

data class MaterialIntroConfiguration(
var maskColor: Int = Constants.DEFAULT_MASK_COLOR,
Expand Down Expand Up @@ -64,5 +65,9 @@ data class MaterialIntroConfiguration(

var shapeType: ShapeType = ShapeType.CIRCLE,
var customShape: Shape? = null,
var materialIntroListener: MaterialIntroListener? = null
var materialIntroListener: MaterialIntroListener? = null,

var skipLocation: SkipLocation = SkipLocation.BOTTOM_LEFT,
var skipText: CharSequence = "Skip",
var skipButtonStyling: MaterialButton.() -> Unit = {}
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class MaterialIntroSequence private constructor(private val activity: Activity)
Handler()
}

/**
* Whether to show the skip button
*/
var showSkip = false

/**
* If enabled, once the user clicks on skip button, all new MIVs will be skipped too
* If disabled, even after the user clicks on skip button and new MIVs are added after that, for e.g. for another fragment, the new MIVs will be shown
*/
var persistSkip = false
private var isSkipped = false

private var materialIntroListener = object : MaterialIntroListener {
override fun onIntroDone(onUserClick: Boolean, viewId: String) {
materialIntroSequenceListener?.onProgress(onUserClick, viewId, counter, mivs.size)
Expand All @@ -61,22 +73,50 @@ class MaterialIntroSequence private constructor(private val activity: Activity)
var materialIntroSequenceListener: MaterialIntroSequenceListener? = null

fun add(config: MaterialIntroConfiguration) {
val found = mivs.filter { it.viewId == config.viewId }
if (found.isNotEmpty() || preferencesManager.isDisplayed(config.viewId)) return
val found = mivs.find { it.viewId == config.viewId || it.viewId == config.targetView?.tag?.toString() }
if (found != null && preferencesManager.isDisplayed(config.viewId ?: config.targetView?.tag?.toString())) return
mivs.add(activity.materialIntro(config = config) {
showSkip = this@MaterialIntroSequence.showSkip
delayMillis = if (mivs.isEmpty()) initialDelay else 0
materialIntroListener = this@MaterialIntroSequence.materialIntroListener
skipButton.setOnClickListener {
skip()
}
})
}

fun addConfig(func: MaterialIntroConfiguration.() -> Unit) {
add(MaterialIntroConfiguration().apply {
func()
})
}

private fun skip() {
isSkipped = true
mivs[counter - 1].dismiss()
for (i in 0 until mivs.size) {
if (mivs[i].showOnlyOnce) {
preferencesManager.setDisplayed(mivs[i].viewId)
}
}
counter = mivs.size
materialIntroSequenceListener?.onCompleted()
}

fun start() {
if (!isMivShowing) {
nextIntro()
if (isSkipped && persistSkip) {
skip()
} else {
if (!isMivShowing) {
nextIntro()
}
}
}

private fun nextIntro() {
if (counter < mivs.size) {
if (isSkipped && persistSkip) {
skip()
} else if (counter < mivs.size) {
isMivShowing = true
handler.post {
mivs[counter++].show(activity)
Expand All @@ -94,10 +134,16 @@ val Activity.materialIntroSequence
get() = MaterialIntroSequence.getInstance(this)

fun Activity.materialIntroSequence(
initialDelay: Long? = null, materialIntroSequenceListener: MaterialIntroSequenceListener? = null,
initialDelay: Long? = null, materialIntroSequenceListener: MaterialIntroSequenceListener? = null, showSkip: Boolean? = null, persistSkip: Boolean? = null,
func: MaterialIntroSequence.() -> Unit
): MaterialIntroSequence {
return materialIntroSequence.apply {
showSkip?.let {
this.showSkip = it
}
persistSkip?.let {
this.persistSkip = it
}
initialDelay?.let {
this.initialDelay = it
}
Expand All @@ -113,10 +159,16 @@ val Fragment.materialIntroSequence
get() = if (activity != null) MaterialIntroSequence.getInstance(activity!!) else null

fun Fragment.materialIntroSequence(
initialDelay: Long? = null, materialIntroSequenceListener: MaterialIntroSequenceListener? = null,
initialDelay: Long? = null, materialIntroSequenceListener: MaterialIntroSequenceListener? = null, showSkip: Boolean? = null, persistSkip: Boolean? = null,
func: MaterialIntroSequence.() -> Unit
): MaterialIntroSequence? {
return materialIntroSequence.apply {
showSkip?.let {
this?.showSkip = it
}
persistSkip?.let {
this?.persistSkip = it
}
initialDelay?.let {
this?.initialDelay = it
}
Expand All @@ -126,4 +178,11 @@ fun Fragment.materialIntroSequence(
this?.func()
this?.start()
}
}
}

enum class SkipLocation {
TOP_RIGHT,
TOP_LEFT,
BOTTOM_LEFT,
BOTTOM_RIGHT
}
Loading

0 comments on commit 7cb0596

Please sign in to comment.