From ac37e69d38ec308a8cec98396f5dcdea47d7b180 Mon Sep 17 00:00:00 2001 From: Kishan Gohel Date: Mon, 30 Mar 2020 14:30:52 +0530 Subject: [PATCH] first commit. --- .gitignore | 1 + build.gradle | 36 ++++ consumer-rules.pro | 0 ktoaster.iml | 176 ++++++++++++++++++ proguard-rules.pro | 21 +++ .../ktoaster/ExampleInstrumentedTest.kt | 22 +++ src/main/AndroidManifest.xml | 1 + .../kishan/library/ktoaster/ToastMessage.kt | 31 +++ .../library/ktoaster/ExampleUnitTest.kt | 16 ++ 9 files changed, 304 insertions(+) create mode 100644 build.gradle create mode 100644 consumer-rules.pro create mode 100644 ktoaster.iml create mode 100644 proguard-rules.pro create mode 100644 src/androidTest/java/kishan/library/ktoaster/ExampleInstrumentedTest.kt create mode 100644 src/main/AndroidManifest.xml create mode 100644 src/main/java/kishan/library/ktoaster/ToastMessage.kt create mode 100644 src/test/java/kishan/library/ktoaster/ExampleUnitTest.kt diff --git a/.gitignore b/.gitignore index 56cc642..70eaa4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/build # Built application files *.apk *.aar diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..8fdd5a6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/consumer-rules.pro b/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/ktoaster.iml b/ktoaster.iml new file mode 100644 index 0000000..df605b4 --- /dev/null +++ b/ktoaster.iml @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/proguard-rules.pro b/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/src/androidTest/java/kishan/library/ktoaster/ExampleInstrumentedTest.kt b/src/androidTest/java/kishan/library/ktoaster/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..b0918d2 --- /dev/null +++ b/src/androidTest/java/kishan/library/ktoaster/ExampleInstrumentedTest.kt @@ -0,0 +1,22 @@ +package kishan.library.ktoaster + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("kishan.library.ktoaster.test", appContext.packageName) + } +} diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml new file mode 100644 index 0000000..51c6d53 --- /dev/null +++ b/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/src/main/java/kishan/library/ktoaster/ToastMessage.kt b/src/main/java/kishan/library/ktoaster/ToastMessage.kt new file mode 100644 index 0000000..ea376e9 --- /dev/null +++ b/src/main/java/kishan/library/ktoaster/ToastMessage.kt @@ -0,0 +1,31 @@ +package kishan.library.ktoaster + +import android.content.Context +import android.widget.Toast +import androidx.annotation.StringRes + +object ToastMessage : Throwable("ToastMessage is not initialized") { + + lateinit var context: Context + + + fun initialize(context: Context) { + this.context = context + } + + fun s(@StringRes message: Int) { + s(context.resources.getString(message)) + } + + fun s(message: String, isShort: Boolean = true) { + Toast.makeText(context, message, Toast.LENGTH_SHORT).show() + } + + fun l(@StringRes message: Int) { + l(context.resources.getString(message)) + } + + fun l(message: String, isShort: Boolean = true) { + Toast.makeText(context, message, Toast.LENGTH_LONG).show() + } +} \ No newline at end of file diff --git a/src/test/java/kishan/library/ktoaster/ExampleUnitTest.kt b/src/test/java/kishan/library/ktoaster/ExampleUnitTest.kt new file mode 100644 index 0000000..bc07b1e --- /dev/null +++ b/src/test/java/kishan/library/ktoaster/ExampleUnitTest.kt @@ -0,0 +1,16 @@ +package kishan.library.ktoaster + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +}