This commit is contained in:
Sagi Dayan 2016-07-10 17:50:26 +03:00
parent 2ca32ca356
commit aae20aa1cc
4 changed files with 716 additions and 750 deletions

View file

@ -1,22 +1,11 @@
package com.android_app.matan.ara.sagi.thesocialnotework; package com.android_app.matan.ara.sagi.thesocialnotework;
import android.*;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
@ -29,54 +18,42 @@ import android.view.MenuItem;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.android.gms.maps.model.MarkerOptions;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener { implements NavigationView.OnNavigationItemSelectedListener {
public static final String LOCAL_DATA_TSN = "TSN_DATA_STORE"; public static final String LOCAL_DATA_TSN = "TSN_DATA_STORE";
protected final String TAG = "[TSN / MainActivity]"; protected final String TAG = "[TSN / MainActivity]";
protected User user; protected User user;
private GPSUtils gpsUtils; private GPSUtils gpsUtils;
private boolean locationPermission;
private GmapFragment gmapFragment; private GmapFragment gmapFragment;
private PersonalFragment personalFragment; private PersonalFragment personalFragment;
private SettingsFragment settingsFragment; private SettingsFragment settingsFragment;
private ExploreFragment exploreFragment; private ExploreFragment exploreFragment;
private Toolbar toolbar; private Toolbar toolbar;
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private ImageView menu_avatar; private ImageView menu_avatar;
private MainActivity self; private MainActivity self;
private NavigationView nav_view; private NavigationView nav_view;
private final int FINE_PERM = 0, CAMERA_PERM = 1; private final int FINE_PERM = 0;
/**
* On Activity Start
* @param savedInstanceState
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
this.self = this; this.self = this;
toolbar = (Toolbar) findViewById(R.id.toolbar); this.toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Personal Notes"); this.toolbar.setTitle("Personal Notes");
setSupportActionBar(toolbar); this.setSupportActionBar(toolbar);
gmapFragment = new GmapFragment(); this.gmapFragment = new GmapFragment();
personalFragment = new PersonalFragment(); this.personalFragment = new PersonalFragment();
settingsFragment = new SettingsFragment(); this.settingsFragment = new SettingsFragment();
exploreFragment = new ExploreFragment(); this.exploreFragment = new ExploreFragment();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); StrictMode.setThreadPolicy(policy);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@ -99,7 +76,6 @@ public class MainActivity extends AppCompatActivity
//Change Layout //Change Layout
Log.d(TAG, "Changing Fragment to Personal Activity"); Log.d(TAG, "Changing Fragment to Personal Activity");
// PersonalFragment personalFragment = new PersonalFragment();
personalFragment.setArguments(b); personalFragment.setArguments(b);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, personalFragment); ft.replace(R.id.fragment_container, personalFragment);
@ -129,15 +105,18 @@ public class MainActivity extends AppCompatActivity
return true; return true;
} }
/**
* Handle action bar item clicks here. The action bar will
* automatically handle clicks on the Home/Up button, so long
* as you specify a parent activity in AndroidManifest.xml.
* @param item - Action bar item (Menu)
* @return
*/
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); int id = item.getItemId();
Log.d(TAG, "onOptionsItemSelected: id -> "+id); Log.d(TAG, "onOptionsItemSelected: id -> "+id);
//noinspection SimplifiableIfStatement // Settings
if (id == R.id.action_settings) { if (id == R.id.action_settings) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
toolbar.setTitle("Settings"); toolbar.setTitle("Settings");
@ -146,17 +125,19 @@ public class MainActivity extends AppCompatActivity
ft.commit(); ft.commit();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
/**
* This function will be called when an item is selected from the nav bar.
* @param item
* @return
*/
@SuppressWarnings("StatementWithEmptyBody") @SuppressWarnings("StatementWithEmptyBody")
@Override @Override
public boolean onNavigationItemSelected(MenuItem item) { public boolean onNavigationItemSelected(MenuItem item) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.nav_explore) { if (id == R.id.nav_explore) {
toolbar.setTitle("Explore"); toolbar.setTitle("Explore");
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -193,16 +174,17 @@ public class MainActivity extends AppCompatActivity
finish(); finish();
} }
// Close the drawer
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
return true; return true;
} }
public GPSUtils getGPSUtils() { public GPSUtils getGPSUtils() {
return this.gpsUtils; return this.gpsUtils;
} }
public User getUser() { public User getUser() {
return user; return user;
} }
@ -211,6 +193,12 @@ public class MainActivity extends AppCompatActivity
return user.getId(); return user.getId();
} }
/**
* Permittion handlers
* @param requestCode
* @param permissions
* @param grantResults
*/
@Override @Override
public void onRequestPermissionsResult(int requestCode, public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) { String permissions[], int[] grantResults) {
@ -248,6 +236,9 @@ public class MainActivity extends AppCompatActivity
} }
/**
* Update the Navbar avatar
*/
public void updateNavAvatar() { public void updateNavAvatar() {
//Change The Avatar //Change The Avatar
Utils.URLtoImageView(menu_avatar, user.getAvatar()); Utils.URLtoImageView(menu_avatar, user.getAvatar());

View file

@ -1,10 +1,10 @@
package com.android_app.matan.ara.sagi.thesocialnotework; package com.android_app.matan.ara.sagi.thesocialnotework;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
/** /**
* Created by JERLocal on 7/8/2016. * Created by JERLocal on 7/8/2016.
* This class will hold information about a Mark on the Map.
*/ */
public class MarkerNoteStruct { public class MarkerNoteStruct {
private Note note; private Note note;

View file

@ -10,6 +10,7 @@ import java.util.Date;
/** /**
* Created by JERLocal on 7/1/2016. * Created by JERLocal on 7/1/2016.
* A Note Class - Represents a note Object
*/ */
public class Note implements Parcelable { public class Note implements Parcelable {
@ -25,7 +26,6 @@ public class Note implements Parcelable {
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
this.address = address; this.address = address;
this.title = title; this.title = title;
this.body = body; this.body = body;
this.timestamp = timestamp; this.timestamp = timestamp;
@ -42,7 +42,6 @@ public class Note implements Parcelable {
tags = in.createStringArrayList(); tags = in.createStringArrayList();
lat = in.readFloat(); lat = in.readFloat();
lon = in.readFloat(); lon = in.readFloat();
id = in.readString(); id = in.readString();
address = in.readString(); address = in.readString();
title = in.readString(); title = in.readString();
@ -205,12 +204,22 @@ public class Note implements Parcelable {
dest.writeByte((byte) (isPublic ? 1 : 0)); dest.writeByte((byte) (isPublic ? 1 : 0));
} }
/**
* Get a Simplified Readable Time (Creation of the note)
*
* @return String
*/
public String getTime() { public String getTime() {
Date d = new Date(timestamp); Date d = new Date(timestamp);
DateFormat format = new SimpleDateFormat("HH:mm"); DateFormat format = new SimpleDateFormat("HH:mm");
return format.format(d); return format.format(d);
} }
/**
* Get a Simplified Readable Date (Creation of the note)
*
* @return String
*/
public String getDate() { public String getDate() {
Date d = new Date(timestamp); Date d = new Date(timestamp);
DateFormat format = new SimpleDateFormat("dd MMM yyy"); DateFormat format = new SimpleDateFormat("dd MMM yyy");

View file

@ -5,18 +5,10 @@ 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.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.location.Location;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -36,8 +28,6 @@ import android.widget.TextView;
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.google.android.gms.maps.model.LatLng;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -54,7 +44,6 @@ import java.util.List;
* to handle interaction events. * to handle interaction events.
*/ */
public class PersonalFragment extends Fragment { public class PersonalFragment extends Fragment {
protected ListView noteList; protected ListView noteList;
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private GPSUtils gpsUtils; private GPSUtils gpsUtils;
@ -63,11 +52,9 @@ public class PersonalFragment extends Fragment {
private String userId; private String userId;
private final String TAG = "[TSN/PersonalFragment]"; private final String TAG = "[TSN/PersonalFragment]";
private MainActivity activity; private MainActivity activity;
private final int FINE_PERM = 0, CAMERA_PERM = 1; private final int FINE_PERM = 0;
private int userFilterSelection; private int userFilterSelection;
private Long dateFilterSelection; private Long dateFilterSelection;
private ImageButton dateFilter; private ImageButton dateFilter;
private ImageButton userFilter; private ImageButton userFilter;
private Button map_small_filter; private Button map_small_filter;
@ -86,7 +73,7 @@ public class PersonalFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, final 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(); this.activity = (MainActivity) getActivity();
Bundle bundle = getArguments(); Bundle bundle = getArguments();
this.userId = activity.getUserId(); this.userId = activity.getUserId();
Log.d(TAG, "onCreateView: userID: " + userId); Log.d(TAG, "onCreateView: userID: " + userId);
@ -130,6 +117,7 @@ public class PersonalFragment extends Fragment {
personalSpaceFilters = (LinearLayout) view.findViewById(R.id.personalSpace_filter_options); personalSpaceFilters = (LinearLayout) view.findViewById(R.id.personalSpace_filter_options);
// Date Filter Listener
dateFilter.setOnClickListener(new View.OnClickListener() { dateFilter.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(final View v) { public void onClick(final View v) {
@ -151,7 +139,7 @@ public class PersonalFragment extends Fragment {
} }
}); });
// User Filter Listener
userFilter.setOnClickListener(new View.OnClickListener() { userFilter.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -175,21 +163,13 @@ public class PersonalFragment extends Fragment {
} }
}); });
// get all notes according to some default filter ? // TODO: Aran?
VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener);
// The New "Add Button" - Floating Fab Button
// getAllNotes();
//https://thesocialnotework-api.appspot.com/api/note/all?uid=<USER_ID>
// The New "Add Button"
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
fab.setOnClickListener(addNewNoteDialog); fab.setOnClickListener(addNewNoteDialog);
return view; return view;
} }
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@ -203,14 +183,14 @@ public class PersonalFragment extends Fragment {
Utils.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, Utils.genericErrorListener); // VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener);
} // }
// New Note Dialog (View)
private View.OnClickListener addNewNoteDialog = new View.OnClickListener() { private View.OnClickListener addNewNoteDialog = new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
//create and configure dialog //create and configure dialog
final Dialog dialog = new Dialog(getActivity()); final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -223,20 +203,17 @@ public class PersonalFragment extends Fragment {
dialog.show(); dialog.show();
dialog.getWindow().setAttributes(lp); dialog.getWindow().setAttributes(lp);
//get note_view_full layout elements //get note_view_full layout elements
final Switch permissionSwitch = (Switch) dialog.findViewById(R.id.nvf_note_permission); final Switch permissionSwitch = (Switch) dialog.findViewById(R.id.nvf_note_permission);
final EditText newTitle = (EditText) dialog.findViewById(R.id.nvf_note_title); final EditText newTitle = (EditText) dialog.findViewById(R.id.nvf_note_title);
final EditText newBody = (EditText) dialog.findViewById(R.id.nvf_note_content); final EditText newBody = (EditText) dialog.findViewById(R.id.nvf_note_content);
Button saveBtn = (Button) dialog.findViewById(R.id.nvf_note_submit_btn); Button saveBtn = (Button) dialog.findViewById(R.id.nvf_note_submit_btn);
Button cancelBtn = (Button) dialog.findViewById(R.id.nvf_note_cancel_btn); Button cancelBtn = (Button) dialog.findViewById(R.id.nvf_note_cancel_btn);
cancelBtn.setOnClickListener(new View.OnClickListener() { cancelBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
dialog.dismiss(); dialog.dismiss();
} }
}); });
saveBtn.setOnClickListener(new View.OnClickListener() { saveBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
@ -253,6 +230,10 @@ public class PersonalFragment extends Fragment {
toast.show(); toast.show();
return; return;
} }
if (newBody.getText().length() < 1) {
Toast.makeText(getActivity(), "Cant Submit an empty body", Toast.LENGTH_LONG).show();
return;
}
//volley post //volley post
final JSONObject noteJson = new JSONObject(); final JSONObject noteJson = new JSONObject();
try { try {
@ -265,20 +246,15 @@ public class PersonalFragment extends Fragment {
noteJson.put("address", gpsUtils.getAddress()); noteJson.put("address", gpsUtils.getAddress());
noteJson.put("body", newBody.getText()); noteJson.put("body", newBody.getText());
noteJson.put("is_public", permissionSwitch.isChecked()); noteJson.put("is_public", permissionSwitch.isChecked());
// noteJson.put("tags",);
Log.d(TAG, "Json: " + noteJson.toString()); Log.d(TAG, "Json: " + noteJson.toString());
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, "saveBtn: " + e.toString()); Log.d(TAG, "saveBtn: " + e.toString());
} }
//send request and close dialog //send request and close dialog
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener); VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener);
dialog.dismiss(); dialog.dismiss();
} }
}); });
//change text of switch according to state. //change text of switch according to state.
permissionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { permissionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -288,8 +264,6 @@ public class PersonalFragment extends Fragment {
permissionSwitch.setText(R.string.nvf_private_label); permissionSwitch.setText(R.string.nvf_private_label);
} }
}); });
} }
}; };
@ -304,9 +278,6 @@ public class PersonalFragment extends Fragment {
time.setTime(noteObject.getLong("created_at")); time.setTime(noteObject.getLong("created_at"));
addNoteFromJsonObj(noteObject, time, 0); addNoteFromJsonObj(noteObject, time, 0);
updateShowedNotes(); updateShowedNotes();
// presentedNotes = listOfNotes;
// noteList.setAdapter(noteListAdapter);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "newNoteSuccess:" + e.getMessage()); Log.e(TAG, "newNoteSuccess:" + e.getMessage());
} }
@ -315,15 +286,6 @@ public class PersonalFragment extends Fragment {
}; };
// //response Error listener for adding new note
// Response.ErrorListener newNoteErrorListener = new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
// Log.d(TAG, "newNoteError: msg: " + error.getMessage());
// }
// };
//response listener for getting all user notes //response listener for getting all user notes
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() { Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
@Override @Override
@ -342,8 +304,6 @@ public class PersonalFragment extends Fragment {
addNoteFromJsonObj(noteObject, time, -1); addNoteFromJsonObj(noteObject, time, -1);
} }
updateShowedNotes(); updateShowedNotes();
// presentedNotes = listOfNotes;
// noteList.setAdapter(noteListAdapter);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "newNoteSuccess:" + e.getMessage()); Log.e(TAG, "newNoteSuccess:" + e.getMessage());
} }
@ -351,6 +311,11 @@ public class PersonalFragment extends Fragment {
} }
}; };
/**
* Converts JSON Array to A Java String ArrayList
* @param jArray JSONArray Object
* @return ArrayList<String>
*/
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++) {
@ -365,6 +330,13 @@ public class PersonalFragment extends Fragment {
} }
/**
* Add note from JSON Object to the list of notes
* @param noteObject
* @param time
* @param position
* @throws JSONException
*/
private void addNoteFromJsonObj(JSONObject noteObject, Date time, int position) throws JSONException { private void addNoteFromJsonObj(JSONObject noteObject, Date time, int position) throws JSONException {
Note addNote = new Note( Note addNote = new Note(
noteObject.getString("id"), noteObject.getString("id"),
@ -389,7 +361,9 @@ public class PersonalFragment extends Fragment {
} }
// click on listView item /**
* The ListView Item Listener
*/
class ItemClickedListener implements AdapterView.OnItemClickListener { class ItemClickedListener implements AdapterView.OnItemClickListener {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
@ -398,14 +372,12 @@ public class PersonalFragment extends Fragment {
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);
// noteViewDialog.setTitle("You wrote...");
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(noteViewDialog.getWindow().getAttributes()); lp.copyFrom(noteViewDialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT;
noteViewDialog.show(); noteViewDialog.show();
// dialog.getWindow().setAttributes(lp);
//get note_view_full layout elements //get note_view_full layout elements
@ -415,7 +387,6 @@ public class PersonalFragment extends Fragment {
final TextView date = (TextView) noteViewDialog.findViewById(R.id.ndf_date_textview); final TextView date = (TextView) noteViewDialog.findViewById(R.id.ndf_date_textview);
final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview); final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview);
final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview);
// final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview);
final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview);
final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton);
final ImageView avatar = (RoundAvatarImageView) noteViewDialog.findViewById(R.id.note_user_avatar); final ImageView avatar = (RoundAvatarImageView) noteViewDialog.findViewById(R.id.note_user_avatar);
@ -427,10 +398,9 @@ public class PersonalFragment extends Fragment {
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) likes.setText("" + note.getLikes());
// tags.setText("Tags: "+ note.getTags().toString());
permission.setText("" + (note.isPublic() ? "Public" : "Private")); permission.setText("" + (note.isPublic() ? "Public" : "Private"));
Utils.URLtoImageView(avatar, note.getAvatar()); Utils.URLtoImageView(avatar, note.getAvatar());
// DElete Button Listener
deleteBtn.setOnClickListener(new View.OnClickListener() { deleteBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
//Put up the Yes/No message box //Put up the Yes/No message box
@ -444,7 +414,6 @@ public class PersonalFragment extends Fragment {
//Yes button clicked, do something //Yes button clicked, do something
Toast.makeText(getActivity(), "Item Deleted!", Toast.makeText(getActivity(), "Item Deleted!",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
//TODO send delete
JSONObject delNote = new JSONObject(); JSONObject delNote = new JSONObject();
try { try {
delNote.put("uid", userId); delNote.put("uid", userId);
@ -452,13 +421,11 @@ public class PersonalFragment extends Fragment {
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener); VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener);
listOfNotes.remove(presentedNotes.get(position)); listOfNotes.remove(presentedNotes.get(position));
presentedNotes.remove(position); presentedNotes.remove(position);
} catch (JSONException e) { } catch (JSONException e) {
Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show();
e.printStackTrace(); e.printStackTrace();
} }
updateShowedNotes(); updateShowedNotes();
// noteList.setAdapter(noteListAdapter);
noteViewDialog.dismiss(); noteViewDialog.dismiss();
} }
}) })
@ -477,7 +444,6 @@ public class PersonalFragment extends Fragment {
} }
} }
//all buttons listener //all buttons listener
public View.OnClickListener button1ClickListener = new View.OnClickListener() { public View.OnClickListener button1ClickListener = new View.OnClickListener() {
@Override @Override
@ -534,21 +500,19 @@ public class PersonalFragment extends Fragment {
}; };
/**
* Update The Shown Notes (FIlters)
*/
public void updateShowedNotes() { public void updateShowedNotes() {
presentedNotes = new ArrayList<>(); presentedNotes = new ArrayList<>();
long timeDifference; long timeDifference;
// Location currLocation = new Location(gpsUtils.getLocation());
Date now = new Date(); Date now = new Date();
// Location targetLocation = new Location("");//provider name is unecessary
Date targetDate; Date targetDate;
for (Note note : listOfNotes) { for (Note note : listOfNotes) {
//get note location and date //get note location and date
// targetLocation.setLatitude(note.getLat());//your coords of course
// targetLocation.setLongitude(note.getLon());
targetDate = new Date(note.getTimestamp()); targetDate = new Date(note.getTimestamp());
//get time and date differences //get time and date differences
timeDifference = now.getTime() - targetDate.getTime(); timeDifference = now.getTime() - targetDate.getTime();
// distance = currLocation.distanceTo(targetLocation);
//add to currently presented list according to filters. //add to currently presented list according to filters.
if (timeDifference <= dateFilterSelection if (timeDifference <= dateFilterSelection
&& ((!note.isPublic && userFilterSelection == 1) || (note.isPublic && userFilterSelection == 2) || (userFilterSelection == 3))) { && ((!note.isPublic && userFilterSelection == 1) || (note.isPublic && userFilterSelection == 2) || (userFilterSelection == 3))) {
@ -560,7 +524,9 @@ public class PersonalFragment extends Fragment {
noteList.setAdapter(noteListAdapter); noteList.setAdapter(noteListAdapter);
} }
//set secondery filter colors filter colors /**
* Set The Filter Button Colors
*/
private void setButtonsColor() { private void setButtonsColor() {
Log.d(TAG, "setButtonsColor: start"); Log.d(TAG, "setButtonsColor: start");