├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── raqun │ │ └── kotlinextdemo │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── raqun │ │ │ └── kotlinextdemo │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── raqun │ └── kotlinextdemo │ └── ExampleUnitTest.kt ├── build.gradle ├── buildSrc ├── .gitignore ├── build.gradle.kts └── src │ └── main │ └── java │ ├── Config.kt │ ├── Dependencies.kt │ ├── Modules.kt │ ├── Paths.kt │ ├── Plugins.kt │ ├── Urls.kt │ └── Versions.kt ├── common-android-library.gradle ├── common.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── kotlinext ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── raqun │ │ └── kotlinext │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── raqun │ │ │ └── kotlinext │ │ │ ├── AnyExt.kt │ │ │ ├── DateTimeExt.kt │ │ │ ├── FileExt.kt │ │ │ ├── MathExt.kt │ │ │ ├── StorageExt.kt │ │ │ ├── StringExt.kt │ │ │ ├── UtilityExt.kt │ │ │ ├── component │ │ │ ├── ActivityExt.kt │ │ │ ├── ContextExt.kt │ │ │ ├── FragmentManagerExt.kt │ │ │ └── LooperExt.kt │ │ │ └── view │ │ │ ├── EditTextExt.kt │ │ │ ├── ImageViewExt.kt │ │ │ ├── TextViewExt.kt │ │ │ ├── ViewExt.kt │ │ │ ├── ViewGroupExt.kt │ │ │ └── ViewPagerExt.kt │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── raqun │ └── kotlinext │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kotlin-ext 2 | Some useful Kotlin extensions and high order functions. 3 | 4 | ## Dependency 5 | Add it in your root build.gradle at the end of repositories: 6 | ``` 7 | allprojects { 8 | repositories { 9 | ... 10 | maven { url 'https://jitpack.io' } 11 | } 12 | } 13 | ``` 14 | Add the dependency 15 | ``` 16 | dependencies { 17 | implementation 'com.github.savepopulation:kotlin-ext:1.0.0' 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: Plugins.androidApplication 2 | apply from: "$rootDir/common.gradle" 3 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/raqun/kotlinextdemo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinextdemo 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.raqun.kotlinextdemo", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/raqun/kotlinextdemo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinextdemo 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | 6 | class MainActivity : AppCompatActivity() { 7 | 8 | override fun onCreate(savedInstanceState: Bundle?) { 9 | super.onCreate(savedInstanceState) 10 | setContentView(R.layout.activity_main) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | kotlinextdemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/raqun/kotlinextdemo/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinextdemo 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | maven { url Urls.jitpack } 8 | } 9 | dependencies { 10 | classpath Paths.gradleClasspath 11 | classpath Paths.kotlinGradlePluginClasspath 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.build.gradle.kts files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | maven { url Urls.jitpack } 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } -------------------------------------------------------------------------------- /buildSrc/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | /build -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.gradle.kotlin.dsl.`kotlin-dsl` 2 | 3 | plugins { 4 | `kotlin-dsl` 5 | } 6 | 7 | repositories { 8 | jcenter() 9 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/Config.kt: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * App configuration 4 | */ 5 | object Config { 6 | const val applicationId = "com.raqun.kotlinextdemo" 7 | const val rawPackageName = "com.raqun.movies" 8 | const val minSdkVersion = Versions.minSdkVersion 9 | const val targetSdkVersion = Versions.targetSdkVersion 10 | const val compileSdkVersion = Versions.compileSdkVersion 11 | const val testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" 12 | const val versionCode = 2 13 | const val versionName = "2.0.0" 14 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/Dependencies.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Core Libraries 3 | */ 4 | object CoreLibraries { 5 | const val kotlin = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlinVersion}" 6 | } 7 | 8 | /* 9 | * Support Libraries 10 | */ 11 | object SupportLibraries { 12 | const val appCompat = "androidx.appcompat:appcompat:${Versions.xVersion}" 13 | const val recyclerView = "androidx.recyclerview:recyclerview:${Versions.xVersion}" 14 | const val design = "com.google.android.material:material:${Versions.supportDesignVersion}" 15 | } 16 | 17 | /* 18 | * Test Libraries 19 | */ 20 | object TestLibraries { 21 | const val jUnit = "junit:junit:${Versions.jUnitVersion}" 22 | const val runnner = "androidx.test:runner:${Versions.testRunnerVersion}" 23 | const val espressoCore = "androidx.test.espresso:espresso-core:${Versions.espressoCoreVersion}" 24 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/Modules.kt: -------------------------------------------------------------------------------- 1 | object Modules { 2 | 3 | /* 4 | * App 5 | */ 6 | const val app = ":app" 7 | 8 | 9 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/Paths.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Common Paths 3 | */ 4 | object Paths { 5 | val gradleClasspath = "com.android.tools.build:gradle:${Versions.gradleVersion}" 6 | val kotlinGradlePluginClasspath = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinVersion}" 7 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/Plugins.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Plugins 3 | */ 4 | object Plugins { 5 | const val androidApplication = "com.android.application" 6 | const val androidLibrary = "com.android.library" 7 | const val kotlinAndroid = "kotlin-android" 8 | const val kotlinAndroidExtensions = "kotlin-android-extensions" 9 | const val kotlinKapt = "kotlin-kapt" 10 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/Urls.kt: -------------------------------------------------------------------------------- 1 | object Urls { 2 | const val jitpack = "https://jitpack.io" 3 | } 4 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/Versions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Sdk and dependency versions 3 | */ 4 | object Versions { 5 | /* 6 | * Sdk Versions 7 | */ 8 | const val minSdkVersion = 19 9 | const val targetSdkVersion = 28 10 | const val compileSdkVersion = 28 11 | 12 | /* 13 | * Dependency Versions 14 | */ 15 | const val xVersion = "1.0.0" 16 | const val gradleVersion = "3.3.1" 17 | const val kotlinVersion = "1.3.20" 18 | const val jUnitVersion = "4.12" 19 | const val testRunnerVersion = "1.1.0" 20 | const val espressoCoreVersion = "3.1.0" 21 | const val supportDesignVersion = "1.0.0-rc01" 22 | } -------------------------------------------------------------------------------- /common-android-library.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: Plugins.androidLibrary 2 | apply from: "$rootDir/common.gradle" -------------------------------------------------------------------------------- /common.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: Plugins.kotlinAndroid 2 | apply plugin: Plugins.kotlinAndroidExtensions 3 | 4 | android { 5 | compileSdkVersion Config.compileSdkVersion 6 | 7 | defaultConfig { 8 | minSdkVersion Config.minSdkVersion 9 | targetSdkVersion Config.targetSdkVersion 10 | versionCode Config.versionCode 11 | versionName Config.versionName 12 | vectorDrawables.useSupportLibrary = true 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | 21 | debug { 22 | debuggable true 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | 29 | // Core 30 | implementation CoreLibraries.kotlin 31 | 32 | // Testing 33 | testImplementation TestLibraries.jUnit 34 | androidTestImplementation TestLibraries.runnner 35 | androidTestImplementation TestLibraries.espressoCore 36 | } 37 | 38 | configurations.all { 39 | resolutionStrategy.eachDependency { DependencyResolveDetails details -> 40 | def requested = details.requested 41 | if (requested.group == 'org.jetbrains.kotlin') { 42 | details.useVersion Versions.kotlinVersion 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/kotlin-ext/9c5ad5d8ba0b7616177a17fc3fabc455b6cefd14/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Oct 21 18:19:20 EET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /kotlinext/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /kotlinext/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android-extensions' 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion 27 7 | 8 | 9 | 10 | defaultConfig { 11 | minSdkVersion 17 12 | targetSdkVersion 27 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | 32 | implementation 'com.android.support:appcompat-v7:27.1.1' 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 36 | 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 38 | } 39 | -------------------------------------------------------------------------------- /kotlinext/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /kotlinext/src/androidTest/java/com/raqun/kotlinext/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.raqun.kotlinext.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /kotlinext/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/AnyExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | /** 4 | * Checks if any object is not null 5 | */ 6 | fun Any?.isNotNull() = this != null 7 | 8 | /** 9 | * Checks if any object is null 10 | */ 11 | fun Any?.isNull() = this == null 12 | 13 | /** 14 | * Try-catch 15 | */ 16 | fun Any.tryCatch(tryBlock: () -> Unit, 17 | catchBlock: ((t: Throwable) -> Unit)? = null, 18 | finalBlock: (() -> Unit)? = null) { 19 | try { 20 | tryBlock() 21 | } catch (e: Exception) { 22 | catchBlock?.invoke(e) 23 | } finally { 24 | finalBlock?.invoke() 25 | } 26 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/DateTimeExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | /* 4 | * Converts date with 0 prefix format 5 | */ 6 | fun Int.convertDateWithPrefix() : String{ 7 | return if(this <10){ 8 | "0${this}" 9 | } else{ 10 | this.toString() 11 | } 12 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/FileExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | import android.content.Context 4 | import android.net.Uri 5 | import android.os.Build 6 | import android.os.Environment 7 | import android.support.v4.content.FileProvider 8 | import java.io.File 9 | import java.io.FileNotFoundException 10 | import java.io.IOException 11 | import java.text.SimpleDateFormat 12 | import java.util.* 13 | 14 | /** 15 | * Gets an uri of file 16 | */ 17 | fun File.getUriFromFile(context: Context, authority: String): Uri { 18 | return if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { 19 | FileProvider.getUriForFile(context, authority, this) 20 | } else { 21 | Uri.fromFile(this) 22 | } 23 | } 24 | 25 | /** 26 | * Checks and returns if there's a valid directory with given path 27 | */ 28 | fun String.getAsDirectory(): File? { 29 | val directory = File(Environment.getExternalStorageDirectory(), this) 30 | return if (directory.exists()) { 31 | directory 32 | } else { 33 | null 34 | } 35 | } 36 | 37 | /** 38 | * Gets all files in given directory 39 | */ 40 | fun File.getFiles(): List { 41 | val inFiles = ArrayList() 42 | val files = this.listFiles() 43 | if (files != null) { 44 | for (file in files) { 45 | if (file.isDirectory) { 46 | inFiles.addAll(file.getFiles()) 47 | } else { 48 | inFiles.add(file) 49 | } 50 | } 51 | } 52 | return inFiles 53 | } 54 | 55 | /** 56 | * Gets the file count of given directory 57 | */ 58 | fun File.getFileCount() = getFiles().size 59 | 60 | /** 61 | * Calculates the folder size 62 | */ 63 | fun File.getFolderSize(): Long { 64 | var size: Long = 0 65 | if (isDirectory) { 66 | val files = listFiles() 67 | if (files != null) { 68 | for (file in files) { 69 | size += if (file.isDirectory) { 70 | file.getFolderSize() 71 | } else { 72 | file.length() 73 | } 74 | } 75 | } else { 76 | size = 0 77 | } 78 | } else { 79 | size = length() 80 | } 81 | 82 | return size 83 | } 84 | 85 | /** 86 | * Deletes given directory and returns result 87 | */ 88 | fun File.deleteDirectory(): Boolean { 89 | if (!exists()) return false 90 | return cleanDirectory() 91 | } 92 | 93 | /** 94 | * Force deletes given directory or file 95 | */ 96 | private fun File.forceDelete() { 97 | if (isDirectory) { 98 | deleteDirectory() 99 | } else { 100 | val filePresent = exists() 101 | if (!delete()) { 102 | if (!filePresent) { 103 | throw FileNotFoundException("File does not exist: $this") 104 | } 105 | val message = "Unable to delete file: $this" 106 | throw IOException(message) 107 | } 108 | } 109 | } 110 | 111 | /** 112 | * Cleans directory and returns result 113 | */ 114 | private fun File.cleanDirectory(): Boolean { 115 | val files = verifiedDirectoryFiles() 116 | var allFilesDeleted = true 117 | for (file in files) { 118 | try { 119 | forceDelete() 120 | } catch (e: IOException) { 121 | e.printStackTrace() 122 | if (allFilesDeleted) allFilesDeleted = false 123 | } 124 | } 125 | return allFilesDeleted 126 | } 127 | 128 | /** 129 | * Verifies files of directory 130 | */ 131 | private fun File.verifiedDirectoryFiles(): Array { 132 | if (!exists()) { 133 | val message = toString() + " does not exist" 134 | throw IllegalArgumentException(message) 135 | } 136 | 137 | if (!isDirectory) { 138 | val message = toString() + " is not a directory" 139 | throw IllegalArgumentException(message) 140 | } 141 | 142 | return listFiles() 143 | ?: // null if security restricted 144 | throw IOException("Failed to list contents of $this") 145 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/MathExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | /* 4 | Mathematical operations of double numbers 5 | */ 6 | fun Double.sin() : Double = Math.sin(this) 7 | fun Double.cos() : Double = Math.cos(this) 8 | fun Double.tan() : Double = Math.tan(this) 9 | fun Double.log() : Double = Math.log(this) 10 | fun Double.log10() : Double = Math.log10(this) 11 | fun Double.floor(): Double = Math.floor(this) 12 | fun Double.ceil() : Double = Math.ceil(this) 13 | fun Double.pow(exp: Double) : Double = Math.pow(this,exp) -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/StorageExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | /** 4 | * Convets given bytes to human readable form. 5 | */ 6 | fun Long.convertBytesToHumanReadableForm(si: Boolean): String { 7 | val unit = if (si) 1000 else 1024 8 | if (this < unit) return toString() + " B" 9 | val exp = (Math.log(toDouble()) / Math.log(unit.toDouble())).toInt() 10 | val pre = (if (si) "kMGTPE" else "KMGTPE")[exp - 1] + if (si) "" else "i" 11 | return String.format("%.1f %sB", this / Math.pow(unit.toDouble(), exp.toDouble()), pre) 12 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/StringExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | /* 4 | Checks a String is null or empty 5 | */ 6 | fun String?.isNotNullOrBlank() = this != null && this.trim().isNotEmpty() 7 | -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/UtilityExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext 2 | 3 | import android.app.Activity 4 | import android.os.Build 5 | import android.support.v7.app.AlertDialog 6 | 7 | /** 8 | * execute "func" if current version is grater than or equal to given version 9 | */ 10 | inline fun supportsVersion(ver: Int, func: () -> Unit) { 11 | if (Build.VERSION.SDK_INT >= ver) { 12 | func.invoke() 13 | } 14 | } 15 | 16 | /** 17 | * execute "body" if app in debug mode 18 | */ 19 | inline fun debug(body: () -> Unit) { 20 | if (BuildConfig.DEBUG) body() 21 | } 22 | -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/component/ActivityExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.component 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import android.content.res.Configuration 6 | import android.support.v7.app.AlertDialog 7 | import android.view.View 8 | import android.view.inputmethod.InputMethodManager 9 | 10 | 11 | /** 12 | * Force close keyboard 13 | */ 14 | fun Activity.forceCloseKeyboard() { 15 | if (currentFocus != null) { 16 | val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 17 | imm.hideSoftInputFromWindow(currentFocus.windowToken, 0) 18 | } 19 | } 20 | 21 | /** 22 | * Get activity's orientation is Portrait or not 23 | */ 24 | fun Activity.isPortrait() = this.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT 25 | 26 | /** 27 | * Simplify using AlertDialog 28 | */ 29 | inline fun Activity.alert(body: AlertDialog.Builder.() -> AlertDialog.Builder) { 30 | AlertDialog.Builder(this) 31 | .body() 32 | .show() 33 | } 34 | 35 | /** 36 | * Hides Status and Navigation Bar 37 | */ 38 | fun Activity.hideStatusAndNavigationBar() { 39 | window.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN; 40 | actionBar?.hide() 41 | } 42 | 43 | /* 44 | * Get Activity status bar 45 | */ 46 | fun Activity.getStatusBarHeight() : Int{ 47 | var result : Int = 0 48 | val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") 49 | if(resourceId > 0){ 50 | result = resources.getDimensionPixelSize(resourceId) 51 | } 52 | return result 53 | } 54 | -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/component/ContextExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.component 2 | 3 | import android.app.ActivityManager 4 | import android.content.Context 5 | import android.content.Context.ACTIVITY_SERVICE 6 | import android.content.Intent 7 | import android.os.Environment 8 | import android.widget.Toast 9 | import java.io.File 10 | import java.text.SimpleDateFormat 11 | import java.util.* 12 | 13 | /** 14 | * Checks if a Broadcast can be resolved 15 | */ 16 | fun Context.canResolveBroadcast(intent: Intent) = packageManager.queryBroadcastReceivers(intent, 0).isNotEmpty() 17 | 18 | /** 19 | * Checks if a Provider exists with given name 20 | */ 21 | fun Context.providerExists(providerName: String) = packageManager.resolveContentProvider(providerName, 0) != null 22 | 23 | /** 24 | * Creates a toast message with given message and duration 25 | */ 26 | fun Context.alert(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, message, duration).show() 27 | 28 | /** 29 | * Checks if a service with given name is running. 30 | */ 31 | fun Context.isServiceRunning(serviceName: String): Boolean { 32 | val manager = getSystemService(ACTIVITY_SERVICE) as ActivityManager 33 | for (service in manager.getRunningServices(Integer.MAX_VALUE)) { 34 | if (serviceName == service.service.className) { 35 | return true 36 | } 37 | } 38 | return false 39 | } 40 | 41 | /** 42 | * Creates an image file 43 | * Date Pattern for Image Name. Defaultly uses yyyyMMdd_HHmmss 44 | * Image extension suffix. Default: .jpg 45 | */ 46 | fun Context.createImageFile(datePattern: String = "yyyyMMdd_HHmmss", 47 | fileSuffix: String = ".jpg"): File { 48 | val timeStamp = SimpleDateFormat(datePattern, Locale.getDefault()).format(Date()) 49 | val imageFileName = "IMAGE_$timeStamp" 50 | val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) 51 | return File.createTempFile(imageFileName, fileSuffix, storageDir) 52 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/component/FragmentManagerExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.component 2 | 3 | import android.support.v4.app.FragmentManager 4 | import android.support.v4.app.FragmentTransaction 5 | 6 | /** 7 | * Commits given FragmentTransaction 8 | */ 9 | inline fun FragmentManager.transact(func: FragmentTransaction.() -> FragmentTransaction) { 10 | beginTransaction().func().commit() 11 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/component/LooperExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.component 2 | 3 | import android.os.Looper 4 | 5 | /** 6 | * Returns if current looper is Main 7 | */ 8 | fun Looper.isMain() = this == Looper.getMainLooper() -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/view/EditTextExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.view 2 | 3 | import android.content.Context 4 | import android.text.Editable 5 | import android.text.TextUtils 6 | import android.text.TextWatcher 7 | import android.widget.EditText 8 | import java.net.MalformedURLException 9 | import java.net.URL 10 | 11 | /** 12 | * Clears EditText 13 | */ 14 | fun EditText.clear() { 15 | setText("") 16 | } 17 | 18 | /** 19 | * returns EditText text as URL 20 | */ 21 | fun EditText.getUrl(): URL? { 22 | return try { 23 | URL(text.toString()) 24 | } catch (e: MalformedURLException) { 25 | null 26 | } 27 | } 28 | 29 | /** 30 | * Sets EditText text from Clipboard 31 | */ 32 | fun EditText.pasteFromClipBoard() { 33 | var text = "" 34 | val currentSdk = android.os.Build.VERSION.SDK_INT 35 | if (currentSdk < android.os.Build.VERSION_CODES.HONEYCOMB) { 36 | val manager: android.text.ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) 37 | as android.text.ClipboardManager 38 | try { 39 | text = manager.text.toString() 40 | } catch (e: Exception) { 41 | // ignored 42 | } 43 | } else { 44 | val manager: android.content.ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) 45 | as android.content.ClipboardManager 46 | manager.primaryClip?.let { 47 | val item = manager.primaryClip.getItemAt(0) 48 | text = item.text.toString() 49 | } 50 | } 51 | 52 | if (!TextUtils.isEmpty(text)) setText(text) 53 | } 54 | 55 | /** 56 | * Adds listener to afterTextChanged of TextWatcher 57 | */ 58 | inline fun EditText.onTextChanged(crossinline listener: (String) -> Unit) { 59 | this.addTextChangedListener(object : TextWatcher { 60 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { 61 | //no-op 62 | } 63 | 64 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { 65 | //no-op 66 | } 67 | 68 | override fun afterTextChanged(s: Editable) { 69 | listener(s.toString()) 70 | } 71 | }) 72 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/view/ImageViewExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.view 2 | 3 | import android.app.WallpaperManager 4 | import android.widget.ImageView 5 | 6 | /** 7 | * Loads current device wallpaper to an Imageview 8 | */ 9 | fun ImageView.setWallpaper() { 10 | val wallpaperManager = WallpaperManager.getInstance(context) 11 | setImageDrawable(wallpaperManager.drawable) 12 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/view/TextViewExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.view 2 | 3 | import android.content.Context 4 | import android.os.Build 5 | import android.text.Html 6 | import android.text.TextUtils 7 | import android.view.View 8 | import android.widget.TextView 9 | 10 | /** 11 | * Copies TextView text to clipboard with given label 12 | */ 13 | fun TextView.copyToClipboard(label: String) { 14 | if (text != null) { 15 | val currentSdk = android.os.Build.VERSION.SDK_INT 16 | 17 | if (currentSdk < android.os.Build.VERSION_CODES.HONEYCOMB) { 18 | val manager: android.text.ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) 19 | as android.text.ClipboardManager 20 | manager.text = text 21 | } else { 22 | val manager: android.content.ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) 23 | as android.content.ClipboardManager 24 | manager.primaryClip = android.content.ClipData.newPlainText(label, text) 25 | } 26 | } 27 | } 28 | 29 | /** 30 | * Set TextView from Html 31 | */ 32 | fun TextView.setTextFromHtml(html: String) { 33 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 34 | this.text = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY) 35 | } else { 36 | @Suppress("DEPRECATION") 37 | this.text = Html.fromHtml(html) 38 | } 39 | } 40 | 41 | /** 42 | * Sets given content to TextView or hides it. 43 | */ 44 | fun TextView.setAsContent(content: CharSequence?) { 45 | if (!TextUtils.isEmpty(content)) { 46 | text = content 47 | visibility = View.VISIBLE 48 | } else { 49 | visibility = View.GONE 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/view/ViewExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.view 2 | 3 | import android.support.annotation.LayoutRes 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | 8 | /** 9 | * Inits visiblity of a view. 10 | */ 11 | fun View.initVisiblity(isVisible: Boolean) { 12 | visibility = if (isVisible) View.VISIBLE else View.GONE 13 | } 14 | 15 | /*** 16 | * Hides or shows view with given predicate 17 | */ 18 | inline fun T.showIf(predicate: (T) -> Boolean) { 19 | if (predicate(this)) { 20 | show() 21 | } else { 22 | hide() 23 | } 24 | } 25 | 26 | /** 27 | * Shows view 28 | */ 29 | fun View.show() { 30 | visibility = View.VISIBLE 31 | } 32 | 33 | /*** 34 | * Hides view 35 | */ 36 | fun View.hide() { 37 | visibility = View.GONE 38 | } -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/view/ViewGroupExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.view 2 | 3 | import android.support.annotation.LayoutRes 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.EditText 8 | 9 | /** 10 | * Inflates a view with given id. 11 | */ 12 | fun ViewGroup.inflate(@LayoutRes resId: Int) = LayoutInflater.from(this.context).inflate(resId, this, false) 13 | 14 | /** 15 | * Gets Child View at index 16 | */ 17 | inline operator fun ViewGroup.get(i: Int): View? = getChildAt(i) 18 | 19 | /** 20 | * Remvoes child View with -= 21 | */ 22 | inline operator fun ViewGroup.minusAssign(child: View) = removeView(child) 23 | 24 | /** 25 | * Adds a View with += 26 | */ 27 | inline operator fun ViewGroup.plusAssign(child: View) = addView(child) 28 | 29 | /** 30 | * Applys given func to all child views 31 | */ 32 | inline fun ViewGroup.eachChild(func: (view: View) -> Unit) { 33 | for (i in 0 until childCount) { 34 | func(getChildAt(i)) 35 | } 36 | } 37 | 38 | /** 39 | * Hides all child views 40 | */ 41 | fun ViewGroup.hideAll() { 42 | eachChild { 43 | it.hide() 44 | } 45 | } 46 | 47 | /** 48 | * SHows all child views 49 | */ 50 | fun ViewGroup.showAll() { 51 | eachChild { 52 | it.show() 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /kotlinext/src/main/java/com/raqun/kotlinext/view/ViewPagerExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext.view 2 | 3 | import android.support.v4.view.ViewPager 4 | 5 | /** 6 | * Checks if ViewPager can swipe back. 7 | */ 8 | fun ViewPager.canGoBack() = currentItem > 0 9 | 10 | /** 11 | * Checks if ViewPager can swipe next 12 | */ 13 | fun ViewPager.canGoNext() = adapter != null && currentItem < adapter!!.count - 1 14 | 15 | /** 16 | * Swipes ViewPager back 17 | */ 18 | fun ViewPager.goPrevious() { 19 | if (canGoBack()) currentItem -= 1 20 | } 21 | 22 | /** 23 | * Swipes ViewPager next 24 | */ 25 | fun ViewPager.goNext() { 26 | if (canGoNext()) currentItem += 1 27 | } -------------------------------------------------------------------------------- /kotlinext/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | kotlinext 3 | 4 | -------------------------------------------------------------------------------- /kotlinext/src/test/java/com/raqun/kotlinext/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.raqun.kotlinext; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':kotlinext' 2 | --------------------------------------------------------------------------------