Merge branch 'master' into 'paul-profile'

# Conflicts:
#   app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml
#   app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml
This commit is contained in:
Marijn Jansen
2017-06-22 11:39:07 +02:00
7 changed files with 97 additions and 41 deletions

View File

@@ -1,10 +1,10 @@
package nl.myhyvesbookplus.tagram; package nl.myhyvesbookplus.tagram;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.os.PersistableBundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@@ -30,6 +30,8 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
protected FirebaseAuth mAuth; protected FirebaseAuth mAuth;
private ProgressDialog progressDialog;
/// Setup /// /// Setup ///
@Override @Override
@@ -42,11 +44,6 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
bindOnClick(); bindOnClick();
} }
@Override
protected void onStart() {
super.onStart();
}
/** /**
* Assigns all views. * Assigns all views.
*/ */
@@ -101,26 +98,37 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
* Performs the logon action. * Performs the logon action.
*/ */
public void logInOnClick() { public void logInOnClick() {
String emailSting = emailField.getText().toString(); String emailString = emailField.getText().toString();
String passwordSting = passwordField.getText().toString(); String passwordString = passwordField.getText().toString();
logIn(emailSting, passwordSting); if (!emailString.isEmpty() && !passwordString.isEmpty()) {
logIn(emailString, passwordString);
} else {
Toast.makeText(LoginActivity.this, R.string.login_error, Toast.LENGTH_SHORT).show();
}
} }
/** /**
* Performs the register action. * Performs the register action.
*/ */
public void registerOnClick() { public void registerOnClick() {
Log.d(TAG, "registerOnClick: "); String emailString = emailField.getText().toString();
String usernameString = usernameField.getText().toString();
String passwordString = passwordField.getText().toString();
String passwordConfirmString = passwordConfirmField.getText().toString();
if (passwordField.getText().toString().equals(passwordConfirmField.getText().toString())) { if (!emailString.isEmpty() && !usernameString.isEmpty()
registerUser(emailField.getText().toString(), passwordField.getText().toString()); && passwordString.isEmpty() && passwordConfirmString.isEmpty()) {
if (passwordField.getText().toString().equals(passwordConfirmField.getText().toString())) {
registerUser(emailField.getText().toString(), passwordField.getText().toString());
} else {
Toast.makeText(LoginActivity.this, R.string.password_match_error,
Toast.LENGTH_SHORT).show();
Log.d(TAG, "registerOnClick: Passwords do not match");
}
} else { } else {
Toast.makeText(LoginActivity.this, "Passwords do not match", Toast.makeText(LoginActivity.this, R.string.register_error, Toast.LENGTH_SHORT).show();
Toast.LENGTH_SHORT).show();
Log.d(TAG, "registerOnClick: Passwords do not match");
} }
} }
/// UI-changes /// /// UI-changes ///
@@ -161,6 +169,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
protected void goToMainScreen() { protected void goToMainScreen() {
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
startActivity(intent); startActivity(intent);
progressDialog.dismiss();
this.finish(); this.finish();
} }
@@ -168,11 +177,13 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
/** /**
* Performs the actual login action. * Performs the actual login action.
* @param emailSting email address * @param emailString email address
* @param passwordSting the entered password * @param passwordString the entered password
*/ */
protected void logIn(String emailSting, String passwordSting) { protected void logIn(String emailString, String passwordString) {
mAuth.signInWithEmailAndPassword(emailSting, passwordSting) progressDialog = ProgressDialog.show(LoginActivity.this, getString(R.string.please_wait), "Logging in", true, false);
mAuth.signInWithEmailAndPassword(emailString, passwordString)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override @Override
public void onComplete(@NonNull Task<AuthResult> task) { public void onComplete(@NonNull Task<AuthResult> task) {
@@ -186,6 +197,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
} else { } else {
// If sign in fails, display a message to the user. // If sign in fails, display a message to the user.
Log.w(TAG, "signInWithEmail:failure", task.getException()); Log.w(TAG, "signInWithEmail:failure", task.getException());
progressDialog.dismiss();
Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(), Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
@@ -199,6 +211,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
* @param password the entered password * @param password the entered password
*/ */
protected void registerUser(String email, String password) { protected void registerUser(String email, String password) {
this.progressDialog = ProgressDialog.show(LoginActivity.this, getString(R.string.please_wait), "Registering", true, false);
mAuth.createUserWithEmailAndPassword(email, password) mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override @Override
@@ -213,6 +226,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
// If sign in fails, display a message to the user. // If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException()); Log.w(TAG, "createUserWithEmail:failure", task.getException());
if (task.getException() != null) { if (task.getException() != null) {
progressDialog.dismiss();
Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(), Toast.makeText(LoginActivity.this, task.getException().getLocalizedMessage(),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }

View File

@@ -0,0 +1,60 @@
package nl.myhyvesbookplus.tagram;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.annotation.NonNull;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.io.ByteArrayOutputStream;
/**
* Created by marijnjansen on 20/06/2017.
*/
public class UploadClass {
private StorageReference mStorageRef;
public UploadClass() {
mStorageRef = FirebaseStorage.getInstance().getReference().child("images");
}
private byte[] bitmapToBytes(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
return baos.toByteArray();
}
public void uploadPicture(Bitmap bitmap) {
UploadTask uploadTask = mStorageRef.putBytes(bitmapToBytes(bitmap));
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
})
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Handle successful uploads on complete
Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
}
});
}
private String getUserUid() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
return user.getUid();
}
return "";
}
}

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
</vector>

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -17,4 +17,5 @@
<string name="profile_picture_button">Wijzig Profiel Foto</string> <string name="profile_picture_button">Wijzig Profiel Foto</string>
<string name="profile_picture_description">profiel foto</string> <string name="profile_picture_description">profiel foto</string>
<string name="change_psw_button">Wachtwoord wijzigen</string> <string name="change_psw_button">Wachtwoord wijzigen</string>
<string name="please_wait">Wacht a.u.b.</string>
</resources> </resources>

View File

@@ -4,7 +4,6 @@
<string name="title_dashboard">Camera</string> <string name="title_dashboard">Camera</string>
<string name="title_notifications">Profile</string> <string name="title_notifications">Profile</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="username">Username</string> <string name="username">Username</string>
<string name="password">Password</string> <string name="password">Password</string>
<string name="confirm_password">Confirm Password</string> <string name="confirm_password">Confirm Password</string>
@@ -14,7 +13,6 @@
<string name="back_to_login">back to Login</string> <string name="back_to_login">back to Login</string>
<string name="email">Email</string> <string name="email">Email</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="hello_camera">Hello Camera</string> <string name="hello_camera">Hello Camera</string>
<string name="logo_text">MyHyvesBookPlusTagram logo</string> <string name="logo_text">MyHyvesBookPlusTagram logo</string>
@@ -22,4 +20,5 @@
<string name="profile_picture_button">Change Profile Picture</string> <string name="profile_picture_button">Change Profile Picture</string>
<string name="profile_picture_description">profile picture</string> <string name="profile_picture_description">profile picture</string>
<string name="change_psw_button">Change Password</string> <string name="change_psw_button">Change Password</string>
<string name="please_wait">Please Wait</string>
</resources> </resources>