/GDSCToast

๐Ÿž Custom Toast Library by Google Developer Student Club University of Brawijaya

Primary LanguageKotlinMIT LicenseMIT

platform License jitpack

GDSCToast

Custom Toast Library by Google Developer Student Club University of Brawijaya

Prerequisites

  • For old version of gradle (before arctic fox update)

    Add this in your root build.gradle file (project scope)

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}
  • For gradle version 7 or latest

    Add this in your root setting.gradle file :

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Dependency

Add this to your module's build.gradle file :

dependencies {
	...
	implementation 'com.github.KylixEza:GDSCToast:version'
}

you can check the version on jitpack badge above or on release tag

Usage

Each function start with 'build...' like buildNormalToast always returns a Toast object, so you can customize your own Toast. But if you just want to show the toast without any customization, you can use function that start with 'show...' like showNormalToast

  • To display a normal Toast:
GDSCToast.buildNormalToast(this@MainActivity, "This is a normal toast", Toast.LENGTH_LONG, true).show()
GDSCToast.showNormalToast(this@MainActivity, "This is a normal toast", Toast.LENGTH_LONG, true)
  • To display a success Toast:
GDSCToast.buildSuccessToast(this@MainActivity, "This is a success toast", Toast.LENGTH_LONG, true).show()
GDSCToast.showSuccessToast(this@MainActivity, "This is a success toast", Toast.LENGTH_LONG, true)
  • To display an error Toast:
GDSCToast.buildErrorToast(this@MainActivity, "This is an error toast", Toast.LENGTH_LONG, true).show()
GDSCToast.showErrorToast(this@MainActivity, "This is an error toast", Toast.LENGTH_LONG, true)
  • To display an warning Toast:
GDSCToast.buildWarningToast(this@MainActivity, "This is a warning toast", Toast.LENGTH_LONG, true).show()
GDSCToast.showWarningToast(this@MainActivity, "This is a warning toast", Toast.LENGTH_LONG, true)
  • To display an info Toast:
GDSCToast.buildInfoToast(this@MainActivity, "This is an info toast", Toast.LENGTH_LONG, true).show()
GDSCToast.showInfoToast(this@MainActivity, "This is an info toast", Toast.LENGTH_LONG, true)
  • To configure any toast (1.2.0)
GDSCToast.configOn(this@MainActivity)
    .setText("Write your message here")
    .setDuration(Toast.LENGTH_LONG)
    .setShowLogo(false)
    .setToastShape(ToastShape.RECTANGLE)
    .setToastType(ToastType.WARNING)
    .showToast()
  • To configure any toast using lambda expression (1.2.1)
GDSCToast.showAnyToast(this@MainActivity) {
    it.apply {
	text = "Write your message here"
	duration = Toast.LENGTH_LONG
	showLogo = false
	toastType = ToastType.WARNING
	toastShape = ToastShape.RECTANGLE
    }
}
  • To use context extension into all of functions that available in GDSCToast (1.2.2)

The First Way -> simple but need to import the function that you called (automatically imported)

this@MainActivity.apply { buildNormalToast("This is normal toast", Toast.LENGTH_SHORT, true).show() }
this@MainActivity.apply { showSuccessToast("This is success toast", Toast.LENGTH_SHORT, true) }

this@MainActivity.apply { configOn().setText(...).setDuration(...).setShowLogo(...).setToastShape(...).setToastType(...).showToast() } 
this@MainActivity.apply { showAnyToast { it.apply { text, duration, etc. } } 

The Second Way -> little bit complicated but no need any import

GDSCToast.apply { this@MainActivity.buildNormalToast("This is normal toast", Toast.LENGTH_SHORT, true).show() }
GDSCToast.apply { this@MainActivity.showSuccessToast("This is success toast", Toast.LENGTH_SHORT, true) }

GDSCToast.apply { this@MainActivity.configOn().setText(...).setDuration(...).setShowLogo(...).setToastShape(...).setToastType(...).showToast() }
GDSCToast.apply { this@MainActivity.showAnyToast { it.apply { text, duration, etc. } }



Method Parameter Usage Attribute Default Value
configOn Context Allow you to access configuration of GDSCToast No default value because it's mandatory
setText String To set message that will shown from toast ""
setToastType ToastType To set type of toast ToastType.NORMAL
setShowLogo Boolean To set visibility of GDSC logo true
setDuration Int To set duration of toast Toast.LENGTH_SHORT
setToastShape ToastShape To set shape of toast ToastShape.ROUNDED
buildToast - To create the toast => returns toast object -
showToast - To show the toast -

Preview

Shape Preview
ToastShape.ROUNDED
ToastShape.RECTANGLE

Contributing

Please fork this repository and contribute back using.

Any contributions, large or small, major features, bug fixes, are welcomed and appreciated but will be thoroughly reviewed .

Contact

kylix-eza-saputra-1bb1b7192 k_ylix #Kylix3272

Don't forget to โญthis repository to motivates me to share more open source library