Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Summer 2020 #505

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6434e6d
Create empty project
caller9 Jun 3, 2020
72244e3
just for test
butterflyforever Jun 4, 2020
7ac54d7
basic view and Running fragment
butterflyforever Jun 19, 2020
8695acd
mapview
butterflyforever Jun 22, 2020
34099ec
1. Using view model to store the status of fragment.
butterflyforever Jun 26, 2020
54ce5cc
1. Use Data Binding to change Layout
butterflyforever Jun 26, 2020
0bfd15c
Fix code reviews
butterflyforever Jun 29, 2020
ec63756
Merge pull request #464 from googlesamples/yang
caller9 Jun 29, 2020
feb69ff
Remove comment
caller9 Jun 30, 2020
5354fbd
Merge branch 'master' into summer-2020
caller9 Jun 30, 2020
b37af95
Add working directory default
caller9 Jun 30, 2020
c348d48
search bar
butterflyforever Jul 1, 2020
f704af2
bringToFront
butterflyforever Jul 1, 2020
8fc8663
serach place and movethe map sight
butterflyforever Jul 9, 2020
d1453a6
formalize code style
butterflyforever Jul 11, 2020
94000b1
modify value type
butterflyforever Jul 14, 2020
7066c93
remove getFloat
butterflyforever Jul 14, 2020
aa21ca3
intergate auth
butterflyforever Jul 15, 2020
b683e1b
move const to companion object
butterflyforever Jul 15, 2020
80e6432
attach to PR
butterflyforever Jul 15, 2020
b60386d
Merge pull request #472 from googlesamples/yang-mapview
caller9 Jul 15, 2020
2b1723c
get UserID
butterflyforever Jul 16, 2020
d0891ce
move const to companion object
butterflyforever Jul 15, 2020
bb6ce25
attach to PR
butterflyforever Jul 15, 2020
c1560e0
attach to PR
butterflyforever Jul 15, 2020
ac80bfe
implemented logout
butterflyforever Jul 17, 2020
4f946c4
Merge branch 'yang-auth' of github.com:googlesamples/google-services …
butterflyforever Jul 17, 2020
dfde7f7
add google-service.json
butterflyforever Jul 17, 2020
a1daf87
naming style
butterflyforever Jul 17, 2020
76c28af
json
butterflyforever Jul 17, 2020
c07e51f
1. Add login fragment. Seperate login process from MainActivity
butterflyforever Jul 22, 2020
2c738ea
remove comment
butterflyforever Jul 22, 2020
fc9cf21
remove comment
butterflyforever Jul 22, 2020
55e0185
remove comment
butterflyforever Jul 22, 2020
9fd9d17
move login in check to ViewModel
butterflyforever Jul 24, 2020
49337b0
resolve conflict
butterflyforever Jul 25, 2020
4ec5ab3
resolve conflict
butterflyforever Jul 25, 2020
e99fae9
resolve conflict
butterflyforever Jul 25, 2020
4bd8bac
resolve conflict
butterflyforever Jul 25, 2020
9d511f9
Merge branch 'summer-2020' into yang-auth
butterflyforever Jul 25, 2020
b90072d
add LiveData class
butterflyforever Jul 27, 2020
f416fc5
1. Adapt it to MVVM architecture
butterflyforever Jul 28, 2020
832118a
Merge pull request #476 from googlesamples/yang-auth
caller9 Jul 29, 2020
a7f9ed3
firestore create user
butterflyforever Aug 3, 2020
849d656
1. Create User in Firstore
butterflyforever Aug 6, 2020
964684b
interaction between runFragment and Forestore
butterflyforever Aug 8, 2020
c88db07
adjust timestamp format
butterflyforever Aug 8, 2020
62eb7fe
ListView
butterflyforever Aug 9, 2020
db97450
Fix login bug -- adjust postion of check-login function
butterflyforever Aug 9, 2020
92df1df
remove unused code block
butterflyforever Aug 9, 2020
61e98d5
Welcome Page
butterflyforever Aug 10, 2020
303f5ad
adjust the position of logout observer
butterflyforever Aug 11, 2020
a06b60e
image button at runFragment
butterflyforever Aug 11, 2020
588851a
fix code review
butterflyforever Aug 15, 2020
0f1f91a
Test
butterflyforever Aug 15, 2020
d10f35f
test with mock account info
butterflyforever Aug 19, 2020
3c58154
ViewHolder Pattern in Adapter
butterflyforever Aug 19, 2020
17c66fa
Update readme.md
butterflyforever Aug 20, 2020
def696a
Merge pull request #479 from googlesamples/yang-firestore
caller9 Aug 20, 2020
33d77f0
Update readme.md
butterflyforever Aug 20, 2020
15a651f
Merge branch 'summer-2020' into Canonical-summer-2020-Readme
caller9 Aug 20, 2020
33ae320
Merge pull request #480 from googlesamples/Canonical-summer-2020-Readme
caller9 Aug 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implemented logout
  • Loading branch information
butterflyforever committed Jul 17, 2020
commit ac80bfe3d9edc0c4dbbc95206b47039e7ccc045d
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package com.google.samples.quickstart.canonical

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.fragment.app.FragmentTransaction
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.SignInButton
import com.google.android.gms.common.api.ApiException
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.GoogleAuthProvider

class MainActivity : AppCompatActivity() {
private lateinit var mGoogleSignInClient: GoogleSignInClient
lateinit var mGoogleSignInClient: GoogleSignInClient
private lateinit var auth: FirebaseAuth
private val tag = "MainActivity-Login"
private val firebaseTag = "MainActivity-Login"

private fun googleSignInInit() {
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
Expand All @@ -38,6 +35,51 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(signInIntent, RC_SIGN_IN)
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
if (task.isSuccessful) {
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!!)
setContentView(R.layout.activity_main)
setupNavigationBar()
} catch (e: ApiException) {
// Google Sign In failed
Log.w(tag, "Google sign in failed", e)
}
} else {
Log.w(tag, "Google sign in unsuccessful")
}

}
// No other requestCode, ignore it.
}


private fun firebaseAuthWithGoogle(idToken: String) {
val credential = GoogleAuthProvider.getCredential(idToken, null)
auth.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Firebase Sign in success, update UI with the signed-in user's information
Log.d(firebaseTag, "signInWithCredential:success")
val user = auth.currentUser
Log.d(firebaseTag, "signed-in user's Email:" + user!!.email)
} else {
// If sign in fails, log a message to the user.
Log.w(firebaseTag, "signInWithCredential:failure", task.exception)
}
}
}


private fun setupNavigationBar() {
val runFragment = RunFragment()
supportFragmentManager
Expand Down Expand Up @@ -85,78 +127,32 @@ class MainActivity : AppCompatActivity() {
}
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

googleSignInInit()
setupNavigationBar()

}


override fun onStart() {
super.onStart()
val account = GoogleSignIn.getLastSignedInAccount(this)
if (account == null) {
setContentView(R.layout.login_in_page)

findViewById<SignInButton>(R.id.sign_in_button).setOnClickListener {
signIn()
}

}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
if (task.isSuccessful) {
try {
// Google Sign In was successful, authenticate with Firebase
val account = task.getResult(ApiException::class.java)!!
Log.d("MainActivity-Login", "firebaseAuthWithGoogle:" + account.id)
firebaseAuthWithGoogle(account.idToken!!)
setContentView(R.layout.activity_main)
setupNavigationBar()
} catch (e: ApiException) {
// Google Sign In failed, update UI appropriately
Log.w("MainActivity-Login", "Google sign in failed", e)
// ...
}
} else {
Log.w("MainActivity-Login", "Google sign in unsuccessful")
}

}
}

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("firebaseAuthWithGoogle", "signInWithCredential:success")
val user = auth.currentUser
} else {
// If sign in fails, display a message to the user.
Log.w("firebaseAuthWithGoogle", "signInWithCredential:failure", task.exception)
// ...
}

// ...
}
}



companion object {
private const val RC_SIGN_IN = 0
}




}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.google.samples.quickstart.canonical

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
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.firebase.auth.FirebaseAuth

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
private const val meTag = "MeFragment"

/**
* A simple [Fragment] subclass.
Expand All @@ -25,24 +25,13 @@ class MeFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
private lateinit var mAuth : FirebaseAuth
private lateinit var mGoogleSignInClient : GoogleSignInClient

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}

// // Configure Google Sign In
// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// .requestIdToken(getString(R.string.default_web_client_id))
// .requestEmail()
// .build()
//
// mGoogleSignInClient = GoogleSignIn.getClient(this.context!!, gso)
// mAuth = FirebaseAuth.getInstance()
}


Expand All @@ -54,16 +43,33 @@ class MeFragment : Fragment() {
return inflater.inflate(R.layout.fragment_me, container, false)
}


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val logoutButton : Button = view.findViewById(R.id.logout_button)
logoutButton.setOnClickListener {
// Sign out both Google account and Firebase
FirebaseAuth.getInstance().signOut()
(activity as MainActivity).mGoogleSignInClient.signOut().addOnCompleteListener {
val intent = Intent(context, MainActivity::class.java)
startActivity(intent)
}
}
}


override fun onStart() {
super.onStart()
val account = GoogleSignIn.getLastSignedInAccount(this.context)
account?.let {
Log.i("MeFragment", "No login")
Log.i(meTag, "Already login")
view?.findViewById<TextView>(R.id.textView)?.text = account.displayName
} ?.run {
Log.i("MeFragment", "Already login")
Log.i(meTag, "No login")
}
}


companion object {
/**
* Use this factory method to create a new instance of
Expand Down
10 changes: 10 additions & 0 deletions android/canonical/app/src/main/res/layout/fragment_me.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/logout_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/logout_button_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions android/canonical/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<string name="stopped">Stopped</string>
<string name="my_location_title">My location</string>
<string name="cannot_access_location">Cannot access location now. Please Try later</string>
<string name="logout_button_text">Logout</string>
</resources>