commit 95289ca2f879d0c9888c9521b2fdc62e9359fb39 Author: mikgaw@st.amu.edu.pl Date: Sat Nov 25 13:05:46 2023 +0100 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ae388c2 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8978d23 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..7f606dd --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'com.android.application' + id 'com.google.gms.google-services' +} + +android { + namespace 'com.example.bsm_notatnik' + compileSdk 34 + + defaultConfig { + applicationId "com.example.bsm_notatnik" + minSdk 24 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.10.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.google.firebase:firebase-auth:22.3.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' +} \ No newline at end of file diff --git a/app/google-services.json b/app/google-services.json new file mode 100644 index 0000000..d8032c3 --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,29 @@ +{ + "project_info": { + "project_number": "973573037765", + "project_id": "bsm-notatnik", + "storage_bucket": "bsm-notatnik.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:973573037765:android:8db5442018c92f94d59aac", + "android_client_info": { + "package_name": "com.example.bsm_notatnik" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyBCbedeIw3ERk5o_k3HnFKyVcW3ESd5nxA" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/bsm_notatnik/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/bsm_notatnik/ExampleInstrumentedTest.java new file mode 100644 index 0000000..44d160c --- /dev/null +++ b/app/src/androidTest/java/com/example/bsm_notatnik/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.bsm_notatnik; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.bsm_notatnik", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d1d96b5 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/bsm_notatnik/Login.java b/app/src/main/java/com/example/bsm_notatnik/Login.java new file mode 100644 index 0000000..01a5fa2 --- /dev/null +++ b/app/src/main/java/com/example/bsm_notatnik/Login.java @@ -0,0 +1,103 @@ +package com.example.bsm_notatnik; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ProgressBar; +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; + +public class Login extends AppCompatActivity { + + EditText editTextEmail, editTextPassword; + Button buttonLogin; + FirebaseAuth mAuth; + ProgressBar progressBar; + TextView textView; + + // Checks if a user is already signed in + @Override + public void onStart() { + super.onStart(); + FirebaseUser currentUser = mAuth.getCurrentUser(); + if(currentUser != null){ + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + finish(); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + mAuth = FirebaseAuth.getInstance(); + editTextEmail = findViewById(R.id.username); + editTextPassword = findViewById(R.id.password); + buttonLogin = findViewById(R.id.btn_login); + progressBar = findViewById(R.id.progressBar); + textView = findViewById(R.id.registerNow); + + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getApplicationContext(), Register.class); + startActivity(intent); + finish(); // finishes current activity + } + }); + + buttonLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + progressBar.setVisibility(View.VISIBLE); + String email, password; + email = String.valueOf(editTextEmail.getText()); + password = String.valueOf(editTextPassword.getText()); + + if(TextUtils.isEmpty(email)){ + Toast.makeText(Login.this, "Enter email!", Toast.LENGTH_SHORT).show(); + return; + } + if(TextUtils.isEmpty(password)){ + Toast.makeText(Login.this, "Enter password!", Toast.LENGTH_SHORT).show(); + return; + } + + + mAuth.signInWithEmailAndPassword(email, password) + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + progressBar.setVisibility(View.GONE); + if (task.isSuccessful()) { + Toast.makeText(getApplicationContext(), "Login Successful", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + finish(); + } else { + Toast.makeText(Login.this, "Authentication failed.", + Toast.LENGTH_SHORT).show(); + } + } + }); + + + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bsm_notatnik/MainActivity.java b/app/src/main/java/com/example/bsm_notatnik/MainActivity.java new file mode 100644 index 0000000..7decb23 --- /dev/null +++ b/app/src/main/java/com/example/bsm_notatnik/MainActivity.java @@ -0,0 +1,49 @@ +package com.example.bsm_notatnik; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +public class MainActivity extends AppCompatActivity { + + FirebaseAuth auth; + Button logout_btn; + TextView textView; + FirebaseUser user; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + auth = FirebaseAuth.getInstance(); + logout_btn = findViewById(R.id.logout_btn); + textView = findViewById(R.id.user_details); + user = auth.getCurrentUser(); + + if (user == null){ + Intent intent = new Intent(getApplicationContext(), Login.class); + startActivity(intent); + finish(); + }else { + textView.setText(user.getEmail()); + } + + logout_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(getApplicationContext(), Login.class); + startActivity(intent); + finish(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bsm_notatnik/Register.java b/app/src/main/java/com/example/bsm_notatnik/Register.java new file mode 100644 index 0000000..f1aad18 --- /dev/null +++ b/app/src/main/java/com/example/bsm_notatnik/Register.java @@ -0,0 +1,104 @@ +package com.example.bsm_notatnik; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ProgressBar; +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.android.material.textfield.TextInputEditText; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +public class Register extends AppCompatActivity { + + EditText editTextEmail, editTextPassword; + Button buttonReg; + FirebaseAuth mAuth; + ProgressBar progressBar; + TextView textView; + + // Checks if a user is already signed in + @Override + public void onStart() { + super.onStart(); + FirebaseUser currentUser = mAuth.getCurrentUser(); + if(currentUser != null){ + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + finish(); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_register); + + mAuth = FirebaseAuth.getInstance(); + editTextEmail = findViewById(R.id.username); + editTextPassword = findViewById(R.id.password); + buttonReg = findViewById(R.id.btn_register); + progressBar = findViewById(R.id.progressBar); + textView = findViewById(R.id.loginNow); + + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getApplicationContext(), Login.class); + startActivity(intent); + finish(); // finishes current activity + } + }); + + buttonReg.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + progressBar.setVisibility(View.VISIBLE); + String email, password; + email = String.valueOf(editTextEmail.getText()); + password = String.valueOf(editTextPassword.getText()); + + if(TextUtils.isEmpty(email)){ + Toast.makeText(Register.this, "Enter email!", Toast.LENGTH_SHORT).show(); + return; + } + if(TextUtils.isEmpty(password)){ + Toast.makeText(Register.this, "Enter password!", Toast.LENGTH_SHORT).show(); + return; + } + + mAuth.createUserWithEmailAndPassword(email, password) + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + progressBar.setVisibility(View.GONE); + if (task.isSuccessful()) { + Toast.makeText(Register.this, "Account created.", + Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(getApplicationContext(), Login.class); + startActivity(intent); + finish(); // finishes current activity + } else { + // If sign in fails, display a message to the user. + Toast.makeText(Register.this, "Authentication failed.", + Toast.LENGTH_SHORT).show(); + } + } + }); + + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_email_24.xml b/app/src/main/res/drawable/baseline_email_24.xml new file mode 100644 index 0000000..80111c8 --- /dev/null +++ b/app/src/main/res/drawable/baseline_email_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/baseline_key_24.xml b/app/src/main/res/drawable/baseline_key_24.xml new file mode 100644 index 0000000..a81b613 --- /dev/null +++ b/app/src/main/res/drawable/baseline_key_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..81e4153 --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,86 @@ + + + + + + + + + +