diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java index 5a7bd99..d592c0d 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java @@ -1,12 +1,9 @@ package com.android_app.matan.ara.sagi.thesocialnotework; -import android.app.AlertDialog; import android.app.Dialog; -import android.content.DialogInterface; import android.location.Location; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; @@ -21,7 +18,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import com.android.volley.Response; @@ -30,11 +26,8 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; -import java.util.Collection; import java.util.Date; -import java.util.Iterator; import java.util.List; -import java.util.ListIterator; /** @@ -43,6 +36,7 @@ import java.util.ListIterator; public class ExploreFragment extends Fragment { private static final String TAG = "[TSN/Explore]"; +// protected final User user = ((MainActivity) getActivity()).getUser(); protected User user; protected MainActivity parent; private ListAdapter noteListAdapter; @@ -61,22 +55,18 @@ public class ExploreFragment extends Fragment { private Long dateFilterSelection; private float locationFilterSelection; private GPSUtils gpsUtils; -// private boolean userFilterIsVisible = false; - - private final String day = "24 hours"; - private final String week = "Week"; - private final String month = "Month"; - private final String hundredMeters = "1 K"; - private final String kilometer = "10 Km"; - private final String threeKilometer = "100 Km"; -// private final String mine = "Mine"; -// private final String others = "Others"; -// private final String all = "All"; public ExploreFragment() { // Required empty public constructor } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + parent = (MainActivity) getActivity(); + gpsUtils = parent.getGPSUtils(); + user = parent.getUser(); + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -84,9 +74,7 @@ public class ExploreFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_explore, container, false); - parent = (MainActivity) getActivity(); - gpsUtils = parent.getGPSUtils(); - user = parent.getUser(); + notes = new ArrayList<>(); //Get Views list_notes = (ListView) view.findViewById(R.id.list_notes); @@ -123,9 +111,9 @@ public class ExploreFragment extends Fragment { // userFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(day); - map_medium_filter.setText(week); - map_large_filter.setText(month); + map_small_filter.setText(R.string.day); + map_medium_filter.setText(R.string.week); + map_large_filter.setText(R.string.month); } setButtonsColor(); } @@ -144,9 +132,9 @@ public class ExploreFragment extends Fragment { // userFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(hundredMeters); - map_medium_filter.setText(kilometer); - map_large_filter.setText(threeKilometer); + map_small_filter.setText(R.string.shortDistance); + map_medium_filter.setText(R.string.mediumDistance); + map_large_filter.setText(R.string.longDistance); } setButtonsColor(); } @@ -205,6 +193,7 @@ public class ExploreFragment extends Fragment { public void onItemClick(AdapterView parent, View view, final int position, long id) { //create and configure dialog final Note note = notes.get(position); + final MainActivity localParent = (MainActivity)getActivity(); final Dialog noteViewDialog = new Dialog(getActivity()); noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); noteViewDialog.setContentView(R.layout.note_display_full); @@ -235,57 +224,42 @@ public class ExploreFragment extends Fragment { date.setText(note.getDate()); time.setText(note.getTime()); location.setText(note.getAddress()); - if (likes != null) likes.setText("" + note.getLikes()); - likeBtn.setBackgroundResource(R.drawable.like_icon); -// tags.setText("Tags: "+ note.getTags().toString()); -// permission.setText("" + (note.isPublic() ? "Public" : "Private")); + + if (likes != null) { + likeBtn.setBackgroundResource(R.drawable.like_icon); + if (localParent.getUser().getLiked_notes().contains(note.getId())) { + likeBtn.setBackgroundResource(R.drawable.like_icon); + } else { + likeBtn.setBackgroundResource(R.drawable.unlike_icon); + } + } + likes.setText("" + note.getLikes()); + permission.setVisibility(View.GONE); Utils.URLtoImageView(avatar, note.getAvatar()); permission_image.setVisibility(View.GONE); likeBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { -// //Put up the Yes/No message box -// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); -// 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(getActivity(), "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(getActivity()).post(BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener); -// listOfNotes.remove(presentedNotes.get(position)); -// presentedNotes.remove(position); -// -// } catch (JSONException e) { -// Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); -// e.printStackTrace(); -// } -// updateShowedNotes(); -//// noteList.setAdapter(noteListAdapter); -// noteViewDialog.dismiss(); -// } -// }) -// .setNegativeButton("No", new DialogInterface.OnClickListener() { -// public void onClick(DialogInterface dialog, int which) { -// //Yes button clicked, do something -// Toast.makeText(getActivity(), "Canceled", -// Toast.LENGTH_SHORT).show(); -// noteViewDialog.dismiss(); -// } -// }) //Do nothing on no -// .show(); -// } -// }); + //add like only if user didnt like already + if (!user.getLiked_notes().contains(note.getId())) { + JSONObject jsonObj = new JSONObject(); + try { + jsonObj.put("uid", localParent.getUserId()); + jsonObj.put("nid", note.getId()); + } catch (JSONException e) { + e.printStackTrace(); + } + VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, Utils.genericSuccessListener, Utils.genericErrorListener); + user.getLiked_notes().add(note.getId()); + user.updateUser(localParent); + note.setLikes(note.getLikes()+1); + likes.setText("" + note.getLikes()); + noteListAdapter.updateList(notes); + list_notes.setAdapter(noteListAdapter); + likeBtn.setBackgroundResource(R.drawable.like_icon); + } } }); } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index b216eb2..7e6ea91 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -4,15 +4,9 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; import android.location.Location; -import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; //import android.app.Fragment; @@ -23,7 +17,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; -import android.view.WindowManager; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; @@ -34,7 +27,6 @@ import android.widget.Toast; import com.android.volley.Response; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptor; @@ -50,15 +42,10 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Timer; public class GmapFragment extends Fragment implements OnMapReadyCallback { @@ -88,17 +75,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { List listOfNotes; private Circle onMapCircle; - private final String day = "24 hours"; - private final String week = "Week"; - private final String month = "Month"; - private final String hundredMeters = "1 Km"; - private final String kilometer = "10 Km"; - private final String tenKilometers = "100 Km"; - private final String mine = "Mine"; - private final String others = "Others"; - private final String all = "All"; - - public GmapFragment() { eventMarkerMap = new HashMap(); dateFilterSelection = Utils.MONTH_MILI; @@ -171,9 +147,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { userFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(day); - map_medium_filter.setText(week); - map_large_filter.setText(month); + map_small_filter.setText(R.string.day); + map_medium_filter.setText(R.string.week); + map_large_filter.setText(R.string.month); } setButtonsColor(); } @@ -192,9 +168,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { userFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(hundredMeters); - map_medium_filter.setText(kilometer); - map_large_filter.setText(tenKilometers); + map_small_filter.setText(R.string.shortDistance); + map_medium_filter.setText(R.string.mediumDistance); + map_large_filter.setText(R.string.longDistance); } setButtonsColor(); } @@ -213,9 +189,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { locationFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(mine); - map_medium_filter.setText(others); - map_large_filter.setText(all); + map_small_filter.setText(R.string.mine); + map_medium_filter.setText(R.string.others); + map_large_filter.setText(R.string.all); } setButtonsColor(); } @@ -338,7 +314,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { permissionImg.setVisibility(View.INVISIBLE); permission.setText(""); deleteBtn.setBackgroundResource(R.drawable.unlike_icon); - int filterColor; if (mainActivity.getUser().getLiked_notes().contains(note.getId())) { deleteBtn.setBackgroundResource(R.drawable.like_icon); } else { @@ -404,7 +379,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } catch (JSONException e) { e.printStackTrace(); } - VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, likeNotesSuccessListener, Utils.genericErrorListener); + VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, Utils.genericSuccessListener, Utils.genericErrorListener); mainActivity.getUser().getLiked_notes().add(note.getId()); mainActivity.getUser().updateUser(mainActivity); note.setLikes(note.getLikes()+1); @@ -450,16 +425,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } }; - //response listener for getting all user notes - Response.Listener likeNotesSuccessListener = new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "likeNotesSuccessListener: " + response.toString()); - } - }; - - - private class getMarkersFromNotes extends AsyncTask, MarkerNoteStruct, Void> { GoogleMap mMap; HashMap eventMarkerMap; 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 01b8bd9..243924c 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 @@ -31,7 +31,6 @@ import java.util.Vector; */ public class LoginActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher { - // UI references. private EditText mUsernameView; private EditText mPasswordView; @@ -66,26 +65,20 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList } - private void removeFocuse() { - // Remove Auto Focus from the Text Fields + private void removeFocuse() { // Remove Auto Focus from the Text Fields mUsernameView.clearFocus(); mPasswordView.clearFocus(); layout.setFocusable(true); layout.setFocusableInTouchMode(true); - } - /** * Attempts to sign in or register the account specified by the login form. * If there are form errors (invalid email, missing fields, etc.), the * errors are presented and no actual login attempt is made. */ - private boolean isParamsValid(String username, String password) { - Log.d(TAG, "user: " + username); - Log.d(TAG, "pwd: " + password); - + private boolean isParamsValid(String username, String password) { // validate form if (TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) { return false; } else { @@ -93,7 +86,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList } } - private void attemptLogin() { + private void attemptLogin() { // attempt login Utils.showLoadingDialog(this, "Connecting", "Authenticating data"); mPasswordView.setError(null); if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) { @@ -101,7 +94,6 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList String username = mUsernameView.getText().toString(); String password = mPasswordView.getText().toString(); - boolean cancel = false; // http request register JSONObject tempJson = new JSONObject(); try { @@ -112,18 +104,16 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList } VolleyUtilSingleton.getInstance(LoginActivity.this).post(Utils.BASE_URL + LOGIN_PATH, tempJson, onLoginSuccess, onLoginError); } else { - Utils.dismissLoadingDialog(); - Log.d(TAG, "Invalid params - make sure username exist & password is 4 characters or more"); + Utils.dismissLoadingDialog(); // invalid params } } Response.Listener onLoginSuccess = new Response.Listener() { @Override - public void onResponse(JSONObject response) { + public void onResponse(JSONObject response) { // listener to success login response from server try { - if (!response.isNull("user")) { - Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console + if (!response.isNull("user")) { // response user from server success String id, password, email, avatar, username, likedNotes = ""; JSONArray likedNotes_JSON; @@ -146,7 +136,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList personalSpaceActivity.putExtras(loginUserBundle); Utils.dismissLoadingDialog(); startActivity(personalSpaceActivity); - } else { + } else { // invalid params Utils.dismissLoadingDialog(); Toast.makeText(self, "Username or Password are incorrect", Toast.LENGTH_LONG).show(); self.mUsernameView.getText().clear(); @@ -164,38 +154,34 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList Response.ErrorListener onLoginError = new Response.ErrorListener() { @Override - public void onErrorResponse(VolleyError error) { + public void onErrorResponse(VolleyError error) { // listener to error login response from server Utils.dismissLoadingDialog(); Toast.makeText(self, "Username Or Password Incorrect", Toast.LENGTH_LONG).show(); - //Clean texts + // Clean texts self.mUsernameView.getText().clear(); self.mPasswordView.getText().clear(); self.removeFocuse(); - Log.d(TAG, "onErrorResponse: setting text to ''"); - Log.d(TAG, "onLoginError: msg: " + error.getMessage()); } }; private boolean isUsernameValid(String username) { return username.length() > 0; - } + } // validate username private boolean isPasswordValid(String password) { return password.length() > 3; - } + } // validate password @Override public void onClick(View view) { switch (view.getId()) { case R.id.al_login_button: - //Do Login - Log.d(TAG, "Login......."); + // Do Login attemptLogin(); break; case R.id.al_register_button: - //Do Register - Log.d(TAG, "going to Register...page"); + // Do Register Intent registerActivity = new Intent(LoginActivity.this, RegisterActivity.class); startActivity(registerActivity); break; @@ -222,42 +208,5 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList public void afterTextChanged(Editable editable) { } -// @Override -// public void onRequestPermissionsResult(int requestCode, -// String permissions[], int[] grantResults) { -// permissionsReturend = true; -// Log.d(TAG, "onRequestPermissionsResult: in func"); -// switch (requestCode) { -// case FINE_PERM: { -// // If request is cancelled, the result arrays are empty. -// if (grantResults.length > 0 -// && grantResults[0] == PackageManager.PERMISSION_GRANTED) { -// Log.d(TAG, "onRequestPermissionsResult: got permission for location"); -// Utils.setLocationPermission(true); -// ActivityCompat.requestPermissions(LoginActivity.this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERM); -// } else { -// Log.d(TAG, "onRequestPermissionsResult:DIDNT get permission for location"); -// -// Toast.makeText(LoginActivity.this,"No Location Permissions granted.\n\"An App is nothing without its permissions\"",Toast.LENGTH_LONG); -//// System.exit(0); -// } -// return; -// } -// case CAMERA_PERM: { -// if (grantResults.length > 0 -// && grantResults[0] == PackageManager.PERMISSION_GRANTED) { -// Log.d(TAG, "onRequestPermissionsResult: got permission for camera"); -// Utils.setCameraPermission(true); -// -// -// } else { -// Log.d(TAG, "onRequestPermissionsResult: DIDNT get permission for camera"); -// Toast.makeText(LoginActivity.this,"No Camera Permissions granted.\n\"An App is nothing without its permissions\"",Toast.LENGTH_LONG); -// } -// return; -// } -// } -// } - } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java index 9190771..863307a 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java @@ -77,20 +77,13 @@ public class PersonalFragment extends Fragment { private boolean dateFilterIsVisible = false; private boolean userFilterIsVisible = false; - private final String day = "24 hours"; - private final String week = "Week"; - private final String month = "Month"; - private final String privateNote = "Private"; - private final String publicNote = "Public"; - private final String privateAndPublic = "All"; - public PersonalFragment() { // Required empty public constructor } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_personal, container, false); // Inflate the layout for this fragment activity = (MainActivity) getActivity(); @@ -150,9 +143,9 @@ public class PersonalFragment extends Fragment { userFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(day); - map_medium_filter.setText(week); - map_large_filter.setText(month); + map_small_filter.setText(R.string.day); + map_medium_filter.setText(R.string.week); + map_large_filter.setText(R.string.month); } setButtonsColor(); @@ -173,9 +166,9 @@ public class PersonalFragment extends Fragment { dateFilterIsVisible = false; // set text button in the right filter string - map_small_filter.setText(privateNote); - map_medium_filter.setText(publicNote); - map_large_filter.setText(privateAndPublic); + map_small_filter.setText(R.string.privateNote); + map_medium_filter.setText(R.string.publicNote); + map_large_filter.setText(R.string.privateAndPublic); } setButtonsColor(); @@ -358,27 +351,6 @@ public class PersonalFragment extends Fragment { } }; - -// //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()); -// MainActivity.dismissLoadingDialog(); -// } -// }; - -// //Generic response ErrorListener -// Response.ErrorListener genericErrorListener = new Response.ErrorListener() { -// @Override -// public void onErrorResponse(VolleyError error) { -// Log.d(TAG, "genericErrorListener"); -// MainActivity.dismissLoadingDialog(); -// error.printStackTrace(); -// } -// }; - - private ArrayList jsonArrayToStringArray(JSONArray jArray) { ArrayList stringArray = new ArrayList(); for (int i = 0, count = jArray.length(); i < count; i++) { @@ -516,7 +488,7 @@ public class PersonalFragment extends Fragment { } //date filters else { - dateFilterSelection = Utils.WEEK_MILI; + dateFilterSelection = Utils.DAY_MILI; } setButtonsColor(); 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 index 4bc5da7..0d0bd26 100644 --- 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 @@ -40,9 +40,9 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); - this.mUsernameView = (EditText) findViewById(R.id.ra_username); - this.mPasswordView = (EditText) findViewById(R.id.ra_password); - this.mEmailView = (EditText) findViewById(R.id.ra_email); + this.mUsernameView = (EditText) findViewById(R.id.ra_username); // holds the username + this.mPasswordView = (EditText) findViewById(R.id.ra_password); // holds the password + this.mEmailView = (EditText) findViewById(R.id.ra_email); // holds the email this.self = this; this.layout = (RelativeLayout) findViewById(R.id.ra_layout); @@ -50,23 +50,23 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL // Remove Auto Focus from the Text Fields this.layout.setFocusable(true); this.layout.setFocusableInTouchMode(true); + // Buttons And Listeners this.testBtn = (Button) findViewById(R.id.btn_cancel); this.testBtn.setOnClickListener(this); this.registerButton = (Button) findViewById(R.id.ra_register_button); this.registerButton.setOnClickListener(this); - } - private boolean isUsernameValid(String username) { + private boolean isUsernameValid(String username) { // username validation return !TextUtils.isEmpty(username) && username.length() > 0; } - private boolean isPasswordValid(String password) { + private boolean isPasswordValid(String password) { // password validation return !TextUtils.isEmpty(password) && password.length() > 3; } - private boolean isEmailValid(String email) { + private boolean isEmailValid(String email) { // email validation if (TextUtils.isEmpty(email)) return false; String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; @@ -75,52 +75,45 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL return matcher.matches(); } - private boolean isParamsValid(String username, String password, String email) { + private boolean isParamsValid(String username, String password, String email) { // private method that validates all params return (isUsernameValid(username) && isPasswordValid(password) && isEmailValid(email)); } - private void attemptRegister() { + private void attemptRegister() { // attempt registering Utils.showLoadingDialog(this, "Registering", "Please Wait..."); - Log.d(TAG, "in attemptRegister: Registering.."); - if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) { - Log.d(TAG, "params are valid"); + if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) { // params are valid String username = mUsernameView.getText().toString(); String password = mPasswordView.getText().toString(); String email = mEmailView.getText().toString(); // http request register JSONObject tempJson = new JSONObject(); - try { + try { // creating a user json to send the server tempJson.put("username", username); tempJson.put("password", password); tempJson.put("email", email); } catch (Exception e) { Log.d(TAG, e.toString()); } - Log.d(TAG, "JSON: " + tempJson.toString()); - VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError); - } else { + VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError); // register request to server + } else { // invalid params Utils.dismissLoadingDialog(); - Log.d(TAG, "Invalid params - make sure username exist, password is 4 characters or more & email is valid"); Toast.makeText(this, "Make Sure tou have entered a valid email. password at least 4 chars", Toast.LENGTH_LONG).show(); } } Response.Listener onRegisterSuccess = new Response.Listener() { @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "response: " + response.toString()); + public void onResponse(JSONObject response) { // listener to success response on register from server Utils.dismissLoadingDialog(); try { - if (response.getString("message").equals("created")) { - Log.d(TAG, "onRegisterSuccess => user created"); // TODO: REMOVE console + if (response.getString("message").equals("created")) { // user created Intent loginActivity = new Intent(RegisterActivity.this, LoginActivity.class); Toast.makeText(self, "You are now a social notework member - You May Login...", Toast.LENGTH_LONG).show(); startActivity(loginActivity); } else { Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show(); - Log.d(TAG, "Cannot create user, " + response.getString("message")); } - } catch (Exception e) { + } catch (Exception e) { // error on register user request Log.e(TAG, "onRegisterSuccess:" + e.getMessage()); } @@ -129,15 +122,14 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL Response.ErrorListener onRegisterError = new Response.ErrorListener() { @Override - public void onErrorResponse(VolleyError error) { + public void onErrorResponse(VolleyError error) { // listener to error response on register from server Utils.dismissLoadingDialog(); Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show(); - Log.d(TAG, "onRegisterError: msg: " + error.getMessage()); } }; @Override - public void onClick(View view) { + public void onClick(View view) { // onclick methods to redirect to register and to login switch (view.getId()) { case R.id.ra_register_button: attemptRegister(); @@ -148,7 +140,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL } } - private void returnToLogin() { + private void returnToLogin() { // redirect to login Intent i = new Intent(RegisterActivity.this, LoginActivity.class); startActivity(i); finish(); diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/SettingsFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/SettingsFragment.java index 784695a..cd0d235 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/SettingsFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/SettingsFragment.java @@ -33,6 +33,7 @@ import org.json.JSONObject; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileOutputStream; public class SettingsFragment extends Fragment implements View.OnClickListener, TextWatcher { private static final String TAG = "[TSN/Settings]"; @@ -170,11 +171,47 @@ public class SettingsFragment extends Fragment implements View.OnClickListener, private void saveImage() { Utils.showLoadingDialog(parent, "Saving Image...", "This Can Take a while"); - File myFile = new File(currentImgUri.getPath()); + + Bitmap b= BitmapFactory.decodeFile(currentImgUri.getPath()); // Original Image + Bitmap out; + if (b.getWidth() >= b.getHeight()){ + + out = Bitmap.createBitmap( + b, + b.getWidth()/2 - b.getHeight()/2, + 0, + b.getHeight(), + b.getHeight() + ); + + }else{ + out = Bitmap.createBitmap( + b, + 0, + b.getHeight()/2 - b.getWidth()/2, + b.getWidth(), + b.getWidth() + ); + } + out = Bitmap.createScaledBitmap(out, 320, 320, false); + + File file = new File(currentImgUri.getPath()); + FileOutputStream fOut; + try { + fOut = new FileOutputStream(file); + out.compress(Bitmap.CompressFormat.PNG, 100, fOut); + fOut.flush(); + fOut.close(); + b.recycle(); + out.recycle(); + } catch (Exception e) {} + + + JSONObject payload = new JSONObject(); try { - payload.put("image", ImageToBase64(myFile.getAbsolutePath())); + payload.put("image", ImageToBase64(file.getAbsolutePath())); } catch (JSONException e) { e.printStackTrace(); Utils.dismissLoadingDialog(); diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java index 3e7ff2a..5b6f234 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java @@ -96,6 +96,14 @@ public class Utils { } }; + //response listener for getting all user notes + public static Response.Listener genericSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "likeNotesSuccessListener: " + response.toString()); + } + }; + public static void showLoadingDialog(Context context, String title, String msg) { progress = new ProgressDialog(context); progress.setTitle(title); @@ -148,7 +156,11 @@ public class Utils { } public static void URLtoImageView(ImageView iv, String url){ - new setUserAvatar(iv, url).execute(); + if(bitmapHash.containsKey(url)){ + iv.setImageBitmap(bitmapHash.get(url)); + }else{ + new setUserAvatar(iv, url).execute(); + } } private static class setUserAvatar extends AsyncTask { @@ -236,8 +248,4 @@ public class Utils { editor.remove("UserData"); editor.commit(); } - - - - } diff --git a/app/src/main/res/drawable/like_icon_black.png b/app/src/main/res/drawable/like_icon_black.png new file mode 100644 index 0000000..3b97bfa Binary files /dev/null and b/app/src/main/res/drawable/like_icon_black.png differ diff --git a/app/src/main/res/layout/note_display_full.xml b/app/src/main/res/layout/note_display_full.xml index 5b33b2a..ac519e3 100644 --- a/app/src/main/res/layout/note_display_full.xml +++ b/app/src/main/res/layout/note_display_full.xml @@ -141,8 +141,9 @@ android:layout_width="20dp" android:layout_height="20dp" android:id="@+id/imageView9" - android:src="@drawable/like_icon" - android:layout_gravity="center_vertical" /> + android:layout_gravity="center_vertical" + android:background="@drawable/like_icon_black" + android:backgroundTintMode="multiply" /> Map Avatar + + + 24 hours + Week + Month + Private + Public + All + 1 Km + 10 Km + 100 Km + Mine + Others + All +