From 227becf8d807d9b333bc8ce36f5e20ef84a5fef2 Mon Sep 17 00:00:00 2001 From: andrer757 Date: Thu, 1 Mar 2018 16:06:11 +0000 Subject: [PATCH 1/5] [new] Added an kotlin version of sample. --- build.gradle | 2 + sample-kotlin/.gitignore | 1 + sample-kotlin/build.gradle | 65 ++++++ sample-kotlin/dependencies.gradle | 58 +++++ sample-kotlin/google-services.json | 42 ++++ sample-kotlin/proguard-rules.pro | 21 ++ .../adal/sample/ExampleInstrumentedTest.kt | 47 ++++ .../src/dev/res/drawable-xxxhdpi/ic_label.png | Bin 0 -> 2907 bytes .../src/dev/res/drawable/ic_launcher.xml | 36 ++++ sample-kotlin/src/main/AndroidManifest.xml | 58 +++++ .../adal/samplekotlin/app/App.kt | 59 +++++ .../base/activity/ActivityFullScreen.kt | 39 ++++ .../base/activity/ActivityToolbar.kt | 65 ++++++ .../feature/accounts/FragmentAccounts.kt | 92 ++++++++ .../feature/alarm/AlarmReceiver.kt | 66 ++++++ .../feature/alarm/FragmentAlarm.kt | 105 +++++++++ .../feature/analytics/FragmentAnalytics.kt | 101 +++++++++ .../analytics/FragmentAnalyticsLabel.kt | 60 ++++++ .../analytics/FragmentFirebaseAnalytics.kt | 128 +++++++++++ .../FragmentFirebaseAnalyticsLabel.kt | 60 ++++++ .../samplekotlin/feature/bus/FragmentA.kt | 101 +++++++++ .../samplekotlin/feature/bus/FragmentB.kt | 81 +++++++ .../connectivity/FragmentConnectivityAware.kt | 136 ++++++++++++ .../feature/dialogs/DialogFragmentTest.kt | 41 ++++ .../feature/dialogs/DialogTest.kt | 43 ++++ .../feature/dialogs/FragmentDialogs.kt | 74 +++++++ .../feature/home/AdapterExample.kt | 43 ++++ .../samplekotlin/feature/home/FragmentHome.kt | 106 +++++++++ .../feature/location/FragmentLocation.kt | 201 ++++++++++++++++++ .../feature/network/AdapterPhoto.kt | 68 ++++++ .../feature/network/AdapterPost.kt | 44 ++++ .../feature/network/FragmentNetworkRequest.kt | 129 +++++++++++ .../permissions/FragmentPermissions.kt | 93 ++++++++ .../feature/splash/ActivitySplashScreen.kt | 37 ++++ .../feature/splash/FragmentSplash.kt | 64 ++++++ .../feature/utils/FragmentUtils.kt | 62 ++++++ .../adal/samplekotlin/model/Photo.kt | 41 ++++ .../adal/samplekotlin/model/Post.kt | 39 ++++ .../adal/samplekotlin/network/APIRequests.kt | 57 +++++ .../adal/samplekotlin/network/IRequests.kt | 41 ++++ .../adal/samplekotlin/network/ResponseList.kt | 41 ++++ .../samplekotlin/network/RetrofitAdapter.kt | 60 ++++++ .../main/res/layout/activity_fullscreen.xml | 31 +++ .../src/main/res/layout/activity_toolbar.xml | 53 +++++ .../src/main/res/layout/adapter_example.xml | 39 ++++ .../src/main/res/layout/adapter_loading.xml | 75 +++++++ .../src/main/res/layout/adapter_photo.xml | 62 ++++++ .../src/main/res/layout/adapter_post.xml | 43 ++++ .../src/main/res/layout/dialog_test.xml | 52 +++++ .../src/main/res/layout/fragment_a.xml | 53 +++++ .../src/main/res/layout/fragment_accounts.xml | 54 +++++ .../src/main/res/layout/fragment_alarm.xml | 47 ++++ .../main/res/layout/fragment_analytics.xml | 84 ++++++++ .../res/layout/fragment_analytics_label.xml | 39 ++++ .../src/main/res/layout/fragment_b.xml | 47 ++++ .../layout/fragment_connectivity_aware.xml | 45 ++++ .../src/main/res/layout/fragment_dialogs.xml | 45 ++++ .../layout/fragment_firebase_analytics.xml | 133 ++++++++++++ .../src/main/res/layout/fragment_home.xml | 30 +++ .../src/main/res/layout/fragment_location.xml | 67 ++++++ .../res/layout/fragment_network_request.xml | 53 +++++ .../main/res/layout/fragment_permissions.xml | 46 ++++ .../res/layout/fragment_splash_screen.xml | 40 ++++ .../src/main/res/layout/fragment_utils.xml | 61 ++++++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../src/main/res/values/analytics.xml | 41 ++++ sample-kotlin/src/main/res/values/colors.xml | 31 +++ sample-kotlin/src/main/res/values/configs.xml | 28 +++ sample-kotlin/src/main/res/values/dimens.xml | 34 +++ sample-kotlin/src/main/res/values/errors.xml | 28 +++ sample-kotlin/src/main/res/values/strings.xml | 91 ++++++++ sample-kotlin/src/main/res/values/styles.xml | 51 +++++ .../src/main/res/xml/authenticator.xml | 31 +++ .../src/main/res/xml/global_tracker.xml | 32 +++ .../src/qa/res/drawable-xxxhdpi/ic_label.png | Bin 0 -> 2566 bytes .../src/qa/res/drawable/ic_launcher.xml | 36 ++++ settings.gradle | 2 +- 81 files changed, 4310 insertions(+), 1 deletion(-) create mode 100644 sample-kotlin/.gitignore create mode 100644 sample-kotlin/build.gradle create mode 100644 sample-kotlin/dependencies.gradle create mode 100644 sample-kotlin/google-services.json create mode 100644 sample-kotlin/proguard-rules.pro create mode 100644 sample-kotlin/src/androidTest/java/com/adal/sample/ExampleInstrumentedTest.kt create mode 100644 sample-kotlin/src/dev/res/drawable-xxxhdpi/ic_label.png create mode 100644 sample-kotlin/src/dev/res/drawable/ic_launcher.xml create mode 100644 sample-kotlin/src/main/AndroidManifest.xml create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/app/App.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityFullScreen.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityToolbar.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/accounts/FragmentAccounts.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/AlarmReceiver.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/FragmentAlarm.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentAnalytics.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentAnalyticsLabel.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentFirebaseAnalytics.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentFirebaseAnalyticsLabel.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/bus/FragmentA.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/bus/FragmentB.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/connectivity/FragmentConnectivityAware.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/dialogs/DialogFragmentTest.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/dialogs/DialogTest.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/dialogs/FragmentDialogs.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/home/AdapterExample.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/home/FragmentHome.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/location/FragmentLocation.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/network/AdapterPhoto.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/network/AdapterPost.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/network/FragmentNetworkRequest.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/permissions/FragmentPermissions.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/splash/ActivitySplashScreen.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/splash/FragmentSplash.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/utils/FragmentUtils.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/model/Photo.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/model/Post.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/network/APIRequests.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/network/IRequests.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/network/ResponseList.kt create mode 100644 sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/network/RetrofitAdapter.kt create mode 100644 sample-kotlin/src/main/res/layout/activity_fullscreen.xml create mode 100644 sample-kotlin/src/main/res/layout/activity_toolbar.xml create mode 100644 sample-kotlin/src/main/res/layout/adapter_example.xml create mode 100644 sample-kotlin/src/main/res/layout/adapter_loading.xml create mode 100644 sample-kotlin/src/main/res/layout/adapter_photo.xml create mode 100644 sample-kotlin/src/main/res/layout/adapter_post.xml create mode 100644 sample-kotlin/src/main/res/layout/dialog_test.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_a.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_accounts.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_alarm.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_analytics.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_analytics_label.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_b.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_connectivity_aware.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_dialogs.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_firebase_analytics.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_home.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_location.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_network_request.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_permissions.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_splash_screen.xml create mode 100644 sample-kotlin/src/main/res/layout/fragment_utils.xml create mode 100644 sample-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 sample-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 sample-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 sample-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 sample-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 sample-kotlin/src/main/res/values/analytics.xml create mode 100644 sample-kotlin/src/main/res/values/colors.xml create mode 100644 sample-kotlin/src/main/res/values/configs.xml create mode 100644 sample-kotlin/src/main/res/values/dimens.xml create mode 100644 sample-kotlin/src/main/res/values/errors.xml create mode 100644 sample-kotlin/src/main/res/values/strings.xml create mode 100644 sample-kotlin/src/main/res/values/styles.xml create mode 100644 sample-kotlin/src/main/res/xml/authenticator.xml create mode 100644 sample-kotlin/src/main/res/xml/global_tracker.xml create mode 100644 sample-kotlin/src/qa/res/drawable-xxxhdpi/ic_label.png create mode 100644 sample-kotlin/src/qa/res/drawable/ic_launcher.xml diff --git a/build.gradle b/build.gradle index cdaec8c..430b28f 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ ext { } buildscript { + ext.kotlin_version = '1.2.10' repositories { google() jcenter() @@ -52,6 +53,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.novoda:bintray-release:0.8.0' classpath 'pt.simdea.verifier:verifier:3.6.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/sample-kotlin/.gitignore b/sample-kotlin/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/sample-kotlin/.gitignore @@ -0,0 +1 @@ +/build diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle new file mode 100644 index 0000000..33ab548 --- /dev/null +++ b/sample-kotlin/build.gradle @@ -0,0 +1,65 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * Added for adal-analytics + */ +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.google.gms:google-services:3.1.0' + } +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion project.compileSdkVersion.toInteger() + buildToolsVersion project.buildToolsVersion + + defaultConfig { + minSdkVersion project.minSdkVersion.toInteger() + targetSdkVersion project.targetSdkVersion.toInteger() + buildConfigField "String", "API_BASE_URL", "\"https://jsonplaceholder.typicode.com/\"" + buildConfigField "long", "API_TIMEOUT", "30" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + lintOptions { + disable 'InvalidPackage' + } +} + + +apply from: 'dependencies.gradle' + +/** + * Added for adal-analytics + */ +apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/sample-kotlin/dependencies.gradle b/sample-kotlin/dependencies.gradle new file mode 100644 index 0000000..13465cf --- /dev/null +++ b/sample-kotlin/dependencies.gradle @@ -0,0 +1,58 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +dependencies { + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + /** APP **/ + + /* ACTIVITY FRAGMENT MANAGER */ + implementation "com.massivedisaster:afm:0.0.1" + + /* ADAL */ + implementation project(':adal') + + /* SUPPORT */ + implementation "com.android.support:appcompat-v7:$project.supportVersion" + implementation "com.android.support:design:$project.supportVersion" + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + + /* GLIDE */ + implementation "com.github.bumptech.glide:glide:$project.glideVersion" + + /** TEST **/ + + /* ESPRESSO */ + androidTestImplementation("com.android.support.test.espresso:espresso-core:$project.espressoVersion") { + exclude group: 'com.android.support', module: 'support-annotations' + } + + /* JUNIT */ + testImplementation "junit:junit:$project.jUnitVersion" + + /* MOCKITO */ + androidTestImplementation "org.mockito:mockito-android:$project.mockitoVersion" + testImplementation "org.mockito:mockito-core:$project.mockitoVersion" +} diff --git a/sample-kotlin/google-services.json b/sample-kotlin/google-services.json new file mode 100644 index 0000000..dc91a9f --- /dev/null +++ b/sample-kotlin/google-services.json @@ -0,0 +1,42 @@ +{ + "project_info": { + "project_number": "698332537945", + "firebase_url": "https://adalsample.firebaseio.com", + "project_id": "adalsample", + "storage_bucket": "adalsample.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:698332537945:android:d2eca8bc104bd788", + "android_client_info": { + "package_name": "com.massivedisaster.adal.samplekotlin" + } + }, + "oauth_client": [ + { + "client_id": "698332537945-kngktebjh1g9g6k3e1icun5696c25esg.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyBG29B6lWwts1zm3BZoeyL7fiQfaRb5pUI" + } + ], + "services": { + "analytics_service": { + "status": 1 + }, + "appinvite_service": { + "status": 1, + "other_platform_oauth_client": [] + }, + "ads_service": { + "status": 2 + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/sample-kotlin/proguard-rules.pro b/sample-kotlin/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/sample-kotlin/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/sample-kotlin/src/androidTest/java/com/adal/sample/ExampleInstrumentedTest.kt b/sample-kotlin/src/androidTest/java/com/adal/sample/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..030c6b0 --- /dev/null +++ b/sample-kotlin/src/androidTest/java/com/adal/sample/ExampleInstrumentedTest.kt @@ -0,0 +1,47 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.adal.sample + +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + assertEquals("com.carbon.sample", appContext.packageName) + } +} diff --git a/sample-kotlin/src/dev/res/drawable-xxxhdpi/ic_label.png b/sample-kotlin/src/dev/res/drawable-xxxhdpi/ic_label.png new file mode 100644 index 0000000000000000000000000000000000000000..ef4fa271abdeb03348ee0c0478d8bb6c4b646a95 GIT binary patch literal 2907 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 literal 0 HcmV?d00001 diff --git a/sample-kotlin/src/dev/res/drawable/ic_launcher.xml b/sample-kotlin/src/dev/res/drawable/ic_launcher.xml new file mode 100644 index 0000000..536423d --- /dev/null +++ b/sample-kotlin/src/dev/res/drawable/ic_launcher.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sample-kotlin/src/main/AndroidManifest.xml b/sample-kotlin/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0a22e1c --- /dev/null +++ b/sample-kotlin/src/main/AndroidManifest.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/app/App.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/app/App.kt new file mode 100644 index 0000000..722ba79 --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/app/App.kt @@ -0,0 +1,59 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.app + +import android.app.Application +import android.widget.Toast +import com.massivedisaster.adal.applicationstate.ApplicationStateManager + +class App : Application(), ApplicationStateManager.BackAndForegroundListener { + + var TAG: String = App::class.simpleName!! + + lateinit var mApplicationStateManager: ApplicationStateManager + + override fun onCreate() { + super.onCreate() + mApplicationStateManager = ApplicationStateManager(this) + registerActivityLifecycleCallbacks(mApplicationStateManager) + } + + override fun onBackground() { + Toast.makeText(this, "onBackground called", Toast.LENGTH_SHORT).show() + } + + override fun onForeground() { + Toast.makeText(this, "onForeground called", Toast.LENGTH_SHORT).show() + } + + fun isBackground(): Boolean { + return mApplicationStateManager.isBackground + } + + fun isForeground(): Boolean { + return mApplicationStateManager.isForeground + } +} \ No newline at end of file diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityFullScreen.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityFullScreen.kt new file mode 100644 index 0000000..dd87634 --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityFullScreen.kt @@ -0,0 +1,39 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.base.activity + +import com.massivedisaster.adal.samplekotlin.R +import com.massivedisaster.afm.activity.BaseActivity + +open class ActivityFullScreen : BaseActivity() { + override fun getContainerViewId(): Int { + return R.id.frmContainer + } + + override fun layoutToInflate(): Int { + return R.layout.activity_fullscreen + } +} diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityToolbar.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityToolbar.kt new file mode 100644 index 0000000..1137091 --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/base/activity/ActivityToolbar.kt @@ -0,0 +1,65 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.base.activity + +import android.os.Bundle +import android.support.v7.widget.Toolbar +import android.view.MenuItem +import com.massivedisaster.adal.samplekotlin.R +import com.massivedisaster.afm.activity.BaseActivity + +class ActivityToolbar : BaseActivity() { + override fun layoutToInflate(): Int { + return R.layout.activity_toolbar + } + + lateinit var mToolbar: Toolbar + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + mToolbar = findViewById(R.id.toolbar) + setSupportActionBar(mToolbar) + + if (supportActionBar != null) { + supportActionBar!!.setDisplayHomeAsUpEnabled(true) + } + } + + override fun getContainerViewId(): Int { + return R.id.frmContainer + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + return when (item?.itemId) { + android.R.id.home -> { + onBackPressed() + true + } + else -> super.onOptionsItemSelected(item) + } + } +} \ No newline at end of file diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/accounts/FragmentAccounts.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/accounts/FragmentAccounts.kt new file mode 100644 index 0000000..597a54d --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/accounts/FragmentAccounts.kt @@ -0,0 +1,92 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.feature.accounts + +import android.os.Bundle +import android.widget.Button +import android.widget.Toast +import com.massivedisaster.adal.account.AccountHelper +import com.massivedisaster.adal.fragment.BaseFragment +import com.massivedisaster.adal.samplekotlin.R +import com.massivedisaster.adal.utils.SnackBuilder + +class FragmentAccounts : BaseFragment() { + + private var mBtnGetAccount: Button? = null + private var mBtnAddHardCodedAccount: Button? = null + private var mBtnClearAccount: Button? = null + + override fun getFromBundle(bundle: Bundle) { + // Intended. + } + + override fun layoutToInflate(): Int { + return R.layout.fragment_accounts + } + + override fun restoreInstanceState(savedInstanceState: Bundle?) { + // Intended. + } + + override fun doOnCreated() { + activity!!.setTitle(R.string.sample_accounts) + + mBtnGetAccount = findViewById(R.id.btnGetAccount) + mBtnAddHardCodedAccount = findViewById(R.id.btnAddHardCodedAccount) + mBtnClearAccount = findViewById(R.id.btnClearAccount) + + initialize() + } + + fun initialize() { + + AccountHelper.initialize(activity) + + mBtnGetAccount!!.setOnClickListener { getAccount() } + + mBtnAddHardCodedAccount!!.setOnClickListener({ addAccount() }) + + mBtnClearAccount!!.setOnClickListener({ clearAccount() }) + } + + private fun clearAccount() { + AccountHelper.clearAccounts(context) { SnackBuilder.show(mBtnGetAccount, "Clear account finished.", R.color.colorAccent) } + } + + private fun addAccount() { + AccountHelper.addAccount(context, "hardcoded_name", "hardcoded_password", "hardcoded_token") + SnackBuilder.show(mBtnGetAccount, "Added account.", R.color.colorAccent) + } + + private fun getAccount() { + val account = AccountHelper.getCurrentAccount(context) + if (account != null) { + Toast.makeText(context, "Name: " + account.name + " \nPassword: " + AccountHelper.getAccountPassword(account) + " \ntoken: " + AccountHelper.getCurrentToken(account, context), Toast.LENGTH_LONG).show() + } else { + SnackBuilder.show(mBtnGetAccount, "No accounts", R.color.colorAccent) + } + } +} \ No newline at end of file diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/AlarmReceiver.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/AlarmReceiver.kt new file mode 100644 index 0000000..764cc85 --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/AlarmReceiver.kt @@ -0,0 +1,66 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.feature.alarm + +import android.R.attr.id +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.media.RingtoneManager +import android.support.v4.app.NotificationCompat +import com.massivedisaster.adal.samplekotlin.R +import com.massivedisaster.adal.samplekotlin.base.activity.ActivityFullScreen + +class AlarmReceiver : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + val i = Intent(context, ActivityFullScreen::class.java) + i.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + + createNotification(context, i, id, intent.getStringExtra(FragmentAlarm::PARAM_EVENT_NAME.toString())) + } + + private fun createNotification(context: Context, intent: Intent, requestCode: Int, message: String) { + val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, + PendingIntent.FLAG_ONE_SHOT) + + val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + val notificationBuilder = NotificationCompat.Builder(context) + .setSmallIcon(R.mipmap.ic_launcher) + .setContentTitle(context.getString(R.string.app_name)) + .setContentText(message) + .setAutoCancel(true) + .setSound(defaultSoundUri) + .setContentIntent(pendingIntent) + + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + notificationManager.notify(0, notificationBuilder.build()) + } +} \ No newline at end of file diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/FragmentAlarm.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/FragmentAlarm.kt new file mode 100644 index 0000000..833d629 --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/alarm/FragmentAlarm.kt @@ -0,0 +1,105 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.feature.alarm + +import android.content.Intent +import android.os.Bundle +import android.view.View +import android.widget.Button +import com.massivedisaster.adal.alarm.AlarmManager +import com.massivedisaster.adal.fragment.BaseFragment +import com.massivedisaster.adal.samplekotlin.R +import com.massivedisaster.adal.utils.SnackBuilder +import java.util.* + +class FragmentAlarm : BaseFragment(), View.OnClickListener { + + val PARAM_EVENT_NAME: String = "PARAM_EVENT_NAME" + + private var mBtnAddAlarm: Button? = null + private var mBtnRemoveAlarm: Button? = null + private var mIntentAlarm: Intent? = null + + override fun layoutToInflate(): Int { + return R.layout.fragment_alarm + } + + override fun getFromBundle(bundle: Bundle) { + + } + + override fun restoreInstanceState(savedInstanceState: Bundle?) { + + } + + override fun doOnCreated() { + activity!!.setTitle(R.string.sample_alarm) + + mBtnAddAlarm = findViewById(R.id.btnAddAlarm) + mBtnRemoveAlarm = findViewById(R.id.btnRemoveAlarm) + + mBtnAddAlarm!!.setOnClickListener(this) + mBtnRemoveAlarm!!.setOnClickListener(this) + + mIntentAlarm = Intent(context, AlarmReceiver::class.java) + mIntentAlarm!!.putExtra(PARAM_EVENT_NAME, "Alarm message!") + } + + override fun onClick(v: View) { + when (v.id) { + R.id.btnAddAlarm -> addAlarm() + R.id.btnRemoveAlarm -> removeAlarm() + } + } + + /** + * Add a new alarm to the system. + */ + private fun addAlarm() { + val calendar = Calendar.getInstance() + calendar.time = Date() + + if (!AlarmManager.hasAlarm(context, mIntentAlarm, 1001)) { + AlarmManager.addAlarm(context, mIntentAlarm, 1001, calendar) + SnackBuilder.show(mBtnRemoveAlarm, "Alarm added!", R.color.colorAccent) + } else { + SnackBuilder.show(mBtnAddAlarm, "Alarm already added.", R.color.colorAccent) + } + } + + /** + * Remove an alarm. + */ + private fun removeAlarm() { + if (AlarmManager.hasAlarm(context, mIntentAlarm, 1001)) { + AlarmManager.cancelAlarm(context, mIntentAlarm, 1001) + SnackBuilder.show(mBtnRemoveAlarm, "Alarm removed!", R.color.colorAccent) + } else { + SnackBuilder.show(mBtnRemoveAlarm, "Please, add an alarm first!", R.color.colorAccent) + } + } + +} \ No newline at end of file diff --git a/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentAnalytics.kt b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentAnalytics.kt new file mode 100644 index 0000000..c929748 --- /dev/null +++ b/sample-kotlin/src/main/java/com/massivedisaster/adal/samplekotlin/feature/analytics/FragmentAnalytics.kt @@ -0,0 +1,101 @@ +/* + * ADAL - A set of Android libraries to help speed up Android development. + * + * Copyright (c) 2018 ADAL + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.massivedisaster.adal.samplekotlin.feature.analytics + +import android.support.v7.widget.AppCompatEditText +import android.text.TextUtils +import android.widget.Button +import com.massivedisaster.adal.analytics.AnalyticsManager +import com.massivedisaster.adal.fragment.BaseFragment +import com.massivedisaster.adal.samplekotlin.R +import com.massivedisaster.adal.samplekotlin.base.activity.ActivityToolbar +import com.massivedisaster.adal.utils.SnackBuilder +import com.massivedisaster.afm.ActivityCall + +class FragmentAnalytics : BaseFragment() { + + private var mEdtAnalyticsEventLabel: AppCompatEditText? = null + + override fun layoutToInflate(): Int { + return R.layout.fragment_analytics + } + + override fun doOnCreated() { + activity!!.setTitle(R.string.sample_analytics) + + /* + * You need to generate a json file + * + * https://developers.google.com/mobile/add?platform=android&cntapi=signin&cnturl=https:%2F%2Fdevelopers.google.com%2Fidentity%2Fsign-in%2Fandroid%2Fsign-in%3Fconfigured%3Dtrue&cntlbl=Continue%20Adding%20Sign-In + */ + + /* + * Send a screen to GA + */ + AnalyticsManager.with(context!!).sendScreen(R.string.analytics_screen_main) + + val button = findViewById