Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.0.0 #8

Merged
merged 31 commits into from
Mar 11, 2020
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
89d38c8
Initial project setup
aditmodhvadia Nov 15, 2019
9a7f01d
- project structure set up
aditmodhvadia Nov 15, 2019
6ad89bb
- add BaseActivity and BaseFragment
aditmodhvadia Nov 15, 2019
fde1134
- set up FireBase library module
aditmodhvadia Nov 15, 2019
afdcea3
- add apiManager instance to BaseActivity and BaseFragment
aditmodhvadia Nov 15, 2019
42e4792
Merge pull request #1 from aditmodhvadia/project-setup
aditmodhvadia Nov 15, 2019
d7035b0
- add Timber for logging
aditmodhvadia Nov 15, 2019
116a05e
- add test case for SplashActivity
aditmodhvadia Nov 15, 2019
813b43f
- registered and create user with email and password on successfully …
aditmodhvadia Nov 15, 2019
ba30493
- add LandingActivity
aditmodhvadia Nov 16, 2019
b6079c7
- add LoginActivity and complete it's flow
aditmodhvadia Nov 17, 2019
f1ae813
Merge pull request #2 from aditmodhvadia/feature/splash_login_flow
aditmodhvadia Nov 17, 2019
46c41e4
- add Chat room display to LandingActivity
aditmodhvadia Nov 18, 2019
7049564
- add ChatActivity with different views for sent and received messages
aditmodhvadia Nov 18, 2019
b4d7536
- setup dummy data for messages
aditmodhvadia Nov 18, 2019
6d955a6
Merge pull request #3 from aditmodhvadia/feature/chat_setup
aditmodhvadia Nov 18, 2019
105ac24
- add room dependencies
aditmodhvadia Nov 18, 2019
cee36c8
Merge pull request #4 from aditmodhvadia/feature/room_setup_for_messages
aditmodhvadia Nov 18, 2019
a5e7eca
- add NetworkManager to application
aditmodhvadia Nov 23, 2019
6447214
- fix LoginActivity and RegistrationActivity flow
aditmodhvadia Nov 23, 2019
e74a5b5
- add API call for querying backend
aditmodhvadia Nov 23, 2019
a2a1c11
Merge pull request #5 from aditmodhvadia/feature/network_manager
aditmodhvadia Nov 23, 2019
04b8113
- change GET request to POST and send message query with it
aditmodhvadia Nov 24, 2019
f73bce5
- add method to store new sent messages and query response messages t…
aditmodhvadia Nov 29, 2019
bfb80c7
- add IntentService to store messages in FireBase and sync messages f…
aditmodhvadia Nov 30, 2019
1063031
- add static method to Message.java to convert given message into a H…
aditmodhvadia Nov 30, 2019
19fdf86
Merge pull request #6 from aditmodhvadia/feature/firebase_sync_service
aditmodhvadia Nov 30, 2019
8da01c8
Ui/ui updates refinement (#7)
aditmodhvadia Dec 12, 2019
9093643
- update develop branch
aditmodhvadia Mar 10, 2020
9b14d42
- update documentation
aditmodhvadia Mar 10, 2020
525ed62
Update README.md
aditmodhvadia Mar 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- registered and create user with email and password on successfully …
…entering details

- add test cases for AppUtils and RegistrationActivity
aditmodhvadia committed Nov 15, 2019
commit 813b43fd1a0897f32c71a63c080d4db7bf045c6f
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1' // logging library

// testing libraries
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.fazemeright.chatbotmetcs622.ui.registration;

import android.widget.EditText;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import com.fazemeright.chatbotmetcs622.R;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.assertEquals;


@RunWith(AndroidJUnit4.class)
public class RegistrationActivityTest {

private static final String INCORRECT_EMAIL_ADDRESS = "abcd@gmail";
private static final String CORRECT_EMAIL_ADDRESS = "[email protected]";
private static final String CORRECT_PASSWORD = "12345678";

@Rule
public ActivityTestRule<RegistrationActivity> mActivityRule = new ActivityTestRule<>(RegistrationActivity.class);

@Test
public void incorrect_email_address_error() throws Exception {
String expected = mActivityRule.getActivity().getString(R.string.incorrect_email_err_msg);
onView(withId(R.id.userLoginEmailEditText)).perform(typeText(INCORRECT_EMAIL_ADDRESS));
onView(withId(R.id.btnRegister)).perform(click());
EditText etEmail = mActivityRule.getActivity().findViewById(R.id.userLoginEmailEditText);
assertEquals(etEmail.getError().toString(), expected);
}

@Test
public void registration_flow_isCorrect() throws Exception {
onView(withId(R.id.userLoginEmailEditText)).perform(typeText(CORRECT_EMAIL_ADDRESS));
onView(withId(R.id.userPasswordEditText)).perform(typeText(CORRECT_PASSWORD));
onView(withId(R.id.userConPasswordEditText)).perform(typeText(CORRECT_PASSWORD));
onView(withId(R.id.btnRegister)).perform(click());
// onView(withId(R.id.btnRegister)).check(matches(withText(mActivityRule.getActivity().getString(R.string.registration_success_msg))));
}

}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -24,7 +24,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.registration.RegistrationActivity" />
<activity
android:name=".ui.registration.RegistrationActivity"
android:windowSoftInputMode="adjustResize" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,25 +1,127 @@
package com.fazemeright.chatbotmetcs622.ui.registration;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.fazemeright.chatbotmetcs622.R;
import com.fazemeright.chatbotmetcs622.ui.base.BaseActivity;
import com.fazemeright.chatbotmetcs622.utils.AppUtils;
import com.fazemeright.firebase_api_library.listeners.OnTaskCompleteListener;

import timber.log.Timber;

public class RegistrationActivity extends BaseActivity {
public class RegistrationActivity extends BaseActivity implements View.OnClickListener {

private EditText userEmailEditText, userPasswordEditText, userConPasswordEditText;
private TextView tvHaveAccount;
private Button btnRegister;

@Override
public void initViews() {
// set title for activity
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(getString(R.string.registration));
}

userEmailEditText = findViewById(R.id.userLoginEmailEditText);
userPasswordEditText = findViewById(R.id.userPasswordEditText);
userConPasswordEditText = findViewById(R.id.userConPasswordEditText);
tvHaveAccount = findViewById(R.id.tvHaveAccount);
btnRegister = findViewById(R.id.btnRegister);

}

@Override
public void setListeners() {

btnRegister.setOnClickListener(this);
tvHaveAccount.setOnClickListener(this);
}

@Override
public int getLayoutResId() {
return R.layout.activity_registration;
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tvHaveAccount:
// TODO: Open LoginActivity
break;
case R.id.btnRegister:
// TODO: Disable and re-enable the button after performing registration and validation
disableRegistrationButton();
String email = userEmailEditText.getText().toString();
String password = userEmailEditText.getText().toString();
String conPassword = userEmailEditText.getText().toString();
performRegistration(email, password, conPassword);
enableRegistrationButton();
break;
}

}

/**
* Call to perform validation on the input parameters and then perform registration
*
* @param email user email address
* @param password user selected password
* @param conPassword user selected confirmation password
*/
private void performRegistration(final String email, final String password, String conPassword) {
if (!AppUtils.isValidEmail(email)) {
userEmailEditText.setError(mContext.getString(R.string.incorrect_email_err_msg));
userEmailEditText.requestFocus();
return;
}

if (!AppUtils.isValidPassword(password)) {
userPasswordEditText.setError(mContext.getString(R.string.incorrect_pass_err_msg));
userPasswordEditText.requestFocus();
return;
}

if (!AppUtils.arePasswordsValid(password, conPassword)) {
userPasswordEditText.setError(mContext.getString(R.string.passwords_dont_match_err_msg));
userPasswordEditText.requestFocus();
userPasswordEditText.setText("");
userConPasswordEditText.setText("");
return;
}

apiManager.registerNewUserWithEmailPassword(email, password, new OnTaskCompleteListener() {
@Override
public void onTaskSuccessful() {
Timber.i("New user registered successfully %s", apiManager.getCurrentLoggedInUserEmail());
btnRegister.setText(getString(R.string.registration_success_msg));
}

@Override
public void onTaskCompleteButFailed(String errMsg) {
Timber.i(errMsg);
}

@Override
public void onTaskFailed(Exception e) {
Timber.i(e);
}
});

}

/**
* Enable Registration button
*/
private void enableRegistrationButton() {
btnRegister.setEnabled(true);
}

/**
* Disable Registration button
*/
private void disableRegistrationButton() {
btnRegister.setEnabled(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fazemeright.chatbotmetcs622.utils;

import android.text.TextUtils;
import android.util.Patterns;

public class AppUtils {

public static boolean isValidEmail(String email) {
return !TextUtils.isEmpty(email) && Patterns.EMAIL_ADDRESS.matcher(email).matches();
}

public static boolean isValidPassword(String password) {
return !TextUtils.isEmpty(password) && password.length() >= 8;
}

public static boolean arePasswordsValid(String password, String conPassword) {
return password.equals(conPassword);
}
}
122 changes: 120 additions & 2 deletions app/src/main/res/layout/activity_registration.xml
Original file line number Diff line number Diff line change
@@ -6,13 +6,131 @@
android:layout_height="match_parent"
tools:context=".ui.registration.RegistrationActivity">

<!-- TODO: Add logo to top-->

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/regular_margin"
android:hint="@string/email_address"
android:textColorHint="@android:color/black"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout2"
app:layout_constraintEnd_toStartOf="@+id/guidelineVerticalEnd"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/guidelineVerticalStart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed">

<EditText
android:id="@+id/userLoginEmailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black" />
</com.google.android.material.textfield.TextInputLayout>

<!-- TODO: Also ask user for username-->

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout2"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/regular_margin"
android:hint="@string/password"
android:textColorHint="@android:color/black"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout3"
app:layout_constraintEnd_toStartOf="@+id/guidelineVerticalEnd"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/guidelineVerticalStart"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@android:color/black">

<EditText
android:id="@+id/userPasswordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout3"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/regular_margin"
android:hint="@string/confirm_password"
android:textColorHint="@android:color/black"
app:layout_constraintBottom_toTopOf="@+id/btnRegister"
app:layout_constraintEnd_toStartOf="@+id/guidelineVerticalEnd"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/guidelineVerticalStart"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout2"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@android:color/black">

<EditText
android:id="@+id/userConPasswordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black" />
</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/regular_margin"
android:text="@string/register_button"
app:layout_constraintBottom_toTopOf="@+id/tvHaveAccount"
app:layout_constraintEnd_toStartOf="@+id/guidelineVerticalEnd"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/guidelineVerticalStart"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout3" />

<TextView
android:id="@+id/textView"
android:id="@+id/tvHaveAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/regular_margin"
android:text="@string/already_have_an_account"
android:textColor="@android:color/holo_blue_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/btnRegister" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineVerticalStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.05" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineVerticalEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.95" />

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="regular_margin">16dp</dimen>
</resources>
12 changes: 12 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<resources>
<string name="app_name">ChatBot MET CS622</string>


<!-- Registration Activity-->
<string name="registration">Registration</string>
<string name="register_button">Register</string>
<string name="email_address">Email Address</string>
<string name="password">Password</string>
<string name="confirm_password">Confirm Password</string>
<string name="already_have_an_account">Already have an account?</string>
<string name="incorrect_email_err_msg">Please enter email address in correct format</string>
<string name="incorrect_pass_err_msg">Please enter password longer than 8 characters</string>
<string name="passwords_dont_match_err_msg">Both passwords should match</string>
<string name="registration_success_msg">Registered Successfully</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.fazemeright.chatbotmetcs622.utils;

public class AppUtilsTest {


}
Original file line number Diff line number Diff line change
@@ -37,11 +37,12 @@ public boolean isUserEmailVerified() {
return isUserVerified();
}

public void createNewUserWithEmailPassword(String userEmail, String password, final OnTaskCompleteListener onTaskCompleteListener) {
public void registerNewUserWithEmailPassword(String userEmail, String password, final OnTaskCompleteListener onTaskCompleteListener) {
createNewUserWithEmailPassword(userEmail, password, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// TODO: Store userId and displayName in users collection under user id to firestore
onTaskCompleteListener.onTaskSuccessful();
} else {
onTaskFailed(task.getException(), onTaskCompleteListener);