Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
android:name="com.zitec.workshopz.user.activities.LoginActivity"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"></activity>
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar">
</activity>
<activity
android:name="com.zitec.workshopz.workshopz.activities.WorkshopzActivity"
class="com.zitec.workshopz.workshopz.activities.WorkshopzActivity"
Expand Down
7 changes: 7 additions & 0 deletions res/layout/login_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
android:layout_height="wrap_content"
android:id="@+id/submit"
android:text="@string/login_submit_label"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/register"
android:text="@string/login_register_label"/>

</LinearLayout>
62 changes: 62 additions & 0 deletions res/layout/register_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/register_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:imeOptions="actionNext"
android:hint="@string/name_label" />

<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:hint="@string/email_label" />

<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:imeOptions="actionNext"
android:hint="@string/phone_label" />

<EditText
android:id="@+id/position"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:imeOptions="actionNext"
android:hint="@string/position_label" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionGo"
android:imeActionLabel="@string/login_submit_label"
android:hint="@string/password_label" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/create"
android:text="@string/create_label" />

<Button
android:id="@+id/cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cancel_label" />

</LinearLayout>
12 changes: 11 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
<string name="empty_username_error">Username cannot be empty</string>
<string name="empty_password_error">Password cannot be empty</string>
<string name="network_error">Network error</string>
<string name="date_label">Date: </string>
<string name="date_label">Date: </string>
<string name="speakers_label">Speakers: </string>
<string name="syncdb_service_name">workshopz syncronizer</string>
<string name="login_register_label">Create an account</string>

<string name="name_label">Name</string>
<string name="email_label">E-mail</string>
<string name="phone_label">Phone number</string>
<string name="position_label">Position</string>
<string name="create_label">Create</string>
<string name="cancel_label">Cancel</string>
<string name="empty_field_label">Field is empty</string>

<string name="account_creted">Your account was created. Proceed to login!</string>
<string name="account_failed">Your account wasn\'t created. Please try again!</string>

<string name="ws_base_url">http://workshopz.apache.dev54.zitec.ro</string>

Expand Down
28 changes: 17 additions & 11 deletions src/com/zitec/workshopz/user/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import java.util.ArrayList;
import java.util.HashMap;

import android.app.FragmentManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.widget.Toast;

import com.zitec.workshopz.R;
import com.zitec.workshopz.base.BaseActivity;
import com.zitec.workshopz.base.BaseEntity;
import com.zitec.workshopz.base.EntityResponseListener;
import com.zitec.workshopz.base.storage.Error;
import com.zitec.workshopz.base.validators.NotEmpty;
import com.zitec.workshopz.user.dialogs.RegisterDialog;
import com.zitec.workshopz.user.entities.User;
import com.zitec.workshopz.user.storage.adapters.UserDbAdapter;
import com.zitec.workshopz.user.storage.adapters.UserWSAdapter;
Expand Down Expand Up @@ -65,7 +70,11 @@ public void onSuccess(ArrayList<BaseEntity> obj) {
}
User usr = (User) obj.get(0);
BaseActivity.identity = usr;
mapper.setAdapter(new UserDbAdapter(LoginActivity.this));
try {
mapper.setAdapter(new UserDbAdapter(LoginActivity.this));
} catch (NameNotFoundException e) {
e.printStackTrace();
}
usr.setCurrentIdentity("true");
mapper.save(usr);
LoginActivity.this.loadWorkshops();
Expand All @@ -79,15 +88,12 @@ public void onError(Error err) {
}
});
mapper.getEntity(username, password);










}

public void showRegisterDialog() {
FragmentManager fm = getFragmentManager();
RegisterDialog registerDialog = new RegisterDialog();
registerDialog.setActivity(this);
registerDialog.show(fm, "register_dialog");
}
}
137 changes: 137 additions & 0 deletions src/com/zitec/workshopz/user/dialogs/RegisterDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.zitec.workshopz.user.dialogs;

import java.util.HashMap;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.zitec.workshopz.R;
import com.zitec.workshopz.base.validators.NotEmpty;
import com.zitec.workshopz.user.activities.LoginActivity;

import android.app.DialogFragment;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class RegisterDialog extends DialogFragment implements View.OnClickListener{
protected EditText name;
protected EditText email;
protected EditText phone;
protected EditText position;
protected EditText password;
protected Button create;
protected Button cancel;
protected View view;
protected LoginActivity act;

public void setActivity(LoginActivity act) {
this.act = act;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.view = inflater.inflate(R.layout.register_dialog, container);
setCancelable(false);
this.name = (EditText) view.findViewById(R.id.name);
this.email = (EditText) view.findViewById(R.id.email);
this.phone = (EditText) view.findViewById(R.id.phone);
this.position = (EditText) view.findViewById(R.id.position);
this.password = (EditText) view.findViewById(R.id.password);

this.create = (Button) view.findViewById(R.id.create);
this.cancel = (Button) view.findViewById(R.id.cancel);

this.create.setOnClickListener(this);
this.cancel.setOnClickListener(this);

getDialog().setTitle("Create new user");

return this.view;
}


@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.cancel:
dismiss();
case R.id.create:
createAccount();
}
}


protected void createAccount(){
SparseArray<String> values = new SparseArray<String>();
values.append(this.name.getId(), this.name.getText().toString());
values.append(this.email.getId(), this.email.getText().toString());
values.append(this.phone.getId(), this.phone.getText().toString());
values.append(this.position.getId(), this.position.getText().toString());
values.append(this.password.getId(), this.password.getText().toString());

if (!isFormValid(values)) {
return;
}
makeWsRequest();
}

protected void makeWsRequest() {
String url = this.view.getResources().getString(R.string.ws_base_url) + "/users";
Log.d("Volley", url);

RequestQueue reqQueue = Volley.newRequestQueue(this.act);
StringRequest req = new StringRequest(
Request.Method.POST,
url,
new Response.Listener<String>(){
@Override
public void onResponse(String response) {
Toast.makeText(RegisterDialog.this.act, RegisterDialog.this.getResources().getString(R.string.account_creted), Toast.LENGTH_SHORT).show();
dismiss();
}

},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegisterDialog.this.act, RegisterDialog.this.getResources().getString(R.string.account_failed), Toast.LENGTH_SHORT).show();
}
}
) {
public HashMap<String, String> getParams() {
HashMap<String, String> params = new HashMap<String, String>();
params.put("name", RegisterDialog.this.name.getText().toString());
params.put("email", RegisterDialog.this.email.getText().toString());
params.put("phone_number", RegisterDialog.this.phone.getText().toString());
params.put("position", RegisterDialog.this.position.getText().toString());
params.put("password", RegisterDialog.this.password.getText().toString());

return params;
}
};
reqQueue.add(req);
}

protected boolean isFormValid(SparseArray<String> values){
boolean result = true;
NotEmpty validator = new NotEmpty();
int nr = values.size();
for(int i = 0; i < nr; i++){
if(!validator.validate(values.valueAt(i))){
result = false;
((EditText)this.view.findViewById(values.keyAt(i))).setError(this.getResources().getString(R.string.empty_field_label));
}
}
return result;
}
}
13 changes: 0 additions & 13 deletions src/com/zitec/workshopz/user/storage/adapters/UserDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.database.Cursor;

import com.zitec.workshopz.base.storage.adapters.BaseDbStorageAdapter;
import com.zitec.workshopz.base.storage.adapters.BaseStorageAdapter;
import com.zitec.workshopz.utils.DbHelper;
import com.zitec.workshopz.utils.VersionUtils;

Expand Down Expand Up @@ -49,16 +48,4 @@ protected ArrayList<HashMap<String, String>> getRows(Cursor crs){
}
return results;
}












}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public HashMap<String, String> getHeaders(){
this.queue.add(req);
}


// @Override
// public String getBaseUrl(){
// String url = super.getBaseUrl();
Expand Down
15 changes: 14 additions & 1 deletion src/com/zitec/workshopz/user/views/LoginView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zitec.workshopz.user.views;


import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
Expand All @@ -21,6 +20,7 @@ public class LoginView extends BaseView {
EditText username;
EditText password;
Button submit;
Button register;
SparseArray<String> errors;


Expand All @@ -37,6 +37,7 @@ public void initView() {
this.username = (EditText)this.act.findViewById(R.id.username);
this.password = (EditText)this.act.findViewById(R.id.password);
this.submit = (Button)this.act.findViewById(R.id.submit);
this.register = (Button)this.act.findViewById(R.id.register);
}

@Override
Expand All @@ -47,6 +48,14 @@ public void onClick(View v) {
LoginView.this.submitLogin();
}
});

this.register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LoginView.this.register();
}
});

this.password.setOnEditorActionListener(new OnEditorActionListener() {

@Override
Expand All @@ -71,6 +80,10 @@ protected void submitLogin(){
}
}

protected void register(){
this.act.showRegisterDialog();
}

public void showErrors(){
SparseArray<String> errs = this.act.getErrors();
int nr = errs.size();
Expand Down