Skip to content

Commit

Permalink
Add sample app (#20)
Browse files Browse the repository at this point in the history
* Use correct direct Identity data store name

* Override toString in IdentityMap and IdentityItem

* Add Kotlin test app for IdentityEdge

* Add fragment for starting an Assurance session

* Remove unused test files from sample app.

* Add implementations for send event and reset identities buttons.

* Add Application class to initialize SDK and extensions

* Add network security config to AndroidManifest

* Comment out call to resetIdentities as API in Core is not yet released

* Remove Java app

* Rename 'appkt' to 'app' and move files to 'code/app'

* Remove launch environment ID

* Rename test app package from 'appkt' to 'app'

* fix IdentityMap.toString to handle case where map is empty.

* Use correct AuthenticatedState.loggedOut string

* Save custom identifier UI entries and update UI with saved values when page is viewed.

* Remove copyright from non-source files (Manifest, layouts, drawables, etc).

* Make StringBuilder final in IdentityMap.toString()
  • Loading branch information
kevinlind authored Mar 25, 2021
1 parent 15679d7 commit 7184829
Show file tree
Hide file tree
Showing 44 changed files with 1,433 additions and 207 deletions.
37 changes: 34 additions & 3 deletions code/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
/*
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.adobe.marketing.mobile.identitytestapp"
applicationId "com.adobe.marketing.edge.identity.app"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -18,16 +33,32 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.3'
implementation 'androidx.navigation:navigation-ui:2.3.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.3'

implementation project(':edgeidentity')
implementation 'com.adobe.marketing.mobile:core:1+'
implementation 'com.adobe.marketing.mobile:signal:1+'
implementation 'com.adobe.marketing.mobile:identity:1+'
implementation 'com.adobe.marketing.mobile:edge:1+'
implementation 'com.adobe.marketing.mobile:assurance:1+'
}
}
28 changes: 9 additions & 19 deletions code/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adobe.marketing.mobile.testApp">
package="com.adobe.marketing.edge.identity.app">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:name="com.adobe.marketing.edge.identity.app.EdgeIdentityApplication"
android:label="@string/app_name"
android:name=".TestApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config">
<activity android:name=".MainActivity">
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
<activity
android:name="com.adobe.marketing.edge.identity.app.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- Accepts URIs that begin with "testapp://main”-->
<data
android:scheme="testapp"
android:host="main" />

</intent-filter>

</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package com.adobe.marketing.edge.identity.app

import android.app.Application
import com.adobe.marketing.mobile.Assurance
import com.adobe.marketing.mobile.Edge
import com.adobe.marketing.mobile.LoggingMode
import com.adobe.marketing.mobile.MobileCore
import com.adobe.marketing.mobile.edge.identity.Identity

class EdgeIdentityApplication : Application() {
// Add your Launch Environment ID to configure the SDK from your Launch property
private var LAUNCH_ENVIRONMENT_ID: String = ""

override fun onCreate() {
super.onCreate()

// register AEP SDK extensions
MobileCore.setApplication(this)
MobileCore.setLogLevel(LoggingMode.VERBOSE)

Identity.registerExtension()
Edge.registerExtension()
Assurance.registerExtension()

MobileCore.start {
MobileCore.configureWithAppID(LAUNCH_ENVIRONMENT_ID)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package com.adobe.marketing.edge.identity.app

import android.os.Bundle
import android.view.Menu
import com.google.android.material.navigation.NavigationView
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar

class MainActivity : AppCompatActivity() {

private lateinit var appBarConfiguration: AppBarConfiguration

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)

val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
appBarConfiguration = AppBarConfiguration(setOf(
R.id.nav_get_identity, R.id.nav_custom_identity, R.id.nav_multiple_identity, R.id.nav_assurance), drawerLayout)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}

override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment)
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package com.adobe.marketing.edge.identity.app.model

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.adobe.marketing.mobile.edge.identity.AuthenticatedState

class SharedViewModel : ViewModel() {
companion object {
const val REGISTER_IDENTITY_STRING = "Register Identity"
const val REGISTER_EDGE_IDENTITY_STRING = "Register Edge Identity"
const val IDENTITY_IS_REGISTERED_STRING = "Identity is registered"
const val EDGE_IDENTITY_IS_REGISTERED_STRING = "Edge Identity is registered"
}

// Models for Get Identities View

private val _ecidText = MutableLiveData<String>("")
val ecidText: LiveData<String> = _ecidText

private val _ecidLegacyText = MutableLiveData<String>("")
val ecidLegacyText: LiveData<String> = _ecidLegacyText

private val _identitiesText = MutableLiveData<String>("")
val identitiesText: LiveData<String> = _identitiesText

fun setEcidValue(value: String) {
_ecidText.value = value
}

fun setEcidLegacyValue(value: String) {
_ecidLegacyText.value = value
}

fun setIdentitiesValue(value: String) {
_identitiesText.value = value
}

// Models for Update Identities View

private val _identifier = MutableLiveData<String>("")
val identifier: LiveData<String> = _identifier

private val _namespace = MutableLiveData<String>("")
val namespace: LiveData<String> = _namespace

private val _isPrimary = MutableLiveData<Boolean>(false)
val isPrimary: LiveData<Boolean> = _isPrimary

private val _authenticatedState = MutableLiveData<AuthenticatedState>(AuthenticatedState.AMBIGUOUS)
val authenticatedState: LiveData<AuthenticatedState> = _authenticatedState

private val _authenticatedStateId = MutableLiveData<Int>(null)
val authenticatedStateId: LiveData<Int> = _authenticatedStateId

fun setIdentifier(value: String) {
if (_identifier.value == value) {
return
}
_identifier.value = value
}

fun setNamespace(value: String) {
if (_namespace.value == value) {
return
}
_namespace.value = value
}

fun setIsPrimary(value: Boolean) {
if (_isPrimary.value == value) {
return
}
_isPrimary.value = value
}

fun setAuthenticatedState(value: AuthenticatedState) {
if (_authenticatedState.value == value) {
return
}
_authenticatedState.value = value
}

fun setAuthenticatedStateId(value: Int) {
if (_authenticatedStateId.value == value) {
return
}
_authenticatedStateId.value = value
}

// Models for Multiple Identities View

private val _isEdgeIdentityRegistered = MutableLiveData<Boolean>(true)
val isEdgeIdentityRegistered: LiveData<Boolean> = _isEdgeIdentityRegistered

private val _edgeIdentityRegisteredText = MutableLiveData<String>().apply {
value = if (_isEdgeIdentityRegistered.value == true) {
EDGE_IDENTITY_IS_REGISTERED_STRING
} else {
REGISTER_EDGE_IDENTITY_STRING
}
}
val edgeIdentityRegisteredText: LiveData<String> = _edgeIdentityRegisteredText

private val _isDirectIdentityRegistered = MutableLiveData<Boolean>(false)
val isDirectIdentityRegistered: LiveData<Boolean> = _isDirectIdentityRegistered

private val _directIdentityRegisteredText = MutableLiveData<String>().apply {
value = if (_isDirectIdentityRegistered.value == true) {
IDENTITY_IS_REGISTERED_STRING
} else {
REGISTER_IDENTITY_STRING
}
}
val directIdentityRegisteredText: LiveData<String> = _directIdentityRegisteredText


fun toggleEdgeIdentityRegistration() {
if (_isEdgeIdentityRegistered.value == true) {
_isEdgeIdentityRegistered.value = false
_edgeIdentityRegisteredText.value = REGISTER_EDGE_IDENTITY_STRING
} else {
_isEdgeIdentityRegistered.value = true
_edgeIdentityRegisteredText.value = EDGE_IDENTITY_IS_REGISTERED_STRING
}
}

fun toggleDirectIdentityRegistration() {
if (_isDirectIdentityRegistered.value == true) {
_isDirectIdentityRegistered.value = false
_directIdentityRegisteredText.value = REGISTER_IDENTITY_STRING
} else {
_isDirectIdentityRegistered.value = true
_directIdentityRegisteredText.value = IDENTITY_IS_REGISTERED_STRING
}
}
}
Loading

0 comments on commit 7184829

Please sign in to comment.