Merge branch 'master' of github.com:sagidayan/TheSocialNotework-Android
This commit is contained in:
commit
db3d15fa0a
8 changed files with 368 additions and 327 deletions
|
@ -50,9 +50,11 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
private GoogleMap mMap;
|
private GoogleMap mMap;
|
||||||
private GPSUtils gpsUtils;
|
private GPSUtils gpsUtils;
|
||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
|
private final int MAX_ZOOM = 16, MIN_ZOOM = 9;
|
||||||
|
|
||||||
|
|
||||||
public GmapFragment() {}
|
public GmapFragment() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static GmapFragment newInstance(String param1, String param2) {
|
public static GmapFragment newInstance(String param1, String param2) {
|
||||||
|
@ -110,17 +112,17 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
|
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCameraChange(CameraPosition cameraPosition) {
|
public void onCameraChange(CameraPosition cameraPosition) {
|
||||||
if (cameraPosition.zoom > 14) {
|
if (cameraPosition.zoom > MAX_ZOOM) {
|
||||||
getMap().animateCamera(CameraUpdateFactory.zoomTo(14));
|
getMap().animateCamera(CameraUpdateFactory.zoomTo(MAX_ZOOM));
|
||||||
}
|
}
|
||||||
if (cameraPosition.zoom < 8) {
|
if (cameraPosition.zoom < MIN_ZOOM) {
|
||||||
getMap().animateCamera(CameraUpdateFactory.zoomTo(8));
|
getMap().animateCamera(CameraUpdateFactory.zoomTo(MIN_ZOOM));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener);
|
||||||
// VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener);
|
// VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener);
|
||||||
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
||||||
// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
||||||
|
@ -146,7 +148,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
for (int i = 0; i < noteObjectsArray.length(); i++) {
|
for (int i = 0; i < noteObjectsArray.length(); i++) {
|
||||||
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
|
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
|
||||||
time.setTime(noteObject.getLong("created_at"));
|
time.setTime(noteObject.getLong("created_at"));
|
||||||
listOfNotes.add(mainActivity.getNoteFromJsonObj(noteObject, time));
|
listOfNotes.add(Utils.getNoteFromJsonObj(noteObject, time));
|
||||||
}
|
}
|
||||||
new getMarkersFromNotes(mMap).execute(listOfNotes);
|
new getMarkersFromNotes(mMap).execute(listOfNotes);
|
||||||
// noteList.setAdapter(noteListAdapter);
|
// noteList.setAdapter(noteListAdapter);
|
||||||
|
@ -158,25 +160,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Bitmap getBitmapFromURL(String imageUrl) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
URL url = new URL(imageUrl);
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.connect();
|
|
||||||
InputStream input = connection.getInputStream();
|
|
||||||
Bitmap myBitmap = BitmapFactory.decodeStream(input);
|
|
||||||
Log.d(TAG, "image: " + myBitmap.toString());
|
|
||||||
return Bitmap.createScaledBitmap(myBitmap, 80, 80, false);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerOptions, List<MarkerOptions>> {
|
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerOptions, List<MarkerOptions>> {
|
||||||
GoogleMap mMap;
|
GoogleMap mMap;
|
||||||
// GmapFragment gmap;
|
// GmapFragment gmap;
|
||||||
|
@ -215,7 +198,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
.title(n.getTitle())
|
.title(n.getTitle())
|
||||||
.position(new LatLng(n.getLat(), n.getLon()))
|
.position(new LatLng(n.getLat(), n.getLon()))
|
||||||
.snippet(n.getBody())
|
.snippet(n.getBody())
|
||||||
.icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromURL(url)));
|
.icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(url), 80, 80, false)));
|
||||||
publishProgress(mo);
|
publishProgress(mo);
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
@ -224,7 +207,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//Bitmap.createScaledBitmap(myBitmap, 80, 80, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,39 +7,39 @@ import android.os.AsyncTask;
|
||||||
/**
|
/**
|
||||||
* Created by aranza on 7/2/2016.
|
* Created by aranza on 7/2/2016.
|
||||||
*/
|
*/
|
||||||
public class HeavyWorker extends AsyncTask< String , Context , Void > {
|
public class HeavyWorker extends AsyncTask<String, Context, Void> {
|
||||||
|
|
||||||
private ProgressDialog progressDialog ;
|
private ProgressDialog progressDialog;
|
||||||
private Context targetCtx ;
|
private Context targetCtx;
|
||||||
|
|
||||||
public HeavyWorker ( Context context ) {
|
public HeavyWorker(Context context) {
|
||||||
this.targetCtx = context ;
|
this.targetCtx = context;
|
||||||
progressDialog = new ProgressDialog ( targetCtx ) ;
|
progressDialog = new ProgressDialog(targetCtx);
|
||||||
progressDialog.setCancelable ( false ) ;
|
progressDialog.setCancelable(false);
|
||||||
progressDialog.setMessage ( "Retrieving data..." ) ;
|
progressDialog.setMessage("Retrieving data...");
|
||||||
progressDialog.setTitle ( "Please wait" ) ;
|
progressDialog.setTitle("Please wait");
|
||||||
progressDialog.setIndeterminate ( true ) ;
|
progressDialog.setIndeterminate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ Override
|
@Override
|
||||||
protected void onPreExecute ( ) {
|
protected void onPreExecute() {
|
||||||
progressDialog.show ( ) ;
|
progressDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ Override
|
@Override
|
||||||
protected Void doInBackground ( String ... params ) {
|
protected Void doInBackground(String... params) {
|
||||||
// Do Your WORK here
|
// Do Your WORK here
|
||||||
|
|
||||||
// MainActivity ps = (MainActivity) targetCtx;
|
// MainActivity ps = (MainActivity) targetCtx;
|
||||||
// ps.getAllNotes();
|
// ps.getAllNotes();
|
||||||
|
|
||||||
return null ;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ Override
|
@Override
|
||||||
protected void onPostExecute ( Void result ) {
|
protected void onPostExecute(Void result) {
|
||||||
if(progressDialog != null && progressDialog.isShowing()){
|
if (progressDialog != null && progressDialog.isShowing()) {
|
||||||
progressDialog.dismiss ( ) ;
|
progressDialog.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,195 +30,195 @@ 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;
|
||||||
private TextView mRegisterButton;
|
private TextView mRegisterButton;
|
||||||
private Button mLoginButton;
|
private Button mLoginButton;
|
||||||
private final String TAG = "[TSN/LoginActivity]";
|
private final String TAG = "[TSN/LoginActivity]";
|
||||||
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
private final String LOGIN_PATH = "/login";
|
private final String LOGIN_PATH = "/login";
|
||||||
private LoginActivity self; //this
|
private LoginActivity self; //this
|
||||||
protected LinearLayout layout;
|
protected LinearLayout layout;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_login);
|
|
||||||
this.self = this;
|
|
||||||
this.layout = (LinearLayout) findViewById(R.id.layout);
|
|
||||||
this.mUsernameView = (EditText) findViewById(R.id.al_username);
|
|
||||||
this.mUsernameView.addTextChangedListener(this);
|
|
||||||
this.mPasswordView = (EditText) findViewById(R.id.al_password);
|
|
||||||
this.mPasswordView.addTextChangedListener(this);
|
|
||||||
removeFocuse();
|
|
||||||
this.mRegisterButton = (TextView) findViewById(R.id.al_register_button);
|
|
||||||
this.mRegisterButton.setOnClickListener(this);
|
|
||||||
|
|
||||||
this.mLoginButton = (Button) findViewById(R.id.al_login_button);
|
|
||||||
this.mLoginButton.setOnClickListener(this);
|
|
||||||
this.mLoginButton.setEnabled(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void attemptLogin() {
|
|
||||||
MainActivity.showLoadingDialog(this, "Connecting", "Authenticating data");
|
|
||||||
mPasswordView.setError(null);
|
|
||||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
|
|
||||||
|
|
||||||
String username = mUsernameView.getText().toString();
|
|
||||||
String password = mPasswordView.getText().toString();
|
|
||||||
|
|
||||||
boolean cancel = false;
|
|
||||||
// http request register
|
|
||||||
JSONObject tempJson = new JSONObject();
|
|
||||||
try {
|
|
||||||
tempJson.put("username", username);
|
|
||||||
tempJson.put("password", password);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.d(TAG, e.toString());
|
|
||||||
}
|
|
||||||
VolleyUtilSingleton.getInstance(LoginActivity.this).post(BASE_URL + LOGIN_PATH, tempJson, onLoginSuccess, onLoginError);
|
|
||||||
} else {
|
|
||||||
MainActivity.dismissLoadingDialog();
|
|
||||||
Log.d(TAG, "Invalid params - make sure username exist & password is 4 characters or more");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Response.Listener<JSONObject> onLoginSuccess = new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
try {
|
super.onCreate(savedInstanceState);
|
||||||
if (!response.isNull("user")) {
|
setContentView(R.layout.activity_login);
|
||||||
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
|
this.self = this;
|
||||||
SharedPreferences sharedPref = self.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
|
this.layout = (LinearLayout) findViewById(R.id.layout);
|
||||||
SharedPreferences.Editor editor = sharedPref.edit();
|
this.mUsernameView = (EditText) findViewById(R.id.al_username);
|
||||||
String id, password, email, avatar, username, likedNotes = "";
|
this.mUsernameView.addTextChangedListener(this);
|
||||||
|
this.mPasswordView = (EditText) findViewById(R.id.al_password);
|
||||||
|
this.mPasswordView.addTextChangedListener(this);
|
||||||
|
removeFocuse();
|
||||||
|
this.mRegisterButton = (TextView) findViewById(R.id.al_register_button);
|
||||||
|
this.mRegisterButton.setOnClickListener(this);
|
||||||
|
|
||||||
JSONArray likedNotes_JSON;
|
this.mLoginButton = (Button) findViewById(R.id.al_login_button);
|
||||||
id = response.getJSONObject("user").getString("id");
|
this.mLoginButton.setOnClickListener(this);
|
||||||
password = response.getJSONObject("user").getString("password");
|
this.mLoginButton.setEnabled(false);
|
||||||
username = response.getJSONObject("user").getString("username");
|
|
||||||
avatar = response.getJSONObject("user").getString("avatar");
|
}
|
||||||
email = response.getJSONObject("user").getString("email");
|
|
||||||
likedNotes_JSON = response.getJSONObject("user").getJSONArray("liked_notes_id");
|
private void removeFocuse() {
|
||||||
for (int i = 0; i < likedNotes_JSON.length(); i++) {
|
// Remove Auto Focus from the Text Fields
|
||||||
likedNotes += likedNotes_JSON.get(i);
|
mUsernameView.clearFocus();
|
||||||
if (i != likedNotes_JSON.length() - 1) {
|
mPasswordView.clearFocus();
|
||||||
likedNotes += User.LIKED_NOTES_DELIMETER;
|
layout.setFocusable(true);
|
||||||
}
|
layout.setFocusableInTouchMode(true);
|
||||||
}
|
|
||||||
editor.putString("UserData", id+User.ATTARS_DELIMETER+username+User.ATTARS_DELIMETER+password+User.ATTARS_DELIMETER+email+User.ATTARS_DELIMETER+avatar+User.ATTARS_DELIMETER+likedNotes);
|
}
|
||||||
editor.commit();
|
|
||||||
Intent personalSpaceActivity = new Intent(LoginActivity.this, MainActivity.class);
|
|
||||||
Bundle loginUserBundle = new Bundle();
|
/**
|
||||||
loginUserBundle.putString("UserData", id+User.ATTARS_DELIMETER+username+User.ATTARS_DELIMETER+password+User.ATTARS_DELIMETER+email+User.ATTARS_DELIMETER+avatar+User.ATTARS_DELIMETER+likedNotes);
|
* Attempts to sign in or register the account specified by the login form.
|
||||||
personalSpaceActivity.putExtras(loginUserBundle);
|
* If there are form errors (invalid email, missing fields, etc.), the
|
||||||
MainActivity.dismissLoadingDialog();
|
* errors are presented and no actual login attempt is made.
|
||||||
startActivity(personalSpaceActivity);
|
*/
|
||||||
|
|
||||||
|
private boolean isParamsValid(String username, String password) {
|
||||||
|
Log.d(TAG, "user: " + username);
|
||||||
|
Log.d(TAG, "pwd: " + password);
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
MainActivity.dismissLoadingDialog();
|
return true;
|
||||||
Toast.makeText(self, "Username or Password are incorrect", Toast.LENGTH_LONG).show();
|
|
||||||
self.mUsernameView.getText().clear();
|
|
||||||
self.mPasswordView.getText().clear();
|
|
||||||
self.removeFocuse();
|
|
||||||
((TextView) findViewById(R.id.textView2)).setVisibility(View.INVISIBLE);
|
|
||||||
Log.d(TAG, "No such user, " + response.get("user"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "onLoginSuccess:" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Response.ErrorListener onLoginError = new Response.ErrorListener() {
|
private void attemptLogin() {
|
||||||
|
Utils.showLoadingDialog(this, "Connecting", "Authenticating data");
|
||||||
|
mPasswordView.setError(null);
|
||||||
|
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
|
||||||
|
|
||||||
|
String username = mUsernameView.getText().toString();
|
||||||
|
String password = mPasswordView.getText().toString();
|
||||||
|
|
||||||
|
boolean cancel = false;
|
||||||
|
// http request register
|
||||||
|
JSONObject tempJson = new JSONObject();
|
||||||
|
try {
|
||||||
|
tempJson.put("username", username);
|
||||||
|
tempJson.put("password", password);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(TAG, e.toString());
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Response.Listener<JSONObject> onLoginSuccess = new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(JSONObject response) {
|
||||||
|
try {
|
||||||
|
if (!response.isNull("user")) {
|
||||||
|
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
|
||||||
|
SharedPreferences sharedPref = self.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
|
String id, password, email, avatar, username, likedNotes = "";
|
||||||
|
|
||||||
|
JSONArray likedNotes_JSON;
|
||||||
|
id = response.getJSONObject("user").getString("id");
|
||||||
|
password = response.getJSONObject("user").getString("password");
|
||||||
|
username = response.getJSONObject("user").getString("username");
|
||||||
|
avatar = response.getJSONObject("user").getString("avatar");
|
||||||
|
email = response.getJSONObject("user").getString("email");
|
||||||
|
likedNotes_JSON = response.getJSONObject("user").getJSONArray("liked_notes_id");
|
||||||
|
for (int i = 0; i < likedNotes_JSON.length(); i++) {
|
||||||
|
likedNotes += likedNotes_JSON.get(i);
|
||||||
|
if (i != likedNotes_JSON.length() - 1) {
|
||||||
|
likedNotes += User.LIKED_NOTES_DELIMETER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor.putString("UserData", id + User.ATTARS_DELIMETER + username + User.ATTARS_DELIMETER + password + User.ATTARS_DELIMETER + email + User.ATTARS_DELIMETER + avatar + User.ATTARS_DELIMETER + likedNotes);
|
||||||
|
editor.commit();
|
||||||
|
Intent personalSpaceActivity = new Intent(LoginActivity.this, MainActivity.class);
|
||||||
|
Bundle loginUserBundle = new Bundle();
|
||||||
|
loginUserBundle.putString("UserData", id + User.ATTARS_DELIMETER + username + User.ATTARS_DELIMETER + password + User.ATTARS_DELIMETER + email + User.ATTARS_DELIMETER + avatar + User.ATTARS_DELIMETER + likedNotes);
|
||||||
|
personalSpaceActivity.putExtras(loginUserBundle);
|
||||||
|
Utils.dismissLoadingDialog();
|
||||||
|
startActivity(personalSpaceActivity);
|
||||||
|
} else {
|
||||||
|
Utils.dismissLoadingDialog();
|
||||||
|
Toast.makeText(self, "Username or Password are incorrect", Toast.LENGTH_LONG).show();
|
||||||
|
self.mUsernameView.getText().clear();
|
||||||
|
self.mPasswordView.getText().clear();
|
||||||
|
self.removeFocuse();
|
||||||
|
((TextView) findViewById(R.id.textView2)).setVisibility(View.INVISIBLE);
|
||||||
|
Log.d(TAG, "No such user, " + response.get("user"));
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onLoginSuccess:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Response.ErrorListener onLoginError = new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
Utils.dismissLoadingDialog();
|
||||||
|
Toast.makeText(self, "Username Or Password Incorrect", Toast.LENGTH_LONG).show();
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPasswordValid(String password) {
|
||||||
|
return password.length() > 3;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onClick(View view) {
|
||||||
MainActivity.dismissLoadingDialog();
|
switch (view.getId()) {
|
||||||
Toast.makeText(self, "Username Or Password Incorrect", Toast.LENGTH_LONG).show();
|
case R.id.al_login_button:
|
||||||
//Clean texts
|
//Do Login
|
||||||
self.mUsernameView.getText().clear();
|
Log.d(TAG, "Login.......");
|
||||||
self.mPasswordView.getText().clear();
|
attemptLogin();
|
||||||
self.removeFocuse();
|
break;
|
||||||
Log.d(TAG, "onErrorResponse: setting text to ''");
|
case R.id.al_register_button:
|
||||||
Log.d(TAG, "onLoginError: msg: " + error.getMessage());
|
//Do Register
|
||||||
|
Log.d(TAG, "going to Register...page");
|
||||||
|
Intent registerActivity = new Intent(LoginActivity.this, RegisterActivity.class);
|
||||||
|
startActivity(registerActivity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||||
|
|
||||||
private boolean isUsernameValid(String username) {
|
|
||||||
return username.length() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPasswordValid(String password) {
|
|
||||||
return password.length() > 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
switch (view.getId()) {
|
|
||||||
case R.id.al_login_button:
|
|
||||||
//Do Login
|
|
||||||
Log.d(TAG, "Login.......");
|
|
||||||
attemptLogin();
|
|
||||||
break;
|
|
||||||
case R.id.al_register_button:
|
|
||||||
//Do Register
|
|
||||||
Log.d(TAG, "going to Register...page");
|
|
||||||
Intent registerActivity = new Intent(LoginActivity.this, RegisterActivity.class);
|
|
||||||
startActivity(registerActivity);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||||
|
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
|
||||||
}
|
((TextView) findViewById(R.id.textView2)).setVisibility(View.INVISIBLE);
|
||||||
|
mLoginButton.setEnabled(true);
|
||||||
@Override
|
} else {
|
||||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
((TextView) findViewById(R.id.textView2)).setVisibility(View.VISIBLE);
|
||||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
|
mLoginButton.setEnabled(false);
|
||||||
((TextView) findViewById(R.id.textView2)).setVisibility(View.INVISIBLE);
|
}
|
||||||
mLoginButton.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
((TextView) findViewById(R.id.textView2)).setVisibility(View.VISIBLE);
|
|
||||||
mLoginButton.setEnabled(false);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable editable) {
|
public void afterTextChanged(Editable editable) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@ package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
/**
|
/**
|
||||||
* Created by aran on 5/26/16.
|
* Created by aran on 5/26/16.
|
||||||
*/
|
*/
|
||||||
import com.android.volley.toolbox.ImageLoader.ImageCache;
|
|
||||||
import android.graphics.Bitmap;
|
import com.android.volley.toolbox.ImageLoader.ImageCache;
|
||||||
import android.support.v4.util.LruCache;
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.v4.util.LruCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to extend the LruCache class - for better image caching
|
* A class to extend the LruCache class - for better image caching
|
||||||
|
|
|
@ -43,7 +43,6 @@ public class MainActivity extends AppCompatActivity
|
||||||
protected User user;
|
protected User user;
|
||||||
private GPSUtils gpsUtils;
|
private GPSUtils gpsUtils;
|
||||||
private boolean locationPermission;
|
private boolean locationPermission;
|
||||||
public static ProgressDialog progress;
|
|
||||||
private GmapFragment gmapFragment;
|
private GmapFragment gmapFragment;
|
||||||
private PersonalFragment personalFragment;
|
private PersonalFragment personalFragment;
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
|
@ -181,62 +180,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void showLoadingDialog(Context context, String title, String msg) {
|
|
||||||
progress = new ProgressDialog(context);
|
|
||||||
progress.setTitle(title);
|
|
||||||
progress.setMessage(msg);
|
|
||||||
progress.setCanceledOnTouchOutside(false);
|
|
||||||
progress.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void dismissLoadingDialog() {
|
|
||||||
|
|
||||||
if (progress != null && progress.isShowing()) {
|
|
||||||
progress.dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// //Generic response ErrorListener
|
|
||||||
Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Log.d(TAG, "genericErrorListener");
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public Note getNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
|
||||||
// List<Note> listOfNotes = new ArrayList<>();
|
|
||||||
|
|
||||||
Note note = new Note(
|
|
||||||
noteObject.getString("id"),
|
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
|
||||||
noteObject.getJSONObject("location").getString("address"),
|
|
||||||
noteObject.getString("title"),
|
|
||||||
noteObject.getString("body"),
|
|
||||||
time.toString(),
|
|
||||||
noteObject.getBoolean("is_public"),
|
|
||||||
noteObject.getInt("likes"),
|
|
||||||
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
|
||||||
);
|
|
||||||
return note;
|
|
||||||
// listOfNotes.add(addNote);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
|
||||||
ArrayList<String> stringArray = new ArrayList<String>();
|
|
||||||
for (int i = 0, count = jArray.length(); i < count; i++) {
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = jArray.getJSONObject(i);
|
|
||||||
stringArray.add(jsonObject.toString());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stringArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser(){
|
public User getUser(){
|
||||||
return user;
|
return user;
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class PersonalFragment extends Fragment {
|
||||||
noteListAdapter = new ListAdapter(getContext(), listOfNotes);
|
noteListAdapter = new ListAdapter(getContext(), listOfNotes);
|
||||||
noteList.setAdapter(noteListAdapter);
|
noteList.setAdapter(noteListAdapter);
|
||||||
noteList.setOnItemClickListener(new ItemClickedListener());
|
noteList.setOnItemClickListener(new ItemClickedListener());
|
||||||
MainActivity.showLoadingDialog(activity, "Fetching..", "getting your notes");
|
Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes");
|
||||||
getAllNotes();
|
getAllNotes();
|
||||||
|
|
||||||
//https://thesocialnotework-api.appspot.com/api/note/all?uid=<USER_ID>
|
//https://thesocialnotework-api.appspot.com/api/note/all?uid=<USER_ID>
|
||||||
|
@ -97,19 +97,19 @@ public class PersonalFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
MainActivity.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
Log.d(TAG, "onAttach");
|
Log.d(TAG, "onAttach");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
MainActivity.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAllNotes() {
|
public void getAllNotes() {
|
||||||
Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId);
|
Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId);
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener addNewNoteDialog = new View.OnClickListener() {
|
private View.OnClickListener addNewNoteDialog = new View.OnClickListener() {
|
||||||
|
@ -178,7 +178,7 @@ public class PersonalFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
//send request and close dialog
|
//send request and close dialog
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -216,13 +216,13 @@ public class PersonalFragment extends Fragment {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//response Error listener for adding new note
|
// //response Error listener for adding new note
|
||||||
Response.ErrorListener newNoteErrorListener = new Response.ErrorListener() {
|
// Response.ErrorListener newNoteErrorListener = new Response.ErrorListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
// public void onErrorResponse(VolleyError error) {
|
||||||
Log.d(TAG, "newNoteError: msg: " + error.getMessage());
|
// Log.d(TAG, "newNoteError: msg: " + error.getMessage());
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
|
||||||
//response listener for getting all user notes
|
//response listener for getting all user notes
|
||||||
|
@ -230,7 +230,7 @@ public class PersonalFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
Log.d(TAG, "getNotesSuccessListener: " + response.toString());
|
Log.d(TAG, "getNotesSuccessListener: " + response.toString());
|
||||||
MainActivity.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
try {
|
try {
|
||||||
//need to get all notes and add to listOfNotes
|
//need to get all notes and add to listOfNotes
|
||||||
JSONArray noteObjectsArray = response.getJSONArray("notes");
|
JSONArray noteObjectsArray = response.getJSONArray("notes");
|
||||||
|
@ -250,24 +250,24 @@ public class PersonalFragment extends Fragment {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//response ErrorListener for getting all user notes
|
// //response ErrorListener for getting all user notes
|
||||||
Response.ErrorListener getNotesErrorListener = new Response.ErrorListener() {
|
// Response.ErrorListener getNotesErrorListener = new Response.ErrorListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
// public void onErrorResponse(VolleyError error) {
|
||||||
Log.d(TAG, "getNotesErrorListener: " + error.getMessage());
|
// Log.d(TAG, "getNotesErrorListener: " + error.getMessage());
|
||||||
MainActivity.dismissLoadingDialog();
|
// MainActivity.dismissLoadingDialog();
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
//Generic response ErrorListener
|
// //Generic response ErrorListener
|
||||||
Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
// Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
// public void onErrorResponse(VolleyError error) {
|
||||||
Log.d(TAG, "genericErrorListener");
|
// Log.d(TAG, "genericErrorListener");
|
||||||
MainActivity.dismissLoadingDialog();
|
// MainActivity.dismissLoadingDialog();
|
||||||
error.printStackTrace();
|
// error.printStackTrace();
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
|
||||||
private ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
private ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
||||||
|
@ -362,7 +362,7 @@ public class PersonalFragment extends Fragment {
|
||||||
try {
|
try {
|
||||||
delNote.put("uid", userId);
|
delNote.put("uid", userId);
|
||||||
delNote.put("nid", note.getId());
|
delNote.put("nid", note.getId());
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, Utils.genericErrorListener);
|
||||||
listOfNotes.remove(position);
|
listOfNotes.remove(position);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
|
@ -10,13 +10,16 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
|
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
|
@ -58,12 +61,14 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
private boolean isUsernameValid(String username) {
|
private boolean isUsernameValid(String username) {
|
||||||
return !TextUtils.isEmpty(username) && username.length() > 0;
|
return !TextUtils.isEmpty(username) && username.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPasswordValid(String password) {
|
private boolean isPasswordValid(String password) {
|
||||||
return !TextUtils.isEmpty(password) && password.length() > 3;
|
return !TextUtils.isEmpty(password) && password.length() > 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmailValid(String email) {
|
private boolean isEmailValid(String email) {
|
||||||
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}$";
|
||||||
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
|
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher matcher = pattern.matcher(email);
|
Matcher matcher = pattern.matcher(email);
|
||||||
|
@ -75,7 +80,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attemptRegister() {
|
private void attemptRegister() {
|
||||||
MainActivity.showLoadingDialog(this, "Registering", "Please Wait...");
|
Utils.showLoadingDialog(this, "Registering", "Please Wait...");
|
||||||
Log.d(TAG, "in attemptRegister: Registering..");
|
Log.d(TAG, "in attemptRegister: Registering..");
|
||||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) {
|
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) {
|
||||||
Log.d(TAG, "params are valid");
|
Log.d(TAG, "params are valid");
|
||||||
|
@ -91,10 +96,10 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(TAG, e.toString());
|
Log.d(TAG, e.toString());
|
||||||
}
|
}
|
||||||
Log.d(TAG,"JSON: "+tempJson.toString());
|
Log.d(TAG, "JSON: " + tempJson.toString());
|
||||||
VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError);
|
VolleyUtilSingleton.getInstance(RegisterActivity.this).post(BASE_URL + REG_PATH, tempJson, onRegisterSuccess, onRegisterError);
|
||||||
} else {
|
} else {
|
||||||
MainActivity.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
Log.d(TAG, "Invalid params - make sure username exist, password is 4 characters or more & email is valid");
|
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();
|
||||||
}
|
}
|
||||||
|
@ -103,19 +108,19 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
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) {
|
||||||
Log.d(TAG,"response: "+ response.toString());
|
Log.d(TAG, "response: " + response.toString());
|
||||||
MainActivity.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
try {
|
try {
|
||||||
if(response.getString("message").equals("created")) {
|
if (response.getString("message").equals("created")) {
|
||||||
Log.d(TAG, "onRegisterSuccess => user created"); // TODO: REMOVE console
|
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"));
|
Log.d(TAG, "Cannot create user, " + response.getString("message"));
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "onRegisterSuccess:" + e.getMessage());
|
Log.e(TAG, "onRegisterSuccess:" + e.getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,15 +130,15 @@ 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) {
|
||||||
MainActivity.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());
|
Log.d(TAG, "onRegisterError: msg: " + error.getMessage());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch(view.getId()){
|
switch (view.getId()) {
|
||||||
case R.id.ra_register_button:
|
case R.id.ra_register_button:
|
||||||
attemptRegister();
|
attemptRegister();
|
||||||
break;
|
break;
|
||||||
|
@ -143,7 +148,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void returnToLogin(){
|
private void returnToLogin() {
|
||||||
Intent i = new Intent(RegisterActivity.this, LoginActivity.class);
|
Intent i = new Intent(RegisterActivity.this, LoginActivity.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JERLocal on 7/7/2016.
|
||||||
|
*/
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
public static final String TAG = "Utils";
|
||||||
|
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
|
public static ProgressDialog progress;
|
||||||
|
|
||||||
|
|
||||||
|
public static Bitmap getBitmapFromURL(String imageUrl) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL url = new URL(imageUrl);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.connect();
|
||||||
|
InputStream input = connection.getInputStream();
|
||||||
|
Bitmap myBitmap = BitmapFactory.decodeStream(input);
|
||||||
|
return myBitmap;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// //Generic response ErrorListener
|
||||||
|
public static Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
Log.d(TAG, "genericErrorListener");
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void showLoadingDialog(Context context, String title, String msg) {
|
||||||
|
progress = new ProgressDialog(context);
|
||||||
|
progress.setTitle(title);
|
||||||
|
progress.setMessage(msg);
|
||||||
|
progress.setCanceledOnTouchOutside(false);
|
||||||
|
progress.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void dismissLoadingDialog() {
|
||||||
|
|
||||||
|
if (progress != null && progress.isShowing()) {
|
||||||
|
progress.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Note getNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
||||||
|
// List<Note> listOfNotes = new ArrayList<>();
|
||||||
|
|
||||||
|
Note note = new Note(
|
||||||
|
noteObject.getString("id"),
|
||||||
|
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
||||||
|
Float.parseFloat(noteObject.getJSONObject("location").getString("lng")),
|
||||||
|
noteObject.getJSONObject("location").getString("address"),
|
||||||
|
noteObject.getString("title"),
|
||||||
|
noteObject.getString("body"),
|
||||||
|
time.toString(),
|
||||||
|
noteObject.getBoolean("is_public"),
|
||||||
|
noteObject.getInt("likes"),
|
||||||
|
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
|
);
|
||||||
|
return note;
|
||||||
|
// listOfNotes.add(addNote);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
||||||
|
ArrayList<String> stringArray = new ArrayList<String>();
|
||||||
|
for (int i = 0, count = jArray.length(); i < count; i++) {
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = jArray.getJSONObject(i);
|
||||||
|
stringArray.add(jsonObject.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringArray;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue