Skip to content

Commit

Permalink
Update Version: 0.2 - TicketBusApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanes14 committed Oct 17, 2022
1 parent f6476f4 commit 12928c5
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 20 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}

android {
Expand Down Expand Up @@ -30,9 +31,10 @@ android {

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth:21.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/rtx14/ticketbus/GetStarted.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,42 @@
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class GetStarted extends AppCompatActivity {
Button keLogin;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_started);
keLogin = findViewById(R.id.buttonGetStarted);

mAuth = FirebaseAuth.getInstance();

keLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent keLogin = new Intent(GetStarted.this, Login.class);
startActivity(keLogin);
finish();
}
});
}

@Override
protected void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser != null){
Toast.makeText(this, "Yeay, kamu sudah masuk sebagai: "+currentUser.getEmail()+".", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(GetStarted.this, MainActivity.class);
startActivity(intent);
finish();
}
}
}
59 changes: 58 additions & 1 deletion app/src/main/java/com/rtx14/ticketbus/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@

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

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class Login extends AppCompatActivity {
Button keRegister;
Button keRegister, btnLogin_1;
EditText ed_email1, ed_password1;
final String TAG = "Login";
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
keRegister = findViewById(R.id.btnRegister_1);
btnLogin_1 = findViewById(R.id.btnLogin_1);
ed_email1 = findViewById(R.id.edEmailLogin);
ed_password1 = findViewById(R.id.edPasswordLogin);

mAuth = FirebaseAuth.getInstance();

keRegister.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -23,5 +37,48 @@ public void onClick(View v) {
startActivity(intent);
}
});

btnLogin_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(ed_email1.getText().toString().isEmpty() || ed_password1.getText().toString().isEmpty()){
Toast.makeText(Login.this, "Email dan Password tidak boleh kosong", Toast.LENGTH_SHORT).show();
}else {
signIn(ed_email1.getText().toString(), ed_password1.getText().toString());
}
}
});
}

private void signIn(String email, String password){
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
// Sign in success.
Log.d(TAG, "signInWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
Toast.makeText(Login.this, "Yeay, berhasil masuk sebagai: "+user.getEmail()+".", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithEmail:failure", task.getException());
Toast.makeText(Login.this, "Yah gagal, coba lagi yuk.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Login.this, Login.class);
startActivity(intent);
finish();
}
});
}

@Override
protected void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null){
Toast.makeText(this, "Yeay, kamu sudah masuk sebagai: "+currentUser.getEmail()+".", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Login.this, MainActivity.class));
finish();
}
}
}
24 changes: 23 additions & 1 deletion app/src/main/java/com/rtx14/ticketbus/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity {

Button btnLogout;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ini buat HomeLayout pada MainActivity
btnLogout = findViewById(R.id.btnLogout);

mAuth = FirebaseAuth.getInstance();

btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mAuth.signOut();
Toast.makeText(MainActivity.this, "Logout Berhasil", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, Login.class);
startActivity(intent);
finish();
}
});
}
}
55 changes: 54 additions & 1 deletion app/src/main/java/com/rtx14/ticketbus/Register.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package com.rtx14.ticketbus;

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

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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;

public class Register extends AppCompatActivity {
Button keLogin;
Button keLogin, btnRegister_2;
EditText ed_email2, ed_password2;
private FirebaseAuth mAuth;
final String TAG = "Register";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
keLogin = findViewById(R.id.btnLogin_2);
btnRegister_2 = findViewById(R.id.btnRegister_2);
ed_email2 = findViewById(R.id.edEmailRegister);
ed_password2 = findViewById(R.id.edPasswordRegister);

mAuth = FirebaseAuth.getInstance();

keLogin.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -23,5 +41,40 @@ public void onClick(View v) {
startActivity(intent);
}
});

btnRegister_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(ed_email2.getText().toString().isEmpty() || ed_password2.getText().toString().isEmpty()){
Toast.makeText(Register.this, "Email dan Password tidak boleh kosong", Toast.LENGTH_SHORT).show();
}else {
signUp(ed_email2.getText().toString(), ed_password2.getText().toString());
}
}
});
}

public void signUp(String email, String password){
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
Toast.makeText(Register.this, "Yeay, berhasil mendaftar sebagai: "+user.getEmail()+".", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Register.this, MainActivity.class);
startActivity(intent);
finish();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(Register.this, "Yah gagal, coba lagi yuk.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Register.this, Register.class);
startActivity(intent);
finish();
}
}
});
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_get_started.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:fontFamily="@font/dmsans_medium"
android:text="TicketKu"
android:textColor="@color/black"
android:textSize="34sp"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
Expand All @@ -58,7 +58,7 @@
android:fontFamily="@font/poppins_extra_light"
android:text="Booking your tickets online with your"
android:textColor="@color/black"
android:textSize="20sp"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -71,7 +71,7 @@
android:fontFamily="@font/poppins_extra_light"
android:text="best searching preferences"
android:textColor="@color/black"
android:textSize="20sp"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="600dp"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/abuputih"
android:orientation="vertical"
Expand All @@ -45,7 +45,7 @@
android:textColor="@color/black" />

<EditText
android:id="@+id/username1"
android:id="@+id/edEmailLogin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
Expand All @@ -59,7 +59,7 @@
android:textColorHint="@color/black" />

<EditText
android:id="@+id/password1"
android:id="@+id/edPasswordLogin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
Expand All @@ -76,12 +76,12 @@
android:id="@+id/btnLogin_1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="175dp"
android:layout_marginTop="40dp"
android:background="@drawable/rectangle_button"
android:fontFamily="@font/dmsans_medium"
android:text="Login"
android:textSize="18sp" />
android:textSize="18sp"
tools:layout_marginStart="175dp" />

<TextView
android:layout_width="match_parent"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context=".MainActivity">

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
Expand All @@ -17,4 +18,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnLogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@drawable/rectangle_button"
android:text="LogOut"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6"
app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
android:textColor="@color/black" />

<EditText
android:id="@+id/username1"
android:id="@+id/edEmailRegister"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
Expand All @@ -59,7 +59,7 @@
android:textColorHint="@color/black" />

<EditText
android:id="@+id/password1"
android:id="@+id/edPasswordRegister"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
Expand All @@ -76,7 +76,7 @@
android:id="@+id/btnRegister_2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="175dp"
tools:layout_marginStart="175dp"
android:layout_marginTop="40dp"
android:background="@drawable/rectangle_button"
android:fontFamily="@font/dmsans_medium"
Expand Down
Loading

0 comments on commit 12928c5

Please sign in to comment.