Skip to content
Browse files

Remove .iml, migrated auth into helpers, add PasswordAuthHelper, clea…

…n-up dependencies
  • Loading branch information...
1 parent 16d932d commit 891947f9b0cffc8ba90f9b22b942a97529b85989 @abehaskins abehaskins committed
View
3 .gitignore
@@ -4,4 +4,5 @@
.DS_Store
/build
/captures
-/library/target
+/library/target
+/**/*.iml
View
19 FirebaseUI-Android.iml
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id="FirebaseUI-Android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="java-gradle" name="Java-Gradle">
- <configuration>
- <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
- <option name="BUILDABLE" value="false" />
- </configuration>
- </facet>
- </component>
- <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <excludeFolder url="file://$MODULE_DIR$/.gradle" />
- </content>
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- </component>
-</module>
View
127 app/app.iml
@@ -1,127 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FirebaseUI-Android" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="android-gradle" name="Android-Gradle">
- <configuration>
- <option name="GRADLE_PROJECT_PATH" value=":app" />
- </configuration>
- </facet>
- <facet type="android" name="Android">
- <configuration>
- <option name="SELECTED_BUILD_VARIANT" value="debug" />
- <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
- <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
- <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
- <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
- <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
- <afterSyncTasks>
- <task>generateDebugAndroidTestSources</task>
- <task>generateDebugSources</task>
- </afterSyncTasks>
- <option name="ALLOW_USER_CONFIGURATION" value="false" />
- <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
- <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
- <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
- <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
- </configuration>
- </facet>
- </component>
- <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
- <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/google-services/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.android/facebook-android-sdk/4.6.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-identity/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-measurement/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-plus/8.1.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
- <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
- <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
- </content>
- <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="play-services-measurement-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="play-services-appindexing-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="play-services-base-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="play-services-ads-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="play-services-identity-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="firebase-client-jvm-2.3.1" level="project" />
- <orderEntry type="library" exported="" name="jackson-core-2.2.2" level="project" />
- <orderEntry type="library" exported="" name="firebase-client-android-2.3.1" level="project" />
- <orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
- <orderEntry type="library" exported="" name="jackson-databind-2.2.2" level="project" />
- <orderEntry type="library" exported="" name="play-services-basement-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="tubesock-0.0.11" level="project" />
- <orderEntry type="library" exported="" name="facebook-android-sdk-4.6.0" level="project" />
- <orderEntry type="library" exported="" name="play-services-analytics-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="jackson-annotations-2.2.2" level="project" />
- <orderEntry type="library" exported="" name="bolts-android-1.2.0" level="project" />
- <orderEntry type="library" exported="" name="twitter4j-core-4.0.2" level="project" />
- <orderEntry type="library" exported="" name="play-services-plus-8.1.0" level="project" />
- <orderEntry type="module" module-name="library" exported="" />
- </component>
-</module>
View
90 app/src/main/java/com/firebase/uidemo/RecyclerViewDemoActivity.java
@@ -1,18 +1,14 @@
package com.firebase.uidemo;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.DialogInterface;
import android.graphics.Color;
+import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
-import android.view.LayoutInflater;
import android.view.Menu;
+import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
@@ -25,13 +21,14 @@
import com.firebase.client.Query;
import com.firebase.ui.FirebaseLoginBaseActivity;
import com.firebase.ui.FirebaseRecyclerViewAdapter;
-import com.firebase.ui.com.firebasei.ui.authimpl.SocialProvider;
public class RecyclerViewDemoActivity extends FirebaseLoginBaseActivity {
public static String TAG = "FirebaseUI.chat";
private Firebase mRef;
private AuthData mAuthData;
+ private String name;
+ private String uid;
private Button mSendButton;
private EditText mMessageEdit;
@@ -40,19 +37,15 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recycler_view_demo);
- final String name = "Android User";
mSendButton = (Button) findViewById(R.id.sendButton);
mMessageEdit = (EditText) findViewById(R.id.messageEdit);
- final RecyclerView messages = (RecyclerView) findViewById(R.id.messagesList);
- messages.setHasFixedSize(true);
- messages.setLayoutManager(new LinearLayoutManager(this));
mRef = new Firebase("https://bucket.firebaseio.com/chat");
mSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Chat chat = new Chat(name, mMessageEdit.getText().toString());
+ Chat chat = new Chat(name, mAuthData.getUid(), mMessageEdit.getText().toString());
mRef.push().setValue(chat, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
@@ -65,20 +58,36 @@ public void onComplete(FirebaseError firebaseError, Firebase firebase) {
}
});
+ updateChat();
+ }
+
+ protected void updateChat() {
+ final RecyclerView messages = (RecyclerView) findViewById(R.id.messagesList);
+
+ LinearLayoutManager manager = new LinearLayoutManager(this);
+ manager.setStackFromEnd(true);
+
+ messages.setHasFixedSize(true);
+ messages.setLayoutManager(manager);
+
Query recentMessages = mRef.limitToLast(50);
FirebaseRecyclerViewAdapter<Chat, ChatHolder> adapter = new FirebaseRecyclerViewAdapter<Chat, ChatHolder>(Chat.class, android.R.layout.two_line_list_item, ChatHolder.class, recentMessages) {
@Override
public void populateViewHolder(ChatHolder chatView, Chat chat) {
chatView.textView.setText(chat.getText());
- chatView.textView.setPadding(10, 0, 10, 0);
+ chatView.textView.setPadding(30, 30, 30, 0);
chatView.nameView.setText(chat.getName());
- chatView.nameView.setPadding(10, 0, 10, 15);
- if (chat.getName().equals(name)) {
+ chatView.nameView.setPadding(30, 0, 30, 30);
+ chatView.textView.setTextColor(Color.parseColor("#000000"));
+ chatView.textView.setTypeface(null, Typeface.NORMAL);
+ if (mAuthData != null && chat.getUid().equals(mAuthData.getUid())) {
chatView.textView.setGravity(Gravity.END);
chatView.nameView.setGravity(Gravity.END);
- chatView.nameView.setTextColor(Color.parseColor("#8BC34A"));
+ chatView.nameView.setTextColor(Color.parseColor("#AAAAAA"));
+ chatView.itemView.setBackground(getDrawable(R.drawable.outgoing_message));
} else {
chatView.nameView.setTextColor(Color.parseColor("#00BCD4"));
+ chatView.itemView.setBackground(getDrawable(R.drawable.incoming_message));
}
}
};
@@ -91,28 +100,28 @@ public void populateViewHolder(ChatHolder chatView, Chat chat) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(LOGIN, LOGIN, LOGIN, "Login");
- menu.add(LOGOUT, LOGOUT, LOGOUT, "Log out");
-
- return super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.chat_login_menu, menu);
+ return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- menu.getItem(LOGIN-Menu.FIRST).setVisible(mAuthData == null);
- menu.getItem(LOGOUT-Menu.FIRST).setVisible(mAuthData != null);
+ menu.findItem(R.id.login_menu_item).setVisible(mAuthData == null);
+ menu.findItem(R.id.logout_menu_item).setVisible(mAuthData != null);
mSendButton.setEnabled(mAuthData != null);
mMessageEdit.setEnabled(mAuthData != null);
- return super.onPrepareOptionsMenu(menu);
+
+ return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case LOGIN:
+ case R.id.login_menu_item:
this.showFirebaseLoginPrompt();
return true;
- case LOGOUT:
+ case R.id.logout_menu_item:
this.logout();
return true;
}
@@ -124,9 +133,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Start of FirebaseLoginBaseActivity
@Override
- public void onFirebaseLogin(AuthData authData) {
- Log.i(TAG, "Logged in");
+ public void onFirebaseLoginSuccess(AuthData authData) {
+ Log.i(TAG, "Logged in to " + authData.getProvider().toString());
mAuthData = authData;
+
+ switch (mAuthData.getProvider()) {
+ case "password":
+ name = (String) mAuthData.getProviderData().get("email");
+ break;
+ default:
+ name = (String) mAuthData.getProviderData().get("displayName");
+ break;
+ }
+
+ updateChat();
invalidateOptionsMenu();
}
@@ -134,16 +154,18 @@ public void onFirebaseLogin(AuthData authData) {
public void onFirebaseLogout() {
Log.i(TAG, "Logged out");
mAuthData = null;
+ name = "";
invalidateOptionsMenu();
+ updateChat();
}
@Override
- public void onFirebaseLoginError(FirebaseError firebaseError) {
+ public void onFirebaseLoginProviderError(FirebaseError firebaseError) {
Log.e(TAG, firebaseError.toString());
}
@Override
- public void onFirebaseLoginCancel() {
+ public void onFirebaseLoginUserError(FirebaseError firebaseError) {
Log.i(TAG, "Login cancelled");
}
@@ -157,19 +179,25 @@ public Firebase getFirebaseRef() {
public static class Chat {
String name;
String text;
+ String uid;
public Chat() {
}
- public Chat(String name, String message) {
+ public Chat(String name, String uid, String message) {
this.name = name;
this.text = message;
+ this.uid = uid;
}
public String getName() {
return name;
}
+ public String getUid() {
+ return uid;
+ }
+
public String getText() {
return text;
}
@@ -177,9 +205,11 @@ public String getText() {
public static class ChatHolder extends RecyclerView.ViewHolder {
TextView nameView, textView;
+ View itemView;
public ChatHolder(View itemView) {
super(itemView);
+ this.itemView = itemView;
nameView = (TextView) itemView.findViewById(android.R.id.text2);
textView = (TextView) itemView.findViewById(android.R.id.text1);
}
View
1 build.gradle
@@ -16,5 +16,6 @@ allprojects {
repositories {
jcenter()
mavenCentral()
+ maven { url 'https://maven.fabric.io/public' }
}
}
View
3 library/build.gradle
@@ -49,5 +49,8 @@ dependencies {
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'org.twitter4j:twitter4j-core:4.0.2'
+ compile('com.twitter.sdk.android:twitter:1.9.1@aar') {
+ transitive = true;
+ }
androidTestCompile 'junit:junit:4.12'
}
View
118 library/library.iml
@@ -1,118 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FirebaseUI-Android" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="android-gradle" name="Android-Gradle">
- <configuration>
- <option name="GRADLE_PROJECT_PATH" value=":library" />
- </configuration>
- </facet>
- <facet type="android" name="Android">
- <configuration>
- <option name="SELECTED_BUILD_VARIANT" value="debug" />
- <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
- <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
- <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
- <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
- <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
- <afterSyncTasks>
- <task>generateDebugAndroidTestSources</task>
- <task>generateDebugSources</task>
- </afterSyncTasks>
- <option name="ALLOW_USER_CONFIGURATION" value="false" />
- <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
- <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
- <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
- <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
- <option name="LIBRARY_PROJECT" value="true" />
- </configuration>
- </facet>
- </component>
- <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
- <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/google-services/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.0/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
- <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
- <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
- </content>
- <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="play-services-measurement-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
- <orderEntry type="library" exported="" name="play-services-appindexing-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="play-services-base-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="play-services-ads-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="play-services-identity-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="firebase-client-jvm-2.3.1" level="project" />
- <orderEntry type="library" exported="" name="firebase-client-android-2.3.1" level="project" />
- <orderEntry type="library" exported="" name="jackson-core-2.2.2" level="project" />
- <orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
- <orderEntry type="library" exported="" name="jackson-databind-2.2.2" level="project" />
- <orderEntry type="library" exported="" name="play-services-basement-8.1.0" level="project" />
- <orderEntry type="library" exported="" name="tubesock-0.0.11" level="project" />
- <orderEntry type="library" exported="" name="facebook-android-sdk-4.6.0" level="project" />
- <orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
- <orderEntry type="library" exported="" name="play-services-analytics-8.1.0" level="project" />
- <orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
- <orderEntry type="library" exported="" name="jackson-annotations-2.2.2" level="project" />
- <orderEntry type="library" exported="" name="bolts-android-1.2.0" level="project" />
- <orderEntry type="library" exported="" name="twitter4j-core-4.0.2" level="project" />
- <orderEntry type="library" exported="" name="play-services-plus-8.1.0" level="project" />
- </component>
-</module>
View
6 library/src/main/java/com/firebase/ui/FirebaseArray.java
@@ -28,10 +28,12 @@
package com.firebase.ui;
-import com.firebase.client.*;
+import com.firebase.client.ChildEventListener;
+import com.firebase.client.DataSnapshot;
+import com.firebase.client.FirebaseError;
+import com.firebase.client.Query;
import java.util.ArrayList;
-import java.util.Collections;
/**
* This class implements an array-like collection on top of a Firebase location.
View
66 library/src/main/java/com/firebase/ui/FirebaseLogin.java
@@ -1,66 +0,0 @@
-package com.firebase.ui;
-
-
-import android.os.Bundle;
-import android.app.Fragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-
-/**
- * A simple {@link Fragment} subclass.
- * Use the {@link FirebaseLogin#newInstance} factory method to
- * create an instance of this fragment.
- */
-public class FirebaseLogin extends Fragment {
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
-
- // TODO: Rename and change types of parameters
- private String mParam1;
- private String mParam2;
-
-
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment FirebaseLogin.
- */
- // TODO: Rename and change types and number of parameters
- public static FirebaseLogin newInstance(String param1, String param2) {
- FirebaseLogin fragment = new FirebaseLogin();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
-
- public FirebaseLogin() {
- // Required empty public constructor
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- return inflater.inflate(R.layout.fragment_firebase_login, container, false);
- }
-
-
-}
View
169 library/src/main/java/com/firebase/ui/FirebaseLoginBaseActivity.java
@@ -1,33 +1,19 @@
package com.firebase.ui;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
import android.content.Intent;
-import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
import com.firebase.client.AuthData;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.ui.com.firebasei.ui.authimpl.FacebookAuthHelper;
-import com.firebase.ui.com.firebasei.ui.authimpl.FirebaseOAuthToken;
import com.firebase.ui.com.firebasei.ui.authimpl.GoogleAuthHelper;
+import com.firebase.ui.com.firebasei.ui.authimpl.PasswordAuthHelper;
import com.firebase.ui.com.firebasei.ui.authimpl.SocialProvider;
import com.firebase.ui.com.firebasei.ui.authimpl.TokenAuthHandler;
import com.firebase.ui.com.firebasei.ui.authimpl.TwitterAuthHelper;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
public abstract class FirebaseLoginBaseActivity extends AppCompatActivity {
private final String TAG = "FirebaseLoginBaseAct";
@@ -35,18 +21,20 @@
private GoogleAuthHelper mGoogleAuthHelper;
private FacebookAuthHelper mFacebookAuthHelper;
private TwitterAuthHelper mTwitterAuthHelper;
+ private PasswordAuthHelper mPasswordAuthHelper;
+
private FirebaseLoginDialog mDialog;
public SocialProvider mChosenProvider;
/* Abstract methods for Login Events */
- protected abstract void onFirebaseLogin(AuthData authData);
+ protected abstract void onFirebaseLoginSuccess(AuthData authData);
protected abstract void onFirebaseLogout();
- protected abstract void onFirebaseLoginError(FirebaseError firebaseError);
+ protected abstract void onFirebaseLoginProviderError(FirebaseError firebaseError);
- protected abstract void onFirebaseLoginCancel();
+ protected abstract void onFirebaseLoginUserError(FirebaseError firebaseError);
/**
* Subclasses of this activity must implement this method and return a valid Firebase reference that
@@ -90,65 +78,8 @@ public void logout() {
getFirebaseRef().unauth();
}
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mFacebookAuthHelper = new FacebookAuthHelper(this, new TokenAuthHandler() {
- @Override
- public void onTokenReceived(FirebaseOAuthToken token) {
- authenticateRefWithFirebaseOAuthToken(token);
- }
-
- @Override
- public void onCancelled() {
- onFirebaseLoginCancel();
- }
-
- @Override
- public void onError(Exception ex) {
- // TODO: Raise GMS Dialog Box?
- }
- });
-
- mGoogleAuthHelper = new GoogleAuthHelper(this, new TokenAuthHandler() {
- @Override
- public void onTokenReceived(FirebaseOAuthToken token) {
- authenticateRefWithFirebaseOAuthToken(token);
- }
-
- @Override
- public void onCancelled() {
- onFirebaseLoginCancel();
- }
-
- @Override
- public void onError(Exception ex) {
- // TODO: Raise GMS Dialog Box?
- }
- });
-
- mTwitterAuthHelper = new TwitterAuthHelper(this, new TokenAuthHandler() {
- @Override
- public void onTokenReceived(FirebaseOAuthToken token) {
- authenticateRefWithFirebaseOAuthToken(token);
- }
-
- @Override
- public void onCancelled() {
- onFirebaseLoginCancel();
- }
-
- @Override
- public void onError(Exception ex) {
- // TODO: Raise GMS Dialog Box?
- }
- });
- }
-
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- Log.d("BASE", "ACTIVITY" + data.toString());
+ // TODO: If someone isn't extending this activity, they need to implement this by hand
mFacebookAuthHelper.mCallbackManager.onActivityResult(requestCode, resultCode, data);
mTwitterAuthHelper.onActivityResult(requestCode, resultCode, data);
}
@@ -159,12 +90,34 @@ public void showFirebaseLoginPrompt() {
.addAuthHelper(mGoogleAuthHelper)
.addAuthHelper(mFacebookAuthHelper)
.addAuthHelper(mTwitterAuthHelper)
+ .addAuthHelper(mPasswordAuthHelper)
.show(getFragmentManager(), "");
}
@Override
protected void onStart() {
super.onStart();
+
+ TokenAuthHandler handler = new TokenAuthHandler() {
+ @Override
+ public void onSuccess(AuthData data) {}
+
+ @Override
+ public void onUserError(FirebaseError err) {
+ onFirebaseLoginUserError(err);
+ }
+
+ @Override
+ public void onProviderError(FirebaseError err) {
+ onFirebaseLoginProviderError(err);
+ }
+ };
+
+ mFacebookAuthHelper = new FacebookAuthHelper(this, getFirebaseRef(), handler);
+ mGoogleAuthHelper = new GoogleAuthHelper(this, getFirebaseRef(), handler);
+ mTwitterAuthHelper = new TwitterAuthHelper(this, getFirebaseRef(), handler);
+ mPasswordAuthHelper = new PasswordAuthHelper(this, getFirebaseRef(), handler);
+
// TODO: is there a way to delay this? Or make it on-demand (i.e. make them call `startMonitoringState`)?
// TODO: should we remove the authStateListener on `onStop()`?
getFirebaseRef().addAuthStateListener(new Firebase.AuthStateListener() {
@@ -173,72 +126,12 @@ public void onAuthStateChanged(AuthData authData) {
if (authData != null) {
mChosenProvider = SocialProvider.valueOf(authData.getProvider());
if (mDialog != null) mDialog.dismiss();
- onFirebaseLogin(authData);
+ onFirebaseLoginSuccess(authData);
+ Log.d(TAG, "Auth data changed");
} else {
onFirebaseLogout();
}
}
});
}
-
- private void authenticateRefWithFirebaseOAuthToken(FirebaseOAuthToken token) {
- if (token.mode == FirebaseOAuthToken.SIMPLE) {
- // Simple mode is used for Facebook and Google auth
- getFirebaseRef().authWithOAuthToken(token.provider, token.token, new Firebase.AuthResultHandler() {
- @Override
- public void onAuthenticated(AuthData authData) {
- // Do nothing. Auth updates are handled in the AuthStateListener
- }
-
- @Override
- public void onAuthenticationError(FirebaseError firebaseError) {
- onFirebaseLoginError(firebaseError);
- }
- });
- } else if (token.mode == FirebaseOAuthToken.COMPLEX) {
- // Complex mode is used for Twitter auth
- Log.d(TAG, "Complex mode" + token.provider);
- Map<String, String> options = new HashMap<>();
- options.put("oauth_token", token.token);
- options.put("oauth_token_secret", token.secret);
- options.put("user_id", token.uid);
-
- getFirebaseRef().authWithOAuthToken(token.provider, options, new Firebase.AuthResultHandler() {
- @Override
- public void onAuthenticated(AuthData authData) {
- // Do nothing. Auth updates are handled in the AuthStateListener
- }
-
- @Override
- public void onAuthenticationError(FirebaseError firebaseError) {
- onFirebaseLoginError(firebaseError);
- }
- });
- }
- }
-
- private String getFirebaseUrlFromConfig() {
- String firebaseUrl;
- try {
- InputStream inputStream = getAssets().open("firebase-config.json");
- int size = inputStream.available();
- byte[] buffer = new byte[size];
-
- inputStream.read(buffer);
- inputStream.close();
-
- String json = new String(buffer, "UTF-8");
- JSONObject obj = new JSONObject(json);
- firebaseUrl = obj.getString("firebaseUrl");
-
- } catch (IOException ex) {
- ex.printStackTrace();
- return null;
- } catch (JSONException ex) {
- ex.printStackTrace();
- return null;
- }
-
- return firebaseUrl;
- }
}
View
20 library/src/main/java/com/firebase/ui/FirebaseLoginDialog.java
@@ -3,24 +3,19 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
-import android.hardware.camera2.params.Face;
import android.os.Bundle;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.Button;
+import android.widget.EditText;
-import com.firebase.ui.com.firebasei.ui.authimpl.FacebookAuthHelper;
import com.firebase.ui.com.firebasei.ui.authimpl.FirebaseAuthHelper;
-import com.firebase.ui.com.firebasei.ui.authimpl.GoogleAuthHelper;
-import com.firebase.ui.com.firebasei.ui.authimpl.SocialProvider;
-import com.firebase.ui.com.firebasei.ui.authimpl.TwitterAuthHelper;
public class FirebaseLoginDialog extends DialogFragment {
FirebaseAuthHelper mFacebookAuthHelper;
FirebaseAuthHelper mTwitterAuthHelper;
FirebaseAuthHelper mGoogleAuthHelper;
+ FirebaseAuthHelper mPasswordAuthHelper;
View mView;
@Override
@@ -42,6 +37,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
if (mTwitterAuthHelper != null) showLoginOption(mTwitterAuthHelper, R.id.twitter_button);
else mView.findViewById(R.id.twitter_button).setVisibility(View.GONE);
+ if (mPasswordAuthHelper != null) showLoginOption(mPasswordAuthHelper, R.id.password_button);
+ else mView.findViewById(R.id.password_section).setVisibility(View.GONE);
+
builder.setView(mView);
return builder.create();
}
@@ -57,6 +55,8 @@ public FirebaseLoginDialog addAuthHelper(FirebaseAuthHelper helper) {
case "twitter":
mTwitterAuthHelper = helper;
break;
+ case "password":
+ mPasswordAuthHelper = helper;
}
return this;
@@ -66,8 +66,14 @@ private void showLoginOption(final FirebaseAuthHelper helper, int id) {
mView.findViewById(id).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
+ if (helper.getProviderName() == "password") {
+ EditText emailText = (EditText) mView.findViewById(R.id.email);
+ EditText passwordText = (EditText) mView.findViewById(R.id.password);
+ helper.login(emailText.getText().toString(), passwordText.getText().toString());
+ } else {
helper.login();
}
+ }
});
}
}
View
33 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/FacebookAuthHelper.java
@@ -2,45 +2,38 @@
import android.app.Activity;
import android.content.Context;
-import android.content.IntentSender;
-import android.os.Bundle;
import android.util.Log;
import com.facebook.AccessToken;
-import com.facebook.AccessTokenTracker;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
-import com.facebook.GraphRequest;
-import com.facebook.GraphResponse;
-import com.facebook.HttpMethod;
-import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
+import com.firebase.client.Firebase;
+import com.firebase.client.FirebaseError;
-import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
/**
*
*/
-public class FacebookAuthHelper implements FirebaseAuthHelper {
+public class FacebookAuthHelper extends FirebaseAuthHelper {
private final String LOG_TAG = "FacebookAuthHelper";
- public final String PROVIDER_NAME = "facebook";
+ public static final String PROVIDER_NAME = "facebook";
private LoginManager mLoginManager;
public CallbackManager mCallbackManager;
private Context mContext;
private TokenAuthHandler mHandler;
private Activity mActivity;
+ private Firebase mRef;
- public FacebookAuthHelper(Context context, TokenAuthHandler handler) {
+ public FacebookAuthHelper(Context context, Firebase ref, final TokenAuthHandler handler) {
mActivity = (Activity) context;
FacebookSdk.sdkInitialize(context.getApplicationContext());
@@ -48,6 +41,8 @@ public FacebookAuthHelper(Context context, TokenAuthHandler handler) {
mCallbackManager = CallbackManager.Factory.create();
mContext = context;
mHandler = handler;
+ Log.d(LOG_TAG, ref.toString());
+ mRef = ref;
mLoginManager.registerCallback(mCallbackManager,
new FacebookCallback<LoginResult>() {
@@ -58,17 +53,18 @@ public void onSuccess(LoginResult loginResult) {
FirebaseOAuthToken foToken = new FirebaseOAuthToken(
PROVIDER_NAME,
token.getToken().toString());
- mHandler.onTokenReceived(foToken);
+
+ onFirebaseTokenReceived(foToken, handler);
}
@Override
public void onCancel() {
- mHandler.onCancelled();
+ mHandler.onUserError(new FirebaseError(0, "user_cancel"));
}
@Override
public void onError(FacebookException ex) {
- mHandler.onError(ex);
+ mHandler.onProviderError(new FirebaseError(1, ex.toString()));
}
}
);
@@ -83,6 +79,11 @@ public String getProviderName() {
return PROVIDER_NAME;
}
+ public Firebase getFirebaseRef() {
+ Log.d(LOG_TAG, mRef.toString());
+ return mRef;
+ }
+
public void logout() {
mLoginManager.logOut();
}
View
64 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/FirebaseAuthHelper.java
@@ -1,15 +1,65 @@
package com.firebase.ui.com.firebasei.ui.authimpl;
-import com.google.android.gms.auth.GoogleAuthException;
-import com.google.android.gms.auth.UserRecoverableAuthException;
+import android.util.Log;
-import java.io.IOException;
+import com.firebase.client.AuthData;
+import com.firebase.client.Firebase;
+import com.firebase.client.FirebaseError;
+
+import java.util.HashMap;
+import java.util.Map;
/**
* Created by abehaskins on 11/4/15.
*/
-public interface FirebaseAuthHelper {
- String getProviderName();
- void login();
- void logout();
+public abstract class FirebaseAuthHelper {
+ public abstract void logout();
+ public abstract String getProviderName();
+ public abstract Firebase getFirebaseRef();
+
+ public void login() {
+ Log.d("FirebaseAuthHelper", "Login() is not supported for provider type " + getProviderName());
+ };
+ public void login(String email, String password) {
+ Log.d("FirebaseAuthHelper", "Login(String email, String password) is not supported for provider type " + getProviderName());
+ };
+
+ public void onFirebaseTokenReceived(FirebaseOAuthToken token, TokenAuthHandler handler) {
+ authenticateRefWithOAuthFirebasetoken(token, handler);
+ }
+
+ private void authenticateRefWithOAuthFirebasetoken(FirebaseOAuthToken token, final TokenAuthHandler handler) {
+ if (token.mode == FirebaseOAuthToken.SIMPLE) {
+ // Simple mode is used for Facebook and Google auth
+ getFirebaseRef().authWithOAuthToken(token.provider, token.token, new Firebase.AuthResultHandler() {
+ @Override
+ public void onAuthenticated(AuthData authData) {
+ // Do nothing. Auth updates are handled in the AuthStateListener
+ }
+
+ @Override
+ public void onAuthenticationError(FirebaseError firebaseError) {
+ handler.onUserError(new FirebaseError(0, "auth_error"));
+ }
+ });
+ } else if (token.mode == FirebaseOAuthToken.COMPLEX) {
+ // Complex mode is used for Twitter auth
+ Map<String, String> options = new HashMap<>();
+ options.put("oauth_token", token.token);
+ options.put("oauth_token_secret", token.secret);
+ options.put("user_id", token.uid);
+
+ getFirebaseRef().authWithOAuthToken(token.provider, options, new Firebase.AuthResultHandler() {
+ @Override
+ public void onAuthenticated(AuthData authData) {
+ // Do nothing. Auth updates are handled in the AuthStateListener
+ }
+
+ @Override
+ public void onAuthenticationError(FirebaseError firebaseError) {
+ handler.onUserError(new FirebaseError(0, "auth_error"));
+ }
+ });
+ }
+ }
}
View
24 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/GoogleAuthHelper.java
@@ -6,6 +6,7 @@
import android.os.Bundle;
import android.util.Log;
+import com.firebase.client.Firebase;
import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.gms.common.ConnectionResult;
@@ -15,23 +16,21 @@
import com.google.android.gms.plus.Plus;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
/**
*
*/
-public class GoogleAuthHelper implements
+public class GoogleAuthHelper extends FirebaseAuthHelper implements
GoogleApiClient.ConnectionCallbacks,
- GoogleApiClient.OnConnectionFailedListener,
- FirebaseAuthHelper {
+ GoogleApiClient.OnConnectionFailedListener{
private final String LOG_TAG = "GoogleAuthHelper";
- public final String PROVIDER_NAME = "google";
+ public static final String PROVIDER_NAME = "google";
/* User provided callback class */
private TokenAuthHandler mHandler;
+ private Firebase mRef;
/* Request code used to invoke sign in user interactions. */
private static final int RC_GOOGLE_SIGN_IN = 0;
@@ -56,7 +55,7 @@
private GoogleTokenTask mGoogleTokenTask;
- public GoogleAuthHelper(Context context, TokenAuthHandler handler) {
+ public GoogleAuthHelper(Context context, Firebase ref, TokenAuthHandler handler) {
// Builder API
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
@@ -68,6 +67,8 @@ public GoogleAuthHelper(Context context, TokenAuthHandler handler) {
// Activity Context
mContext = context;
+ mRef = ref;
+
// User defined callbacks
mHandler = handler;
@@ -79,22 +80,22 @@ public void onTokenReceived(String token) {
FirebaseOAuthToken foToken = new FirebaseOAuthToken(
PROVIDER_NAME,
token);
- mHandler.onTokenReceived(foToken);
+ //mHandler.onTokenReceived(foToken);
}
@Override
public void onUserRecoverableAuthException(UserRecoverableAuthException ex) {
- mHandler.onError(ex);
+ //mHandler.onError(ex);
}
@Override
public void onGoogleAuthException(GoogleAuthException ex) {
- mHandler.onError(ex);
+ //mHandler.onError(ex);
}
@Override
public void onIOException(IOException ex) {
- mHandler.onError(ex);
+ //mHandler.onError(ex);
}
});
}
@@ -117,6 +118,7 @@ public void logout() {
mGoogleApiClient.disconnect();
}
public String getProviderName() { return PROVIDER_NAME; }
+ public Firebase getFirebaseRef() { return mRef; }
@Override
public void onConnected(Bundle bundle) {
View
1 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/GoogleTokenTask.java
@@ -11,7 +11,6 @@
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
-
import java.io.IOException;
/**
View
3 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/SocialProvider.java
@@ -4,5 +4,6 @@
public enum SocialProvider {
google,
facebook,
- twitter
+ twitter,
+ password
}
View
10 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/TokenAuthHandler.java
@@ -1,13 +1,13 @@
package com.firebase.ui.com.firebasei.ui.authimpl;
-import java.util.HashMap;
-import java.util.Map;
+import com.firebase.client.AuthData;
+import com.firebase.client.FirebaseError;
/**
* Created by deast on 9/25/15.
*/
public interface TokenAuthHandler {
- void onTokenReceived(FirebaseOAuthToken token);
- void onCancelled();
- void onError(Exception ex);
+ void onSuccess(AuthData auth);
+ void onUserError(FirebaseError err);
+ void onProviderError(FirebaseError err);
}
View
29 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/TwitterAuthHelper.java
@@ -7,26 +7,26 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.util.Log;
-import java.util.HashMap;
-import java.util.Map;
+import com.firebase.client.Firebase;
+import com.firebase.client.FirebaseError;
-public class TwitterAuthHelper implements FirebaseAuthHelper {
+public class TwitterAuthHelper extends FirebaseAuthHelper {
public static final String TAG = "TwitterAuthHelper";
- public final String PROVIDER_NAME = "twitter";
+ public static final String PROVIDER_NAME = "twitter";
public static final int RC_TWITTER_LOGIN = 1;
public static final int RC_TWITTER_CANCEL = 2;
public static final int RC_TWITTER_ERROR = 3;
private Activity mActivity;
private TokenAuthHandler mHandler;
+ private Firebase mRef;
- public TwitterAuthHelper(Context context, TokenAuthHandler handler) {
- // setup ic_twitter client
+ public TwitterAuthHelper(Context context, Firebase ref, TokenAuthHandler handler) {
mActivity = (Activity) context;
mHandler = handler;
+ mRef = ref;
}
public void login() {
@@ -37,25 +37,22 @@ public void logout() {
}
- public String getProviderName() {
- return PROVIDER_NAME;
- }
+ public String getProviderName() { return PROVIDER_NAME; }
+ public Firebase getFirebaseRef() { return mRef; }
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RC_TWITTER_LOGIN) {
- Log.d(TAG, "Login success");
FirebaseOAuthToken token = new FirebaseOAuthToken(
PROVIDER_NAME,
data.getStringExtra("oauth_token"),
data.getStringExtra("oauth_token_secret"),
data.getStringExtra("user_id"));
- mHandler.onTokenReceived(token);
+ onFirebaseTokenReceived(token, mHandler);
} else if (resultCode == RC_TWITTER_CANCEL) {
- Log.d(TAG, "Login cancel");
- mHandler.onCancelled();
+ mHandler.onUserError(new FirebaseError(0, "user_cancel"));
+ //mHandler.onCancelled();
} else if (resultCode == RC_TWITTER_ERROR) {
- Log.d(TAG, "Login error");
- mHandler.onError(new Exception("Unknown Twitter Error"));
+ mHandler.onUserError(new FirebaseError(0, "user_error"));
}
}
}
View
2 library/src/main/java/com/firebase/ui/com/firebasei/ui/authimpl/TwitterPromptActivity.java
@@ -61,10 +61,8 @@ public void onPageFinished(final WebView view, final String url) {
if (url.startsWith("oauth://cb")) {
mTwitterView.destroy();
if (url.contains("oauth_verifier")) {
- Log.d(TAG, "CAUGHT OAUTH");
getTwitterOAuthTokenAndLogin(token, Uri.parse(url).getQueryParameter("oauth_verifier"));
} else if (url.contains("denied")) {
- Log.d(TAG, "DENIED");
Intent resultIntent = new Intent();
setResult(TwitterAuthHelper.RC_TWITTER_CANCEL, resultIntent);
finish();
View
106 library/src/main/res/layout/fragment_firebase_login.xml
@@ -17,7 +17,8 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal">
+ android:layout_gravity="center_horizontal"
+ android:id="@+id/password_section">
<EditText
android:layout_width="match_parent"
@@ -52,8 +53,8 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/or_line"
- android:layout_marginBottom="10dp"
- android:layout_marginTop="5dp">
+ android:layout_marginBottom="0dp"
+ android:layout_marginTop="15dp">
<TextView
android:layout_width="wrap_content"
@@ -62,8 +63,8 @@
android:textColor="#CCCCCC"
android:typeface="normal"
android:textAlignment="center"
- android:layout_marginTop="9dp"
- android:layout_marginBottom="10dp"
+ android:layout_marginTop="0dp"
+ android:layout_marginBottom="0dp"
android:gravity="center"
android:background="#F5f5f5"
android:paddingLeft="15dp"
@@ -72,54 +73,61 @@
</FrameLayout>
</LinearLayout>
- <Button
+ <LinearLayout
+ android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Login with Facebook"
- android:id="@+id/facebook_button"
- android:background="@drawable/facebook_button"
- android:textColor="#ffffff"
- android:typeface="normal"
- android:textAlignment="center"
- android:drawableLeft="@drawable/ic_facebook"
- android:drawablePadding="10dp"
- android:gravity="left|center"
- android:textStyle="bold"
- android:paddingLeft="12dp"
- android:layout_marginBottom="10dp" />
+ android:layout_height="match_parent"
+ android:id="@+id/social_section"
+ android:layout_marginTop="15dp"
+ android:layout_marginBottom="8dp">
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Login with Facebook"
+ android:id="@+id/facebook_button"
+ android:background="@drawable/facebook_button"
+ android:textColor="#ffffff"
+ android:typeface="normal"
+ android:textAlignment="center"
+ android:drawableLeft="@drawable/ic_facebook"
+ android:drawablePadding="10dp"
+ android:gravity="left|center"
+ android:textStyle="bold"
+ android:paddingLeft="12dp"
+ android:layout_marginBottom="10dp" />
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Login with Google+"
- android:id="@+id/google_button"
- android:background="@drawable/google_button"
- android:textColor="#ffffff"
- android:typeface="normal"
- android:textAlignment="center"
- android:drawableLeft="@drawable/ic_google"
- android:drawablePadding="10dp"
- android:gravity="left|center"
- android:textStyle="bold"
- android:paddingLeft="12dp"
- android:layout_marginBottom="10dp" />
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Login with Google+"
+ android:id="@+id/google_button"
+ android:background="@drawable/google_button"
+ android:textColor="#ffffff"
+ android:typeface="normal"
+ android:textAlignment="center"
+ android:drawableLeft="@drawable/ic_google"
+ android:drawablePadding="10dp"
+ android:gravity="left|center"
+ android:textStyle="bold"
+ android:paddingLeft="12dp"
+ android:layout_marginBottom="10dp" />
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Login with Twitter"
- android:id="@+id/twitter_button"
- android:background="@drawable/twitter_button"
- android:textColor="#ffffff"
- android:typeface="normal"
- android:textAlignment="center"
- android:drawableLeft="@drawable/ic_twitter"
- android:drawablePadding="10dp"
- android:gravity="left|center"
- android:textStyle="bold"
- android:paddingLeft="12dp"
- android:layout_marginBottom="10dp" />
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Login with Twitter"
+ android:id="@+id/twitter_button"
+ android:background="@drawable/twitter_button"
+ android:textColor="#ffffff"
+ android:typeface="normal"
+ android:textAlignment="center"
+ android:drawableLeft="@drawable/ic_twitter"
+ android:drawablePadding="10dp"
+ android:gravity="left|center"
+ android:textStyle="bold"
+ android:paddingLeft="12dp" />
+ </LinearLayout>
</LinearLayout>

0 comments on commit 891947f

Please sign in to comment.
Something went wrong with that request. Please try again.