Skip to content
Permalink
Browse files

Link to database and sign in

  • Loading branch information
dacost13 committed Apr 7, 2021
1 parent 6661df6 commit 9f905ecf49d1d5e0dea00fd44828264113db5b4d
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
@@ -1,5 +1,6 @@
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}

android {
@@ -33,6 +34,9 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation platform('com.google.firebase:firebase-bom:26.8.0')
implementation 'com.google.firebase:firebase-database:19.7.0'
implementation 'com.google.firebase:firebase-auth:20.0.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Class-Path="http://schemas.android.com/apk/distribution"
package="com.example.booksharing">

<application
@@ -8,15 +9,21 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BookSharing">
<activity android:name=".SplashActivity"></activity>
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".RegisterActivity"></activity>
<activity android:name=".SplashActivity" />

<activity android:name=".MainActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>

</manifest>
@@ -9,12 +9,13 @@
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 4000;

ActionBar actionBar;
public class MainActivity extends AppCompatActivity {

private static int SPLASH_TIME_OUT = 4000;


@Override
@@ -23,20 +24,16 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_splash);


// ActionBar Colouring https://www.youtube.com/watch?v=1DoA7aJplKA
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#8BC34A")));


// Splash page
new Handler().postDelayed(new Runnable(){
new Handler().postDelayed(new Runnable() {
@Override
public void run(){
public void run() {
Intent homeIntent = new Intent(MainActivity.this, com.example.booksharing.SplashActivity.class);
startActivity(homeIntent);
finish();
}
}, SPLASH_TIME_OUT);

}

}
@@ -0,0 +1,153 @@
package com.example.booksharing;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.FirebaseDatabase;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {


private FirebaseAuth mAuth;
private TextView banner, RegisterUser;
private EditText editp1,editp2,editusername,editemail ;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);


mAuth = FirebaseAuth.getInstance();
banner = (TextView) findViewById(R.id.banner);
banner.setOnClickListener(this);

RegisterUser = (Button) findViewById(R.id.reg1);
RegisterUser.setOnClickListener(this);

// Assigning variables to Design ID

editp1 = (EditText) findViewById(R.id.password);
editp2 = (EditText) findViewById(R.id.password2);
editusername = (EditText) findViewById(R.id.username);
editemail = (EditText) findViewById(R.id.email);




}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.banner:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.reg1:
RegisterUser();
break;

}

}

// Register Validation https://www.youtube.com/watch?v=Z-RE1QuUWPg&t=340s

private void RegisterUser() {
String email = editemail.getText().toString().trim();
String password = editp1.getText().toString().trim();
String password2 = editp2.getText().toString().trim();
String username = editusername.getText().toString().trim();

if (email.isEmpty()){
editemail.setError("Email is Required");
editemail.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
editemail.setError("Please provide valid email");
editemail.requestFocus();
return;
}
if (username.isEmpty()) {
editusername.setError("Username is Required");
editusername.requestFocus();
return;
}

if (password.isEmpty()){
editp1.setError("Password is Required");
editp1.requestFocus();
return;
}

if (password2.isEmpty()){
editp2.setError("Password is Required");
editp2.requestFocus();
return;
}

if (password.length()< 8 ){
editp1.setError("Password should have at least 8 characters");
editp1.requestFocus();
return;
}

mAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {

@Override
public void onComplete(@NonNull Task<AuthResult> task) {

if (task.isSuccessful()){
User user = new User (username, email);
FirebaseDatabase.getInstance().getReference("Book Sharing")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {

@Override
public void onComplete(@NonNull Task<Void> task) {

if (task.isSuccessful()){
Toast.makeText(RegisterActivity.this, "User has been registered successfully", Toast.LENGTH_LONG).show();

}else{

Toast.makeText(RegisterActivity.this, "Failed Try Again", Toast.LENGTH_LONG).show();

}

}
});


}else{

Toast.makeText(RegisterActivity.this, "Failed Try Again", Toast.LENGTH_LONG).show();


}
}
});

}



}
@@ -8,18 +8,31 @@
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

public class SplashActivity extends AppCompatActivity {
public class SplashActivity extends AppCompatActivity implements View.OnClickListener {

ActionBar actionBar;
private TextView register;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ActionBar Colouring
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#8BC34A")));


register = (TextView) findViewById(R.id.reg);
register.setOnClickListener(this);


}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.reg:
startActivity(new Intent(this, RegisterActivity.class));
break;
}
}
}
@@ -0,0 +1,25 @@
package com.example.booksharing;

public class User {

public String username, email;


public User(){

}

public User(String username , String email){

this.username = username ;

this.email = email;


}





}
Binary file not shown.
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Alfa Slab One"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>

0 comments on commit 9f905ec

Please sign in to comment.
You can’t perform that action at this time.