Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android
This commit is contained in:
commit
e9ba4dbddd
10 changed files with 165 additions and 252 deletions
|
@ -1,12 +1,9 @@
|
||||||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -21,7 +18,6 @@ import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
|
|
||||||
|
@ -30,11 +26,8 @@ import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +36,7 @@ import java.util.ListIterator;
|
||||||
public class ExploreFragment extends Fragment {
|
public class ExploreFragment extends Fragment {
|
||||||
|
|
||||||
private static final String TAG = "[TSN/Explore]";
|
private static final String TAG = "[TSN/Explore]";
|
||||||
|
// protected final User user = ((MainActivity) getActivity()).getUser();
|
||||||
protected User user;
|
protected User user;
|
||||||
protected MainActivity parent;
|
protected MainActivity parent;
|
||||||
private ListAdapter noteListAdapter;
|
private ListAdapter noteListAdapter;
|
||||||
|
@ -61,22 +55,18 @@ public class ExploreFragment extends Fragment {
|
||||||
private Long dateFilterSelection;
|
private Long dateFilterSelection;
|
||||||
private float locationFilterSelection;
|
private float locationFilterSelection;
|
||||||
private GPSUtils gpsUtils;
|
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() {
|
public ExploreFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
parent = (MainActivity) getActivity();
|
||||||
|
gpsUtils = parent.getGPSUtils();
|
||||||
|
user = parent.getUser();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -84,9 +74,7 @@ public class ExploreFragment extends Fragment {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_explore, container, false);
|
View view = inflater.inflate(R.layout.fragment_explore, container, false);
|
||||||
|
|
||||||
parent = (MainActivity) getActivity();
|
|
||||||
gpsUtils = parent.getGPSUtils();
|
|
||||||
user = parent.getUser();
|
|
||||||
notes = new ArrayList<>();
|
notes = new ArrayList<>();
|
||||||
//Get Views
|
//Get Views
|
||||||
list_notes = (ListView) view.findViewById(R.id.list_notes);
|
list_notes = (ListView) view.findViewById(R.id.list_notes);
|
||||||
|
@ -123,9 +111,9 @@ public class ExploreFragment extends Fragment {
|
||||||
// userFilterIsVisible = false;
|
// userFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(day);
|
map_small_filter.setText(R.string.day);
|
||||||
map_medium_filter.setText(week);
|
map_medium_filter.setText(R.string.week);
|
||||||
map_large_filter.setText(month);
|
map_large_filter.setText(R.string.month);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
}
|
}
|
||||||
|
@ -144,9 +132,9 @@ public class ExploreFragment extends Fragment {
|
||||||
// userFilterIsVisible = false;
|
// userFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(hundredMeters);
|
map_small_filter.setText(R.string.shortDistance);
|
||||||
map_medium_filter.setText(kilometer);
|
map_medium_filter.setText(R.string.mediumDistance);
|
||||||
map_large_filter.setText(threeKilometer);
|
map_large_filter.setText(R.string.longDistance);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
}
|
}
|
||||||
|
@ -205,6 +193,7 @@ public class ExploreFragment extends Fragment {
|
||||||
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
//create and configure dialog
|
//create and configure dialog
|
||||||
final Note note = notes.get(position);
|
final Note note = notes.get(position);
|
||||||
|
final MainActivity localParent = (MainActivity)getActivity();
|
||||||
final Dialog noteViewDialog = new Dialog(getActivity());
|
final Dialog noteViewDialog = new Dialog(getActivity());
|
||||||
noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
noteViewDialog.setContentView(R.layout.note_display_full);
|
noteViewDialog.setContentView(R.layout.note_display_full);
|
||||||
|
@ -235,57 +224,42 @@ public class ExploreFragment extends Fragment {
|
||||||
date.setText(note.getDate());
|
date.setText(note.getDate());
|
||||||
time.setText(note.getTime());
|
time.setText(note.getTime());
|
||||||
location.setText(note.getAddress());
|
location.setText(note.getAddress());
|
||||||
if (likes != null) likes.setText("" + note.getLikes());
|
|
||||||
|
if (likes != null) {
|
||||||
likeBtn.setBackgroundResource(R.drawable.like_icon);
|
likeBtn.setBackgroundResource(R.drawable.like_icon);
|
||||||
// tags.setText("Tags: "+ note.getTags().toString());
|
if (localParent.getUser().getLiked_notes().contains(note.getId())) {
|
||||||
// permission.setText("" + (note.isPublic() ? "Public" : "Private"));
|
likeBtn.setBackgroundResource(R.drawable.like_icon);
|
||||||
|
} else {
|
||||||
|
likeBtn.setBackgroundResource(R.drawable.unlike_icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
likes.setText("" + note.getLikes());
|
||||||
|
|
||||||
permission.setVisibility(View.GONE);
|
permission.setVisibility(View.GONE);
|
||||||
Utils.URLtoImageView(avatar, note.getAvatar());
|
Utils.URLtoImageView(avatar, note.getAvatar());
|
||||||
permission_image.setVisibility(View.GONE);
|
permission_image.setVisibility(View.GONE);
|
||||||
|
|
||||||
likeBtn.setOnClickListener(new View.OnClickListener() {
|
likeBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// //Put up the Yes/No message box
|
//add like only if user didnt like already
|
||||||
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
if (!user.getLiked_notes().contains(note.getId())) {
|
||||||
// builder
|
JSONObject jsonObj = new JSONObject();
|
||||||
// .setTitle("Delete Note")
|
try {
|
||||||
// .setMessage("Are you sure you want to delete the note?")
|
jsonObj.put("uid", localParent.getUserId());
|
||||||
// .setIcon(android.R.drawable.ic_dialog_alert)
|
jsonObj.put("nid", note.getId());
|
||||||
// .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();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,9 @@ import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
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.location.Location;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
//import android.app.Fragment;
|
//import android.app.Fragment;
|
||||||
|
@ -23,7 +17,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -34,7 +27,6 @@ import android.widget.Toast;
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||||
import com.google.android.gms.maps.GoogleMap;
|
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.OnMapReadyCallback;
|
||||||
import com.google.android.gms.maps.SupportMapFragment;
|
import com.google.android.gms.maps.SupportMapFragment;
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptor;
|
import com.google.android.gms.maps.model.BitmapDescriptor;
|
||||||
|
@ -50,15 +42,10 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
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.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
|
||||||
|
|
||||||
|
|
||||||
public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
@ -88,17 +75,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
List<Note> listOfNotes;
|
List<Note> listOfNotes;
|
||||||
private Circle onMapCircle;
|
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() {
|
public GmapFragment() {
|
||||||
eventMarkerMap = new HashMap<Marker, Note>();
|
eventMarkerMap = new HashMap<Marker, Note>();
|
||||||
dateFilterSelection = Utils.MONTH_MILI;
|
dateFilterSelection = Utils.MONTH_MILI;
|
||||||
|
@ -171,9 +147,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
userFilterIsVisible = false;
|
userFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(day);
|
map_small_filter.setText(R.string.day);
|
||||||
map_medium_filter.setText(week);
|
map_medium_filter.setText(R.string.week);
|
||||||
map_large_filter.setText(month);
|
map_large_filter.setText(R.string.month);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
}
|
}
|
||||||
|
@ -192,9 +168,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
userFilterIsVisible = false;
|
userFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(hundredMeters);
|
map_small_filter.setText(R.string.shortDistance);
|
||||||
map_medium_filter.setText(kilometer);
|
map_medium_filter.setText(R.string.mediumDistance);
|
||||||
map_large_filter.setText(tenKilometers);
|
map_large_filter.setText(R.string.longDistance);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
}
|
}
|
||||||
|
@ -213,9 +189,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
locationFilterIsVisible = false;
|
locationFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(mine);
|
map_small_filter.setText(R.string.mine);
|
||||||
map_medium_filter.setText(others);
|
map_medium_filter.setText(R.string.others);
|
||||||
map_large_filter.setText(all);
|
map_large_filter.setText(R.string.all);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
}
|
}
|
||||||
|
@ -338,7 +314,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
permissionImg.setVisibility(View.INVISIBLE);
|
permissionImg.setVisibility(View.INVISIBLE);
|
||||||
permission.setText("");
|
permission.setText("");
|
||||||
deleteBtn.setBackgroundResource(R.drawable.unlike_icon);
|
deleteBtn.setBackgroundResource(R.drawable.unlike_icon);
|
||||||
int filterColor;
|
|
||||||
if (mainActivity.getUser().getLiked_notes().contains(note.getId())) {
|
if (mainActivity.getUser().getLiked_notes().contains(note.getId())) {
|
||||||
deleteBtn.setBackgroundResource(R.drawable.like_icon);
|
deleteBtn.setBackgroundResource(R.drawable.like_icon);
|
||||||
} else {
|
} else {
|
||||||
|
@ -404,7 +379,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
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().getLiked_notes().add(note.getId());
|
||||||
mainActivity.getUser().updateUser(mainActivity);
|
mainActivity.getUser().updateUser(mainActivity);
|
||||||
note.setLikes(note.getLikes()+1);
|
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<JSONObject> likeNotesSuccessListener = new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(JSONObject response) {
|
|
||||||
Log.d(TAG, "likeNotesSuccessListener: " + response.toString());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerNoteStruct, Void> {
|
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerNoteStruct, Void> {
|
||||||
GoogleMap mMap;
|
GoogleMap mMap;
|
||||||
HashMap<Marker, Note> eventMarkerMap;
|
HashMap<Marker, Note> eventMarkerMap;
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.util.Vector;
|
||||||
*/
|
*/
|
||||||
public class LoginActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher {
|
public class LoginActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher {
|
||||||
|
|
||||||
|
|
||||||
// UI references.
|
// UI references.
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
|
@ -66,26 +65,20 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFocuse() {
|
private void removeFocuse() { // Remove Auto Focus from the Text Fields
|
||||||
// Remove Auto Focus from the Text Fields
|
|
||||||
mUsernameView.clearFocus();
|
mUsernameView.clearFocus();
|
||||||
mPasswordView.clearFocus();
|
mPasswordView.clearFocus();
|
||||||
layout.setFocusable(true);
|
layout.setFocusable(true);
|
||||||
layout.setFocusableInTouchMode(true);
|
layout.setFocusableInTouchMode(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to sign in or register the account specified by the login form.
|
* Attempts to sign in or register the account specified by the login form.
|
||||||
* If there are form errors (invalid email, missing fields, etc.), the
|
* If there are form errors (invalid email, missing fields, etc.), the
|
||||||
* errors are presented and no actual login attempt is made.
|
* errors are presented and no actual login attempt is made.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private boolean isParamsValid(String username, String password) {
|
private boolean isParamsValid(String username, String password) { // validate form
|
||||||
Log.d(TAG, "user: " + username);
|
|
||||||
Log.d(TAG, "pwd: " + password);
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
|
if (TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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");
|
Utils.showLoadingDialog(this, "Connecting", "Authenticating data");
|
||||||
mPasswordView.setError(null);
|
mPasswordView.setError(null);
|
||||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
|
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 username = mUsernameView.getText().toString();
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
|
|
||||||
boolean cancel = false;
|
|
||||||
// http request register
|
// http request register
|
||||||
JSONObject tempJson = new JSONObject();
|
JSONObject tempJson = new JSONObject();
|
||||||
try {
|
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);
|
VolleyUtilSingleton.getInstance(LoginActivity.this).post(Utils.BASE_URL + LOGIN_PATH, tempJson, onLoginSuccess, onLoginError);
|
||||||
} else {
|
} else {
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog(); // invalid params
|
||||||
Log.d(TAG, "Invalid params - make sure username exist & password is 4 characters or more");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Response.Listener<JSONObject> onLoginSuccess = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> onLoginSuccess = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) { // listener to success login response from server
|
||||||
try {
|
try {
|
||||||
if (!response.isNull("user")) {
|
if (!response.isNull("user")) { // response user from server success
|
||||||
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
|
|
||||||
String id, password, email, avatar, username, likedNotes = "";
|
String id, password, email, avatar, username, likedNotes = "";
|
||||||
|
|
||||||
JSONArray likedNotes_JSON;
|
JSONArray likedNotes_JSON;
|
||||||
|
@ -146,7 +136,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
personalSpaceActivity.putExtras(loginUserBundle);
|
personalSpaceActivity.putExtras(loginUserBundle);
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
startActivity(personalSpaceActivity);
|
startActivity(personalSpaceActivity);
|
||||||
} else {
|
} else { // invalid params
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
Toast.makeText(self, "Username or Password are incorrect", Toast.LENGTH_LONG).show();
|
Toast.makeText(self, "Username or Password are incorrect", Toast.LENGTH_LONG).show();
|
||||||
self.mUsernameView.getText().clear();
|
self.mUsernameView.getText().clear();
|
||||||
|
@ -164,38 +154,34 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
|
|
||||||
Response.ErrorListener onLoginError = new Response.ErrorListener() {
|
Response.ErrorListener onLoginError = new Response.ErrorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) { // listener to error login response from server
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
Toast.makeText(self, "Username Or Password Incorrect", Toast.LENGTH_LONG).show();
|
Toast.makeText(self, "Username Or Password Incorrect", Toast.LENGTH_LONG).show();
|
||||||
// Clean texts
|
// Clean texts
|
||||||
self.mUsernameView.getText().clear();
|
self.mUsernameView.getText().clear();
|
||||||
self.mPasswordView.getText().clear();
|
self.mPasswordView.getText().clear();
|
||||||
self.removeFocuse();
|
self.removeFocuse();
|
||||||
Log.d(TAG, "onErrorResponse: setting text to ''");
|
|
||||||
Log.d(TAG, "onLoginError: msg: " + error.getMessage());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private boolean isUsernameValid(String username) {
|
private boolean isUsernameValid(String username) {
|
||||||
return username.length() > 0;
|
return username.length() > 0;
|
||||||
}
|
} // validate username
|
||||||
|
|
||||||
private boolean isPasswordValid(String password) {
|
private boolean isPasswordValid(String password) {
|
||||||
return password.length() > 3;
|
return password.length() > 3;
|
||||||
}
|
} // validate password
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.al_login_button:
|
case R.id.al_login_button:
|
||||||
// Do Login
|
// Do Login
|
||||||
Log.d(TAG, "Login.......");
|
|
||||||
attemptLogin();
|
attemptLogin();
|
||||||
break;
|
break;
|
||||||
case R.id.al_register_button:
|
case R.id.al_register_button:
|
||||||
// Do Register
|
// Do Register
|
||||||
Log.d(TAG, "going to Register...page");
|
|
||||||
Intent registerActivity = new Intent(LoginActivity.this, RegisterActivity.class);
|
Intent registerActivity = new Intent(LoginActivity.this, RegisterActivity.class);
|
||||||
startActivity(registerActivity);
|
startActivity(registerActivity);
|
||||||
break;
|
break;
|
||||||
|
@ -222,42 +208,5 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
public void afterTextChanged(Editable editable) {
|
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;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,20 +77,13 @@ public class PersonalFragment extends Fragment {
|
||||||
private boolean dateFilterIsVisible = false;
|
private boolean dateFilterIsVisible = false;
|
||||||
private boolean userFilterIsVisible = 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() {
|
public PersonalFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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);
|
View view = inflater.inflate(R.layout.fragment_personal, container, false);
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
activity = (MainActivity) getActivity();
|
activity = (MainActivity) getActivity();
|
||||||
|
@ -150,9 +143,9 @@ public class PersonalFragment extends Fragment {
|
||||||
userFilterIsVisible = false;
|
userFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(day);
|
map_small_filter.setText(R.string.day);
|
||||||
map_medium_filter.setText(week);
|
map_medium_filter.setText(R.string.week);
|
||||||
map_large_filter.setText(month);
|
map_large_filter.setText(R.string.month);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
|
|
||||||
|
@ -173,9 +166,9 @@ public class PersonalFragment extends Fragment {
|
||||||
dateFilterIsVisible = false;
|
dateFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(privateNote);
|
map_small_filter.setText(R.string.privateNote);
|
||||||
map_medium_filter.setText(publicNote);
|
map_medium_filter.setText(R.string.publicNote);
|
||||||
map_large_filter.setText(privateAndPublic);
|
map_large_filter.setText(R.string.privateAndPublic);
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
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<String> jsonArrayToStringArray(JSONArray jArray) {
|
private ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
||||||
ArrayList<String> stringArray = new ArrayList<String>();
|
ArrayList<String> stringArray = new ArrayList<String>();
|
||||||
for (int i = 0, count = jArray.length(); i < count; i++) {
|
for (int i = 0, count = jArray.length(); i < count; i++) {
|
||||||
|
@ -516,7 +488,7 @@ public class PersonalFragment extends Fragment {
|
||||||
}
|
}
|
||||||
//date filters
|
//date filters
|
||||||
else {
|
else {
|
||||||
dateFilterSelection = Utils.WEEK_MILI;
|
dateFilterSelection = Utils.DAY_MILI;
|
||||||
|
|
||||||
}
|
}
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
|
|
|
@ -40,9 +40,9 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_register);
|
setContentView(R.layout.activity_register);
|
||||||
|
|
||||||
this.mUsernameView = (EditText) findViewById(R.id.ra_username);
|
this.mUsernameView = (EditText) findViewById(R.id.ra_username); // holds the username
|
||||||
this.mPasswordView = (EditText) findViewById(R.id.ra_password);
|
this.mPasswordView = (EditText) findViewById(R.id.ra_password); // holds the password
|
||||||
this.mEmailView = (EditText) findViewById(R.id.ra_email);
|
this.mEmailView = (EditText) findViewById(R.id.ra_email); // holds the email
|
||||||
|
|
||||||
this.self = this;
|
this.self = this;
|
||||||
this.layout = (RelativeLayout) findViewById(R.id.ra_layout);
|
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
|
// Remove Auto Focus from the Text Fields
|
||||||
this.layout.setFocusable(true);
|
this.layout.setFocusable(true);
|
||||||
this.layout.setFocusableInTouchMode(true);
|
this.layout.setFocusableInTouchMode(true);
|
||||||
|
|
||||||
// Buttons And Listeners
|
// Buttons And Listeners
|
||||||
this.testBtn = (Button) findViewById(R.id.btn_cancel);
|
this.testBtn = (Button) findViewById(R.id.btn_cancel);
|
||||||
this.testBtn.setOnClickListener(this);
|
this.testBtn.setOnClickListener(this);
|
||||||
this.registerButton = (Button) findViewById(R.id.ra_register_button);
|
this.registerButton = (Button) findViewById(R.id.ra_register_button);
|
||||||
this.registerButton.setOnClickListener(this);
|
this.registerButton.setOnClickListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isUsernameValid(String username) {
|
private boolean isUsernameValid(String username) { // username validation
|
||||||
return !TextUtils.isEmpty(username) && username.length() > 0;
|
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;
|
return !TextUtils.isEmpty(password) && password.length() > 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmailValid(String email) {
|
private boolean isEmailValid(String email) { // email validation
|
||||||
if (TextUtils.isEmpty(email))
|
if (TextUtils.isEmpty(email))
|
||||||
return false;
|
return false;
|
||||||
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
|
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
|
||||||
|
@ -75,52 +75,45 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
return matcher.matches();
|
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));
|
return (isUsernameValid(username) && isPasswordValid(password) && isEmailValid(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attemptRegister() {
|
private void attemptRegister() { // attempt registering
|
||||||
Utils.showLoadingDialog(this, "Registering", "Please Wait...");
|
Utils.showLoadingDialog(this, "Registering", "Please Wait...");
|
||||||
Log.d(TAG, "in attemptRegister: Registering..");
|
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) { // params are valid
|
||||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) {
|
|
||||||
Log.d(TAG, "params are valid");
|
|
||||||
String username = mUsernameView.getText().toString();
|
String username = mUsernameView.getText().toString();
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
String email = mEmailView.getText().toString();
|
String email = mEmailView.getText().toString();
|
||||||
// http request register
|
// http request register
|
||||||
JSONObject tempJson = new JSONObject();
|
JSONObject tempJson = new JSONObject();
|
||||||
try {
|
try { // creating a user json to send the server
|
||||||
tempJson.put("username", username);
|
tempJson.put("username", username);
|
||||||
tempJson.put("password", password);
|
tempJson.put("password", password);
|
||||||
tempJson.put("email", email);
|
tempJson.put("email", email);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(TAG, e.toString());
|
Log.d(TAG, e.toString());
|
||||||
}
|
}
|
||||||
Log.d(TAG, "JSON: " + tempJson.toString());
|
VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError); // register request to server
|
||||||
VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError);
|
} else { // invalid params
|
||||||
} else {
|
|
||||||
Utils.dismissLoadingDialog();
|
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();
|
Toast.makeText(this, "Make Sure tou have entered a valid email. password at least 4 chars", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Response.Listener<JSONObject> onRegisterSuccess = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> onRegisterSuccess = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) { // listener to success response on register from server
|
||||||
Log.d(TAG, "response: " + response.toString());
|
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
try {
|
try {
|
||||||
if (response.getString("message").equals("created")) {
|
if (response.getString("message").equals("created")) { // user created
|
||||||
Log.d(TAG, "onRegisterSuccess => user created"); // TODO: REMOVE console
|
|
||||||
Intent loginActivity = new Intent(RegisterActivity.this, LoginActivity.class);
|
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();
|
Toast.makeText(self, "You are now a social notework member - You May Login...", Toast.LENGTH_LONG).show();
|
||||||
startActivity(loginActivity);
|
startActivity(loginActivity);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show();
|
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());
|
Log.e(TAG, "onRegisterSuccess:" + e.getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -129,15 +122,14 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
|
|
||||||
Response.ErrorListener onRegisterError = new Response.ErrorListener() {
|
Response.ErrorListener onRegisterError = new Response.ErrorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) { // listener to error response on register from server
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show();
|
Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show();
|
||||||
Log.d(TAG, "onRegisterError: msg: " + error.getMessage());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) { // onclick methods to redirect to register and to login
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.ra_register_button:
|
case R.id.ra_register_button:
|
||||||
attemptRegister();
|
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);
|
Intent i = new Intent(RegisterActivity.this, LoginActivity.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
public class SettingsFragment extends Fragment implements View.OnClickListener, TextWatcher {
|
public class SettingsFragment extends Fragment implements View.OnClickListener, TextWatcher {
|
||||||
private static final String TAG = "[TSN/Settings]";
|
private static final String TAG = "[TSN/Settings]";
|
||||||
|
@ -170,11 +171,47 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
private void saveImage() {
|
private void saveImage() {
|
||||||
Utils.showLoadingDialog(parent, "Saving Image...", "This Can Take a while");
|
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();
|
JSONObject payload = new JSONObject();
|
||||||
try {
|
try {
|
||||||
payload.put("image", ImageToBase64(myFile.getAbsolutePath()));
|
payload.put("image", ImageToBase64(file.getAbsolutePath()));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
|
|
|
@ -96,6 +96,14 @@ public class Utils {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//response listener for getting all user notes
|
||||||
|
public static Response.Listener<JSONObject> genericSuccessListener = new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(JSONObject response) {
|
||||||
|
Log.d(TAG, "likeNotesSuccessListener: " + response.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static void showLoadingDialog(Context context, String title, String msg) {
|
public static void showLoadingDialog(Context context, String title, String msg) {
|
||||||
progress = new ProgressDialog(context);
|
progress = new ProgressDialog(context);
|
||||||
progress.setTitle(title);
|
progress.setTitle(title);
|
||||||
|
@ -148,8 +156,12 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void URLtoImageView(ImageView iv, String url){
|
public static void URLtoImageView(ImageView iv, String url){
|
||||||
|
if(bitmapHash.containsKey(url)){
|
||||||
|
iv.setImageBitmap(bitmapHash.get(url));
|
||||||
|
}else{
|
||||||
new setUserAvatar(iv, url).execute();
|
new setUserAvatar(iv, url).execute();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
|
private static class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
|
||||||
private ImageView iv;
|
private ImageView iv;
|
||||||
|
@ -236,8 +248,4 @@ public class Utils {
|
||||||
editor.remove("UserData");
|
editor.remove("UserData");
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
BIN
app/src/main/res/drawable/like_icon_black.png
Normal file
BIN
app/src/main/res/drawable/like_icon_black.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
|
@ -141,8 +141,9 @@
|
||||||
android:layout_width="20dp"
|
android:layout_width="20dp"
|
||||||
android:layout_height="20dp"
|
android:layout_height="20dp"
|
||||||
android:id="@+id/imageView9"
|
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" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/ndf_likes_textview"
|
android:id="@+id/ndf_likes_textview"
|
||||||
|
|
|
@ -40,4 +40,19 @@
|
||||||
<string name="title_activity_maps">Map</string>
|
<string name="title_activity_maps">Map</string>
|
||||||
<string name="avatar">Avatar</string>
|
<string name="avatar">Avatar</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<string name="day">24 hours</string>
|
||||||
|
<string name="week">Week</string>
|
||||||
|
<string name="month">Month</string>
|
||||||
|
<string name="privateNote">Private</string>
|
||||||
|
<string name="publicNote">Public</string>
|
||||||
|
<string name="privateAndPublic">All</string>
|
||||||
|
<string name="shortDistance">1 Km</string>
|
||||||
|
<string name="mediumDistance">10 Km</string>
|
||||||
|
<string name="longDistance">100 Km</string>
|
||||||
|
<string name="mine">Mine</string>
|
||||||
|
<string name="others">Others</string>
|
||||||
|
<string name="all">All</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue