This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.arch.lifecycle.LiveData | |
enum class IdentityRequest { | |
NEED_SIGNUP, | |
NEED_CREDENTIALS, | |
NEED_NEWPASSWORD, | |
NEED_MULTIFACTORCODE, | |
SUCCESS, | |
FAILURE | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onNavigationItemSelected(item: MenuItem): Boolean { | |
when (item.itemId) { | |
R.id.main_drawer_login -> { | |
if (service.identityManager.isUserSignedIn) { | |
service.identityManager.signOut() | |
updateNavigationDrawer(service.identityManager.isUserSignedIn) | |
} else { | |
service.identityManager.login(this@MainActivity, object : DefaultSignInResultHandler() { | |
/** | |
* Called when the user has obtained an identity by signing in with a provider. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Update the menu for signed in/out status | |
*/ | |
private fun updateNavigationDrawer(isSignedIn: Boolean = false) { | |
val loginItem = nav_view.menu.findItem(R.id.main_drawer_login) | |
if (!isSignedIn) { | |
loginItem.title = resources.getString(R.string.nav_signin) | |
} else { | |
loginItem.title = resources.getString(R.string.nav_signout) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
/* Configure the action bar */ | |
setSupportActionBar(main_toolbar) | |
/* Configure the navigation drawer */ | |
val toggle = ActionBarDrawerToggle(this, drawer_layout, main_toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) | |
drawer_layout.addDrawerListener(toggle) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthenticatorActivity(private val service: AWSService) : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_authenticator) | |
// Set up the callbacks to handle the authentication response | |
service.identityManager.login(this, object : DefaultSignInResultHandler() { | |
override fun onSuccess(activity: Activity, identityProvider: IdentityProvider) { | |
Toast.makeText(this@AuthenticatorActivity, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
// AWS Dependencies | |
implementation "com.amazonaws:aws-android-sdk-core:$versions.aws" | |
implementation "com.amazonaws:aws-android-sdk-auth-core:$versions.aws" | |
implementation("com.amazonaws:aws-android-sdk-auth-userpools:$versions.aws@aar") { transitive = true } | |
implementation("com.amazonaws:aws-android-sdk-auth-ui:$versions.aws") { transitive = true } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.amazonaws.mobile.samples.picturefeed.services.aws | |
import android.content.Context | |
import com.amazonaws.auth.AWSCredentialsProvider | |
import com.amazonaws.mobile.auth.core.IdentityManager | |
import com.amazonaws.mobile.auth.userpools.CognitoUserPoolsSignInProvider | |
import com.amazonaws.mobile.config.AWSConfiguration | |
class AWSService(context: Context) { | |
val configuration = AWSConfiguration(context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AWSAnalyticsService(context: Context, service: AWSService, private val locationService: LocationService) : AnalyticsService { | |
/** | |
* Record a custom event into the analytics stream | |
* | |
* @param name the custom event name | |
* @param [attributes] a list of key-value pairs for recording string attributes | |
* @param [metrics] a list of key-value pairs for recording numeric metrics | |
*/ | |
override fun recordEvent(name: String, attributes: Map<String, String>?, metrics: Map<String, Double>?) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.amazonaws.mobile.samples.picturefeed.services.aws | |
import android.content.Context | |
import android.content.Context.LOCATION_SERVICE | |
import android.location.Location | |
import android.location.LocationListener | |
import android.location.LocationManager | |
import android.os.Bundle | |
import android.util.Log | |
import com.amazonaws.mobile.samples.picturefeed.TAG |