├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── drawable │ │ │ │ ├── github_logo_icon.png │ │ │ │ ├── google_logo_icon.png │ │ │ │ ├── facebook_logo_icon.png │ │ │ │ ├── twitter_logo_icon.png │ │ │ │ ├── login_top_background.jpg │ │ │ │ ├── login_screen_background.jpg │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── preloaded_fonts.xml │ │ │ │ ├── attr.xml │ │ │ │ ├── shape.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── type.xml │ │ │ │ ├── font_certs.xml │ │ │ │ └── themes.xml │ │ │ ├── layout │ │ │ │ ├── single_radio_button_layout.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── social_merge_button_layout.xml │ │ │ │ ├── activity_social.xml │ │ │ │ ├── custom_simple_dialog_layout.xml │ │ │ │ └── custom_single_choice_dialog.xml │ │ │ ├── color │ │ │ │ ├── color_on_surface_divider.xml │ │ │ │ ├── color_on_surface_emphasis_high.xml │ │ │ │ ├── color_on_surface_emphasis_medium.xml │ │ │ │ ├── color_on_surface_emphasis_disabled.xml │ │ │ │ └── color_on_primary_surface_emphasis_disabled.xml │ │ │ ├── font │ │ │ │ ├── work_sans.xml │ │ │ │ ├── work_sans_bold.xml │ │ │ │ ├── work_sans_extrabold.xml │ │ │ │ ├── work_sans_medium.xml │ │ │ │ └── work_sans_semibold.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── spartons │ │ │ │ └── com │ │ │ │ └── firebasesocialauthentication │ │ │ │ ├── koinDI │ │ │ │ └── FirebaseModule.kt │ │ │ │ ├── extensions │ │ │ │ ├── ContextExtension.kt │ │ │ │ ├── ActivityExtension.kt │ │ │ │ ├── ViewExtension.kt │ │ │ │ ├── GoogleTaskExtension.kt │ │ │ │ └── ViewGroupExtension.kt │ │ │ │ ├── data │ │ │ │ ├── MaterialDialogContent.kt │ │ │ │ └── Result.kt │ │ │ │ ├── activities │ │ │ │ ├── social │ │ │ │ │ ├── data │ │ │ │ │ │ ├── AuthUiModel.kt │ │ │ │ │ │ └── AuthType.kt │ │ │ │ │ ├── di │ │ │ │ │ │ └── SocialActivityModule.kt │ │ │ │ │ ├── ui │ │ │ │ │ │ └── SocialActivity.kt │ │ │ │ │ └── viewModel │ │ │ │ │ │ └── SocialActivityViewModel.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ └── BaseActivity.kt │ │ │ │ ├── backend │ │ │ │ └── MyCustomApp.kt │ │ │ │ ├── util │ │ │ │ ├── NavigationHelper.kt │ │ │ │ └── NetworkUtil.kt │ │ │ │ └── helper │ │ │ │ └── CustomMaterialDialog.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── spartons │ │ │ └── com │ │ │ └── firebasesocialauthentication │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── spartons │ │ └── com │ │ └── firebasesocialauthentication │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── dictionaries │ └── root.xml ├── misc.xml ├── runConfigurations.xml └── gradle.xml ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='FirebaseSocialAuthentication' 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/github_logo_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/drawable/github_logo_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/google_logo_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/drawable/google_logo_icon.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/facebook_logo_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/drawable/facebook_logo_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/twitter_logo_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/drawable/twitter_logo_icon.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/login_top_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/drawable/login_top_background.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/login_screen_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/drawable/login_screen_background.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AhsenSaeed/FirebaseSocialAuth/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Nov 20 00:53:26 PKT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 25dp 6 | 25dp 7 | 25dp 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/koinDI/FirebaseModule.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.koinDI 2 | 3 | import com.google.firebase.auth.FirebaseAuth 4 | import org.koin.dsl.module 5 | 6 | 7 | /** 8 | * Ahsen Saeed} 9 | * ahsansaeed067@gmail.com} 10 | * 11/20/19} 11 | */ 12 | 13 | val firebaseModule = module { 14 | single { FirebaseAuth.getInstance() } 15 | } -------------------------------------------------------------------------------- /.idea/dictionaries/root.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ahsen 5 | coroutines 6 | firebase 7 | firebasesocialauthentication 8 | googleusercontent 9 | koin 10 | overline 11 | saeed 12 | spartons 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/extensions/ContextExtension.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.extensions 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | 7 | 8 | /** 9 | * Ahsen Saeed} 10 | * ahsansaeed067@gmail.com} 11 | * 11/20/19} 12 | */ 13 | 14 | fun Context.launch( 15 | options: Bundle? = null, 16 | intent: Intent 17 | ) = startActivity(intent, options) 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/single_radio_button_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/extensions/ActivityExtension.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.extensions 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.os.Bundle 6 | 7 | 8 | /** 9 | * Ahsen Saeed} 10 | * ahsansaeed067@gmail.com} 11 | * 11/20/19} 12 | */ 13 | 14 | fun Activity.launch( 15 | requestCode: Int = -1, 16 | options: Bundle? = null, 17 | intent: Intent 18 | ) = startActivityForResult(intent, requestCode) -------------------------------------------------------------------------------- /app/src/test/java/spartons/com/firebasesocialauthentication/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/data/MaterialDialogContent.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.data 2 | 3 | import androidx.annotation.StringRes 4 | 5 | 6 | /** 7 | * Ahsen Saeed} 8 | * ahsansaeed067@gmail.com} 9 | * 11/13/19} 10 | */ 11 | 12 | data class MaterialDialogContent( 13 | @StringRes val positiveText: Int, 14 | @StringRes val content: Int? = null, 15 | @StringRes val title: Int, 16 | @StringRes val negativeText: Int? = null, 17 | val contentText: String? = null 18 | ) -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/social/data/AuthUiModel.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities.social.data 2 | 3 | import spartons.com.firebasesocialauthentication.data.MaterialDialogContent 4 | import spartons.com.firebasesocialauthentication.util.Event 5 | 6 | 7 | /** 8 | * Ahsen Saeed} 9 | * ahsansaeed067@gmail.com} 10 | * 11/13/19} 11 | */ 12 | 13 | data class AuthUiModel( 14 | val showProgress: Boolean, 15 | val error: Event>?, 16 | val success: Boolean, 17 | val showAllLinkProvider: Event, MaterialDialogContent>>? 18 | ) -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/social/di/SocialActivityModule.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities.social.di 2 | 3 | import org.koin.android.ext.koin.androidApplication 4 | import org.koin.androidx.viewmodel.dsl.viewModel 5 | import org.koin.dsl.module 6 | import spartons.com.firebasesocialauthentication.activities.social.viewModel.SocialActivityViewModel 7 | import spartons.com.firebasesocialauthentication.backend.MyCustomApp 8 | 9 | 10 | /** 11 | * Ahsen Saeed} 12 | * ahsansaeed067@gmail.com} 13 | * 11/20/19} 14 | */ 15 | 16 | val socialActivityModule = module { 17 | viewModel { SocialActivityViewModel(androidApplication() as MyCustomApp, get()) } 18 | } -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/data/Result.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.data 2 | 3 | 4 | /** 5 | * Ahsen Saeed} 6 | * ahsansaeed067@gmail.com} 7 | * 11/14/19} 8 | */ 9 | 10 | sealed class Result { 11 | 12 | data class Failed(val message: String) : Result() 13 | data class Success(val data: T) : Result() 14 | data class Error(val exception: Exception) : Result() 15 | 16 | override fun toString(): String { 17 | return when (this) { 18 | is Success<*> -> "Success[data=$data]" 19 | is Failed -> "Failed[Message=[$message]" 20 | is Error -> "Error[exception=$exception]" 21 | } 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/extensions/ViewExtension.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.extensions 2 | 3 | import android.content.res.ColorStateList 4 | import android.view.View 5 | import androidx.annotation.ColorRes 6 | import androidx.appcompat.content.res.AppCompatResources 7 | 8 | 9 | /** 10 | * Ahsen Saeed} 11 | * ahsansaeed067@gmail.com} 12 | * 11/20/19} 13 | */ 14 | 15 | fun View.visible() { 16 | if (visibility == View.VISIBLE) return 17 | visibility = View.VISIBLE 18 | } 19 | 20 | fun View.gone() { 21 | visibility = View.GONE 22 | } 23 | 24 | fun View.visible(flag: Boolean) = if (flag) visible() else gone() 25 | 26 | fun View.colorStateList(@ColorRes color: Int): ColorStateList = 27 | AppCompatResources.getColorStateList(context, color) -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/social/data/AuthType.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities.social.data 2 | 3 | 4 | /** 5 | * Ahsen Saeed} 6 | * ahsansaeed067@gmail.com} 7 | * 11/13/19} 8 | */ 9 | 10 | fun String.toAuthType(): AuthType { 11 | return when (this) { 12 | AuthType.FACEBOOK.authValue -> AuthType.FACEBOOK 13 | AuthType.TWITTER.authValue -> AuthType.TWITTER 14 | AuthType.GOOGLE.authValue -> AuthType.GOOGLE 15 | AuthType.GITHUB.authValue -> AuthType.GITHUB 16 | else -> AuthType.EMAIL 17 | } 18 | } 19 | 20 | enum class AuthType(var authValue: String) { 21 | FACEBOOK("facebook.com"), 22 | GOOGLE("google.com"), 23 | GITHUB("github.com"), 24 | TWITTER("twitter.com"), 25 | EMAIL("") 26 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_on_surface_divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/androidTest/java/spartons/com/firebasesocialauthentication/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("spartons.com.firebasesocialauthentication", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_on_surface_emphasis_high.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_on_surface_emphasis_medium.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_on_surface_emphasis_disabled.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_on_primary_surface_emphasis_disabled.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/backend/MyCustomApp.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.backend 2 | 3 | import android.app.Application 4 | import org.koin.android.ext.koin.androidContext 5 | import org.koin.android.ext.koin.androidLogger 6 | import org.koin.core.context.startKoin 7 | import org.koin.core.logger.Level 8 | import spartons.com.firebasesocialauthentication.koinDI.firebaseModule 9 | import spartons.com.firebasesocialauthentication.activities.social.di.socialActivityModule 10 | 11 | 12 | /** 13 | * Ahsen Saeed} 14 | * ahsansaeed067@gmail.com} 15 | * 11/20/19} 16 | */ 17 | 18 | class MyCustomApp : Application() { 19 | 20 | override fun onCreate() { 21 | super.onCreate() 22 | startKoin { 23 | androidLogger(Level.DEBUG) 24 | androidContext(this@MyCustomApp) 25 | modules( 26 | listOf( 27 | firebaseModule, socialActivityModule 28 | ) 29 | ) 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/res/font/work_sans.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values/preloaded_fonts.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | @font/work_sans 18 | @font/work_sans_bold 19 | @font/work_sans_extrabold 20 | @font/work_sans_medium 21 | @font/work_sans_semibold 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/font/work_sans_bold.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/font/work_sans_extrabold.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/font/work_sans_medium.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/font/work_sans_semibold.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.google.firebase.auth.FirebaseAuth 6 | import kotlinx.android.synthetic.main.activity_main.* 7 | import org.koin.android.ext.android.inject 8 | import spartons.com.firebasesocialauthentication.R 9 | import spartons.com.firebasesocialauthentication.util.SocialActivityArgs 10 | 11 | 12 | /** 13 | * Ahsen Saeed} 14 | * ahsansaeed067@gmail.com} 15 | * 11/20/19} 16 | */ 17 | 18 | class MainActivity : AppCompatActivity() { 19 | 20 | private val firebaseAuth: FirebaseAuth by inject() 21 | 22 | override fun onCreate(savedInstanceState: Bundle?) { 23 | super.onCreate(savedInstanceState) 24 | setContentView(R.layout.activity_main) 25 | 26 | logoutButton.setOnClickListener { 27 | firebaseAuth.signOut() 28 | SocialActivityArgs().launch(this) 29 | finish() 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/util/NavigationHelper.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.util 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import android.content.Intent 6 | import android.os.Bundle 7 | import spartons.com.firebasesocialauthentication.activities.MainActivity 8 | import spartons.com.firebasesocialauthentication.activities.social.ui.SocialActivity 9 | import spartons.com.firebasesocialauthentication.extensions.launch 10 | 11 | 12 | /** 13 | * Ahsen Saeed} 14 | * ahsansaeed067@gmail.com} 15 | * 11/20/19} 16 | */ 17 | 18 | 19 | interface ActivityArgs { 20 | 21 | fun intent(context: Context): Intent 22 | 23 | fun launch(context: Context, options: Bundle? = null) = 24 | context.launch(intent = intent(context), options = options) 25 | 26 | fun launch(activity: Activity, options: Bundle? = null, requestCode: Int = -1) = 27 | activity.launch(intent = intent(activity), requestCode = requestCode, options = options) 28 | } 29 | 30 | class MainActivityArgs : ActivityArgs { 31 | 32 | override fun intent(context: Context) = Intent(context, MainActivity::class.java) 33 | } 34 | 35 | class SocialActivityArgs : ActivityArgs { 36 | 37 | override fun intent(context: Context) = Intent(context, SocialActivity::class.java) 38 | } -------------------------------------------------------------------------------- /app/src/main/res/values/shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 14 | 15 | 16 | 20 | 21 | 24 | 25 | 24dp 26 | 0dp 27 | 12dp 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/util/NetworkUtil.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.util 2 | 3 | import spartons.com.firebasesocialauthentication.data.Result 4 | 5 | /** 6 | * Ahsen Saeed} 7 | * ahsansaeed067@gmail.com} 8 | * 11/13/19} 9 | */ 10 | 11 | suspend fun safeApiCall(call: suspend () -> Result): Result { 12 | return try { 13 | call() 14 | } catch (e: Exception) { 15 | Result.Error(e) 16 | } 17 | } 18 | 19 | open class Event(private val content: T) { 20 | 21 | var consumed = false 22 | private set // Allow external read but not write 23 | 24 | /** 25 | * Consumes the content if it's not been consumed yet. 26 | * @return The unconsumed content or `null` if it was consumed already. 27 | */ 28 | fun consume(): T? { 29 | return if (consumed) { 30 | null 31 | } else { 32 | consumed = true 33 | content 34 | } 35 | } 36 | 37 | /** 38 | * @return The content whether it's been handled or not. 39 | */ 40 | fun peek(): T = content 41 | 42 | override fun equals(other: Any?): Boolean { 43 | if (this === other) return true 44 | if (javaClass != other?.javaClass) return false 45 | 46 | other as Event<*> 47 | 48 | if (content != other.content) return false 49 | if (consumed != other.consumed) return false 50 | 51 | return true 52 | } 53 | 54 | override fun hashCode(): Int { 55 | var result = content?.hashCode() ?: 0 56 | result = 31 * result + consumed.hashCode() 57 | return result 58 | } 59 | } -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/extensions/GoogleTaskExtension.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.extensions 2 | 3 | import com.google.android.gms.tasks.Task 4 | import kotlinx.coroutines.CancellationException 5 | import kotlinx.coroutines.suspendCancellableCoroutine 6 | import kotlin.coroutines.resume 7 | import kotlin.coroutines.resumeWithException 8 | 9 | 10 | /** 11 | * Ahsen Saeed} 12 | * ahsansaeed067@gmail.com} 13 | * 11/13/19} 14 | */ 15 | 16 | /** 17 | * Awaits for completion of the task without blocking a thread. 18 | * 19 | * This suspending function is cancellable. 20 | * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function 21 | * stops waiting for the completion stage and immediately resumes with [CancellationException]. 22 | */ 23 | suspend fun Task.await(): T { 24 | // fast path 25 | if (isComplete) { 26 | val e = exception 27 | return if (e == null) { 28 | if (isCanceled) { 29 | throw CancellationException("Task $this was cancelled normally.") 30 | } else { 31 | @Suppress("UNCHECKED_CAST") 32 | result as T 33 | } 34 | } else { 35 | throw e 36 | } 37 | } 38 | 39 | return suspendCancellableCoroutine { cont -> 40 | addOnCompleteListener { 41 | val e = exception 42 | if (e == null) { 43 | @Suppress("UNCHECKED_CAST") 44 | if (isCanceled) cont.cancel() else cont.resume(result as T) 45 | } else { 46 | cont.resumeWithException(e) 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities 2 | 3 | import android.annotation.SuppressLint 4 | import android.os.Bundle 5 | import android.view.WindowManager 6 | import androidx.appcompat.app.AppCompatActivity 7 | import androidx.lifecycle.LiveData 8 | import androidx.lifecycle.Observer 9 | import androidx.lifecycle.ViewModel 10 | import org.koin.androidx.viewmodel.ext.android.viewModel 11 | import org.koin.core.parameter.DefinitionParameters 12 | import org.koin.core.parameter.emptyParametersHolder 13 | import kotlin.reflect.KClass 14 | 15 | 16 | /** 17 | * Ahsen Saeed} 18 | * ahsansaeed067@gmail.com} 19 | * 10/17/19} 20 | */ 21 | 22 | @SuppressLint("Registered") 23 | abstract class BaseActivity( 24 | private val layoutResourceId: Int, 25 | viewModelClass: KClass, 26 | viewmodelParameters: DefinitionParameters = emptyParametersHolder() 27 | ) : AppCompatActivity() { 28 | 29 | protected open val viewModel: VM by viewModel(clazz = viewModelClass) 30 | 31 | protected open val isFullscreen: Boolean = false 32 | 33 | override fun onCreate(savedInstanceState: Bundle?) { 34 | super.onCreate(savedInstanceState) 35 | if (isFullscreen) setFullScreenWindow() 36 | setContentView(layoutResourceId) 37 | } 38 | 39 | protected fun > observe(liveData: LD, onChanged: (T) -> Unit) { 40 | liveData.observe(this, Observer { 41 | it?.let(onChanged) 42 | }) 43 | } 44 | 45 | private fun setFullScreenWindow() { 46 | window.setFlags( 47 | WindowManager.LayoutParams.FLAG_FULLSCREEN, 48 | WindowManager.LayoutParams.FLAG_FULLSCREEN 49 | ) 50 | } 51 | } -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/extensions/ViewGroupExtension.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.extensions 2 | 3 | import android.content.res.ColorStateList 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.annotation.ColorRes 8 | import androidx.annotation.LayoutRes 9 | import androidx.core.view.children 10 | import com.google.android.material.button.MaterialButton 11 | 12 | 13 | /** 14 | * Ahsen Saeed} 15 | * ahsansaeed067@gmail.com} 16 | * 11/20/19} 17 | */ 18 | 19 | fun ViewGroup.applyColorToAllDescendantsAndDisableState(@ColorRes color: Int) { 20 | for (view in children) { 21 | if (view is MaterialButton) { 22 | view.tag = view.backgroundTintList 23 | view.backgroundTintList = colorStateList(color) 24 | view.isEnabled = false 25 | } else if (view is ViewGroup) 26 | view.applyColorToAllDescendantsAndDisableState(color) 27 | } 28 | } 29 | 30 | fun ViewGroup.enableAllDescendantsAndApplyPreviousColor() { 31 | for (view in children) { 32 | if (view is MaterialButton) { 33 | val tag = view.tag ?: return 34 | val colorStateList: ColorStateList = tag as ColorStateList 35 | view.backgroundTintList = colorStateList 36 | view.isEnabled = true 37 | } else if (view is ViewGroup) 38 | view.enableAllDescendantsAndApplyPreviousColor() 39 | } 40 | } 41 | 42 | fun ViewGroup.inflateView(@LayoutRes layoutRes: Int): View { 43 | return LayoutInflater.from(context).inflate(layoutRes, this, false) 44 | } 45 | 46 | fun ViewGroup.addAllViews(views: List) { 47 | for (view in views) 48 | addView(view) 49 | } -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FirebaseSocialAuthentication 3 | 4 | 5 | 6 | 41*****************88 7 | // change it with your your facebook app id 8 | fb41******************88 9 | // change it with your facebook protocol scheme 10 | Welcome back! 11 | Log in to your account 12 | Twitter 13 | Facebook 14 | GitHub 15 | Google 16 | forgot about 17 | PREVIOUS LOGIN ? 18 | 19 | Uh..oh… We\'re unable proceed, its seems like your internet connection is broke or maybe limited. Please check it and try again. 20 | Cancel 21 | Try Again 22 | Limited Internet Connection 23 | It seems like %1$s is already linked with the following login providers. Please select any of following provider in order to login with your previous information. 24 | User Collision 25 | Select 26 | Operation Cancelled 27 | It seems like you cancel the on-going operation. You can restart the process by simply clicking Try Again. 28 | Logout 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #5B7BB0 7 | #3700b3 8 | #03dac6 9 | #018786 10 | 11 | 12 | 13 | 14 | 15 | #eef0f2 16 | #FCFDFD 17 | #b00020 18 | 19 | 20 | 21 | #FCFDFD 22 | #060914 23 | #060914 24 | #060914 25 | #FCFDFD 26 | #FF272727 27 | 28 | #99ffffff 29 | #33000000 30 | 31 | #99eef0f2 32 | @color/reply_black_900_alpha_020 33 | 34 | 35 | #4267B2 36 | #F54436 37 | #38A1F3 38 | #060914 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 29 7 | defaultConfig { 8 | applicationId "spartons.com.firebasesocialauthentication" 9 | minSdkVersion 21 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | packagingOptions { 22 | exclude 'META-INF/main.kotlin_module' 23 | exclude 'META-INF/library_release.kotlin_module' 24 | exclude 'META-INF/atomicfu.kotlin_module' 25 | } 26 | compileOptions { 27 | targetCompatibility = '1.8' 28 | sourceCompatibility = '1.8' 29 | } 30 | kotlinOptions { 31 | jvmTarget = "1.8" 32 | } 33 | androidExtensions { 34 | experimental = true 35 | } 36 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 37 | kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.Experimental"] 38 | } 39 | } 40 | 41 | dependencies { 42 | implementation fileTree(dir: 'libs', include: ['*.jar']) 43 | 44 | // kotlin library dependency 45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 46 | 47 | // Android support dependencies 48 | implementation 'androidx.appcompat:appcompat:1.1.0' 49 | implementation 'androidx.core:core-ktx:1.2.0-beta02' 50 | implementation 'com.google.android.material:material:1.2.0-alpha01' 51 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 52 | 53 | // kotlin based dependency injection koin 54 | implementation 'org.koin:koin-androidx-viewmodel:2.0.1' 55 | 56 | // Kotlin coroutines dependencies 57 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0' 58 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0' 59 | 60 | // ViewModel dependency 61 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-rc02' 62 | implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-rc02' 63 | 64 | // Material dialog dependency 65 | implementation 'com.afollestad.material-dialogs:core:3.1.1' 66 | 67 | // Firebase dependencies 68 | implementation 'com.google.firebase:firebase-auth:19.1.0' 69 | implementation 'com.google.android.gms:play-services-auth:17.0.0' 70 | 71 | // Facebook dependency 72 | implementation 'com.facebook.android:facebook-login:5.0.0' 73 | 74 | testImplementation 'junit:junit:4.12' 75 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 76 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 77 | } 78 | apply plugin: 'com.google.gms.google-services' 79 | -------------------------------------------------------------------------------- /app/src/main/res/layout/social_merge_button_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 19 | 20 | 29 | 30 | 38 | 39 | 40 | 41 | 46 | 47 | 56 | 57 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_social.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 22 | 23 | 31 | 32 | 39 | 40 | 41 | 42 | 48 | 49 | 50 | 51 | 59 | 60 | 65 | 66 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_simple_dialog_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 29 | 30 | 37 | 38 | 44 | 45 | 59 | 60 | 68 | 69 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /app/src/main/res/values/type.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | 18 | 19 | 23 | 24 | 28 | 29 | 33 | 34 | 38 | 39 | 45 | 46 | 51 | 52 | 57 | 58 | 62 | 63 | 69 | 70 | -------------------------------------------------------------------------------- /app/src/main/res/values/font_certs.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | @array/com_google_android_gms_fonts_certs_dev 18 | @array/com_google_android_gms_fonts_certs_prod 19 | 20 | 21 | 22 | MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpFeVyxW0qMBujb8X8ETrWy550NaFtI6t9+u7hZeTfHwqNvacKhp1RbE6dBRGWynwMVX8XW8N1+UjFaq6GCJukT4qmpN2afb8sCjUigq0GuMwYXrFVee74bQgLHWGJwPmvmLHC69EH6kWr22ijx4OKXlSIx2xT1AsSHee70w5iDBiK4aph27yH3TxkXy9V89TDdexAcKk/cVHYNnDBapcavl7y0RiQ4biu8ymM8Ga/nmzhRKya6G0cGw8CAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6VTEM8YYY6FbBMvAPyT+CyoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJANWFuGx90071MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBABnTDPEF+3iSP0wNfdIjIz1AlnrPzgAIHVvXxunW7SBrDhEglQZBbKJEk5kT0mtKoOD1JMrSu1xuTKEBahWRbqHsXclaXjoBADb0kkjVEJu/Lh5hgYZnOjvlba8Ld7HCKePCVePoTJBdI4fvugnL8TsgK05aIskyY0hKI9L8KfqfGTl1lzOv2KoWD0KWwtAWPoGChZxmQ+nBli+gwYMzM1vAkP+aayLe0a1EQimlOalO762r0GXO0ks+UeXde2Z4e+8S/pf7pITEI/tP+MxJTALw9QUWEv9lKTk+jkbqxbsh8nfBUapfKqYn0eidpwq2AzVp3juYl7//fKnaPhJD9gs= 23 | 24 | 25 | 26 | 27 | MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDAeFw0wODA4MjEyMzEzMzRaFw0zNjAxMDcyMzEzMzRaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAKtWLgDYO6IIrgqWbxJOKdoR8qtW0I9Y4sypEwPpt1TTcvZApxsdyxMJZ2JORland2qSGT2y5b+3JKkedxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjAsb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_single_choice_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 28 | 29 | 37 | 38 | 47 | 48 | 54 | 55 | 69 | 70 | 78 | 79 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 11 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | xmlns:android 20 | 21 | ^$ 22 | 23 | 24 | 25 |
26 |
27 | 28 | 29 | 30 | xmlns:.* 31 | 32 | ^$ 33 | 34 | 35 | BY_NAME 36 | 37 |
38 |
39 | 40 | 41 | 42 | .*:id 43 | 44 | http://schemas.android.com/apk/res/android 45 | 46 | 47 | 48 |
49 |
50 | 51 | 52 | 53 | .*:name 54 | 55 | http://schemas.android.com/apk/res/android 56 | 57 | 58 | 59 |
60 |
61 | 62 | 63 | 64 | name 65 | 66 | ^$ 67 | 68 | 69 | 70 |
71 |
72 | 73 | 74 | 75 | style 76 | 77 | ^$ 78 | 79 | 80 | 81 |
82 |
83 | 84 | 85 | 86 | .* 87 | 88 | ^$ 89 | 90 | 91 | BY_NAME 92 | 93 |
94 |
95 | 96 | 97 | 98 | .* 99 | 100 | http://schemas.android.com/apk/res/android 101 | 102 | 103 | ANDROID_ATTRIBUTE_ORDER 104 | 105 |
106 |
107 | 108 | 109 | 110 | .* 111 | 112 | .* 113 | 114 | 115 | BY_NAME 116 | 117 |
118 |
119 |
120 |
121 | 122 | 124 |
125 |
-------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 76 | 77 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/social/ui/SocialActivity.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities.social.ui 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.view.ViewGroup 6 | import com.google.android.material.button.MaterialButton 7 | import kotlinx.android.synthetic.main.activity_social.* 8 | import spartons.com.firebasesocialauthentication.R 9 | import spartons.com.firebasesocialauthentication.activities.BaseActivity 10 | import spartons.com.firebasesocialauthentication.activities.social.data.AuthType 11 | import spartons.com.firebasesocialauthentication.activities.social.data.toAuthType 12 | import spartons.com.firebasesocialauthentication.activities.social.viewModel.SocialActivityViewModel 13 | import spartons.com.firebasesocialauthentication.activities.social.viewModel.SocialActivityViewModel.Companion.RC_GOOGLE_SIGN_IN_CODE 14 | import spartons.com.firebasesocialauthentication.extensions.applyColorToAllDescendantsAndDisableState 15 | import spartons.com.firebasesocialauthentication.extensions.enableAllDescendantsAndApplyPreviousColor 16 | import spartons.com.firebasesocialauthentication.extensions.visible 17 | import spartons.com.firebasesocialauthentication.helper.CustomMaterialDialog.showSimpleDialog 18 | import spartons.com.firebasesocialauthentication.helper.CustomMaterialDialog.showSingleChoiceDialog 19 | import spartons.com.firebasesocialauthentication.util.MainActivityArgs 20 | 21 | class SocialActivity : 22 | BaseActivity( 23 | R.layout.activity_social, 24 | SocialActivityViewModel::class 25 | ) { 26 | 27 | private lateinit var socialIncludeLayout: ViewGroup 28 | 29 | override val isFullscreen: Boolean 30 | get() = true 31 | 32 | private companion object { 33 | private val facebook_permissions = mutableListOf("email", "public_profile") 34 | } 35 | 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | 39 | socialIncludeLayout = findViewById(R.id.loginSocialLayout) 40 | 41 | socialIncludeLayout.findViewById(R.id.socialTwitterButton) 42 | .setOnClickListener { doSocialAuth(AuthType.TWITTER) } 43 | 44 | socialIncludeLayout.findViewById(R.id.socialGoogleButton) 45 | .setOnClickListener { doSocialAuth(AuthType.GOOGLE) } 46 | 47 | socialIncludeLayout.findViewById(R.id.socialFacebookButton) 48 | .setOnClickListener { doSocialAuth(AuthType.FACEBOOK) } 49 | 50 | socialIncludeLayout.findViewById(R.id.socialGithubButton) 51 | .setOnClickListener { doSocialAuth(AuthType.GITHUB) } 52 | 53 | observe(viewModel.uiState) { authModel -> 54 | loginProgressBar.visible(authModel.showProgress) 55 | 56 | if (authModel.success) navigateActivity() 57 | else if (authModel.error != null && !authModel.error.consumed) 58 | authModel.error.consume()?.let { pair -> 59 | showSimpleDialog(this, pair.second) { 60 | doSocialAuth(pair.first) 61 | } 62 | socialIncludeLayout.enableAllDescendantsAndApplyPreviousColor() 63 | } 64 | else if (authModel.showAllLinkProvider != null && !authModel.showAllLinkProvider.consumed) 65 | authModel.showAllLinkProvider.consume()?.let { pair -> 66 | showSingleChoiceDialog( 67 | this, pair.second, pair.first, 68 | negativeButtonClickListener = { 69 | socialIncludeLayout.enableAllDescendantsAndApplyPreviousColor() 70 | }) { 71 | val authType = it.toAuthType() 72 | doSocialAuth(authType) 73 | } 74 | } 75 | } 76 | } 77 | 78 | private fun navigateActivity() { 79 | MainActivityArgs().launch(this) 80 | finish() 81 | } 82 | 83 | override fun onStart() { 84 | super.onStart() 85 | if (viewModel.firebaseAuth.currentUser != null) 86 | navigateActivity() 87 | } 88 | 89 | private fun disableButtons(views: ViewGroup) { 90 | views.applyColorToAllDescendantsAndDisableState(R.color.color_on_surface_emphasis_disabled) 91 | } 92 | 93 | private fun doSocialAuth(authType: AuthType) { 94 | when (authType) { 95 | AuthType.GOOGLE -> viewModel.googleSignIn().also { 96 | startActivityForResult(it, RC_GOOGLE_SIGN_IN_CODE) 97 | } 98 | AuthType.TWITTER -> { 99 | disableButtons(socialIncludeLayout) 100 | viewModel.doTwitterAuthentication(this) 101 | } 102 | AuthType.FACEBOOK -> { 103 | disableButtons(socialIncludeLayout) 104 | viewModel.loginManager.logInWithReadPermissions(this, facebook_permissions) 105 | } 106 | AuthType.EMAIL -> { 107 | disableButtons(socialIncludeLayout) 108 | viewModel.fetchAllProviderForEmail(authType.authValue) 109 | } 110 | AuthType.GITHUB -> { 111 | disableButtons(socialIncludeLayout) 112 | viewModel.doGithubAuthentication(this) 113 | } 114 | } 115 | } 116 | 117 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 118 | super.onActivityResult(requestCode, resultCode, data) 119 | viewModel.handleOnActivityResult(requestCode, resultCode, data) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/helper/CustomMaterialDialog.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.helper 2 | 3 | import android.app.Activity 4 | import android.widget.ImageView 5 | import android.widget.RadioGroup 6 | import android.widget.TextView 7 | import com.afollestad.materialdialogs.MaterialDialog 8 | import com.afollestad.materialdialogs.callbacks.onPreShow 9 | import com.afollestad.materialdialogs.customview.customView 10 | import com.google.android.material.radiobutton.MaterialRadioButton 11 | import spartons.com.firebasesocialauthentication.R 12 | import spartons.com.firebasesocialauthentication.data.MaterialDialogContent 13 | import spartons.com.firebasesocialauthentication.extensions.addAllViews 14 | import spartons.com.firebasesocialauthentication.extensions.inflateView 15 | import spartons.com.firebasesocialauthentication.extensions.visible 16 | 17 | /** 18 | * Ahsen Saeed} 19 | * ahsansaeed067@gmail.com} 20 | * 11/13/19} 21 | */ 22 | 23 | object CustomMaterialDialog { 24 | 25 | fun showSimpleDialog( 26 | callingClassActivity: Activity, dialogContent: MaterialDialogContent, 27 | positiveButtonClickClosure: () -> Unit 28 | ) { 29 | MaterialDialog(callingClassActivity).show { 30 | customView(viewRes = R.layout.custom_simple_dialog_layout, noVerticalPadding = true) 31 | if (dialogContent.negativeText != null) 32 | view.apply { 33 | findViewById(R.id.centeredSimpleDialogNegativeTextView).apply { 34 | setText(dialogContent.negativeText) 35 | setOnClickListener { dismiss() } 36 | visible() 37 | } 38 | findViewById(R.id.centeredSimpleDialogContentActionButtonDivider) 39 | .visible() 40 | } 41 | 42 | view.apply { 43 | findViewById(R.id.centeredSimpleDialogPositiveTextView).apply { 44 | setText(dialogContent.positiveText) 45 | setOnClickListener { 46 | dismiss() 47 | positiveButtonClickClosure.invoke() 48 | } 49 | } 50 | findViewById(R.id.customSimpleDialogTitleTextView).setText(dialogContent.title) 51 | val contentTextResource = dialogContent.content 52 | val content = dialogContent.contentText 53 | if (contentTextResource != null) 54 | findViewById(R.id.customSimpleDialogContentTextView).setText( 55 | contentTextResource 56 | ) 57 | else if (content != null) 58 | findViewById(R.id.customSimpleDialogContentTextView).text = content 59 | cancelOnTouchOutside(false) 60 | } 61 | } 62 | } 63 | 64 | fun showSingleChoiceDialog( 65 | callingClassActivity: Activity, 66 | dialogContent: MaterialDialogContent, items: List, 67 | negativeButtonClickListener: (() -> Unit)? = null, choiceSelection: (String) -> Unit 68 | ) { 69 | 70 | require(items.isNotEmpty()) { 71 | "The items list for single choice must not be empty" 72 | } 73 | 74 | MaterialDialog(callingClassActivity).show { 75 | 76 | customView(viewRes = R.layout.custom_single_choice_dialog, noVerticalPadding = true) 77 | 78 | val radioButtons = items.map { singleContent -> 79 | (view.inflateView(R.layout.single_radio_button_layout) as MaterialRadioButton).apply { 80 | text = singleContent 81 | } 82 | } 83 | 84 | if (dialogContent.negativeText != null) 85 | view.apply { 86 | findViewById(R.id.customSingleChoiceDialogNegativeTextView).apply { 87 | setText(dialogContent.negativeText) 88 | setOnClickListener { 89 | dismiss() 90 | negativeButtonClickListener?.invoke() 91 | } 92 | visible() 93 | } 94 | findViewById(R.id.customSingleChoiceDialogActionButtonDivider) 95 | .visible() 96 | } 97 | 98 | view.apply { 99 | findViewById(R.id.customSingleChoiceDialogRadioGroup).apply { 100 | addAllViews(radioButtons) 101 | } 102 | findViewById(R.id.customSingleChoiceDialogTitleTextView).setText( 103 | dialogContent.title 104 | ) 105 | val contentTextResource = dialogContent.content 106 | val content = dialogContent.contentText 107 | if (contentTextResource != null) 108 | findViewById(R.id.customSingleChoiceDialogContentTextView).setText( 109 | contentTextResource 110 | ) 111 | else if (content != null) 112 | findViewById(R.id.customSingleChoiceDialogContentTextView).text = 113 | content 114 | findViewById(R.id.customSingleChoiceDialogPositiveTextView).apply { 115 | setText(dialogContent.positiveText) 116 | setOnClickListener { 117 | val selectedRadioButton = radioButtons.first { it.isChecked } 118 | choiceSelection.invoke(selectedRadioButton.text.toString()) 119 | dismiss() 120 | } 121 | } 122 | } 123 | 124 | onPreShow { 125 | radioButtons[0].isChecked = true 126 | } 127 | 128 | cancelOnTouchOutside(false) 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/java/spartons/com/firebasesocialauthentication/activities/social/viewModel/SocialActivityViewModel.kt: -------------------------------------------------------------------------------- 1 | package spartons.com.firebasesocialauthentication.activities.social.viewModel 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import androidx.lifecycle.AndroidViewModel 6 | import androidx.lifecycle.LiveData 7 | import androidx.lifecycle.MutableLiveData 8 | import androidx.lifecycle.viewModelScope 9 | import com.facebook.CallbackManager 10 | import com.facebook.FacebookCallback 11 | import com.facebook.FacebookException 12 | import com.facebook.login.LoginManager 13 | import com.facebook.login.LoginResult 14 | import com.google.android.gms.auth.api.signin.GoogleSignIn 15 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions 16 | import com.google.firebase.auth.* 17 | import kotlinx.coroutines.Dispatchers 18 | import kotlinx.coroutines.launch 19 | import kotlinx.coroutines.withContext 20 | import spartons.com.firebasesocialauthentication.R 21 | import spartons.com.firebasesocialauthentication.activities.social.data.AuthType 22 | import spartons.com.firebasesocialauthentication.activities.social.data.AuthUiModel 23 | import spartons.com.firebasesocialauthentication.backend.MyCustomApp 24 | import spartons.com.firebasesocialauthentication.data.MaterialDialogContent 25 | import spartons.com.firebasesocialauthentication.data.Result 26 | import spartons.com.firebasesocialauthentication.extensions.await 27 | import spartons.com.firebasesocialauthentication.util.Event 28 | import spartons.com.firebasesocialauthentication.util.safeApiCall 29 | 30 | /** 31 | * Ahsen Saeed} 32 | * ahsansaeed067@gmail.com} 33 | * 11/20/19} 34 | */ 35 | 36 | class SocialActivityViewModel( 37 | application: MyCustomApp, 38 | val firebaseAuth: FirebaseAuth 39 | ) : AndroidViewModel(application) { 40 | 41 | val uiState: LiveData get() = _uiState 42 | 43 | private val resources = application.resources 44 | private val _uiState = MutableLiveData() 45 | 46 | /////////////////////////// Firebase Facebook Authentication Starts //////////////////////////// 47 | 48 | val loginManager: LoginManager = LoginManager.getInstance() 49 | private val mCallbackManager = CallbackManager.Factory.create() 50 | private val mFacebookCallback = object : FacebookCallback { 51 | override fun onSuccess(result: LoginResult?) { 52 | val credential = FacebookAuthProvider.getCredential(result?.accessToken?.token!!) 53 | handleFacebookCredential(credential) 54 | } 55 | 56 | override fun onCancel() { 57 | viewModelScope.launch { 58 | emitUiState( 59 | error = Event( 60 | AuthType.FACEBOOK to MaterialDialogContent( 61 | R.string.try_again, R.string.operation_cancelled_content, 62 | R.string.operation_cancelled, R.string.cancel 63 | ) 64 | ) 65 | ) 66 | } 67 | } 68 | 69 | override fun onError(error: FacebookException?) { 70 | viewModelScope.launch { 71 | sendErrorState(AuthType.FACEBOOK) 72 | } 73 | } 74 | } 75 | 76 | init { 77 | loginManager.registerCallback(mCallbackManager, mFacebookCallback) 78 | } 79 | 80 | private fun handleFacebookCredential(authCredential: AuthCredential) { 81 | viewModelScope.launch { 82 | emitUiState(showProgress = true) 83 | safeApiCall { Result.Success(signInWithCredential(authCredential)!!) }.also { 84 | if (it is Result.Success && it.data.user != null) emitUiState(success = true) 85 | else if (it is Result.Error) handleErrorStateForSignInCredential( 86 | it.exception, AuthType.FACEBOOK 87 | ) 88 | } 89 | } 90 | } 91 | 92 | //////////////////////// Firebase Facebook Authentication Ends ///////////////////////////////// 93 | 94 | 95 | //////////////////////// Firebase Google Authentication Starts ///////////////////////////////// 96 | 97 | companion object { 98 | private const val GOOGLE_PRIVATE_CLIENT_ID = 99 | "165417854765-***********************************m.apps.googleusercontent.com" // change it with your google private client id 100 | const val RC_GOOGLE_SIGN_IN_CODE = 2555 101 | } 102 | 103 | private val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 104 | .requestIdToken(GOOGLE_PRIVATE_CLIENT_ID) 105 | .requestEmail() 106 | .build() 107 | private val mGoogleSignClient by lazy { 108 | GoogleSignIn.getClient(application, gso) 109 | } 110 | 111 | private fun handleGoogleSignInResult(data: Intent) { 112 | viewModelScope.launch { 113 | emitUiState(showProgress = true) 114 | safeApiCall { 115 | val account = GoogleSignIn.getSignedInAccountFromIntent(data).await() 116 | val authResult = 117 | signInWithCredential(GoogleAuthProvider.getCredential(account.idToken, null))!! 118 | Result.Success(authResult) 119 | }.also { 120 | if (it is Result.Success && it.data.user != null) 121 | emitUiState(success = true) 122 | else sendErrorState(AuthType.GOOGLE) 123 | } 124 | } 125 | } 126 | 127 | fun googleSignIn() = mGoogleSignClient.signInIntent 128 | 129 | //////////////////////// Firebase Google Authentication Ends /////////////////////////////////// 130 | 131 | 132 | //////////////////////// Firebase Twitter Authentication Starts //////////////////////////////// 133 | 134 | private val twitterAuthProvider = OAuthProvider.newBuilder("twitter.com") 135 | .build() 136 | 137 | fun doTwitterAuthentication(activity: Activity) { 138 | val twitterTask = 139 | firebaseAuth.startActivityForSignInWithProvider(activity, twitterAuthProvider) 140 | viewModelScope.launch { 141 | safeApiCall { Result.Success(twitterTask.await()) }.also { 142 | if (it is Result.Success && it.data.user != null) 143 | emitUiState(success = true) 144 | else if (it is Result.Error) handleErrorStateForSignInCredential( 145 | it.exception, AuthType.TWITTER 146 | ) 147 | } 148 | } 149 | } 150 | 151 | //////////////////////// Firebase Twitter Authentication Ends ////////////////////////////////// 152 | 153 | 154 | //////////////////////// Firebase GitHub Authentication Starts ///////////////////////////////// 155 | 156 | private val githubAuthProvider = OAuthProvider.newBuilder("github.com") 157 | .build() 158 | 159 | fun doGithubAuthentication(activity: Activity) { 160 | val githubTask = 161 | firebaseAuth.startActivityForSignInWithProvider(activity, githubAuthProvider) 162 | viewModelScope.launch { 163 | safeApiCall { Result.Success(githubTask.await()) }.also { 164 | if (it is Result.Success && it.data.user != null) 165 | emitUiState(success = true) 166 | else if (it is Result.Error) handleErrorStateForSignInCredential( 167 | it.exception, AuthType.GITHUB 168 | ) 169 | } 170 | } 171 | } 172 | 173 | //////////////////////// Firebase GitHub Authentication Ends /////////////////////////////////// 174 | 175 | private suspend fun sendErrorState(authType: AuthType) { 176 | emitUiState( 177 | error = Event( 178 | authType to MaterialDialogContent( 179 | R.string.try_again, R.string.internet_not_working, 180 | R.string.limited_internet_connection, R.string.cancel 181 | ) 182 | ) 183 | ) 184 | } 185 | 186 | /** 187 | * Fetch all providers associated with this email. In case when user previously login with xyz provider and after logout he/she try to login with abc provider. 188 | */ 189 | 190 | fun fetchAllProviderForEmail(email: String) { 191 | viewModelScope.launch { 192 | safeApiCall { Result.Success(firebaseAuth.fetchSignInMethodsForEmail(email).await()) }.also { 193 | if (it is Result.Success && it.data.signInMethods != null) 194 | emitUiState( 195 | linkProvider = Event( 196 | it.data.signInMethods!! to MaterialDialogContent( 197 | R.string.select, null, R.string.user_collision, R.string.cancel, 198 | String.format( 199 | resources.getString(R.string.auth_user_collision_message), email 200 | ) 201 | ) 202 | ) 203 | ) 204 | else sendErrorState(AuthType.EMAIL.apply { authValue = email }) 205 | } 206 | } 207 | } 208 | 209 | //////////////////////// Firebase Authentication Common Code Starts //////////////////////////// 210 | 211 | private suspend fun handleErrorStateForSignInCredential( 212 | exception: Exception, authType: AuthType 213 | ) { 214 | if (exception is FirebaseAuthUserCollisionException) { 215 | val email = exception.email 216 | if (email != null) fetchAllProviderForEmail(email) 217 | else sendErrorState(authType) 218 | } else sendErrorState(authType) 219 | } 220 | 221 | fun handleOnActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 222 | if (requestCode == RC_GOOGLE_SIGN_IN_CODE && data != null) { 223 | handleGoogleSignInResult(data) 224 | } else if (mCallbackManager.onActivityResult(requestCode, resultCode, data)) 225 | println("Result should be handled") 226 | } 227 | 228 | @Throws(Exception::class) 229 | private suspend fun signInWithCredential(authCredential: AuthCredential): AuthResult? { 230 | return firebaseAuth.signInWithCredential(authCredential).await() 231 | } 232 | 233 | private suspend fun emitUiState( 234 | showProgress: Boolean = false, 235 | error: Event>? = null, 236 | success: Boolean = false, 237 | linkProvider: Event, MaterialDialogContent>>? = null 238 | ) = withContext(Dispatchers.Main) 239 | { 240 | AuthUiModel(showProgress, error, success, linkProvider).also { 241 | _uiState.value = it 242 | } 243 | } 244 | 245 | //////////////////////// Firebase Authentication Common Code Ends ////////////////////////////// 246 | } --------------------------------------------------------------------------------