Commit e55bbd9a authored by Christof Wolke's avatar Christof Wolke

add RegisterActivity to LoginActivity

parent 0dd39e0b
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.uni_oldenburg.bidl"> package="de.uni_oldenburg.bidl">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- To auto-complete the email text field in the login form with the user's emails --> <!-- To auto-complete the email text field in the login form with the user's emails -->
...@@ -26,14 +25,16 @@ ...@@ -26,14 +25,16 @@
</activity> </activity>
<activity <activity
android:name=".base_view.SplashActivity" android:name=".base_view.SplashActivity"
android:screenOrientation="sensorPortrait" android:parentActivityName=".base_view.SplashActivity"
android:parentActivityName=".base_view.SplashActivity"> android:screenOrientation="sensorPortrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"></category>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".guest_view.LoginActivity"></activity> <activity android:name=".guest_view.LoginActivity" />
<activity android:name=".guest_view.RegisterActivity"></activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
/**
* Created by Christof on 05.08.2016.
* Represents the Status Responseobject. Possible values are 'ok' or 'error'
*/
@JsonObject
public class StatusResponse {
@JsonField(name = "status")
private String status;
public StatusResponse(){
}
/**
*
* @param status
*/
public StatusResponse(String status){
this.status = status;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public String toString() {
return "StatusResponse{" +
"status='" + status + '\'' +
'}';
}
}
package de.uni_oldenburg.bidl.base_view; package de.uni_oldenburg.bidl.base_view;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import de.uni_oldenburg.bidl.R; import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import static com.estimote.sdk.repackaged.gson_v2_3_1.com.google.gson.internal.UnsafeAllocator.create;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
...@@ -12,6 +19,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -12,6 +19,9 @@ public class MainActivity extends AppCompatActivity {
/** GUI **/ /** GUI **/
private TextView beaconID; private TextView beaconID;
/** values **/
boolean doubleBackToExitPressedOnce = false;
@Override @Override
...@@ -27,5 +37,24 @@ public class MainActivity extends AppCompatActivity { ...@@ -27,5 +37,24 @@ public class MainActivity extends AppCompatActivity {
} }
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
this.finishAffinity();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, getString(R.string.clickAgainToExit), Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
} }
...@@ -114,6 +114,7 @@ public class SplashActivity extends AppCompatActivity { ...@@ -114,6 +114,7 @@ public class SplashActivity extends AppCompatActivity {
super.onPause(); super.onPause();
} }
private void toLoginActivity() { private void toLoginActivity() {
startActivity(new Intent(this, LoginActivity.class)); startActivity(new Intent(this, LoginActivity.class));
} }
......
...@@ -79,6 +79,37 @@ public class LoginActivity extends AppCompatActivity { ...@@ -79,6 +79,37 @@ public class LoginActivity extends AppCompatActivity {
}); });
} }
}); });
/** to Forgot Password Activity **/
forgotPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toForgotPasswortActivity();
}
});
/** to Register Activity **/
tvRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toRegisterActivity();
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
this.finishAffinity();
return;
}
private void toRegisterActivity() {
startActivity(new Intent(this, RegisterActivity.class));
}
private void toForgotPasswortActivity() {
// TODO: 04.08.2016 Create to ForgotPasswortActivity
} }
private void toMainActivity() { private void toMainActivity() {
......
package de.uni_oldenburg.bidl.guest_view;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.base_view.MainActivity;
import services.servercommunication.NetworkService;
public class RegisterActivity extends AppCompatActivity {
/** GUI **/
private EditText etUsername;
private EditText etEmail;
private EditText etPassword;
private Button btNewAccount;
private TextView tvToLogin;
/** values **/
private String name;
private String email;
private String password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
/** init **/
etUsername = (EditText) findViewById(R.id.etFullName);
etEmail = (EditText) findViewById(R.id.etEmail);
etPassword = (EditText) findViewById(R.id.etPassword);
btNewAccount = (Button) findViewById(R.id.btRegister);
tvToLogin = (TextView) findViewById(R.id.link_to_login);
/** clickhandler for registration **/
btNewAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
name = etUsername.getText().toString();
email = etEmail.getText().toString();
password = etPassword.getText().toString();
if (!(name.isEmpty() || email.isEmpty() || password.isEmpty())){
if (isEmailOk()){
btNewAccount.setEnabled(false);
register(name, email, password);
toMainActivity();
}else {
showToastMessage(getString(R.string.register_response_emailNotOk));
}
}else{
showToastMessage(getString(R.string.register_response_fillOutAllFields));
}
}
});
tvToLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
}
});
}
private void toMainActivity() {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
/**
* checks, if the email is valid
* @return true: ok
*/
private boolean isEmailOk() {
String email = this.etEmail.getText().toString();
return (email.contains("@"));
}
/**
* Register a User in the DB.
* @param email Email from the USer.
* @param name Name of the new User.
* @param password Password from the User.
*/
private void register(String email, String name, String password) {
NetworkService.register(email, name, password, new NetworkService.RequestRegisterHandler() {
@Override
public void done(String statusResponse) {
switch (statusResponse) {
case "ok":
showToastMessage(getString(R.string.register_response_registerSuccess));
break;
case "error":
showToastMessage(getString(R.string.register_response_registerFail));
break;
default:
showToastMessage(getString(R.string.register_response_noconnection));
break;
}
// Wechseln auf UI Thread....x
RegisterActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
btNewAccount.setEnabled(true);
}
});
}
});
}
/**
* Shows the User different messages.
* @param message Toast message for the User.
*/
private void showToastMessage(final String message) {
RegisterActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
});
}
}
...@@ -12,6 +12,7 @@ import com.squareup.okhttp.Response; ...@@ -12,6 +12,7 @@ import com.squareup.okhttp.Response;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import classes.StatusResponse;
import classes.User; import classes.User;
/** /**
...@@ -82,4 +83,48 @@ public abstract class NetworkService { ...@@ -82,4 +83,48 @@ public abstract class NetworkService {
public interface RequestLoginHandler { public interface RequestLoginHandler {
void done(User user); void done(User user);
} }
/**
* Registriert einen Nutzer
* @param email
* @param username
* @param password
* @param handler
*/
public static void register(String email, String username, String password, final RequestRegisterHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
/* Request body with POST params */
RequestBody requestBody = new FormEncodingBuilder()
.add("email", email)
.add("username", username)
.add("pass", password)
.build();
/* add body to POST-request */
Request req = new Request.Builder()
.url(REST.SPRING_REGISTER)
.post(requestBody)
.build();
/* Server call preparation */
Call call = okHttpClient.newCall(req);
/* ASync call */
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
handler.done("failure");
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
if (response.isSuccessful()){
StatusResponse statusResponseObj = LoganSquare.parse(response.body().byteStream(), StatusResponse.class);
handler.done(statusResponseObj.getStatus());
}
}
});
}
public interface RequestRegisterHandler {
void done(String statusResponse);
}
} }
...@@ -27,4 +27,8 @@ public abstract class REST { ...@@ -27,4 +27,8 @@ public abstract class REST {
private static final String LOGIN = "/login"; private static final String LOGIN = "/login";
public static String SPRING_LOGIN = FULL_URL + LOGIN; public static String SPRING_LOGIN = FULL_URL + LOGIN;
//Register path
private static final String REGISTER = "/register";
public static String SPRING_REGISTER = FULL_URL + REGISTER;
} }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.uni_oldenburg.bidl.guest_view.RegisterActivity"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvFullName"
android:text="@string/textViewFullName"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:singleLine="true"
android:id="@+id/etFullName"
android:inputType="textPersonName"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvEmail"
android:text="@string/textViewEmail"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:singleLine="true"
android:id="@+id/etEmail"
android:inputType="textEmailAddress"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvPassword"
android:text="@string/textViewPassword"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:singleLine="true"
android:id="@+id/etPassword"
android:inputType="textPassword" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/btRegister"
android:text="@string/textButton"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:layout_marginTop="40dp"
android:id="@+id/link_to_login"
android:text="@string/textViewToLogin"
android:gravity="center"
android:textSize="20dp"/>
</LinearLayout>
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#FF4081</color>
<color name="white">#FFFFFF</color> <color name="white">#FFFFFF</color>
<color name="grey">#c8c8ce</color>
<color name="black_overlay">#66000000</color> <color name="black_overlay">#66000000</color>
</resources> </resources>
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
<string name="noBeaconFound">Kein Beacon in der Nähe!</string> <string name="noBeaconFound">Kein Beacon in der Nähe!</string>
<string name="title_activity_login">Sign in</string> <string name="title_activity_login">Sign in</string>
<!-- Main Activity !-->
<string name="clickAgainToExit">Erneut klicken zum Beenden!</string>
<!-- Login Activity !--> <!-- Login Activity !-->
<string name="hintTextEmail">E-Mail Adresse</string> <string name="hintTextEmail">E-Mail Adresse</string>
<string name="hintTextPass">Passwort</string> <string name="hintTextPass">Passwort</string>
...@@ -17,5 +20,18 @@ ...@@ -17,5 +20,18 @@
<string name="registerDescription">Registrieren</string> <string name="registerDescription">Registrieren</string>
<string name="forgotPassword">Passwort vergessen?</string> <string name="forgotPassword">Passwort vergessen?</string>
<!-- Register Activity !-->
<string name="textViewEmail">Email</string>
<string name="textViewPassword">Passwort</string>
<string name="textButton">Neuen Account erstellen</string>
<string name="textViewFullName">Benutzername</string>
<string name="textViewToLogin">Ich habe einen Account!</string>
<string name="register_response_fillOutAllFields">Bitte alle Felder ausfüllen!</string>
<string name="register_response_emailNotOk">Email nicht in Ordnung!</string>
<string name="register_response_registerFail">Email bereits verwendet!</string>
<string name="register_response_registerSuccess">Registrierung erfolgreich!</string>
<string name="register_response_noconnection">Es konnte keine Verbindung zum Server hergestellt werden!</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment