Skip to content

Commit

Permalink
Merge pull request #25 from 5AbhishekSaxena/development
Browse files Browse the repository at this point in the history
Push to release
  • Loading branch information
5AbhishekSaxena authored Jan 13, 2023
2 parents c13661c + fb3e92c commit 439606c
Show file tree
Hide file tree
Showing 23 changed files with 298 additions and 234 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ It has some predefined templates for common use-cases like warning, error and su

```
dependencies {
implementation 'tech.developingdeveloper.toaster-android:toaster:2.3.0'
implementation 'tech.developingdeveloper.toaster-android:toaster-ktx:2.3.0' //for ktx support
implementation 'com.github.5AbhishekSaxena.toaster-android:toaster:2.3.0'
implementation 'com.github.5AbhishekSaxena.toaster-android:toaster-ktx:2.3.0' //for ktx support
}
```
*Please Note:* toaster-ktx includes toaster module so, if you are using toaster-ktx version then you don't have to add taoster
Expand Down
22 changes: 11 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 31
buildToolsVersion "29.0.3"
compileSdkVersion 33

defaultConfig {
applicationId "tech.developingdeveloper.toasterexample"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.2"
versionCode 3
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -31,21 +30,22 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'tech.developingdeveloper.toasterexample'

}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.30"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.20"
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':toaster')
implementation project(path: ':toaster-ktx')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation 'com.google.android.material:material:1.4.0'
implementation 'com.google.android.material:material:1.7.0'

}
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tech.developingdeveloper.toasterexample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand All @@ -9,7 +8,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="tech.developingdeveloper.toasterexample.MainActivity">
<activity
android:name="tech.developingdeveloper.toasterexample.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import tech.developingdeveloper.toaster.Toaster
import tech.developingdeveloper.toasterexample.databinding.ActivityMainBinding
import tech.developingdeveloper.toasterktx.ToasterBuilderKtx
import tech.developingdeveloper.toasterktx.prepareToast
import tech.developingdeveloper.toasterktx.prepareToaster


/**
Expand All @@ -22,7 +23,7 @@ class KtxExampleActivity : AppCompatActivity() {
setContentView(binding.root)

binding.builderButton.setOnClickListener {
val toaster = ToasterBuilderKtx.prepareToaster(this) {
val toaster = prepareToaster(this) {
message = "File uploaded successfully"
leftDrawableRes = R.drawable.ic_baseline_cloud_done_24
leftDrawableTint = R.color.blue
Expand All @@ -34,7 +35,7 @@ class KtxExampleActivity : AppCompatActivity() {

// or

ToasterBuilderKtx.prepareToast(this) {
prepareToast(this) {
message = "File uploaded successfully"
leftDrawableRes = R.drawable.ic_baseline_cloud_done_24
leftDrawableTint = R.color.blue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tech.developingdeveloper.toasterexample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import tech.developingdeveloper.toaster.DefaultToasterType
import tech.developingdeveloper.toaster.Toaster
import tech.developingdeveloper.toasterexample.databinding.ActivityMainBinding

Expand Down Expand Up @@ -30,36 +31,41 @@ class MainActivity : AppCompatActivity() {
}

binding.builderButton.setOnClickListener {
val toastBuilder = Toaster.Builder(this)
.setMessage("File uploaded successfully")
.setLeftDrawable(R.drawable.ic_baseline_cloud_done_24)
.setLeftDrawableTint(R.color.blue)
.setStripTint(R.color.blue)
.setDuration(Toaster.LENGTH_SHORT)
Toaster.pop(toastBuilder.make()).show()
val toaster = Toaster.Config(
message = "File uploaded successfully",
leftDrawableRes = R.drawable.ic_baseline_cloud_done_24,
leftDrawableTint = R.color.blue,
stripTint = R.color.blue,
duration = Toaster.LENGTH_SHORT,
).make(this)

Toaster.pop(toaster).show()
}

binding.errorButton.setOnClickListener {
Toaster.popError(
this,
"This is an error message",
Toaster.LENGTH_SHORT
Toaster.pop(
context = this,
message = "This is an error message",
duration = Toaster.LENGTH_SHORT,
toasterType = DefaultToasterType.ERROR,
).show()
}

binding.warningButton.setOnClickListener {
Toaster.popWarning(
this,
"This is a warning message",
Toaster.LENGTH_SHORT
Toaster.pop(
context = this,
message = "This is a warning message",
duration = Toaster.LENGTH_SHORT,
toasterType = DefaultToasterType.WARNING,
).show()
}

binding.successButton.setOnClickListener {
Toaster.popSuccess(
this,
"This is a success message",
Toaster.LENGTH_SHORT
Toaster.pop(
context = this,
message = "This is a success message",
duration = Toaster.LENGTH_SHORT,
toasterType = DefaultToasterType.SUCCESS,
).show()
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
Empty file modified gradlew
100644 → 100755
Empty file.
11 changes: 6 additions & 5 deletions toaster-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'tech.developingdeveloper.toasterktx'
}

dependencies {

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
api project(path: ':toaster')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
3 changes: 1 addition & 2 deletions toaster-ktx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tech.developingdeveloper.toasterktx">
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tech.developingdeveloper.toasterktx

import android.content.Context
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import tech.developingdeveloper.toaster.Toaster
Expand All @@ -13,7 +11,7 @@ import tech.developingdeveloper.toaster.Toaster
* @since 07-09-2021 12:01
*/

class ToasterBuilderKtx private constructor(private val context: Context) {
class ToasterBuilderKtx internal constructor(private val context: Context) {

@DrawableRes
var leftDrawableRes: Int = DEFAULT_VALUE
Expand All @@ -27,40 +25,17 @@ class ToasterBuilderKtx private constructor(private val context: Context) {
var message: CharSequence = ""
var duration: Int = Toaster.LENGTH_SHORT

private fun prepare(): Toaster {
val toasterBuilder = Toaster.Builder(context)
.setMessage(message)
.setDuration(duration)

if (leftDrawableRes != DEFAULT_VALUE)
toasterBuilder.setLeftDrawable(leftDrawableRes)

if (leftDrawableTint != DEFAULT_VALUE)
toasterBuilder.setLeftDrawableTint(leftDrawableTint)

if (stripTint != DEFAULT_VALUE)
toasterBuilder.setStripTint(stripTint)

return toasterBuilder.make()
internal fun prepare(): Toaster {
return Toaster.Config(
message = message,
duration = duration,
leftDrawableRes = leftDrawableRes.takeIf { it != DEFAULT_VALUE },
leftDrawableTint = leftDrawableTint.takeIf { it != DEFAULT_VALUE },
stripTint = stripTint.takeIf { it != DEFAULT_VALUE },
).make(context)
}

companion object {
private const val DEFAULT_VALUE = -1

fun prepareToast(
context: Context,
block: ToasterBuilderKtx.() -> Unit
): Toast {
val toaster = prepareToaster(context, block)
return Toaster.pop(toaster)
}

fun prepareToaster(
context: Context,
block: ToasterBuilderKtx.() -> Unit
): Toaster {
val toastBuilder = ToasterBuilderKtx(context).apply(block)
return toastBuilder.prepare()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tech.developingdeveloper.toasterktx

import android.content.Context
import android.widget.Toast
import tech.developingdeveloper.toaster.Toaster

fun prepareToast(
context: Context,
block: ToasterBuilderKtx.() -> Unit
): Toast {
val toaster = prepareToaster(context, block)
return Toaster.pop(toaster)
}

fun prepareToaster(
context: Context,
block: ToasterBuilderKtx.() -> Unit
): Toaster {
val toastBuilder = ToasterBuilderKtx(context).apply(block)
return toastBuilder.prepare()
}
20 changes: 10 additions & 10 deletions toaster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 31
buildToolsVersion "29.0.3"
compileSdkVersion 33

defaultConfig {
minSdkVersion 19
targetSdkVersion 31
versionCode 2
versionName "2.3.0"
versionCode 3
versionName "2.3.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -22,17 +21,18 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
namespace 'tech.developingdeveloper.toaster'
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.30"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.20"
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// CardView
implementation "androidx.cardview:cardview:1.0.0"
Expand Down
6 changes: 1 addition & 5 deletions toaster/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tech.developingdeveloper.toaster">

/
</manifest>
<manifest></manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tech.developingdeveloper.toaster

/**
* An enumeration of all possible default [Toaster]s that
* the user can create.
*/
enum class DefaultToasterType {
SUCCESS,
WARNING,
ERROR,
}
Loading

0 comments on commit 439606c

Please sign in to comment.