From c27d2aadf9ce73a80a4f573fc6fd3770d81e65f9 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 3 Jul 2016 16:41:11 +0300 Subject: [PATCH 1/8] UI improve in Display Note --- .idea/libraries/android_android_23.xml | 9 ++ .../animated_vector_drawable_23_3_0.xml | 1 + .idea/libraries/appcompat_v7_23_3_0.xml | 1 + .idea/libraries/design_23_3_0.xml | 1 + .idea/libraries/recyclerview_v7_23_3_0.xml | 3 +- .../libraries/support_annotations_23_3_0.xml | 3 +- .idea/libraries/support_v4_23_3_0.xml | 3 +- .../support_vector_drawable_23_3_0.xml | 1 + .idea/libraries/volley_1_0_0.xml | 2 +- .idea/misc.xml | 2 +- .../PersonalSpaceActivity.java | 60 +++++++++---- app/src/main/res/layout/note_display_full.xml | 89 +++++++++++-------- 12 files changed, 116 insertions(+), 59 deletions(-) create mode 100644 .idea/libraries/android_android_23.xml diff --git a/.idea/libraries/android_android_23.xml b/.idea/libraries/android_android_23.xml new file mode 100644 index 0000000..a279d4a --- /dev/null +++ b/.idea/libraries/android_android_23.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_23_3_0.xml b/.idea/libraries/animated_vector_drawable_23_3_0.xml index d5460f1..1272933 100644 --- a/.idea/libraries/animated_vector_drawable_23_3_0.xml +++ b/.idea/libraries/animated_vector_drawable_23_3_0.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/libraries/appcompat_v7_23_3_0.xml b/.idea/libraries/appcompat_v7_23_3_0.xml index 0dbe7ef..da3b5a3 100644 --- a/.idea/libraries/appcompat_v7_23_3_0.xml +++ b/.idea/libraries/appcompat_v7_23_3_0.xml @@ -9,6 +9,7 @@ + diff --git a/.idea/libraries/design_23_3_0.xml b/.idea/libraries/design_23_3_0.xml index 441bb88..ffd6ab6 100644 --- a/.idea/libraries/design_23_3_0.xml +++ b/.idea/libraries/design_23_3_0.xml @@ -9,6 +9,7 @@ + diff --git a/.idea/libraries/recyclerview_v7_23_3_0.xml b/.idea/libraries/recyclerview_v7_23_3_0.xml index c4ab7de..e2d2128 100644 --- a/.idea/libraries/recyclerview_v7_23_3_0.xml +++ b/.idea/libraries/recyclerview_v7_23_3_0.xml @@ -4,11 +4,12 @@ - + + diff --git a/.idea/libraries/support_annotations_23_3_0.xml b/.idea/libraries/support_annotations_23_3_0.xml index e592bd6..a2f182e 100644 --- a/.idea/libraries/support_annotations_23_3_0.xml +++ b/.idea/libraries/support_annotations_23_3_0.xml @@ -1,10 +1,11 @@ - + + diff --git a/.idea/libraries/support_v4_23_3_0.xml b/.idea/libraries/support_v4_23_3_0.xml index a2479db..e75eec2 100644 --- a/.idea/libraries/support_v4_23_3_0.xml +++ b/.idea/libraries/support_v4_23_3_0.xml @@ -5,11 +5,12 @@ - + + diff --git a/.idea/libraries/support_vector_drawable_23_3_0.xml b/.idea/libraries/support_vector_drawable_23_3_0.xml index 7f87d23..a47f58e 100644 --- a/.idea/libraries/support_vector_drawable_23_3_0.xml +++ b/.idea/libraries/support_vector_drawable_23_3_0.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/libraries/volley_1_0_0.xml b/.idea/libraries/volley_1_0_0.xml index 8e317b7..81a83dd 100644 --- a/.idea/libraries/volley_1_0_0.xml +++ b/.idea/libraries/volley_1_0_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 1a3eaff..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java index 426bf28..b38cf5c 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java @@ -10,11 +10,13 @@ import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.WindowManager; +import android.widget.AdapterView; import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ListView; import android.widget.Switch; +import android.widget.TextView; import android.widget.Toast; import com.android.volley.Request; @@ -79,16 +81,57 @@ public class PersonalSpaceActivity extends AppCompatActivity { noteListAdapter = new ListAdapter(this, listOfNotes); noteList.setAdapter(noteListAdapter); -// new HeavyWorker(this).execute(); - getAllNotes(); + new HeavyWorker(this).execute(); +// getAllNotes(); //https://thesocialnotework-api.appspot.com/api/note/all?uid= addBtn.setOnClickListener(addNewNoteDialog); + // click on listView item + noteList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + //create and configure dialog + Note note = listOfNotes.get(position); + final Dialog dialog = new Dialog(PersonalSpaceActivity.this); + dialog.setContentView(R.layout.note_display_full); + dialog.setTitle("You wrote..."); + + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.MATCH_PARENT; + lp.height = WindowManager.LayoutParams.MATCH_PARENT; + dialog.show(); +// dialog.getWindow().setAttributes(lp); + + + //get note_view_full layout elements + final TextView title = (TextView) dialog.findViewById(R.id.ndf_title_textview); + final TextView body = (TextView) dialog.findViewById(R.id.ndf_body_textview); + final TextView time = (TextView) dialog.findViewById(R.id.ndf_time_textview); + final TextView location = (TextView) dialog.findViewById(R.id.ndf_address_textview); + final TextView likes = (TextView) dialog.findViewById(R.id.ndf_likes_textview); + final TextView tags = (TextView) dialog.findViewById(R.id.ndf_tags_textview); + final TextView permission = (TextView) dialog.findViewById(R.id.ndf_permission_textview); + + + title.setText(note.getTitle()); + body.setText(note.getBody()); + time.setText(note.getTimestamp()); + location.setText("Tags: "+note.getAddress()); + likes.setText("Likes: "+note.getLikes()); + tags.setText(note.getTags().toString()); + permission.setText("Permission: "+ (note.isPublic() ? "Public" : "Private")); + + } + + }); + } + public void getAllNotes(){ Log.d(TAG, "url: "+BASE_URL + "/note/all?uid="+userId); VolleyUtilSingleton.getInstance(PersonalSpaceActivity.this).get(BASE_URL + "/note/all?uid="+userId, getNotesSuccessListener, genericErrorListener); @@ -183,19 +226,6 @@ public class PersonalSpaceActivity extends AppCompatActivity { -// //TODO remove -// public void addDemoNotes(List listOfNotes) { -// Note n1 = new Note("1", 100, 100, "location1", "My 1st Title", "ohh i'm so sexy1", ""+System.currentTimeMillis() / 1000, true); -// Note n2 = new Note("2", 200, 200, "location2", "My 2st Title", "ohh i'm so sexy2", ""+System.currentTimeMillis() / 1000, true); -// Note n3 = new Note("3", 300, 300, "hell", "My 3st Title", "ohh i'm so sexy3", ""+System.currentTimeMillis() / 1000, true); -//// Note n4 = new Note("4", 400, 400, "hell2", "My 4st Title", "ohh i'm so sexy4", ""+System.currentTimeMillis() / 1000, true); -// listOfNotes.add(n1); -// listOfNotes.add(n2); -// listOfNotes.add(n3); -//// listOfNotes.add(n4); -// } - - public void setLocationPermission(boolean locationPermission) { this.locationPermission = locationPermission; } diff --git a/app/src/main/res/layout/note_display_full.xml b/app/src/main/res/layout/note_display_full.xml index 6ffde10..f7fd781 100644 --- a/app/src/main/res/layout/note_display_full.xml +++ b/app/src/main/res/layout/note_display_full.xml @@ -1,49 +1,60 @@ - + android:layout_height="match_parent"> - - + - + - + - + - + - + - \ No newline at end of file + + + + + + + \ No newline at end of file From 4dae63bb754c99d248424e27c211b60b69a44275 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 3 Jul 2016 17:24:07 +0300 Subject: [PATCH 2/8] added delete option to note display --- .../PersonalSpaceActivity.java | 153 +++++++++++------- app/src/main/res/layout/note_display_full.xml | 7 + 2 files changed, 100 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java index b38cf5c..f86ea97 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalSpaceActivity.java @@ -1,7 +1,9 @@ package com.android_app.matan.ara.sagi.thesocialnotework; import android.Manifest; +import android.app.AlertDialog; import android.app.Dialog; +import android.content.DialogInterface; import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; @@ -14,6 +16,7 @@ import android.widget.AdapterView; import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.ListView; import android.widget.Switch; import android.widget.TextView; @@ -61,7 +64,7 @@ public class PersonalSpaceActivity extends AppCompatActivity { setContentView(R.layout.activity_personal_space); Bundle b = getIntent().getExtras(); userId = b.getString("user_id"); - Log.d(TAG,"-------------------------USER ID: "+ userId); + Log.d(TAG, "-------------------------USER ID: " + userId); this.locationPermission = true; @@ -84,57 +87,98 @@ public class PersonalSpaceActivity extends AppCompatActivity { new HeavyWorker(this).execute(); // getAllNotes(); -//https://thesocialnotework-api.appspot.com/api/note/all?uid= addBtn.setOnClickListener(addNewNoteDialog); // click on listView item noteList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { + public void onItemClick(AdapterView parent, View view, final int position, long id) { //create and configure dialog - Note note = listOfNotes.get(position); - final Dialog dialog = new Dialog(PersonalSpaceActivity.this); - dialog.setContentView(R.layout.note_display_full); - dialog.setTitle("You wrote..."); + final Note note = listOfNotes.get(position); + final Dialog noteViewDialog = new Dialog(PersonalSpaceActivity.this); + noteViewDialog.setContentView(R.layout.note_display_full); + noteViewDialog.setTitle("You wrote..."); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); + lp.copyFrom(noteViewDialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; - dialog.show(); + noteViewDialog.show(); // dialog.getWindow().setAttributes(lp); //get note_view_full layout elements - final TextView title = (TextView) dialog.findViewById(R.id.ndf_title_textview); - final TextView body = (TextView) dialog.findViewById(R.id.ndf_body_textview); - final TextView time = (TextView) dialog.findViewById(R.id.ndf_time_textview); - final TextView location = (TextView) dialog.findViewById(R.id.ndf_address_textview); - final TextView likes = (TextView) dialog.findViewById(R.id.ndf_likes_textview); - final TextView tags = (TextView) dialog.findViewById(R.id.ndf_tags_textview); - final TextView permission = (TextView) dialog.findViewById(R.id.ndf_permission_textview); + final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview); + final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview); + final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_textview); + final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview); + final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); + final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview); + final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); + final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); title.setText(note.getTitle()); body.setText(note.getBody()); time.setText(note.getTimestamp()); - location.setText("Tags: "+note.getAddress()); - likes.setText("Likes: "+note.getLikes()); + location.setText("Tags: " + note.getAddress()); + likes.setText("Likes: " + note.getLikes()); tags.setText(note.getTags().toString()); - permission.setText("Permission: "+ (note.isPublic() ? "Public" : "Private")); + permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); + + deleteBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + //Put up the Yes/No message box + AlertDialog.Builder builder = new AlertDialog.Builder(PersonalSpaceActivity.this); + builder + .setTitle("Delete Note") + .setMessage("Are you sure you want to delete the note?") + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton("Yes", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Yes button clicked, do something + Toast.makeText(PersonalSpaceActivity.this, "Item Deleted!", + Toast.LENGTH_SHORT).show(); + //TODO send delete + JSONObject delNote = new JSONObject(); + try { + delNote.put("uid", userId); + delNote.put("nid", note.getId()); + VolleyUtilSingleton.getInstance(PersonalSpaceActivity.this).post(BASE_URL + "/note/delete",delNote, deleteNoteSuccessListener, genericErrorListener); + listOfNotes.remove(position); + + } catch (JSONException e) { + Toast.makeText(PersonalSpaceActivity.this, "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); + e.printStackTrace(); + } + noteList.setAdapter(noteListAdapter); +// dialog.dismiss(); + noteViewDialog.dismiss(); + } + }) + .setNegativeButton("No", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Yes button clicked, do something + Toast.makeText(PersonalSpaceActivity.this, "Note still here!", + Toast.LENGTH_SHORT).show(); +// dialog.dismiss(); + noteViewDialog.dismiss(); + } + }) //Do nothing on no + .show(); + } + }); } - }); - } - public void getAllNotes(){ - Log.d(TAG, "url: "+BASE_URL + "/note/all?uid="+userId); - VolleyUtilSingleton.getInstance(PersonalSpaceActivity.this).get(BASE_URL + "/note/all?uid="+userId, getNotesSuccessListener, genericErrorListener); + public void getAllNotes() { + Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId); + VolleyUtilSingleton.getInstance(PersonalSpaceActivity.this).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, genericErrorListener); } private View.OnClickListener addNewNoteDialog = new View.OnClickListener() { @@ -170,16 +214,14 @@ public class PersonalSpaceActivity extends AppCompatActivity { public void onClick(View v) { //title too short - if (newTitle.getText().length() == 0) - { + if (newTitle.getText().length() == 0) { Toast toast = Toast.makeText(PersonalSpaceActivity.this, "Title too short.", Toast.LENGTH_LONG); toast.show(); return; } //title too long - if (newTitle.getText().length() > 20) - { + if (newTitle.getText().length() > 20) { Toast toast = Toast.makeText(PersonalSpaceActivity.this, "Title too long.\n Use up to 20 notes.", Toast.LENGTH_LONG); toast.show(); return; @@ -201,7 +243,7 @@ public class PersonalSpaceActivity extends AppCompatActivity { } catch (Exception e) { - Log.d(TAG, "saveBtn: "+e.toString()); + Log.d(TAG, "saveBtn: " + e.toString()); } //send request and close dialog @@ -225,7 +267,6 @@ public class PersonalSpaceActivity extends AppCompatActivity { }; - public void setLocationPermission(boolean locationPermission) { this.locationPermission = locationPermission; } @@ -278,7 +319,7 @@ public class PersonalSpaceActivity extends AppCompatActivity { Response.Listener getNotesSuccessListener = new Response.Listener() { @Override public void onResponse(JSONObject response) { - Log.d(TAG,"getNotesSuccessListener: "+response.toString()); + Log.d(TAG, "getNotesSuccessListener: " + response.toString()); try { //need to get all notes and add to listOfNotes JSONArray noteObjectsArray = response.getJSONArray("notes"); @@ -288,34 +329,29 @@ public class PersonalSpaceActivity extends AppCompatActivity { time.setTime(noteObject.getLong("created_at")); addNoteFromJsonObj(noteObject, time); -// Note addNote = new Note( -// noteObject.getString("id"), -// Float.parseFloat(noteObject.getJSONObject("location").getString("lat")), -// Float.parseFloat(noteObject.getJSONObject("location").getString("lng")), -// noteObject.getJSONObject("location").getString("address"), -// noteObject.getString("title"), -// noteObject.getString("body"), -// time.toString(), -// noteObject.getBoolean("is_public"), -// noteObject.getInt("likes"), -// jsonArrayToStringArray(noteObject.getJSONArray("tags")) -// ); -// listOfNotes.add(addNote); } noteList.setAdapter(noteListAdapter); } catch (Exception e) { Log.e(TAG, "newNoteSuccess:" + e.getMessage()); } - } }; + //response listener for getting all user notes + Response.Listener deleteNoteSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "deleteNoteSuccessListener: " + response.toString()); + + + } + }; //response ErrorListener for getting all user notes Response.ErrorListener getNotesErrorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - Log.d(TAG,"getNotesErrorListener: "+error.getMessage()); + Log.d(TAG, "getNotesErrorListener: " + error.getMessage()); } }; @@ -323,26 +359,26 @@ public class PersonalSpaceActivity extends AppCompatActivity { Response.ErrorListener genericErrorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - Log.d(TAG,"genericErrorListener"); + Log.d(TAG, "genericErrorListener"); error.printStackTrace(); } }; - public void requestPermissions(){ + public void requestPermissions() { // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(PersonalSpaceActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(PersonalSpaceActivity.this, - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - FINE_PERM); + ActivityCompat.requestPermissions(PersonalSpaceActivity.this, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + FINE_PERM); - // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an - // app-defined int constant. The callback method gets the - // result of the request. + // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an + // app-defined int constant. The callback method gets the + // result of the request. } @@ -379,16 +415,13 @@ public class PersonalSpaceActivity extends AppCompatActivity { } - - private ArrayList jsonArrayToStringArray(JSONArray jArray){ + private ArrayList jsonArrayToStringArray(JSONArray jArray) { ArrayList stringArray = new ArrayList(); - for(int i = 0, count = jArray.length(); i< count; i++) - { + for (int i = 0, count = jArray.length(); i < count; i++) { try { JSONObject jsonObject = jArray.getJSONObject(i); stringArray.add(jsonObject.toString()); - } - catch (JSONException e) { + } catch (JSONException e) { e.printStackTrace(); } } diff --git a/app/src/main/res/layout/note_display_full.xml b/app/src/main/res/layout/note_display_full.xml index f7fd781..fc71e57 100644 --- a/app/src/main/res/layout/note_display_full.xml +++ b/app/src/main/res/layout/note_display_full.xml @@ -55,6 +55,13 @@ android:layout_height="wrap_content" android:text="New Text" /> + + \ No newline at end of file From 039edb206d391b37d1ce2ac7a9d4860a70019b04 Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Sun, 3 Jul 2016 17:38:58 +0300 Subject: [PATCH 3/8] - in progress --- .../animated_vector_drawable_23_3_0.xml | 3 +- .idea/libraries/appcompat_v7_23_3_0.xml | 3 +- .idea/libraries/design_23_3_0.xml | 3 +- .idea/libraries/recyclerview_v7_23_3_0.xml | 3 +- .../libraries/support_annotations_23_3_0.xml | 3 +- .idea/libraries/support_v4_23_3_0.xml | 3 +- .../support_vector_drawable_23_3_0.xml | 1 + .idea/misc.xml | 2 +- .../sagi/thesocialnotework/LoginActivity.java | 43 +++++++++++-------- app/src/main/res/layout/activity_login.xml | 4 +- app/src/main/res/values/strings.xml | 1 + 11 files changed, 43 insertions(+), 26 deletions(-) diff --git a/.idea/libraries/animated_vector_drawable_23_3_0.xml b/.idea/libraries/animated_vector_drawable_23_3_0.xml index d5460f1..17f57e0 100644 --- a/.idea/libraries/animated_vector_drawable_23_3_0.xml +++ b/.idea/libraries/animated_vector_drawable_23_3_0.xml @@ -1,11 +1,12 @@ - + + diff --git a/.idea/libraries/appcompat_v7_23_3_0.xml b/.idea/libraries/appcompat_v7_23_3_0.xml index 0dbe7ef..570c386 100644 --- a/.idea/libraries/appcompat_v7_23_3_0.xml +++ b/.idea/libraries/appcompat_v7_23_3_0.xml @@ -4,11 +4,12 @@ - + + diff --git a/.idea/libraries/design_23_3_0.xml b/.idea/libraries/design_23_3_0.xml index 441bb88..5c6ebc6 100644 --- a/.idea/libraries/design_23_3_0.xml +++ b/.idea/libraries/design_23_3_0.xml @@ -4,11 +4,12 @@ - + + diff --git a/.idea/libraries/recyclerview_v7_23_3_0.xml b/.idea/libraries/recyclerview_v7_23_3_0.xml index c4ab7de..4538017 100644 --- a/.idea/libraries/recyclerview_v7_23_3_0.xml +++ b/.idea/libraries/recyclerview_v7_23_3_0.xml @@ -4,11 +4,12 @@ - + + diff --git a/.idea/libraries/support_annotations_23_3_0.xml b/.idea/libraries/support_annotations_23_3_0.xml index e592bd6..d428581 100644 --- a/.idea/libraries/support_annotations_23_3_0.xml +++ b/.idea/libraries/support_annotations_23_3_0.xml @@ -1,10 +1,11 @@ - + + diff --git a/.idea/libraries/support_v4_23_3_0.xml b/.idea/libraries/support_v4_23_3_0.xml index a2479db..0daf0b5 100644 --- a/.idea/libraries/support_v4_23_3_0.xml +++ b/.idea/libraries/support_v4_23_3_0.xml @@ -5,11 +5,12 @@ - + + diff --git a/.idea/libraries/support_vector_drawable_23_3_0.xml b/.idea/libraries/support_vector_drawable_23_3_0.xml index 7f87d23..8dc998c 100644 --- a/.idea/libraries/support_vector_drawable_23_3_0.xml +++ b/.idea/libraries/support_vector_drawable_23_3_0.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 1a3eaff..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java index 8b71b22..c2da56a 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java @@ -74,24 +74,34 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba private EditText mPasswordView; private View mProgressView; private View mLoginFormView; + private TextView mRegisterButton; + private Button mLoginButton; + private final String TAG = "Login Activity"; private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; private final String LOGIN_PATH = "/login"; + private final String REG_PATH = "/register"; private LoginActivity self; protected LinearLayout layout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - //Remove title bar - this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_login); this.self = this; this.layout = (LinearLayout) findViewById(R.id.layout); mUsernameView = (EditText) findViewById(R.id.al_username); mPasswordView = (EditText) findViewById(R.id.al_password); + mLoginFormView = findViewById(R.id.login_form); + mProgressView = findViewById(R.id.login_progress); + showProgress(false); + + // Remove Auto Focus from the Text Fields + layout.setFocusable(true); + layout.setFocusableInTouchMode(true); + mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { @@ -102,30 +112,28 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba return false; } }); -// Button mRegisterButton = (Button) findViewById(R.id.al_register_button); -// mRegisterButton.setOnClickListener(new OnClickListener() { -// @Override -// public void onClick(View view) { -// Log.d(TAG, "Register....... this section under construction"); -// //attemptRegister(); // TODO : implement -// } -// }); - Button mEmailSignInButton = (Button) findViewById(R.id.al_login_button); - mEmailSignInButton.setOnClickListener(new OnClickListener() { + mRegisterButton = (TextView) findViewById(R.id.al_register_button); + mRegisterButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "Register....... this section under construction"); + //attemptRegister(); // TODO : implement + } + }); + + mLoginButton = (Button) findViewById(R.id.al_login_button); + mLoginButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Log.d(TAG, "Login......."); + showProgress(false); attemptLogin(); } }); mLoginFormView = findViewById(R.id.login_form); mProgressView = findViewById(R.id.login_progress); - - // Remove Auto Focus from the Text Fields - layout.setFocusable(true); - layout.setFocusableInTouchMode(true); } private void populateAutoComplete() { @@ -201,6 +209,8 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba String username = mUsernameView.getText().toString(); String password = mPasswordView.getText().toString(); + boolean cancel = false; + View focusView = null; // http request register JSONObject tempJson = new JSONObject(); @@ -223,7 +233,6 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba @Override public void onResponse(JSONObject response) { try { - // if(response.get("user") != null) { if(!response.isNull("user")) { Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class); diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 03073f0..61f42f2 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -43,7 +43,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" - android:hint="Usename" /> + android:hint="Username" /> @@ -69,7 +69,7 @@ android:padding="12dp" android:text="Login"/> - Password Login Register + No account yet? Create one for FREE Sign in This email address is invalid This password is too short From 5d2f04017959219c9431528ca8a508ad63cd14b4 Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Sun, 3 Jul 2016 23:25:58 +0300 Subject: [PATCH 4/8] - add register activity and redirect to login after registration is successfully done --- .idea/libraries/android_android_23.xml | 9 - .../animated_vector_drawable_23_3_0.xml | 3 +- .idea/libraries/appcompat_v7_23_3_0.xml | 3 +- .idea/libraries/design_23_3_0.xml | 3 +- .idea/libraries/recyclerview_v7_23_3_0.xml | 1 + .../libraries/support_annotations_23_3_0.xml | 3 +- .idea/libraries/support_v4_23_3_0.xml | 1 + .../support_vector_drawable_23_3_0.xml | 1 + .idea/libraries/volley_1_0_0.xml | 2 +- app/src/main/AndroidManifest.xml | 8 +- .../sagi/thesocialnotework/LoginActivity.java | 6 +- .../thesocialnotework/RegisterActivity.java | 172 ++++++++++++++++++ app/src/main/res/layout/activity_login.xml | 2 +- app/src/main/res/layout/activity_register.xml | 77 ++++++++ app/src/main/res/values/strings.xml | 7 +- 15 files changed, 273 insertions(+), 25 deletions(-) delete mode 100644 .idea/libraries/android_android_23.xml create mode 100644 app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/RegisterActivity.java create mode 100644 app/src/main/res/layout/activity_register.xml diff --git a/.idea/libraries/android_android_23.xml b/.idea/libraries/android_android_23.xml deleted file mode 100644 index a279d4a..0000000 --- a/.idea/libraries/android_android_23.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_23_3_0.xml b/.idea/libraries/animated_vector_drawable_23_3_0.xml index 1272933..c887d48 100644 --- a/.idea/libraries/animated_vector_drawable_23_3_0.xml +++ b/.idea/libraries/animated_vector_drawable_23_3_0.xml @@ -1,11 +1,12 @@ - + + diff --git a/.idea/libraries/appcompat_v7_23_3_0.xml b/.idea/libraries/appcompat_v7_23_3_0.xml index da3b5a3..39b4f84 100644 --- a/.idea/libraries/appcompat_v7_23_3_0.xml +++ b/.idea/libraries/appcompat_v7_23_3_0.xml @@ -4,11 +4,12 @@ - + + diff --git a/.idea/libraries/design_23_3_0.xml b/.idea/libraries/design_23_3_0.xml index ffd6ab6..6172f7d 100644 --- a/.idea/libraries/design_23_3_0.xml +++ b/.idea/libraries/design_23_3_0.xml @@ -4,11 +4,12 @@ - + + diff --git a/.idea/libraries/recyclerview_v7_23_3_0.xml b/.idea/libraries/recyclerview_v7_23_3_0.xml index e2d2128..7b42040 100644 --- a/.idea/libraries/recyclerview_v7_23_3_0.xml +++ b/.idea/libraries/recyclerview_v7_23_3_0.xml @@ -9,6 +9,7 @@ + diff --git a/.idea/libraries/support_annotations_23_3_0.xml b/.idea/libraries/support_annotations_23_3_0.xml index a2f182e..f9004af 100644 --- a/.idea/libraries/support_annotations_23_3_0.xml +++ b/.idea/libraries/support_annotations_23_3_0.xml @@ -1,10 +1,11 @@ - + + diff --git a/.idea/libraries/support_v4_23_3_0.xml b/.idea/libraries/support_v4_23_3_0.xml index e75eec2..68eb591 100644 --- a/.idea/libraries/support_v4_23_3_0.xml +++ b/.idea/libraries/support_v4_23_3_0.xml @@ -10,6 +10,7 @@ + diff --git a/.idea/libraries/support_vector_drawable_23_3_0.xml b/.idea/libraries/support_vector_drawable_23_3_0.xml index a47f58e..55e107d 100644 --- a/.idea/libraries/support_vector_drawable_23_3_0.xml +++ b/.idea/libraries/support_vector_drawable_23_3_0.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/libraries/volley_1_0_0.xml b/.idea/libraries/volley_1_0_0.xml index 81a83dd..8e317b7 100644 --- a/.idea/libraries/volley_1_0_0.xml +++ b/.idea/libraries/volley_1_0_0.xml @@ -1,8 +1,8 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 914731c..e678e27 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,11 +2,10 @@ - - - + + @@ -28,8 +27,9 @@ - + + \ No newline at end of file diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java index c2da56a..2056df6 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java @@ -82,7 +82,6 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; private final String LOGIN_PATH = "/login"; - private final String REG_PATH = "/register"; private LoginActivity self; protected LinearLayout layout; @@ -117,8 +116,9 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba mRegisterButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - Log.d(TAG, "Register....... this section under construction"); - //attemptRegister(); // TODO : implement + Log.d(TAG, "going to Register...page"); + Intent registerActivity = new Intent(LoginActivity.this, RegisterActivity.class); + startActivity(registerActivity); } }); diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/RegisterActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/RegisterActivity.java new file mode 100644 index 0000000..337cd92 --- /dev/null +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/RegisterActivity.java @@ -0,0 +1,172 @@ +package com.android_app.matan.ara.sagi.thesocialnotework; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.android.volley.Response; +import com.android.volley.VolleyError; + +import org.json.JSONObject; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RegisterActivity extends AppCompatActivity { + + private EditText mUsernameView; + private EditText mPasswordView; + private EditText mEmailView; + private Button registerButton; + private Button testBtn; + private RegisterActivity self; + + protected RelativeLayout layout; + private final String TAG = "Register Activity"; + + private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; + private final String REG_PATH = "/register"; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_register); + + mUsernameView = (EditText) findViewById(R.id.ra_username); + mPasswordView = (EditText) findViewById(R.id.ra_password); + mEmailView = (EditText) findViewById(R.id.ra_email); + + this.self = this; + this.layout = (RelativeLayout) findViewById(R.id.ra_layout); + + // Remove Auto Focus from the Text Fields + layout.setFocusable(true); + layout.setFocusableInTouchMode(true); + + Log.d(TAG, "oncreate..."); + testBtn = (Button) findViewById(R.id.test_button); + testBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "NOW??......."); + + } + }); + + registerButton = (Button) findViewById(R.id.ra_register_button); + registerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "here......."); + attemptRegister(); + } + }); + + } + + private boolean isUsernameValid(String username) { + return username.length() > 0; + } + private boolean isPasswordValid(String password) { + return password.length() > 3; + } + private boolean isEmailValid(String email) { + boolean isValid = false; + + String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; + CharSequence inputStr = email; + + Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(inputStr); + if (matcher.matches()) { + isValid = true; + } + Log.d(TAG, "isValid: " + isValid); + return isValid; + } + + private boolean isParamsValid(String username, String password, String email) { + Log.d(TAG, "user: " + username); + Log.d(TAG, "pwd: " + password); + Log.d(TAG, "email: " + email); + + if(TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) { + return false; + } else if(TextUtils.isEmpty(email) || !isEmailValid(email)) { + return false; + } else { + return true; + } + } + + private void attemptRegister() { +// showProgress(true); + Log.d(TAG, "in attemptRegister: Registering.."); + if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) { + + Log.d(TAG, "params are valid"); + + String username = mUsernameView.getText().toString(); + String password = mPasswordView.getText().toString(); + String email = mEmailView.getText().toString(); + + boolean cancel = false; + View focusView = null; + + // http request register + JSONObject tempJson = new JSONObject(); + try { + tempJson.put("username", username); + tempJson.put("password", password); + tempJson.put("email", email); + } catch (Exception e) { + Log.d(TAG, e.toString()); + } + + VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError); + } else { +// showProgress(false); + Log.d(TAG, "Invalid params - make sure username exist, password is 4 characters or more & email is valid"); + } + } + + Response.Listener onRegisterSuccess = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + try { + if(!response.isNull("user")) { + Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console + Intent loginActivity = new Intent(RegisterActivity.this, LoginActivity.class); +// Bundle loginUserBundle = new Bundle(); +// loginUserBundle.putString("user_id", response.getJSONObject("user").getString("id")); +// personalSpaceActivity.putExtras(loginUserBundle); + startActivity(loginActivity); + } else { +// showProgress(false); + Log.d(TAG, "Cannot create user, " + response.get("user")); + } + }catch (Exception e) { + Log.e(TAG, "onRegisterSuccess:" + e.getMessage()); + } + } + }; + + Response.ErrorListener onRegisterError = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { +// showProgress(false); + Toast.makeText(self , "Username, Password or Email are Incorrect", Toast.LENGTH_LONG).show(); + Log.d(TAG, "onRegisterError: msg: " + error.getMessage()); + } + }; +} diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 61f42f2..fdfe2f8 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -73,7 +73,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="24dp" - android:text="No account yet? Create one for FREE" + android:text="@string/create_new_account" android:gravity="center" android:textSize="16dip"/> diff --git a/app/src/main/res/layout/activity_register.xml b/app/src/main/res/layout/activity_register.xml new file mode 100644 index 0000000..df8e6ae --- /dev/null +++ b/app/src/main/res/layout/activity_register.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + +