Skip to content

Commit

Permalink
Completed basic UI, added OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAGhost23 committed Sep 17, 2022
1 parent 2f6595e commit c6cbd32
Show file tree
Hide file tree
Showing 52 changed files with 1,683 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
69 changes: 69 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}

android {
compileSdk 32

defaultConfig {
applicationId "com.example.cmsclonelite"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

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 {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {
implementation 'com.google.firebase:firebase-auth-ktx:21.0.8'
def nav_version = "2.5.2"

implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.android.gms:play-services-auth:20.3.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.9"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.navigation:navigation-compose:$nav_version"
}
47 changes: 47 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"project_info": {
"project_number": "557828460372",
"project_id": "cmsclonelite",
"storage_bucket": "cmsclonelite.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:557828460372:android:1ea29c7eaad14e919702c1",
"android_client_info": {
"package_name": "com.example.cmsclonelite"
}
},
"oauth_client": [
{
"client_id": "557828460372-82dcvmvi874781kbbs5ugsff8k5pglg0.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.cmsclonelite",
"certificate_hash": "e7f0bc0ee733e96030facac386a8273cfb25e726"
}
},
{
"client_id": "557828460372-0184fqcfulugr78smv592m76u2rsqppm.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCXHWRM-3TkQB3VXUSALP01x8tJvHBVXtU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "557828460372-0184fqcfulugr78smv592m76u2rsqppm.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.cmsclonelite

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.cmsclonelite", appContext.packageName)
}
}
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cmsclonelite" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CMSCloneLite" >
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.CMSCloneLite" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/cmsclonelite/BottomBarScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.cmsclonelite

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.List
import androidx.compose.material.icons.filled.ListAlt
import androidx.compose.material.icons.filled.Settings
import androidx.compose.ui.graphics.vector.ImageVector

sealed class BottomBarScreen(
val route: String,
val title: String,
val icon: ImageVector
) {
object MyCourses : BottomBarScreen(
route = "myCourses",
title = "My Courses",
icon = Icons.Default.List
)

object AllCourses : BottomBarScreen(
route = "allCourses",
title = "All Courses",
icon = Icons.Default.ListAlt
)

object Settings : BottomBarScreen(
route = "settings",
title = "Settings",
icon = Icons.Default.Settings
)
}
100 changes: 100 additions & 0 deletions app/src/main/java/com/example/cmsclonelite/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.example.cmsclonelite

import android.content.ContentValues.TAG
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.cmsclonelite.graphs.SetupNavGraph
import com.example.cmsclonelite.ui.theme.CMSCloneLiteTheme
import com.google.android.gms.auth.api.identity.Identity
import com.google.android.gms.auth.api.identity.SignInClient
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.GoogleAuthProvider

class MainActivity : ComponentActivity() {
private lateinit var navController: NavHostController
private lateinit var mAuth: FirebaseAuth
private lateinit var oneTapClient: SignInClient
private val REQ_ONE_TAP = 2
private var showOneTapUI = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mAuth = FirebaseAuth.getInstance()
val user = mAuth.currentUser
setContent {
CMSCloneLiteTheme {
this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
navController = rememberNavController()
SetupNavGraph(navController = navController)
if(user == null) {
navController.navigate(route = Screen.Login.route) {
popUpTo(Screen.MainScreen.route) {
inclusive = true
}
}
}
}
}
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

when (requestCode) {
REQ_ONE_TAP -> {
try {
oneTapClient = Identity.getSignInClient(this)
val credential = oneTapClient.getSignInCredentialFromIntent(data)
val idToken = credential.googleIdToken
when {
idToken != null -> {
firebaseAuthWithGoogle(idToken)
Log.d(TAG, "Got ID token.")
}
else -> {
Log.d(TAG, "No ID token!")
}
}
} catch (e: ApiException) {when (e.statusCode) {
CommonStatusCodes.CANCELED -> {
Log.d(TAG, "One-tap dialog was closed.")
showOneTapUI = false
}
CommonStatusCodes.NETWORK_ERROR -> {
Log.d(TAG, "One-tap encountered a network error.")
}
else -> {
Log.d(TAG, "Couldn't get credential from result." +
" (${e.localizedMessage})")
}
}
}
}
}
}
private fun firebaseAuthWithGoogle(idToken: String) {
val credential = GoogleAuthProvider.getCredential(idToken, null)
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if(task.isSuccessful) {
Log.d(TAG, "Signed In with Credential")
navController.navigate(route = Screen.MainScreen.route) {
popUpTo(Screen.Login.route) {
inclusive = true
}
}
}
else {
Log.w(TAG, "Failed to Sign In")
}
}
}
}
Loading

0 comments on commit c6cbd32

Please sign in to comment.