├── settings.gradle.kts
├── app
├── .gitignore
├── src
│ ├── test
│ │ └── resources
│ │ │ └── robolectric.properties
│ ├── debug
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ └── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ └── AndroidManifest.xml
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── ids.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ └── app_logo_120dp.xml
│ │ │ └── layout
│ │ │ │ └── activity_sign_in.xml
│ │ ├── kotlin
│ │ │ └── net
│ │ │ │ └── rafaeltoledo
│ │ │ │ └── social
│ │ │ │ ├── data
│ │ │ │ ├── model
│ │ │ │ │ └── User.kt
│ │ │ │ ├── auth
│ │ │ │ │ ├── AuthManager.kt
│ │ │ │ │ ├── DelegatedAuth.kt
│ │ │ │ │ ├── GoogleAuth.kt
│ │ │ │ │ └── FacebookAuth.kt
│ │ │ │ └── firebase
│ │ │ │ │ └── FirebaseAuthManager.kt
│ │ │ │ ├── di
│ │ │ │ ├── FirstModule.kt
│ │ │ │ ├── FirebaseModule.kt
│ │ │ │ ├── AuthModule.kt
│ │ │ │ └── ViewModelModule.kt
│ │ │ │ ├── ui
│ │ │ │ ├── feature
│ │ │ │ │ ├── main
│ │ │ │ │ │ ├── MainViewModel.kt
│ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ │ └── signin
│ │ │ │ │ │ ├── SignInActivity.kt
│ │ │ │ │ │ └── SignInViewModel.kt
│ │ │ │ └── BaseViewModel.kt
│ │ │ │ └── SocialApp.kt
│ │ └── AndroidManifest.xml
│ ├── release
│ │ └── res
│ │ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ │ └── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ ├── sharedTest
│ │ └── kotlin
│ │ │ └── net
│ │ │ └── rafaeltoledo
│ │ │ └── social
│ │ │ ├── base
│ │ │ └── BaseTest.kt
│ │ │ ├── test
│ │ │ └── ui
│ │ │ │ ├── MainActivityTest.kt
│ │ │ │ └── SignInActivityTest.kt
│ │ │ ├── data
│ │ │ └── auth
│ │ │ │ ├── GoogleAuthTest.kt
│ │ │ │ └── FacebookAuthTest.kt
│ │ │ └── TestSetup.kt
│ └── androidTest
│ │ └── kotlin
│ │ └── net
│ │ └── rafaeltoledo
│ │ └── social
│ │ └── SocialAppTestRunner.kt
├── proguard-rules.pro
└── build.gradle
├── distribution
├── debug.keystore
└── release.keystore-cipher
├── gradle.properties
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── lint.gradle
└── coverage.gradle
├── .gitignore
├── scripts
├── ftl-download-results.sh
├── ftl-run-tests.sh
└── ftl-setup.sh
├── .editorconfig
├── README.md
├── gradlew.bat
├── .github
└── workflows
│ └── ci.yml
├── gradlew
└── LICENSE.txt
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | include(":app")
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | google-services.json
--------------------------------------------------------------------------------
/app/src/test/resources/robolectric.properties:
--------------------------------------------------------------------------------
1 | # Needed until Robolectric don't support API 29
2 | sdk=28
3 |
--------------------------------------------------------------------------------
/distribution/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/distribution/debug.keystore
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.useAndroidX=true
2 | android.enableJetifier=true
3 | kotlin.code.style=official
4 |
--------------------------------------------------------------------------------
/app/src/debug/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Social Dev.
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/release/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Social
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/distribution/release.keystore-cipher:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/distribution/release.keystore-cipher
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/data/model/User.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.model
2 |
3 | data class User(val id: String)
4 |
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/debug/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffab00
4 |
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rafaeltoledo/social-app/HEAD/app/src/release/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/release/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1DE9B6
4 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/di/FirstModule.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.di
2 |
3 | import org.koin.dsl.module
4 |
5 | val firstModule = module {
6 | single { "Social App" }
7 | }
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/scripts/ftl-download-results.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | TEST_DIR=$1
4 |
5 | # Create directory for results
6 | mkdir "$TEST_DIR"
7 |
8 | # Pull down test results
9 | gsutil -m cp -r -U "$(gsutil ls gs://cloud-test-social-app-development | tail -1)*" "$TEST_DIR"
10 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.kt]
12 | max_line_length = 120
13 | continuation_indent_size = 8
14 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/ui/feature/main/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.ui.feature.main
2 |
3 | import net.rafaeltoledo.social.ui.BaseViewModel
4 |
5 | class MainViewModel(private val string: String) : BaseViewModel() {
6 |
7 | fun getString() = string
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/debug/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/release/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/di/FirebaseModule.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.di
2 |
3 | import net.rafaeltoledo.social.data.auth.AuthManager
4 | import net.rafaeltoledo.social.data.firebase.FirebaseAuthManager
5 | import org.koin.dsl.module
6 |
7 | val firebaseModule = module {
8 |
9 | single { FirebaseAuthManager() }
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/data/auth/AuthManager.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.auth
2 |
3 | import net.rafaeltoledo.social.data.model.User
4 |
5 | interface AuthManager {
6 |
7 | suspend fun socialSignIn(token: String, provider: SocialProvider): User
8 |
9 | fun isUserLoggedIn(): Boolean
10 | }
11 |
12 | enum class SocialProvider {
13 | GOOGLE, FACEBOOK
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Sign in with Google
4 | Sign in with Facebook
5 |
6 | Failed to perform sign in
7 | Oops… something went wrong!
8 |
9 |
--------------------------------------------------------------------------------
/app/src/debug/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffab00
4 | #c67c00
5 | #ffdd4b
6 |
7 | #1de9b6
8 | #00b686
9 | #6effe8
10 |
11 |
--------------------------------------------------------------------------------
/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/release/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1de9b6
4 | #00b686
5 | #6effe8
6 |
7 | #ffab00
8 | #c67c00
9 | #ffdd4b
10 |
11 |
--------------------------------------------------------------------------------
/scripts/ftl-run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Run tests on test lab
4 | gcloud firebase test android run \
5 | --type instrumentation \
6 | --app debug-apk/app-debug.apk \
7 | --test test-apk/app-debug-androidTest.apk \
8 | --device model=Nexus6P,version=27,locale=en_US,orientation=portrait \
9 | --timeout 30m \
10 | --results-bucket cloud-test-social-app-development \
11 | --no-record-video \
12 | --no-performance-metrics \
13 | --use-orchestrator
14 |
--------------------------------------------------------------------------------
/scripts/ftl-setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if [ "$GCLOUD_SERVICE_KEY" = "" ]; then
4 | echo "GCLOUD_SERVICE_KEY env variable is empty. Exiting."
5 | exit 1
6 | fi
7 |
8 | # Export to secrets file
9 | echo $GCLOUD_SERVICE_KEY | base64 -di > client-secret.json
10 |
11 | # Set project ID
12 | gcloud config set project social-app-development
13 |
14 | # Auth account
15 | gcloud auth activate-service-account social-app-ftl@social-app-development.iam.gserviceaccount.com --key-file client-secret.json
16 |
17 | # Delete secret
18 | rm client-secret.json
19 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/di/AuthModule.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.di
2 |
3 | import net.rafaeltoledo.social.data.auth.DelegatedAuth
4 | import net.rafaeltoledo.social.data.auth.FacebookAuth
5 | import net.rafaeltoledo.social.data.auth.GoogleAuth
6 | import net.rafaeltoledo.social.data.auth.SocialProvider
7 | import org.koin.core.qualifier.named
8 | import org.koin.dsl.module
9 |
10 | val authModule = module {
11 | single(named(SocialProvider.GOOGLE.name)) { GoogleAuth() }
12 | single(named(SocialProvider.FACEBOOK.name)) { FacebookAuth() }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/data/auth/DelegatedAuth.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.auth
2 |
3 | import android.content.Intent
4 | import androidx.activity.ComponentActivity
5 |
6 | interface DelegatedAuth {
7 |
8 | fun build(activity: ComponentActivity): T
9 |
10 | fun signIn(activity: ComponentActivity)
11 |
12 | fun onResult(requestCode: Int, resultCode: Int, data: Intent?): AuthResult
13 |
14 | fun signOut(callback: (Status) -> Unit)
15 | }
16 |
17 | enum class Status { CANCELED, SUCCESS, FAILURE }
18 |
19 | data class AuthResult(val status: Status, val token: String? = null)
20 |
--------------------------------------------------------------------------------
/app/src/sharedTest/kotlin/net/rafaeltoledo/social/base/BaseTest.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.base
2 |
3 | import androidx.test.core.app.ApplicationProvider
4 | import androidx.test.espresso.intent.Intents
5 | import net.rafaeltoledo.social.TestSocialApp
6 | import org.junit.After
7 | import org.junit.Before
8 |
9 | abstract class BaseTest {
10 |
11 | protected val app: TestSocialApp by lazy { ApplicationProvider.getApplicationContext() as TestSocialApp }
12 |
13 | @Before
14 | fun baseSetUp() {
15 | Intents.init()
16 | }
17 |
18 | @After
19 | fun baseTearDown() {
20 | Intents.release()
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/app_logo_120dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/di/ViewModelModule.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.di
2 |
3 | import net.rafaeltoledo.social.data.auth.SocialProvider
4 | import net.rafaeltoledo.social.ui.feature.main.MainViewModel
5 | import net.rafaeltoledo.social.ui.feature.signin.SignInViewModel
6 | import org.koin.androidx.viewmodel.dsl.viewModel
7 | import org.koin.core.qualifier.named
8 | import org.koin.dsl.module
9 |
10 | val viewModelModule = module {
11 | viewModel { MainViewModel(get()) }
12 | viewModel {
13 | SignInViewModel(
14 | get(),
15 | get(named(SocialProvider.GOOGLE.name)),
16 | get(named(SocialProvider.FACEBOOK.name)),
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/kotlin/net/rafaeltoledo/social/SocialAppTestRunner.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social
2 |
3 | import android.app.Application
4 | import android.content.Context
5 | import androidx.test.runner.AndroidJUnitRunner
6 | import com.github.tmurakami.dexopener.DexOpener
7 |
8 | /**
9 | * A custom test runner that setups DexOpener and make all our classes non-final on runtime.
10 | * Also, it replaces the App instance with a custom one.
11 | */
12 | class SocialAppTestRunner : AndroidJUnitRunner() {
13 |
14 | override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
15 | DexOpener.install(this)
16 | return super.newApplication(cl, TestSocialApp::class.java.name, context)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/gradle/lint.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'io.gitlab.arturbosch.detekt'
2 |
3 | detekt {
4 | input = files('src/main/kotlin')
5 | }
6 |
7 | configurations {
8 | ktlint
9 | }
10 |
11 | dependencies {
12 | ktlint 'com.pinterest:ktlint:0.42.1'
13 | }
14 |
15 | task ktlint(type: JavaExec, group: 'verification') {
16 | description 'Check Kotlin code style.'
17 | classpath = configurations.ktlint
18 | main = 'com.pinterest.ktlint.Main'
19 | args 'src/**/*.kt'
20 | }
21 |
22 | check.dependsOn 'ktlint', 'detekt'
23 |
24 | task ktlintFormat(type: JavaExec, group: 'formatting') {
25 | description 'Fix Kotlin code style deviations.'
26 | classpath = configurations.ktlint
27 | main = 'com.pinterest.ktlint.Main'
28 | args '-F', 'src/**/*.kt'
29 | }
30 |
--------------------------------------------------------------------------------
/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/kotlin/net/rafaeltoledo/social/SocialApp.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social
2 |
3 | import android.app.Application
4 | import net.rafaeltoledo.social.di.authModule
5 | import net.rafaeltoledo.social.di.firebaseModule
6 | import net.rafaeltoledo.social.di.firstModule
7 | import net.rafaeltoledo.social.di.viewModelModule
8 | import org.koin.android.ext.koin.androidContext
9 | import org.koin.core.context.startKoin
10 |
11 | open class SocialApp : Application() {
12 |
13 | override fun onCreate() {
14 | super.onCreate()
15 | startKoin {
16 | androidContext(applicationContext)
17 |
18 | modules(
19 | listOf(
20 | viewModelModule,
21 | firstModule,
22 | authModule,
23 | firebaseModule
24 | )
25 | )
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/gradle/coverage.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'jacoco'
2 | apply plugin: 'com.github.kt3k.coveralls'
3 |
4 | jacoco.toolVersion versions.jacoco
5 |
6 | tasks.withType(Test) {
7 | jacoco.includeNoLocationClasses = true
8 | jacoco.excludes = ['jdk.internal.*']
9 | }
10 |
11 | def classes = fileTree(dir: "$buildDir/tmp/kotlin-classes/debug")
12 | def sources = files("$projectDir/src/main/kotlin")
13 | def report = "$buildDir/reports/jacoco/report.xml"
14 |
15 | task createCombinedCoverageReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
16 |
17 | sourceDirectories.setFrom(sources)
18 | classDirectories.setFrom(files(classes))
19 | executionData.setFrom(fileTree(dir: buildDir, includes: ['jacoco/testDebugUnitTest.exec']))
20 |
21 | reports {
22 | xml.enabled = true
23 | xml.destination file(report)
24 | html.enabled = true
25 | }
26 | }
27 |
28 | coveralls {
29 | sourceDirs = sources.flatten()
30 | jacocoReportPath = report
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/sharedTest/kotlin/net/rafaeltoledo/social/test/ui/MainActivityTest.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.test.ui
2 |
3 | import androidx.test.core.app.ActivityScenario
4 | import androidx.test.espresso.Espresso.onView
5 | import androidx.test.espresso.assertion.ViewAssertions.matches
6 | import androidx.test.espresso.matcher.ViewMatchers.withId
7 | import androidx.test.espresso.matcher.ViewMatchers.withText
8 | import androidx.test.ext.junit.runners.AndroidJUnit4
9 | import net.rafaeltoledo.social.R
10 | import net.rafaeltoledo.social.base.BaseTest
11 | import net.rafaeltoledo.social.ui.feature.main.MainActivity
12 | import org.junit.Test
13 | import org.junit.runner.RunWith
14 |
15 | @RunWith(AndroidJUnit4::class)
16 | class MainActivityTest : BaseTest() {
17 |
18 | @Test
19 | fun checkIfActivityIsSuccessfullyCreated() {
20 | // Arrange
21 | val newValue = "Test Social App"
22 | app.stringValue = newValue
23 |
24 | // Act - nothing to do
25 | ActivityScenario.launch(MainActivity::class.java)
26 |
27 | // Assert
28 | onView(withId(R.id.content)).check(matches(withText(newValue)))
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/sharedTest/kotlin/net/rafaeltoledo/social/data/auth/GoogleAuthTest.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.auth
2 |
3 | import androidx.test.core.app.ActivityScenario
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 | import com.google.common.truth.Truth.assertThat
6 | import net.rafaeltoledo.social.ui.feature.main.MainActivity
7 | import org.junit.Test
8 | import org.junit.runner.RunWith
9 |
10 | @RunWith(AndroidJUnit4::class)
11 | class GoogleAuthTest {
12 |
13 | @Test
14 | fun onBuild_createClientWithSuccess() {
15 | val auth = GoogleAuth()
16 | val activity = ActivityScenario.launch(MainActivity::class.java)
17 |
18 | activity.onActivity {
19 | val result = auth.build(it)
20 | assertThat(result).isNotNull()
21 | }
22 | }
23 |
24 | @Test
25 | fun onBuild_returnsSameInstanceWhenCalledTwice() {
26 | val auth = GoogleAuth()
27 | val activity = ActivityScenario.launch(MainActivity::class.java)
28 |
29 | activity.onActivity {
30 | val first = auth.build(it)
31 | val second = auth.build(it)
32 | assertThat(first).isSameInstanceAs(second)
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/ui/feature/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.ui.feature.main
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.widget.TextView
6 | import androidx.appcompat.app.AppCompatActivity
7 | import net.rafaeltoledo.social.R
8 | import net.rafaeltoledo.social.data.auth.AuthManager
9 | import net.rafaeltoledo.social.ui.feature.signin.SignInActivity
10 | import org.koin.android.ext.android.inject
11 | import org.koin.androidx.viewmodel.ext.android.viewModel
12 |
13 | class MainActivity : AppCompatActivity() {
14 |
15 | private val auth: AuthManager by inject()
16 | private val mainViewModel: MainViewModel by viewModel()
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | setContentView(
21 | TextView(this).apply {
22 | id = R.id.content
23 | text = mainViewModel.getString()
24 | }
25 | )
26 | }
27 |
28 | override fun onStart() {
29 | super.onStart()
30 | if (!auth.isUserLoggedIn()) {
31 | startActivity(Intent(this, SignInActivity::class.java))
32 | finish()
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/ui/BaseViewModel.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.ui
2 |
3 | import android.util.Log
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import kotlinx.coroutines.CoroutineScope
8 | import kotlinx.coroutines.Job
9 | import kotlinx.coroutines.launch
10 | import net.rafaeltoledo.social.R
11 | import java.io.IOException
12 |
13 | abstract class BaseViewModel : ViewModel() {
14 |
15 | val loading = MutableLiveData()
16 | val error = MutableLiveData()
17 |
18 | init {
19 | loading.postValue(false)
20 | }
21 |
22 | protected fun launchDataLoad(block: suspend CoroutineScope.() -> Unit): Job {
23 | return viewModelScope.launch {
24 | try {
25 | loading.postValue(true)
26 | block()
27 | } catch (error: IOException) {
28 | errorHandler(error)
29 | } finally {
30 | loading.postValue(false)
31 | }
32 | }
33 | }
34 |
35 | private val errorHandler = { e: Throwable ->
36 | Log.e("BaseViewModel", "Failed to execute", e)
37 | loading.postValue(false)
38 | error.postValue(R.string.error_default_message)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Social App
2 | ==========
3 |
4 | [](https://github.com/rafaeltoledo/social-app/actions)
5 | [](https://coveralls.io/github/rafaeltoledo/social-app?branch=develop)
6 | [](https://codebeat.co/projects/github-com-rafaeltoledo-social-app-develop)
7 | [](https://www.codacy.com/app/rafaeltoledo/social-app)
8 |
9 | License
10 | =======
11 |
12 | Copyright 2021 Rafael Toledo
13 |
14 | Licensed under the Apache License, Version 2.0 (the "License");
15 | you may not use this file except in compliance with the License.
16 | You may obtain a copy of the License at
17 |
18 | http://www.apache.org/licenses/LICENSE-2.0
19 |
20 | Unless required by applicable law or agreed to in writing, software
21 | distributed under the License is distributed on an "AS IS" BASIS,
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 | See the License for the specific language governing permissions and
24 | limitations under the License.
25 |
--------------------------------------------------------------------------------
/app/src/sharedTest/kotlin/net/rafaeltoledo/social/data/auth/FacebookAuthTest.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.auth
2 |
3 | import androidx.test.core.app.ActivityScenario
4 | import androidx.test.core.app.ApplicationProvider
5 | import androidx.test.ext.junit.runners.AndroidJUnit4
6 | import com.facebook.FacebookSdk
7 | import com.google.common.truth.Truth.assertThat
8 | import net.rafaeltoledo.social.ui.feature.main.MainActivity
9 | import org.junit.Before
10 | import org.junit.Test
11 | import org.junit.runner.RunWith
12 |
13 | @RunWith(AndroidJUnit4::class)
14 | class FacebookAuthTest {
15 |
16 | @Suppress("DEPRECATION")
17 | @Before
18 | fun setup() {
19 | FacebookSdk.sdkInitialize(ApplicationProvider.getApplicationContext())
20 | }
21 |
22 | @Test
23 | fun onBuild_createClientWithSuccess() {
24 | val auth = FacebookAuth()
25 | val activity = ActivityScenario.launch(MainActivity::class.java)
26 |
27 | activity.onActivity {
28 | val result = auth.build(it)
29 | assertThat(result).isNotNull()
30 | }
31 | }
32 |
33 | @Test
34 | fun onBuild_returnsSameInstanceWhenCalledTwice() {
35 | val auth = FacebookAuth()
36 | val activity = ActivityScenario.launch(MainActivity::class.java)
37 |
38 | activity.onActivity {
39 | val first = auth.build(it)
40 | val second = auth.build(it)
41 | assertThat(first).isSameInstanceAs(second)
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/ui/feature/signin/SignInActivity.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.ui.feature.signin
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.databinding.DataBindingUtil
7 | import com.google.android.material.snackbar.Snackbar
8 | import net.rafaeltoledo.social.R
9 | import net.rafaeltoledo.social.databinding.ActivitySignInBinding
10 | import net.rafaeltoledo.social.ui.feature.main.MainActivity
11 | import org.koin.androidx.viewmodel.ext.android.viewModel
12 |
13 | class SignInActivity : AppCompatActivity() {
14 |
15 | private lateinit var binding: ActivitySignInBinding
16 | private val signInViewModel: SignInViewModel by viewModel()
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | binding = DataBindingUtil.setContentView(this, R.layout.activity_sign_in)
21 |
22 | binding.lifecycleOwner = this
23 | binding.viewModel = signInViewModel
24 |
25 | observeAuthClient()
26 | observeViewState()
27 | }
28 |
29 | private fun observeAuthClient() {
30 | signInViewModel.authClient.observe(this) {
31 | it.signIn(this)
32 | }
33 |
34 | signInViewModel.user.observe(this) {
35 | startActivity(Intent(this, MainActivity::class.java))
36 | finish()
37 | }
38 | }
39 |
40 | private fun observeViewState() {
41 | signInViewModel.error.observe(this) {
42 | Snackbar.make(binding.root, it, Snackbar.LENGTH_LONG).show()
43 | }
44 | }
45 |
46 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
47 | super.onActivityResult(requestCode, resultCode, data)
48 | signInViewModel.onResult(requestCode, resultCode, data)
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/data/firebase/FirebaseAuthManager.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.firebase
2 |
3 | import com.google.android.gms.tasks.Task
4 | import com.google.firebase.auth.AuthResult
5 | import com.google.firebase.auth.FacebookAuthProvider
6 | import com.google.firebase.auth.GoogleAuthProvider
7 | import com.google.firebase.auth.ktx.auth
8 | import com.google.firebase.ktx.Firebase
9 | import net.rafaeltoledo.social.data.auth.AuthManager
10 | import net.rafaeltoledo.social.data.auth.SocialProvider
11 | import net.rafaeltoledo.social.data.model.User
12 | import kotlin.coroutines.Continuation
13 | import kotlin.coroutines.resume
14 | import kotlin.coroutines.resumeWithException
15 | import kotlin.coroutines.suspendCoroutine
16 |
17 | class FirebaseAuthManager : AuthManager {
18 |
19 | override suspend fun socialSignIn(token: String, provider: SocialProvider): User =
20 | suspendCoroutine {
21 | Firebase.auth.signInWithCredential(
22 | when (provider) {
23 | SocialProvider.GOOGLE -> GoogleAuthProvider.getCredential(token, null)
24 | SocialProvider.FACEBOOK -> FacebookAuthProvider.getCredential(token)
25 | }
26 | ).addOnCompleteListener { task ->
27 | handleResult(task, it)
28 | }
29 | }
30 |
31 | private fun handleResult(task: Task, continuation: Continuation) {
32 | if (task.isSuccessful.not()) {
33 | continuation.resumeWithException(
34 | task.exception ?: Exception("No exception was thrown by Firebase")
35 | )
36 | } else {
37 | continuation.resume(
38 | User(task.result?.user?.uid ?: throw IllegalStateException("Expected a user ID"))
39 | )
40 | }
41 | }
42 |
43 | override fun isUserLoggedIn() = Firebase.auth.currentUser != null
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
26 |
27 |
32 |
33 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/data/auth/GoogleAuth.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.auth
2 |
3 | import android.content.Intent
4 | import android.util.Log
5 | import androidx.activity.ComponentActivity
6 | import com.google.android.gms.auth.api.signin.GoogleSignIn
7 | import com.google.android.gms.auth.api.signin.GoogleSignInClient
8 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions
9 | import com.google.android.gms.common.api.ApiException
10 | import net.rafaeltoledo.social.BuildConfig
11 |
12 | /**
13 | * Authenticates a user using Google Auth.
14 | */
15 | class GoogleAuth : DelegatedAuth {
16 |
17 | private var client: GoogleSignInClient? = null
18 |
19 | override fun build(activity: ComponentActivity): T {
20 | if (client == null) {
21 | val options = GoogleSignInOptions.Builder()
22 | .requestIdToken(BuildConfig.GOOGLE_REQUEST_ID_TOKEN)
23 | .requestEmail()
24 | .build()
25 |
26 | client = GoogleSignIn.getClient(activity, options)
27 | }
28 |
29 | @Suppress("UNCHECKED_CAST") return this as T
30 | }
31 |
32 | override fun signIn(activity: ComponentActivity) {
33 | activity.startActivityForResult(client?.signInIntent, RESULT_SIGN_IN)
34 | }
35 |
36 | override fun onResult(requestCode: Int, resultCode: Int, data: Intent?): AuthResult {
37 | val task = GoogleSignIn.getSignedInAccountFromIntent(data)
38 | return try {
39 | val account = task.getResult(ApiException::class.java)
40 | AuthResult(Status.SUCCESS, account!!.idToken)
41 | } catch (e: ApiException) {
42 | Log.w("Google Auth", "Failed to retrieve token", e)
43 | AuthResult(Status.FAILURE)
44 | }
45 | }
46 |
47 | override fun signOut(callback: (Status) -> Unit) {
48 | client?.signOut()?.addOnCompleteListener { callback(if (it.isSuccessful) Status.SUCCESS else Status.FAILURE) }
49 | }
50 |
51 | companion object {
52 | const val RESULT_SIGN_IN = 1441
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/sharedTest/kotlin/net/rafaeltoledo/social/TestSetup.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social
2 |
3 | import com.facebook.FacebookSdk
4 | import net.rafaeltoledo.social.data.auth.AuthManager
5 | import net.rafaeltoledo.social.data.auth.DelegatedAuth
6 | import net.rafaeltoledo.social.data.auth.FacebookAuth
7 | import net.rafaeltoledo.social.data.auth.GoogleAuth
8 | import net.rafaeltoledo.social.data.auth.SocialProvider
9 | import net.rafaeltoledo.social.data.model.User
10 | import org.koin.core.context.loadKoinModules
11 | import org.koin.core.context.stopKoin
12 | import org.koin.core.qualifier.named
13 | import org.koin.dsl.module
14 |
15 | class TestSocialApp : SocialApp() {
16 |
17 | override fun onCreate() {
18 | super.onCreate()
19 | FacebookSdk.setAutoInitEnabled(false)
20 | loadKoinModules(
21 | listOf(
22 | module {
23 | single(named(SocialProvider.GOOGLE.name)) { googleAuth }
24 | single(named(SocialProvider.FACEBOOK.name)) { fbAuth }
25 | single { authManager }
26 | single { stringValue }
27 | }
28 | )
29 | )
30 | }
31 |
32 | override fun onTerminate() {
33 | stopKoin()
34 | super.onTerminate()
35 | }
36 |
37 | var googleAuth: DelegatedAuth = GoogleAuth()
38 | set(value) {
39 | loadKoinModules(module { single(named(SocialProvider.GOOGLE.name)) { value } })
40 | field = value
41 | }
42 |
43 | var fbAuth: DelegatedAuth = FacebookAuth()
44 | set(value) {
45 | loadKoinModules(module { single(named(SocialProvider.FACEBOOK.name)) { value } })
46 | field = value
47 | }
48 |
49 | var authManager: AuthManager = noOpAuthManager
50 | set(value) {
51 | loadKoinModules(module { single { value } })
52 | field = value
53 | }
54 |
55 | var stringValue: String = "Social App"
56 | set(value) {
57 | loadKoinModules(module { single { value } })
58 | field = value
59 | }
60 | }
61 |
62 | val noOpAuthManager = object : AuthManager {
63 |
64 | override suspend fun socialSignIn(token: String, provider: SocialProvider) =
65 | User("0")
66 |
67 | override fun isUserLoggedIn() = true
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/data/auth/FacebookAuth.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.data.auth
2 |
3 | import android.content.Intent
4 | import android.util.Log
5 | import androidx.activity.ComponentActivity
6 | import com.facebook.CallbackManager
7 | import com.facebook.FacebookCallback
8 | import com.facebook.FacebookException
9 | import com.facebook.login.LoginManager
10 | import com.facebook.login.LoginResult
11 | import java.util.concurrent.CountDownLatch
12 |
13 | /**
14 | * Authenticates a user using the Facebook Login SDK.
15 | */
16 | class FacebookAuth : DelegatedAuth {
17 |
18 | private lateinit var callbackManager: CallbackManager
19 | private lateinit var status: AuthResult
20 | private lateinit var countDownLatch: CountDownLatch
21 |
22 | private val callback = object : FacebookCallback {
23 | override fun onSuccess(result: LoginResult) {
24 | status = AuthResult(Status.SUCCESS, result.accessToken.token)
25 | countDownLatch.countDown()
26 | }
27 |
28 | override fun onCancel() {
29 | status = AuthResult(Status.CANCELED)
30 | countDownLatch.countDown()
31 | }
32 |
33 | override fun onError(error: FacebookException) {
34 | Log.e("FacebookAuth", "Could not complete Facebook signin", error)
35 | status = AuthResult(Status.FAILURE)
36 | countDownLatch.countDown()
37 | }
38 | }
39 |
40 | override fun build(activity: ComponentActivity): T {
41 | callbackManager = CallbackManager.Factory.create()
42 | LoginManager.getInstance().registerCallback(callbackManager, callback)
43 | @Suppress("UNCHECKED_CAST") return this as T
44 | }
45 |
46 | override fun signIn(activity: ComponentActivity) {
47 | countDownLatch = CountDownLatch(1)
48 | LoginManager.getInstance().logInWithReadPermissions(activity, listOf("email", "public_profile"))
49 | }
50 |
51 | override fun onResult(requestCode: Int, resultCode: Int, data: Intent?): AuthResult {
52 | callbackManager.onActivityResult(requestCode, resultCode, data)
53 | countDownLatch.await()
54 | return status
55 | }
56 |
57 | override fun signOut(callback: (Status) -> Unit) {
58 | LoginManager.getInstance().logOut()
59 | callback(Status.SUCCESS)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/net/rafaeltoledo/social/ui/feature/signin/SignInViewModel.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.ui.feature.signin
2 |
3 | import android.content.Intent
4 | import androidx.activity.ComponentActivity
5 | import androidx.lifecycle.MutableLiveData
6 | import net.rafaeltoledo.social.R
7 | import net.rafaeltoledo.social.data.auth.AuthManager
8 | import net.rafaeltoledo.social.data.auth.DelegatedAuth
9 | import net.rafaeltoledo.social.data.auth.FacebookAuth
10 | import net.rafaeltoledo.social.data.auth.GoogleAuth
11 | import net.rafaeltoledo.social.data.auth.SocialProvider
12 | import net.rafaeltoledo.social.data.auth.Status
13 | import net.rafaeltoledo.social.data.model.User
14 | import net.rafaeltoledo.social.ui.BaseViewModel
15 |
16 | /**
17 | * Handles UI state and orchestrates AuthManager implementations
18 | * based on user selection.
19 | */
20 | class SignInViewModel(
21 | private val auth: AuthManager,
22 | private val googleAuth: DelegatedAuth,
23 | private val facebookAuth: DelegatedAuth
24 | ) : BaseViewModel() {
25 |
26 | val authClient = MutableLiveData()
27 | val user = MutableLiveData()
28 |
29 | /**
30 | * Triggers the auth flow with Google
31 | * @param activity the Activity object needed for lifecycle
32 | */
33 | fun googleSignIn(activity: ComponentActivity) {
34 | loading.value = true
35 |
36 | authClient.value = googleAuth.build(activity)
37 | }
38 |
39 | /**
40 | * Triggers the auth flow with Facebook
41 | * @param activity the Activity object needed for lifecycle
42 | */
43 | fun facebookSignIn(activity: ComponentActivity) {
44 | loading.value = true
45 |
46 | authClient.value = facebookAuth.build(activity)
47 | }
48 |
49 | /**
50 | * Handles the result returned by the native auth SDKs
51 | */
52 | fun onResult(requestCode: Int, resultCode: Int, data: Intent?) {
53 | launchDataLoad {
54 | val result = authClient.value?.onResult(requestCode, resultCode, data)
55 | if (result?.status == Status.SUCCESS) {
56 | user.postValue(
57 | auth.socialSignIn(
58 | token = result.token ?: throw IllegalStateException("Empty token"),
59 | provider = authClient.value?.provider() ?: throw IllegalStateException("Empty provider")
60 | )
61 | )
62 | } else {
63 | error.postValue(R.string.error_sign_in)
64 | }
65 | }
66 | }
67 |
68 | private fun DelegatedAuth.provider() = when (this) {
69 | is GoogleAuth -> SocialProvider.GOOGLE
70 | is FacebookAuth -> SocialProvider.FACEBOOK
71 | else -> throw IllegalArgumentException("unknown social provider")
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sign_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
14 |
15 |
16 |
20 |
21 |
32 |
33 |
44 |
45 |
55 |
56 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | env:
9 | JAVA_TOOL_OPTIONS: "-Xmx5120m -XX:+UnlockExperimentalVMOptions"
10 | GRADLE_OPTS: "-Xms1g -Xmx5120m -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=2 -Dkotlin.incremental=false -Dkotlin.compiler.execution.strategy=in-process"
11 |
12 | RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
13 | RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
14 | RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }}
15 |
16 | GOOGLE_REQUEST_ID_TOKEN_DEVELOPMENT: ${{ secrets.GOOGLE_REQUEST_ID_TOKEN_DEVELOPMENT }}
17 | GOOGLE_REQUEST_ID_TOKEN_RELEASE: ${{ secrets.GOOGLE_REQUEST_ID_TOKEN_RELEASE }}
18 |
19 | FB_LOGIN_PROTOCOL_SCHEME_DEVELOPMENT: ${{ secrets.FB_LOGIN_PROTOCOL_SCHEME_DEVELOPMENT }}
20 | FB_APP_ID_DEVELOPMENT: ${{ secrets.FB_APP_ID_DEVELOPMENT }}
21 | FB_LOGIN_PROTOCOL_SCHEME_RELEASE: ${{ secrets.FB_LOGIN_PROTOCOL_SCHEME_RELEASE }}
22 | FB_APP_ID_RELEASE: ${{ secrets.FB_APP_ID_RELEASE }}
23 |
24 | steps:
25 | - name: Checkout
26 | uses: actions/checkout@v2
27 |
28 | - name: Gradle Wrapper Validation
29 | uses: gradle/wrapper-validation-action@v1
30 |
31 | - name: Install JDK
32 | uses: actions/setup-java@v2
33 | with:
34 | distribution: 'temurin'
35 | java-version: '11'
36 | cache: 'gradle'
37 |
38 | - name: Decrypt release key
39 | run: openssl aes-256-cbc -d -in distribution/release.keystore-cipher -out distribution/release.keystore -md sha256 -k ${{ secrets.CIPHER_DECRYPT_KEY }}
40 |
41 | - name: Setup Google Services JSON
42 | run: |
43 | mkdir -p app/src/debug/ && touch app/src/debug/google-services.json
44 | echo '${{ secrets.JSON_FIREBASE_DEVELOPMENT }}' >> "app/src/debug/google-services.json"
45 | mkdir -p app/src/release/ && touch app/src/release/google-services.json
46 | echo '${{ secrets.JSON_FIREBASE_RELEASE }}' >> "app/src/release/google-services.json"
47 |
48 | - name: Download dependencies
49 | run: ./gradlew help --stacktrace
50 |
51 | - name: Run Linters
52 | run: ./gradlew check --stacktrace
53 |
54 | - name: Run Tests and generate Code Coverage
55 | run: ./gradlew createCombinedCoverageReport --stacktrace
56 |
57 | - name: Upload test reports
58 | if: always()
59 | uses: actions/upload-artifact@v2
60 | with:
61 | name: test-reports
62 | path: ./app/build/reports
63 |
64 | - name: Upload code coverage data
65 | run: ./gradlew coveralls --stacktrace
66 | env:
67 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
68 |
69 | - name: Build
70 | run: ./gradlew assemble bundle assembleAndroidTest --stacktrace
71 |
72 | - name: Upload Test APK
73 | uses: actions/upload-artifact@v2
74 | with:
75 | name: test-apk
76 | path: ./app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
77 |
78 | - name: Upload Debug APK
79 | uses: actions/upload-artifact@v2
80 | with:
81 | name: debug-apk
82 | path: ./app/build/outputs/apk/debug/app-debug.apk
83 |
84 | - name: Upload APK
85 | uses: actions/upload-artifact@v2
86 | with:
87 | name: apk
88 | path: ./app/build/outputs/apk/release/app-release.apk
89 |
90 | - name: Upload Bundle
91 | uses: actions/upload-artifact@v2
92 | with:
93 | name: bundle
94 | path: ./app/build/outputs/bundle/release/app-release.aab
95 |
96 | test_instrumented:
97 | needs: build
98 | runs-on: ubuntu-latest
99 | env:
100 | GCLOUD_SERVICE_KEY: ${{ secrets.GCLOUD_SERVICE_KEY }}
101 |
102 | steps:
103 | - name: Checkout
104 | uses: actions/checkout@v2
105 |
106 | - name: Download app APK
107 | uses: actions/download-artifact@v1
108 | with:
109 | name: debug-apk
110 |
111 | - name: Download app APK
112 | uses: actions/download-artifact@v1
113 | with:
114 | name: test-apk
115 |
116 | - name: Login to Google Cloud
117 | uses: google-github-actions/setup-gcloud@master
118 |
119 | - name: Setup Google Cloud auth
120 | run: scripts/ftl-setup.sh
121 |
122 | - name: Run tests on Firebase Test Lab
123 | run: scripts/ftl-run-tests.sh
124 |
125 | - name: Download results
126 | if: always()
127 | run: scripts/ftl-download-results.sh firebase_test_results
128 |
129 | - name: Upload Test Results
130 | uses: actions/upload-artifact@v2
131 | with:
132 | name: firebase-test-results
133 | path: ./firebase_test_results
134 |
--------------------------------------------------------------------------------
/app/src/sharedTest/kotlin/net/rafaeltoledo/social/test/ui/SignInActivityTest.kt:
--------------------------------------------------------------------------------
1 | package net.rafaeltoledo.social.test.ui
2 |
3 | import android.app.Activity
4 | import android.app.Instrumentation
5 | import android.content.Intent
6 | import androidx.test.core.app.ActivityScenario
7 | import androidx.test.espresso.Espresso.onView
8 | import androidx.test.espresso.action.ViewActions.click
9 | import androidx.test.espresso.assertion.ViewAssertions.matches
10 | import androidx.test.espresso.intent.Intents.getIntents
11 | import androidx.test.espresso.intent.Intents.intending
12 | import androidx.test.espresso.intent.matcher.BundleMatchers.hasEntry
13 | import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtras
14 | import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
15 | import androidx.test.espresso.matcher.ViewMatchers.withId
16 | import androidx.test.espresso.matcher.ViewMatchers.withText
17 | import androidx.test.ext.junit.runners.AndroidJUnit4
18 | import androidx.test.ext.truth.content.IntentSubject.assertThat
19 | import io.mockk.coEvery
20 | import io.mockk.coVerify
21 | import io.mockk.every
22 | import io.mockk.mockk
23 | import io.mockk.verify
24 | import net.rafaeltoledo.social.R
25 | import net.rafaeltoledo.social.base.BaseTest
26 | import net.rafaeltoledo.social.data.auth.AuthManager
27 | import net.rafaeltoledo.social.data.auth.AuthResult
28 | import net.rafaeltoledo.social.data.auth.DelegatedAuth
29 | import net.rafaeltoledo.social.data.auth.GoogleAuth
30 | import net.rafaeltoledo.social.data.auth.SocialProvider
31 | import net.rafaeltoledo.social.data.auth.Status
32 | import net.rafaeltoledo.social.data.model.User
33 | import net.rafaeltoledo.social.ui.feature.main.MainActivity
34 | import net.rafaeltoledo.social.ui.feature.signin.SignInActivity
35 | import org.hamcrest.Matchers.equalTo
36 | import org.junit.Before
37 | import org.junit.Test
38 | import org.junit.runner.RunWith
39 |
40 | @RunWith(AndroidJUnit4::class)
41 | class SignInActivityTest : BaseTest() {
42 |
43 | lateinit var delegatedAuth: DelegatedAuth
44 | lateinit var authManager: AuthManager
45 |
46 | @Before
47 | fun setup() {
48 | authManager = mockk()
49 | app.authManager = authManager
50 |
51 | delegatedAuth = mockk()
52 | app.googleAuth = delegatedAuth
53 |
54 | every { delegatedAuth.build(any()) } returns delegatedAuth
55 | }
56 |
57 | @Test
58 | fun shouldSignInWhenSuccessGoogleLogin() {
59 | // Arrange
60 | every { delegatedAuth.signIn(any()) } answers {
61 | (it.invocation.args[0] as Activity).startActivityForResult(
62 | Intent().putExtra("key", "value"),
63 | 0
64 | )
65 | }
66 | every { delegatedAuth.onResult(any(), any(), any()) } returns AuthResult(
67 | Status.SUCCESS,
68 | token = "ok"
69 | )
70 |
71 | coEvery { authManager.socialSignIn(any(), any()) } returns User("1")
72 | every { authManager.isUserLoggedIn() } returns true
73 |
74 | ActivityScenario.launch(SignInActivity::class.java)
75 |
76 | intending(hasExtras(hasEntry(equalTo("key"), equalTo("value"))))
77 | .respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
78 |
79 | // Act
80 | onView(withId(R.id.button_google_sign_in)).perform(click())
81 |
82 | // Assert
83 | assertThat(getIntents().last()).hasComponentClass(MainActivity::class.java)
84 |
85 | verify(exactly = 1) { delegatedAuth.signIn(ofType(SignInActivity::class)) }
86 | coVerify(exactly = 1) { authManager.socialSignIn("ok", SocialProvider.GOOGLE) }
87 | }
88 |
89 | @Test
90 | fun shouldDisplayErrorOnFailedGoogleLogin() {
91 | // Arrange
92 | every { delegatedAuth.signIn(any()) } answers {
93 | (it.invocation.args[0] as Activity).startActivityForResult(
94 | Intent().putExtra("key", "value"),
95 | 0
96 | )
97 | }
98 | every { delegatedAuth.onResult(any(), any(), any()) } returns AuthResult(Status.FAILURE)
99 |
100 | ActivityScenario.launch(SignInActivity::class.java)
101 | intending(hasExtras(hasEntry(equalTo("key"), equalTo("value"))))
102 | .respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
103 |
104 | // Act
105 | onView(withId(R.id.button_google_sign_in)).perform(click())
106 |
107 | // Assert
108 | onView(withText(R.string.error_sign_in)).check(matches(isDisplayed()))
109 |
110 | verify(exactly = 1) { delegatedAuth.signIn(ofType(SignInActivity::class)) }
111 | coVerify(exactly = 0) { authManager.socialSignIn(any(), any()) }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.github.kt3k.coveralls' version '2.12.0'
3 | }
4 |
5 | apply plugin: 'com.android.application'
6 | apply plugin: 'org.jetbrains.kotlin.android'
7 | apply plugin: 'org.jetbrains.kotlin.kapt'
8 |
9 | apply from: "$rootDir/gradle/coverage.gradle"
10 | apply from: "$rootDir/gradle/lint.gradle"
11 |
12 | android {
13 | compileSdkVersion 31
14 | buildToolsVersion '31.0.0'
15 |
16 | defaultConfig {
17 | applicationId 'net.rafaeltoledo.social'
18 | minSdkVersion 21
19 | targetSdkVersion 31
20 | versionCode 1
21 | versionName '1.0.0'
22 |
23 | vectorDrawables.useSupportLibrary = true
24 |
25 | testInstrumentationRunner 'net.rafaeltoledo.social.SocialAppTestRunner'
26 | }
27 |
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 |
33 | kotlinOptions {
34 | jvmTarget = '1.8'
35 | }
36 |
37 | buildFeatures.dataBinding true
38 |
39 | sourceSets {
40 | final sharedTestDir = 'src/sharedTest/kotlin'
41 |
42 | main.java.srcDirs += 'src/main/kotlin'
43 | test.java.srcDirs += ['src/test/kotlin', sharedTestDir]
44 | androidTest.java.srcDirs += ['src/androidTest/kotlin', sharedTestDir]
45 | }
46 |
47 | signingConfigs {
48 | debug {
49 | storeFile file("$rootDir/distribution/debug.keystore")
50 | }
51 |
52 | release {
53 | storeFile file("$rootDir/distribution/release.keystore")
54 | storePassword System.env.RELEASE_STORE_PASSWORD
55 | keyAlias System.env.RELEASE_KEY_ALIAS
56 | keyPassword System.env.RELEASE_KEY_PASSWORD
57 | }
58 | }
59 |
60 | buildTypes {
61 | debug {
62 | buildConfigField 'String', 'GOOGLE_REQUEST_ID_TOKEN', "\"$System.env.GOOGLE_REQUEST_ID_TOKEN_DEVELOPMENT\""
63 |
64 | resValue 'string', 'fb_app_id', "\"$System.env.FB_APP_ID_DEVELOPMENT\""
65 | resValue 'string', 'fb_login_protocol_scheme', "\"$System.env.FB_LOGIN_PROTOCOL_SCHEME_DEVELOPMENT\""
66 |
67 | multiDexEnabled true
68 |
69 | applicationIdSuffix '.dev'
70 | signingConfig signingConfigs.debug
71 | }
72 |
73 | release {
74 | buildConfigField 'String', 'GOOGLE_REQUEST_ID_TOKEN', "\"$System.env.GOOGLE_REQUEST_ID_TOKEN_RELEASE\""
75 |
76 | resValue 'string', 'fb_app_id', "\"$System.env.FB_APP_ID_RELEASE\""
77 | resValue 'string', 'fb_login_protocol_scheme', "\"$System.env.FB_LOGIN_PROTOCOL_SCHEME_RELEASE\""
78 |
79 | signingConfig signingConfigs.release
80 | minifyEnabled true
81 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
82 | }
83 | }
84 |
85 | testOptions {
86 | execution 'ANDROIDX_TEST_ORCHESTRATOR'
87 | animationsDisabled true
88 |
89 | unitTests.includeAndroidResources true
90 | }
91 | }
92 |
93 | def bothTestImplementation(String dependency) {
94 | project.dependencies.add('testImplementation', dependency)
95 | project.dependencies.add('androidTestImplementation', dependency)
96 | }
97 |
98 | dependencies {
99 | implementation 'androidx.appcompat:appcompat:1.3.1'
100 | implementation 'com.google.android.material:material:1.4.0'
101 |
102 | implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
103 |
104 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$versions.androidx.lifecycle"
105 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:$versions.androidx.lifecycle"
106 |
107 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
108 |
109 | implementation 'com.google.firebase:firebase-core:20.0.0'
110 | implementation 'com.google.firebase:firebase-auth-ktx:21.0.1'
111 |
112 | implementation 'com.google.android.gms:play-services-auth:19.2.0'
113 | implementation 'com.facebook.android:facebook-login:12.0.1'
114 |
115 | implementation "io.insert-koin:koin-android:$versions.koin"
116 |
117 | bothTestImplementation "androidx.test:core-ktx:$versions.androidx.testcore"
118 | bothTestImplementation 'androidx.test.ext:junit-ktx:1.1.4-alpha03'
119 | bothTestImplementation 'androidx.test.ext:truth:1.5.0-alpha03'
120 | bothTestImplementation "androidx.test:runner:$versions.androidx.testcore"
121 | bothTestImplementation "androidx.test:rules:$versions.androidx.testcore"
122 | bothTestImplementation "androidx.test.espresso:espresso-core:$versions.androidx.espresso"
123 | bothTestImplementation "androidx.test.espresso:espresso-intents:$versions.androidx.espresso"
124 | bothTestImplementation 'com.google.truth:truth:1.1.3'
125 | bothTestImplementation "io.insert-koin:koin-test:$versions.koin"
126 | bothTestImplementation "androidx.arch.core:core-testing:$versions.androidx.archcore"
127 |
128 | testImplementation 'org.robolectric:robolectric:4.6.1'
129 | testImplementation "io.mockk:mockk:$versions.mockk"
130 |
131 | androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5'
132 | androidTestImplementation "io.mockk:mockk-android:$versions.mockk"
133 |
134 | androidTestUtil "androidx.test:orchestrator:$versions.androidx.testcore"
135 | }
136 |
137 | apply plugin: 'com.google.gms.google-services'
138 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------