Skip to content

Commit

Permalink
Merge pull request #13
Browse files Browse the repository at this point in the history
[APP] Refactor Code
  • Loading branch information
MichaelSafwatHanna authored Aug 27, 2019
2 parents 85ad193 + 3053f1c commit 8ff56ff
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 91 deletions.
16 changes: 6 additions & 10 deletions app/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
apply plugin: 'com.android.application'

apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
multiDexEnabled true
applicationId "uah.vaccination"
minSdkVersion 16
targetSdkVersion 29
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -31,17 +30,14 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-analytics:17.1.0'
implementation 'com.google.firebase:firebase-firestore:20.1.0'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-database:19.0.0'
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-firestore:21.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin

15 changes: 7 additions & 8 deletions app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
package="uah.vaccination">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".activities.SignInActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
38 changes: 18 additions & 20 deletions app/app/src/main/java/uah/vaccination/activities/SignInActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,65 @@ import uah.vaccination.R

class SignInActivity : AppCompatActivity() {

private lateinit var auth: FirebaseAuth
private val auth = FirebaseAuth.getInstance()

override fun onStart() {
super.onStart()
FirebaseAuth.getInstance().currentUser ?: return

val intent = Intent(this, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

finish()
startActivity(intent)
startMainActivity(true)
}

override fun onCreate(savedInstanceState: Bundle?) {

auth = FirebaseAuth.getInstance()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sign_in)

sign_in_button.setOnClickListener {
if(validateInput()){
SignIn(email_edit_text.text.toString(),password_edit_text.text.toString())
if (validateInput()) {
signIn(email_edit_text.text.toString(), password_edit_text.text.toString())
}
}

createAnAccount_text_view.setOnClickListener {
StartMainActivity()
startMainActivity(false)
}

}

fun validateInput() :Boolean{
private fun validateInput(): Boolean {
val isEmailEmpty = email_edit_text.text.isNullOrEmpty()
val isPasswordEmpty = password_edit_text.text.isNullOrEmpty()

if (!isEmailEmpty &&
!isPasswordEmpty)
!isPasswordEmpty
)
return true
else {
if (isEmailEmpty) email_edit_text.error = "Required Field."
if (isPasswordEmpty) password_edit_text.error = "Required Field."
}
return false
}
fun SignIn(email:String, password:String) {

private fun signIn(email: String, password: String) {
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
StartMainActivity()
startMainActivity(true)
}
}
}
fun StartMainActivity(){

private fun startMainActivity(addFlags: Boolean) {
val intent = Intent(this, SignUpActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (addFlags) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
finish()
startActivity(intent)
}


}


Expand Down
26 changes: 12 additions & 14 deletions app/app/src/main/java/uah/vaccination/activities/SignUpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uah.vaccination.activities

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.auth.FirebaseAuth
Expand All @@ -13,11 +12,10 @@ import uah.vaccination.models.Parent

class SignUpActivity : AppCompatActivity() {

private lateinit var auth: FirebaseAuth
val db = FirebaseFirestore.getInstance()
private val auth = FirebaseAuth.getInstance()
private val firestore = FirebaseFirestore.getInstance()

override fun onCreate(savedInstanceState: Bundle?) {
auth = FirebaseAuth.getInstance()

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sign_up)
Expand All @@ -31,12 +29,12 @@ class SignUpActivity : AppCompatActivity() {
}

private fun validateInput(): Boolean {
val isNameEmpty = name_edit_text.text.isNullOrEmpty()
val isSurnameEmpty = surname_edit_text.text.isNullOrEmpty()
val isStreetEmpty = street_edit_text.text.isNullOrEmpty()
val isCityEmpty = city_edit_text.text.isNullOrEmpty()
val isEmailEmpty = email_edit_text.text.isNullOrEmpty()
val isPhoneEmpty = phone_edit_text.text.isNullOrEmpty()
val isNameEmpty = name_edit_text.text.isNullOrEmpty()
val isSurnameEmpty = surname_edit_text.text.isNullOrEmpty()
val isStreetEmpty = street_edit_text.text.isNullOrEmpty()
val isCityEmpty = city_edit_text.text.isNullOrEmpty()
val isEmailEmpty = email_edit_text.text.isNullOrEmpty()
val isPhoneEmpty = phone_edit_text.text.isNullOrEmpty()
val isPasswordEmpty = password_edit_text.text.isNullOrEmpty()

if (!isNameEmpty &&
Expand All @@ -61,17 +59,17 @@ class SignUpActivity : AppCompatActivity() {
}

private fun signUp(email: String, password: String) {
Log.d("lol", email + password)
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val parent = task.result!!.user
addParent(
"101",
parent!!.uid,
name_edit_text.text.toString(),
surname_edit_text.text.toString(),
street_edit_text.text.toString(),
city_edit_text.text.toString(),
email_edit_text.text.toString(),
email,
phone_edit_text.text.toString()
)
val intent = Intent(this, MainActivity::class.java)
Expand All @@ -98,6 +96,6 @@ class SignUpActivity : AppCompatActivity() {
phoneNumber: String
) {
val parent = Parent(id, name, surname, street, city, email, phoneNumber)
db.collection("parents").document(email).set(parent)
firestore.collection("parents").document(email).set(parent)
}
}
5 changes: 2 additions & 3 deletions app/app/src/main/java/uah/vaccination/models/Child.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package uah.vaccination.models

import com.google.firebase.Timestamp

data class Child(
val id: String? = null,
val name: String? = null,
val surname: String? = null,
val dateOfBirth: Timestamp? = null,
val parentId : String? = null
val dateOfBirth: Timestamp? = null
)
2 changes: 1 addition & 1 deletion app/app/src/main/java/uah/vaccination/models/Parent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class Parent(
val city: String? = null,
val email: String? = null,
val phoneNumber: String? = null,
val child: Array<Child>? = null
val child: ArrayList<Child>? = arrayListOf()
)
64 changes: 32 additions & 32 deletions app/app/src/main/res/layout/activity_sign_in.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.SignInActivity">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.SignInActivity">

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="48dp"
android:layout_gravity="center">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="48dp"
android:gravity="center"
android:layout_gravity="center">

<EditText android:id="@+id/email_edit_text"
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="البريد الالكترونى"
android:layout_marginBottom="16dp"/>
<EditText android:id="@+id/email_edit_text"
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="@string/email"
android:layout_marginBottom="16dp"/>

<EditText android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="كلمه المرور"
android:layout_marginBottom="16dp"/>
<EditText android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="@string/password"
android:layout_marginBottom="16dp"/>

<Button android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="تسجيل دخول"
android:layout_marginBottom="16dp"/>
<Button android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_in"
android:layout_marginBottom="16dp"/>

<TextView android:id="@+id/createAnAccount_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="انشاء حساب"
android:layout_gravity="center"
android:textColor="@color/colorPrimary"/>
</LinearLayout>
<TextView android:id="@+id/createAnAccount_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_up"
android:textColor="@color/colorPrimary"/>

</LinearLayout>

</ScrollView>
2 changes: 2 additions & 0 deletions app/app/src/main/res/values/strings-ar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
<string name="phoneNumber">الهاتف الجوال</string>
<string name="password">كلمة المرور</string>
<string name="signUp">تسجيل</string>
<string name="sign_in">تسجيل دخول</string>
<string name="sign_up">انشاء حساب</string>
</resources>
3 changes: 0 additions & 3 deletions app/app/src/main/res/values/strings.xml

This file was deleted.

0 comments on commit 8ff56ff

Please sign in to comment.