Hello all,
I'm implement this resource (https://www.b4x.com/android/forum/t...-your-users-google-facebook.68625/post-435340) in a B4XPages App and noticed that for B4i there is a lot of code in Main module.
Considering that following B4X best practices implementation I must to avoid to put code in Main, preferring the B4XMainPage module (only the Ios exclusive code should be in Main ) and there is no "page" object (it's required to use B4X Pages), I changed the code to :
Then I have one question and one problem:
1. Question: is this correct to change the routines from Main to B4XMainPage in this case?
Problem:
2. I don't know what to do with this piece of code, as there is no direct page manipulation in B4XPages:
It's raising and error (in the original example there was page instead of B4XPages.GetPage("mainPage"))...
Thanks everybody!
I'm implement this resource (https://www.b4x.com/android/forum/t...-your-users-google-facebook.68625/post-435340) in a B4XPages App and noticed that for B4i there is a lot of code in Main module.
Considering that following B4X best practices implementation I must to avoid to put code in Main, preferring the B4XMainPage module (only the Ios exclusive code should be in Main ) and there is no "page" object (it's required to use B4X Pages), I changed the code to :
B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private btnSignInFacebook As Button
Private btnSignInGoogle As Button
Private btnSignOut As Button
Public analytics As FirebaseAnalytics
Public auth As FirebaseAuth
Public facebook As FacebookSdk
Public FacebookAppId As String = "xxxxxxxxxxxxxxx"
Private lblName As Label
End Sub
Public Sub Initialize
analytics.Initialize
B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
auth.Initialize("auth")
facebook.Initialize(FacebookAppId)
End Sub
Private Sub Auth_SignedIn (User As FirebaseUser)
SetState
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub SetState
Dim SignedIn As Boolean = auth.CurrentUser.IsInitialized
If SignedIn Then
lblName.Text = "Hello: " & auth.CurrentUser.DisplayName
End If
btnSignInGoogle.Enabled = Not(SignedIn)
btnSignInFacebook.Enabled = Not(SignedIn)
btnSignOut.Enabled = SignedIn
End Sub
Sub btnSignOut_Click
auth.SignOutFromGoogle
facebook.SignOut
lblName.Text = "Goodbye!"
SetState
End Sub
Sub btnSignInFacebook_Click
facebook.SignIn
End Sub
Sub btnSignInGoogle_Click
auth.SignInWithGoogle(B4XPages.GetPage("mainPage"))
End Sub
Then I have one question and one problem:
1. Question: is this correct to change the routines from Main to B4XMainPage in this case?
Problem:
2. I don't know what to do with this piece of code, as there is no direct page manipulation in B4XPages:
B4X:
auth.SignInWithGoogle(B4XPages.GetPage("mainPage"))
Thanks everybody!