├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── mouredev
│ │ │ │ └── kotlinparaprincipiantes
│ │ │ │ ├── Programmer.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── mouredev
│ │ │ └── kotlinparaprincipiantes
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── mouredev
│ │ └── kotlinparaprincipiantes
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
└── runConfigurations.xml
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── .gitignore
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Kotlin para principiantes
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mouredev/KotlinDesdeCero/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun May 12 16:37:02 CEST 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.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/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/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/mouredev/kotlinparaprincipiantes/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.mouredev.kotlinparaprincipiantes
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 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mouredev/kotlinparaprincipiantes/Programmer.kt:
--------------------------------------------------------------------------------
1 | package com.mouredev.kotlinparaprincipiantes
2 |
3 | /**
4 | * Created by MoureDev by Brais Moure on 2020-03-18.
5 | * www.mouredev.com
6 | */
7 | class Programmer(val name: String,
8 | var age: Int,
9 | val languages: Array,
10 | val friends: Array? = null) {
11 |
12 | enum class Language {
13 | KOTLIN,
14 | SWIFT,
15 | JAVA,
16 | JAVASCRIPT
17 | }
18 |
19 | fun code() {
20 | for (language in languages) {
21 | println("Estoy programando en $language")
22 | }
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/mouredev/kotlinparaprincipiantes/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.mouredev.kotlinparaprincipiantes
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.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.mouredev.kotlinparaprincipiantes", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/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/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.mouredev.kotlinparaprincipiantes"
11 | minSdkVersion 21
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | implementation 'androidx.appcompat:appcompat:1.0.2'
29 | implementation 'androidx.core:core-ktx:1.0.2'
30 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test:runner:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KOTLIN: Curso ANDROID desde CERO para PRINCIPIANTES | Español | MoureDev by Brais Moure
2 | []()
3 | []()
4 |
5 | **`¡HOLA HACKERMEN! 👋🏼`**
6 |
7 | Bienvenidos al canal de [YouTube](https://www.youtube.com/channel/UCxPD7bsocoAMq8Dj18kmGyQ?sub_confirmation=1) ***MoureDev by Brais Moure***.
8 |
9 | Soy Brais Moure, desarrollador de software freelance. Comparto tutoriales sobre desarrollo de aplicaciones **iOS** y **Android**.
10 |
11 | ## Descripción
12 | Tutorial en el que aprenderemos Kotlin desde cero, explicando cada concepto desde su base. Utilizaremos Android Studio, el entorno de desarrollo de aplicaciones Android.
13 |
14 | Este primer bloque básico consta de 10 clases:
15 |
16 | * Variables y constantes
17 | * Tipos de datos
18 | * Sentencia If
19 | * Sentencia When
20 | * Arrays
21 | * Mapas o diccionarios
22 | * Bucle For y While
23 | * Null safety
24 | * Funciones
25 | * Clases
26 |
27 | ## Videotutorial
28 | [](https://www.youtube.com/watch?v=hug4TNmhw78)
29 | [](https://www.youtube.com/watch?v=uWwVyww30SI)
30 | [](https://www.youtube.com/watch?v=QUGFBYIVs4g)
31 | [](https://www.youtube.com/watch?v=udPbfzfZA_s)
32 | [](https://www.youtube.com/watch?v=ufsrPf7vao4)
33 | [](https://www.youtube.com/watch?v=VHhc-ndfI-Y)
34 | [](https://www.youtube.com/watch?v=4gGrkpArlyI)
35 | [](https://www.youtube.com/watch?v=ln0sub514YQ)
36 | [](https://www.youtube.com/watch?v=057JbCQ4ico)
37 | [](https://www.youtube.com/watch?v=FmRdWLab5nY)
38 | [](https://www.youtube.com/watch?v=pSWaEc_sn-Q)
39 |
40 | ## Requisitos
41 | * [Android Studio](https://developer.android.com/studio) 3.x
42 | * Kotlin 1.x
43 |
44 | ## Recursos
45 | * [Cómo crear un proyecto Android en Android Studio](https://youtu.be/BQaxPwZWboA)
46 |
47 | ## ¿Por dónde sigo?
48 |
49 | Puedes visitar [mi canal](https://www.youtube.com/mouredevapps), en el tengo más tutoriales avanzados.
50 |
51 | Si te interesa, también he creado un curso completo de Swift e iOS en Udemy: [https://www.udemy.com/course/swift_ios](https://www.udemy.com/course/swift_ios)
52 |
53 | **¡GRACIAS!**
54 |
55 | ## Encuéntrame en:
56 |
57 | [](https://mouredev.com/)
58 | [](https://www.youtube.com/channel/UCxPD7bsocoAMq8Dj18kmGyQ)
59 | [](https://twitter.com/MoureDev)
60 | [](https://facebook.com/mouredev)
61 | [](https://instagram.com/mouredev)
62 | [](https://www.linkedin.com/in/braismoure/)
63 |
64 | ### Autor
65 | *Brais Moure. © 2019-2020*
66 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/gradle,android,intellij,androidstudio
3 | # Edit at https://www.gitignore.io/?templates=gradle,android,intellij,androidstudio
4 |
5 | ### Android ###
6 | # Built application files
7 | *.apk
8 | *.ap_
9 | *.aab
10 |
11 | # Files for the ART/Dalvik VM
12 | *.dex
13 |
14 | # Java class files
15 | *.class
16 |
17 | # Generated files
18 | bin/
19 | gen/
20 | out/
21 | release/
22 |
23 | # Gradle files
24 | .gradle/
25 | build/
26 |
27 | # Local configuration file (sdk path, etc)
28 | local.properties
29 |
30 | # Proguard folder generated by Eclipse
31 | proguard/
32 |
33 | # Log Files
34 | *.log
35 |
36 | # Android Studio Navigation editor temp files
37 | .navigation/
38 |
39 | # Android Studio captures folder
40 | captures/
41 |
42 | # IntelliJ
43 | *.iml
44 | .idea/workspace.xml
45 | .idea/tasks.xml
46 | .idea/gradle.xml
47 | .idea/assetWizardSettings.xml
48 | .idea/dictionaries
49 | .idea/libraries
50 | # Android Studio 3 in .gitignore file.
51 | .idea/caches
52 | .idea/modules.xml
53 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
54 | .idea/navEditor.xml
55 |
56 | # Keystore files
57 | # Uncomment the following lines if you do not want to check your keystore files in.
58 | #*.jks
59 | #*.keystore
60 |
61 | # External native build folder generated in Android Studio 2.2 and later
62 | .externalNativeBuild
63 |
64 | # Google Services (e.g. APIs or Firebase)
65 | # google-services.json
66 |
67 | # Freeline
68 | freeline.py
69 | freeline/
70 | freeline_project_description.json
71 |
72 | # fastlane
73 | fastlane/report.xml
74 | fastlane/Preview.html
75 | fastlane/screenshots
76 | fastlane/test_output
77 | fastlane/readme.md
78 |
79 | # Version control
80 | vcs.xml
81 |
82 | # lint
83 | lint/intermediates/
84 | lint/generated/
85 | lint/outputs/
86 | lint/tmp/
87 | # lint/reports/
88 |
89 | ### Android Patch ###
90 | gen-external-apklibs
91 | output.json
92 |
93 | # Replacement of .externalNativeBuild directories introduced
94 | # with Android Studio 3.5.
95 | .cxx/
96 |
97 | ### Intellij ###
98 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
99 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
100 |
101 | # User-specific stuff
102 | .idea/**/workspace.xml
103 | .idea/**/tasks.xml
104 | .idea/**/usage.statistics.xml
105 | .idea/**/dictionaries
106 | .idea/**/shelf
107 |
108 | # Generated files
109 | .idea/**/contentModel.xml
110 |
111 | # Sensitive or high-churn files
112 | .idea/**/dataSources/
113 | .idea/**/dataSources.ids
114 | .idea/**/dataSources.local.xml
115 | .idea/**/sqlDataSources.xml
116 | .idea/**/dynamic.xml
117 | .idea/**/uiDesigner.xml
118 | .idea/**/dbnavigator.xml
119 |
120 | # Gradle
121 | .idea/**/gradle.xml
122 | .idea/**/libraries
123 |
124 | # Gradle and Maven with auto-import
125 | # When using Gradle or Maven with auto-import, you should exclude module files,
126 | # since they will be recreated, and may cause churn. Uncomment if using
127 | # auto-import.
128 | # .idea/modules.xml
129 | # .idea/*.iml
130 | # .idea/modules
131 | # *.iml
132 | # *.ipr
133 |
134 | # CMake
135 | cmake-build-*/
136 |
137 | # Mongo Explorer plugin
138 | .idea/**/mongoSettings.xml
139 |
140 | # File-based project format
141 | *.iws
142 |
143 | # IntelliJ
144 |
145 | # mpeltonen/sbt-idea plugin
146 | .idea_modules/
147 |
148 | # JIRA plugin
149 | atlassian-ide-plugin.xml
150 |
151 | # Cursive Clojure plugin
152 | .idea/replstate.xml
153 |
154 | # Crashlytics plugin (for Android Studio and IntelliJ)
155 | com_crashlytics_export_strings.xml
156 | crashlytics.properties
157 | crashlytics-build.properties
158 | fabric.properties
159 |
160 | # Editor-based Rest Client
161 | .idea/httpRequests
162 |
163 | # Android studio 3.1+ serialized cache file
164 | .idea/caches/build_file_checksums.ser
165 |
166 | ### Intellij Patch ###
167 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
168 |
169 | # *.iml
170 | # modules.xml
171 | # .idea/misc.xml
172 | # *.ipr
173 |
174 | # Sonarlint plugin
175 | .idea/**/sonarlint/
176 |
177 | # SonarQube Plugin
178 | .idea/**/sonarIssues.xml
179 |
180 | # Markdown Navigator plugin
181 | .idea/**/markdown-navigator.xml
182 | .idea/**/markdown-navigator/
183 |
184 | ### Gradle ###
185 | .gradle
186 |
187 | # Ignore Gradle GUI config
188 | gradle-app.setting
189 |
190 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
191 | !gradle-wrapper.jar
192 |
193 | # Cache of project
194 | .gradletasknamecache
195 |
196 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
197 | # gradle/wrapper/gradle-wrapper.properties
198 |
199 | ### Gradle Patch ###
200 | **/build/
201 |
202 | ### AndroidStudio ###
203 | # Covers files to be ignored for android development using Android Studio.
204 |
205 | # Built application files
206 |
207 | # Files for the ART/Dalvik VM
208 |
209 | # Java class files
210 |
211 | # Generated files
212 |
213 | # Gradle files
214 |
215 | # Signing files
216 | .signing/
217 |
218 | # Local configuration file (sdk path, etc)
219 |
220 | # Proguard folder generated by Eclipse
221 |
222 | # Log Files
223 |
224 | # Android Studio
225 | /*/build/
226 | /*/local.properties
227 | /*/out
228 | /*/*/build
229 | /*/*/production
230 | *.ipr
231 | *~
232 | *.swp
233 |
234 | # Android Patch
235 |
236 | # External native build folder generated in Android Studio 2.2 and later
237 |
238 | # NDK
239 | obj/
240 |
241 | # IntelliJ IDEA
242 | /out/
243 |
244 | # User-specific configurations
245 | .idea/caches/
246 | .idea/libraries/
247 | .idea/shelf/
248 | .idea/.name
249 | .idea/compiler.xml
250 | .idea/copyright/profiles_settings.xml
251 | .idea/encodings.xml
252 | .idea/misc.xml
253 | .idea/scopes/scope_settings.xml
254 | .idea/vcs.xml
255 | .idea/jsLibraryMappings.xml
256 | .idea/datasources.xml
257 | .idea/dataSources.ids
258 | .idea/sqlDataSources.xml
259 | .idea/dynamic.xml
260 | .idea/uiDesigner.xml
261 |
262 | # OS-specific files
263 | .DS_Store
264 | .DS_Store?
265 | ._*
266 | .Spotlight-V100
267 | .Trashes
268 | ehthumbs.db
269 | Thumbs.db
270 |
271 | # Legacy Eclipse project files
272 | .classpath
273 | .project
274 | .cproject
275 | .settings/
276 |
277 | # Mobile Tools for Java (J2ME)
278 | .mtj.tmp/
279 |
280 | # Package Files #
281 | *.war
282 | *.ear
283 |
284 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
285 | hs_err_pid*
286 |
287 | ## Plugin-specific files:
288 |
289 | # mpeltonen/sbt-idea plugin
290 |
291 | # JIRA plugin
292 |
293 | # Mongo Explorer plugin
294 | .idea/mongoSettings.xml
295 |
296 | # Crashlytics plugin (for Android Studio and IntelliJ)
297 |
298 | ### AndroidStudio Patch ###
299 |
300 | !/gradle/wrapper/gradle-wrapper.jar
301 |
302 | # End of https://www.gitignore.io/api/gradle,android,intellij,androidstudio
--------------------------------------------------------------------------------
/app/src/main/java/com/mouredev/kotlinparaprincipiantes/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.mouredev.kotlinparaprincipiantes
2 |
3 | import androidx.appcompat.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 | // Lección 1
13 | //variablesYConstantes()
14 |
15 | // Lección 2
16 | //tiposDeDatos()
17 |
18 | // Lección 3
19 | //sentenciaIf()
20 |
21 | // Lección 4
22 | //sentenciaWhen()
23 |
24 | // Lección 5
25 | //arrays()
26 |
27 | // Lección 6
28 | //maps()
29 |
30 | // Lección 7
31 | //loops()
32 |
33 | // Lección 8
34 | //nullSafety()
35 |
36 | // Lección 9
37 | //funciones()
38 |
39 | // Lección 10
40 | classes()
41 | }
42 |
43 | /*
44 | Aquí vamos a hablar de variables y constantes
45 | */
46 | private fun variablesYConstantes() {
47 |
48 | // Variables
49 |
50 | var myFirstVariable = "Hello Hackermen!"
51 | var myFirstNumber = 1
52 |
53 | println(myFirstVariable)
54 |
55 | myFirstVariable = "Bienvenidos a MoureDev"
56 |
57 | println(myFirstVariable)
58 |
59 | // No podemos asignar un tipo Int a una variable de tipo String
60 | //myFirstVariable = 1
61 |
62 | var mySecondVariable = "Suscríbete!"
63 |
64 | println(mySecondVariable)
65 |
66 | mySecondVariable = myFirstVariable
67 |
68 | println(mySecondVariable)
69 |
70 | myFirstVariable = "¿Ya te has suscrito?"
71 |
72 | println(myFirstVariable)
73 |
74 | // Constantes
75 |
76 | val myFirstConstant = "¿Te ha gustado el tutorial?"
77 |
78 | println(myFirstConstant)
79 |
80 | // Una constante no puede modificar su valor
81 | //myFirstConstant = "Si te ha gustado, dale a LIKE"
82 |
83 | val mySecondConstant = myFirstVariable
84 |
85 | println(mySecondConstant)
86 | }
87 |
88 | /*
89 | Aquí vamos hablar de tipos de datos (data types)
90 | */
91 | private fun tiposDeDatos() {
92 |
93 | // String
94 |
95 | val myString: String = "Hola Hackermen!"
96 | val myString2 = "Bienvenidos a MoureDev"
97 | val myString3 = myString + " " + myString2
98 | println(myString3)
99 |
100 | // Enteros (Byte, Short, Int, Long)
101 |
102 | val myInt: Int = 1
103 | val myInt2 = 2
104 | val myInt3 = myInt + myInt2
105 | println(myInt3)
106 |
107 | // Decimales (Float, Double)
108 |
109 | val myFloat: Float = 1.5f
110 | val myDouble = 1.5
111 | val myDouble2 = 2.6
112 | val myDouble3 = 1 // En realidad este es Int
113 | val myDouble4 = myDouble + myDouble2 + myDouble3
114 | println(myDouble4)
115 |
116 | // Boolean (Bool)
117 | val myBool: Boolean = true
118 | val myBool2 = false
119 | //val myBool3 = myBool + myBool2
120 | println(myBool == myBool2)
121 | println(myBool && myBool2)
122 |
123 | }
124 |
125 | /*
126 | Aquí vamos a hablar de la sentencia if
127 | */
128 | private fun sentenciaIf() {
129 |
130 | val myNumber = 71
131 |
132 | // Operadores condicionales
133 | // > mayor que
134 | // < menor que
135 | // >= (> =) mayor o igual que
136 | // <= (< =) menor o igual que
137 | // == (= =) igualdad
138 | // != (! =) desigualdad
139 |
140 | // Operadores lógicos
141 | // && operador "y"
142 | // || operador "o"
143 | // ! operador "no"
144 |
145 | if (!(myNumber <= 10 && myNumber > 5) || myNumber == 53) {
146 | // Sentencia if
147 | println("$myNumber es menor o igual que 10 y mayor que 5 o es igual a 53")
148 |
149 | } else if(myNumber == 60) {
150 |
151 | // Sentencia else if
152 | println("$myNumber es igual a 60")
153 |
154 | } else if(myNumber != 70) {
155 |
156 | // Sentencia else if
157 | println("$myNumber no es igual a 70")
158 |
159 | } else {
160 | // Sentencia else
161 | println("$myNumber es mayor que 10 o menor o igual que 5 y no es igual a 53")
162 | }
163 |
164 | }
165 |
166 | /*
167 | Aquí vamos a hablar de la sentencia when
168 | */
169 | fun sentenciaWhen() {
170 |
171 | // When con String
172 | val country = "Italia"
173 |
174 | when (country) {
175 | "España", "Mexico", "Perú", "Colombia", "Argentina" -> {
176 | println("El idioma es Español")
177 | } "EEUU" -> {
178 | println("El idioma es Inglés")
179 | } "Francia" -> {
180 | println("El idioma es Francés")
181 | } else -> {
182 | println("No conocemos el idioma")
183 | }
184 | }
185 |
186 | // When con Int
187 | val age = 100
188 |
189 | when (age) {
190 | 0, 1, 2 -> {
191 | println("Eres un bebé")
192 | } in 3..10 -> {
193 | println("Eres un niño")
194 | } in 11..17 -> {
195 | println("Eres un adolescente")
196 | } in 18..69 -> {
197 | println("Eres adulto")
198 | } in 70..99 -> {
199 | println("Eres anciano")
200 | } else -> {
201 | println("😱")
202 | }
203 | }
204 |
205 | }
206 |
207 | /*
208 | Aquí vamos a hablar de arrays o arreglos
209 | */
210 | fun arrays() {
211 |
212 | val name = "Brais"
213 | val surname = "Moure"
214 | val company = "MoureDev"
215 | val age = "32"
216 |
217 | // Creación de un Array
218 |
219 | val myArray = arrayListOf()
220 |
221 | // Añadir datos de uno en uno
222 |
223 | myArray.add(name)
224 | myArray.add(surname)
225 | myArray.add(company)
226 | myArray.add(age)
227 | //myArray.add(age)
228 | //myArray.add(age)
229 |
230 | println(myArray)
231 |
232 | // Añadir un conjunto de datos
233 |
234 | myArray.addAll(listOf("Hola", "Bienvenidos al tutorial"))
235 |
236 | println(myArray)
237 |
238 | // Acceso a datos
239 |
240 | val myCompany = myArray[2]
241 |
242 | println(myCompany)
243 |
244 | // Modificación de datos
245 |
246 | myArray[5] = "Suscríbete y activa la campana"
247 |
248 | println(myArray)
249 |
250 | // Eliminar datos
251 |
252 | myArray.removeAt(4)
253 |
254 | println(myArray)
255 |
256 | // Recorrer datos
257 |
258 | myArray.forEach {
259 | println(it)
260 | }
261 |
262 | // Otras operaciones
263 |
264 | println(myArray.count())
265 |
266 | myArray.clear()
267 |
268 | println(myArray.count())
269 |
270 | // myArray.first()
271 | // myArray.last()
272 | // myArray.sort()
273 | }
274 |
275 | /*
276 | Aquí vamos a hablar de mapas, también llamados diccionarios
277 | */
278 | fun maps() {
279 |
280 | // Sintaxis
281 | var myMap: Map = mapOf()
282 | println(myMap)
283 |
284 | // Añadir elementos
285 | myMap = mutableMapOf("Brais" to 1, "Pedro" to 2, "Sara" to 5)
286 | println(myMap)
287 |
288 | // Añadir un solo valor
289 | myMap["Ana"] = 7
290 | myMap.put("María",8)
291 | println(myMap)
292 |
293 | // Actualización de un dato
294 | myMap.put("Brais",3)
295 | myMap["Brais"] = 4
296 | println(myMap)
297 |
298 | myMap.put("Marcos",3)
299 | println(myMap)
300 |
301 | // Acceso a un dato
302 | println(myMap["Brais"])
303 |
304 | // Eliminar un dato
305 | myMap.remove("Brais")
306 | println(myMap)
307 | }
308 |
309 | /*
310 | Aquí vamos a hablar de loops, también llamados bucles
311 | */
312 | private fun loops() {
313 |
314 | // Bucles
315 |
316 | val myArray = listOf("Hola", "Bienvenidos al tutorial", "Suscríbete!")
317 | val myMap = mutableMapOf("Brais" to 1, "Pedro" to 2, "Sara" to 5)
318 |
319 | // For
320 |
321 | for (myString in myArray) {
322 | println(myString)
323 | }
324 |
325 | for (myElement in myMap) {
326 | println("${myElement.key}-${myElement.value}")
327 | }
328 |
329 | for (x in 0..10) {
330 | println(x)
331 | }
332 |
333 | for (x in 9 until 30) {
334 | println(x)
335 | }
336 |
337 | for (x in 0..10 step 2) {
338 | println(x)
339 | }
340 |
341 | for (x in 10 downTo 0 step 3) {
342 | println(x)
343 | }
344 |
345 | val myNumericArray = (0..20)
346 | for (myNum in myNumericArray) {
347 | println(myNum)
348 | }
349 |
350 | // While
351 |
352 | var x = 0
353 |
354 | while (x < 10) {
355 | println(x)
356 | x += 2
357 | }
358 |
359 | }
360 |
361 | /*
362 | Aquí vamos a hablar de seguridad contra nulos (Null Safety)
363 | */
364 | fun nullSafety() {
365 |
366 | var myString = "MoureDev"
367 | // myString = null Esto daría un error de compilación
368 | println(myString)
369 |
370 | // Variable null safety
371 | var mySafetyString: String? = "MoureDev null safety"
372 | mySafetyString = null
373 | println(mySafetyString)
374 |
375 | //mySafetyString = "Suscríbete!"
376 | //println(mySafetyString)
377 |
378 | /*if (mySafetyString != null) {
379 | println(mySafetyString!!)
380 | } else {
381 | println(mySafetyString)
382 | }*/
383 |
384 | // Safe call
385 |
386 | println(mySafetyString?.length)
387 |
388 | mySafetyString?.let {
389 | println(it)
390 | } ?: run {
391 | println(mySafetyString)
392 | }
393 |
394 | }
395 |
396 | /*
397 | Aquí vamos a hablar de funciones
398 | */
399 | fun funciones() {
400 |
401 | sayHello()
402 | sayHello()
403 | sayHello()
404 |
405 | sayMyName("Brais")
406 | sayMyName("Pedro")
407 | sayMyName("Sara")
408 |
409 | sayMyNameAndAge("Brais", 32)
410 |
411 | val sumResult = sumTwoNumbers(10, 5)
412 | println(sumResult)
413 |
414 | println(sumTwoNumbers(15, 9))
415 |
416 | println(sumTwoNumbers(10, sumTwoNumbers(5, 5)))
417 | }
418 |
419 | // Función simple
420 | fun sayHello() {
421 | println("Hola!")
422 | }
423 |
424 | // Funciones con un parámetro de entrada
425 | fun sayMyName(name: String) {
426 | println("Hola, mi nombre es $name")
427 | }
428 |
429 | // Funciones con más de un parámetro de entrada
430 | fun sayMyNameAndAge(name: String, age: Int) {
431 | println("Hola, mi nombre es $name y mi edad es $age")
432 | }
433 |
434 | // Funciones con un valor de retorno
435 | fun sumTwoNumbers(firstNumber: Int, secondNumber: Int) : Int {
436 | val sum = firstNumber + secondNumber
437 | return sum
438 | }
439 |
440 | /*
441 | Aquí vamos a hablar de las clases
442 | */
443 | fun classes() {
444 |
445 | val brais = Programmer("Brais", 32, arrayOf(Programmer.Language.KOTLIN, Programmer.Language.SWIFT))
446 | println(brais.name)
447 |
448 | brais.age = 40
449 | brais.code()
450 |
451 | val sara = Programmer("Sara", 35, arrayOf(Programmer.Language.JAVA), arrayOf(brais))
452 | sara.code()
453 |
454 | println("${sara.friends?.first()?.name} es amigo de ${sara.name}")
455 | }
456 |
457 | }
458 |
--------------------------------------------------------------------------------