- string consts added

- personal space filter 24 hours fixed
- added documentation
This commit is contained in:
Matan Bar Yosef 2016-07-10 17:11:07 +03:00
parent 58519d2431
commit 2ab96a1cfa
6 changed files with 70 additions and 184 deletions

View file

@ -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;
/**
@ -62,17 +55,6 @@ 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
@ -129,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();
}
@ -150,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();
}

View file

@ -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<Note> 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<Marker, Note>();
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();
}

View file

@ -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<JSONObject> onLoginSuccess = new Response.Listener<JSONObject>() {
@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;
// }
// }
// }
}

View file

@ -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<String> jsonArrayToStringArray(JSONArray jArray) {
ArrayList<String> stringArray = new ArrayList<String>();
for (int i = 0, count = jArray.length(); i < count; i++) {
@ -511,7 +483,7 @@ public class PersonalFragment extends Fragment {
}
//date filters
else {
dateFilterSelection = Utils.WEEK_MILI;
dateFilterSelection = Utils.DAY_MILI;
}
setButtonsColor();

View file

@ -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<JSONObject> onRegisterSuccess = new Response.Listener<JSONObject>() {
@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();

View file

@ -40,4 +40,19 @@
<string name="title_activity_maps">Map</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>