Features requested for Firebase Component

newfeature

#1

Hello Builders!

I’m super excited for the opportunity to collaborate with Appybuilder now that it is opensource! I don’t have a formal education in programming, but what I have learned it is thanks to AppInventor and its distributions.

So I took the step to edit a component that I like very much, and find it very useful for nowadays apps like FirebaseDB. To be able to participate, I researched the library used and found its documentation available at: FirebaseDocumentation.

The main features I would like to add are:

  • GoOnline and GoOffline methods to “save” data usage and manually reestablish a connection or disconnect to the Firebase server.

  • Authenticate users. Be able to use the rules to set a database private and access it only with authenticated users.

  • Firebase Analytics


Editing-Component First Experience

First of all, when a first tried my first feeling was:
Wow! Editing a component is a very hard work!

You can check the AppInventor Documentation about How to build App Inventor from the MIT sources and How to add a component if you don’t believe me.

I didn’t know about the internationalization process because it isn’t needed for Extension Developing. It cost me a few hours to understand it and avoid those errors when building from the sources. But here I am! Ready to share.

First Feature: GoOnline and GoOffline methods

This is the first feature I accomplished editing the FirebaseDB component:

  • GoOnline: A method to manually reestablish a connection to the Firebase server and enable automatic reconnection.
    image

  • GoOffline: A method to manually disconnect the Firebase client from the server and disable automatic reconnection.
    image

These methods are useful to decide whether the app will be continuosly trying to connect to the server. When offline, the user will be able to store values to the database, but they only are going to sync when using the GoOnline method again.

Here is the very simple code I used:

@SimpleFunction(description = "")
public void GoOnline() {
	if (myFirebase != null) {
		myFirebase.goOnline();
	} else {
		connectFirebase();
	}
}

@SimpleFunction(description = "")
public void GoOffline() {
	if (myFirebase != null) {
		myFirebase.goOffline();
	}
}

I am new to GitHub, I will learn how to make a Pull Request(?) to add it to the AppyBuilder and AppInventor sources. I share it here because it is very simple, and in case I don’t figure out how to make it :smile:

Second Feature: Authenticating users

I think this is the main feature I would like to add.
This can be achieved by two ways:

For the first solution, it is required to show a Property Block to set the FirebaseToken given by the extension after authenticating. It will lead to be able to set the rules to the database to private and access it only by authenticated users.

That block already exists, but it cannot be seen. My modification proposal is: (I still have to test this)

/**
* Getter for the FirebaseToken.
*
* @return the JWT used to authenticate users on the default Firebase
*/
@SimpleProperty(category = PropertyCategory.BEHAVIOR,
	description = "Returns the JWT used to authenticate users on the default Firebase.")
public String FirebaseToken() { return firebaseToken; }

/**
* Specifies the JWT for the default Firebase.
*
* @param JWT the JSON Web Token (JWT) used to authenticate on the
*            default Firebase
*/
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING,
	defaultValue = "")
@SimpleProperty
public void FirebaseToken(String token) {
	firebaseToken = token;
	resetListener();
}

For the second solution, I tried to use .createUser() and .authWithPassword() methods from the FirebaseDocumentation, but it returns: a FirebaseError that says: Project created at console.firebase.google.com must use the new Firebase Authentication SDKs available from firebase.google.com/docs/auth. This means that it cannot be done with the library used, we will have to add the new library in order to achieve this.

Here I share the code I used, it is very simple because I wanted to try it first:

@SimpleFunction(description = "")
public String SignUp(String email, String password) {
	CreateUserWithPassword(email,password);
	return firebaseResultSignUp;
}

private void CreateUserWithPassword(String email, String password){
	if (myFirebase == null) {
		connectFirebase();
	}
	myFirebase.createUser(email,password, new Firebase.ResultHandler() {
		public void onSuccess() {
		    firebaseResultSignUp = "We have made it";
		}
		
		public void onError(FirebaseError firebaseError) {
			firebaseResultSignUp = firebaseError.getMessage();
		}
	});
}

@SimpleFunction(description = "")
public String LogIn(String email, String password) {
	
	LogInUserWithPassword(email,password);
	return firebaseResultSignUp;
}

private void LogInUserWithPassword(String email, String password){
	if (myFirebase == null) {
		connectFirebase();
	}
	myFirebase.authWithPassword(email,password, new Firebase.AuthResultHandler() {
        public void onAuthenticated(AuthData authData) {
			firebaseResultSignUp = authData.getToken();
			resetListener();
        }
        public void onAuthenticationError(FirebaseError firebaseError) {
			firebaseResultSignUp = firebaseError.getMessage();
		}
    });
}

Third feature: Firebase Analytics

I didn’t make any progress in this feature because it needs the new library as well. (Homework!)
Noob question: Is it a way to get the .jar or .aar file in order to use it in the component by using Gradle in Android Studio? (I don’t how Gradle works)


FirebaseAddOn Extension (To be sponsored!)
#2

@CarlosPedroza27 Its great that you are starting on this through the open-source. This is what’s great about open-source; collaboration, extensions, continuous improvements and NOT a closed system

.aar is a basically a compressed zip file. Lots of folks simply open it using archive tools (e.g. 7-zip) and extract the jar. Is that what you are looking for?


#3

Oh! I didn’t know that, thanks!
My question is about how can I use Gradle to get the .jar library so I can use it in AppyBuilder? I will watch some tutorials in the internet to achieve that.

I have news! Updating the library (2.5.0 to 2.5.2) I can create the missing methods! and few more! Stay tuned!


#4

Nope, I couldn’t made it possible. It was a nice try though.

My next try will be importing the last library from Firebase.


#5

@Hossein I really like this idea because you don’t have to set your database on public this should be put into appybuilder online please I’m waiting for this sooo long


#6

Right now, this is possible using two extensions: @mirxtrem_appsFirebaseAuth Extension V3 and my recently published FirebaseAddOn extension. This is a temporary solution until I achieve updating the Firebase Component to the latest Firebase library. By sponsoring my FirebaseAddOn extension, you are also sponsoring my work with the Firebase component. Please check this post where I provided an example to know how to use them.

Also, please vote on the poll! I want to know your opinion!


#7

@CarlosPedroza27 did you got anything?


#8

how to get the Firebase ADDON?Can you please send the link?