-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Rifzzu/main
update 1
- Loading branch information
Showing
67 changed files
with
2,103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
id 'com.google.gms.google-services' | ||
} | ||
|
||
android { | ||
namespace 'com.example.buzzwiseapp' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.example.buzzwiseapp" | ||
minSdk 24 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
buildFeatures { | ||
viewBinding true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.7.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' | ||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' | ||
implementation 'androidx.annotation:annotation:1.3.0' | ||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' | ||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' | ||
implementation 'com.google.firebase:firebase-auth-ktx:21.0.3' | ||
implementation 'com.google.firebase:firebase-auth:21.0.3' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
|
||
//Library Google GMS | ||
implementation 'com.google.android.gms:play-services-auth:20.1.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/example/buzzwiseapp/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.buzzwiseapp | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.buzzwiseapp", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.BuzzWiseApp" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".ui.auth.RegisterActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".ui.auth.LoginActivity" | ||
android:exported="false"> | ||
|
||
</activity> | ||
<activity | ||
android:name=".ui.SplashActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".ui.main.MainActivity" | ||
android:exported="false" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.BuzzWiseApp" /> | ||
<activity | ||
android:name=".ui.auth.AuthActivity" | ||
android:exported="true"> | ||
|
||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/example/buzzwiseapp/ui/SplashActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.buzzwiseapp.ui | ||
|
||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import com.example.buzzwiseapp.R | ||
import com.example.buzzwiseapp.databinding.ActivitySplashBinding | ||
import com.example.buzzwiseapp.ui.auth.LoginActivity | ||
import com.google.firebase.auth.FirebaseAuth | ||
import com.google.firebase.auth.ktx.auth | ||
import com.google.firebase.ktx.Firebase | ||
|
||
class SplashActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivitySplashBinding | ||
private lateinit var auth: FirebaseAuth | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivitySplashBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
auth = Firebase.auth | ||
val firebaseUser = auth.currentUser | ||
|
||
if (firebaseUser != null) { | ||
// Not signed in, launch the Login activity | ||
startActivity(Intent(this, LoginActivity::class.java)) | ||
finish() | ||
return | ||
} | ||
|
||
binding.elevatedButton.setOnClickListener{ | ||
val intent = Intent(this, LoginActivity::class.java) | ||
startActivity(intent) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/example/buzzwiseapp/ui/auth/AuthActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.buzzwiseapp.ui.auth | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import androidx.navigation.findNavController | ||
import androidx.navigation.ui.AppBarConfiguration | ||
import androidx.navigation.ui.navigateUp | ||
import androidx.navigation.ui.setupActionBarWithNavController | ||
import com.example.buzzwiseapp.R | ||
import com.example.buzzwiseapp.databinding.ActivityAuthBinding | ||
|
||
class AuthActivity : AppCompatActivity() { | ||
|
||
private lateinit var appBarConfiguration: AppBarConfiguration | ||
private lateinit var binding: ActivityAuthBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = ActivityAuthBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
setSupportActionBar(binding.toolbar) | ||
|
||
val navController = findNavController(R.id.container_auth) | ||
appBarConfiguration = AppBarConfiguration(navController.graph) | ||
setupActionBarWithNavController(navController, appBarConfiguration) | ||
|
||
} | ||
|
||
override fun onSupportNavigateUp(): Boolean { | ||
val navController = findNavController(R.id.container_auth) | ||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
app/src/main/java/com/example/buzzwiseapp/ui/auth/LoginActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.example.buzzwiseapp.ui.auth | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import com.example.buzzwiseapp.R | ||
import com.example.buzzwiseapp.databinding.ActivityLoginBinding | ||
import com.example.buzzwiseapp.ui.main.MainActivity | ||
import com.google.android.gms.auth.api.signin.GoogleSignIn | ||
import com.google.android.gms.auth.api.signin.GoogleSignInClient | ||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions | ||
import com.google.android.gms.common.api.ApiException | ||
import com.google.firebase.auth.FirebaseAuth | ||
import com.google.firebase.auth.FirebaseUser | ||
import com.google.firebase.auth.GoogleAuthProvider | ||
import com.google.firebase.auth.ktx.auth | ||
import com.google.firebase.ktx.Firebase | ||
|
||
class LoginActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityLoginBinding | ||
private lateinit var googleSignInClient: GoogleSignInClient | ||
private lateinit var auth: FirebaseAuth | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityLoginBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
supportActionBar?.hide() | ||
|
||
binding.buttonLogin.setOnClickListener{ | ||
Intent(this, MainActivity::class.java).also { intent -> | ||
startActivity(intent) | ||
finish() | ||
} | ||
} | ||
|
||
binding.buttonToRegister.setOnClickListener { | ||
val intent = Intent(this@LoginActivity, RegisterActivity::class.java) | ||
startActivity(intent) | ||
} | ||
|
||
binding.signInButton.setOnClickListener{ | ||
signIn() | ||
} | ||
|
||
// Configure Google Sign In | ||
val gso = GoogleSignInOptions | ||
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | ||
.requestIdToken(getString(R.string.default_web_client_id)) | ||
.requestEmail() | ||
.build() | ||
googleSignInClient = GoogleSignIn.getClient(this, gso) | ||
// Initialize Firebase Auth | ||
auth = Firebase.auth | ||
} | ||
|
||
private fun signIn() { | ||
val signInIntent = googleSignInClient.signInIntent | ||
resultLauncher.launch(signInIntent) | ||
} | ||
|
||
private var resultLauncher = registerForActivityResult( | ||
ActivityResultContracts.StartActivityForResult() | ||
) { result -> | ||
if (result.resultCode == Activity.RESULT_OK) { | ||
val task = GoogleSignIn.getSignedInAccountFromIntent(result.data) | ||
try { | ||
// Google Sign In was successful, authenticate with Firebase | ||
val account = task.getResult(ApiException::class.java)!! | ||
Log.d(TAG, "firebaseAuthWithGoogle:" + account.id) | ||
firebaseAuthWithGoogle(account.idToken!!) | ||
} catch (e: ApiException) { | ||
// Google Sign In failed, update UI appropriately | ||
Log.w(TAG, "Google sign in failed", e) | ||
} | ||
} | ||
} | ||
|
||
private fun firebaseAuthWithGoogle(idToken: String) { | ||
val credential = GoogleAuthProvider.getCredential(idToken, null) | ||
auth.signInWithCredential(credential) | ||
.addOnCompleteListener(this) { task -> | ||
if (task.isSuccessful) { | ||
// Sign in success, update UI with the signed-in user's information | ||
Log.d(TAG, "signInWithCredential:success") | ||
val user = auth.currentUser | ||
updateUI(user) | ||
} else { | ||
// If sign in fails, display a message to the user. | ||
Log.w(TAG, "signInWithCredential:failure", task.exception) | ||
updateUI(null) | ||
} | ||
} | ||
} | ||
|
||
private fun updateUI(currentUser: FirebaseUser?) { | ||
if (currentUser != null){ | ||
startActivity(Intent(this@LoginActivity, MainActivity::class.java)) | ||
finish() | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
// Check if user is signed in (non-null) and update UI accordingly. | ||
val currentUser = auth.currentUser | ||
updateUI(currentUser) | ||
} | ||
|
||
companion object { | ||
private const val TAG = "LoginActivity" | ||
} | ||
} |
Oops, something went wrong.