From aae20aa1cc563b96b22911eaee148d37dd104823 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 10 Jul 2016 17:50:26 +0300 Subject: [PATCH] Docs --- .../sagi/thesocialnotework/MainActivity.java | 83 +- .../thesocialnotework/MarkerNoteStruct.java | 2 +- .../ara/sagi/thesocialnotework/Note.java | 391 +++---- .../thesocialnotework/PersonalFragment.java | 990 +++++++++--------- 4 files changed, 716 insertions(+), 750 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index e6c3de0..33784dd 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -1,22 +1,11 @@ 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.SharedPreferences; import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.AsyncTask; import android.os.Bundle; 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.util.Log; -import android.view.LayoutInflater; import android.view.View; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -29,54 +18,42 @@ import android.view.MenuItem; import android.widget.ImageView; 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 implements NavigationView.OnNavigationItemSelectedListener { public static final String LOCAL_DATA_TSN = "TSN_DATA_STORE"; protected final String TAG = "[TSN / MainActivity]"; protected User user; private GPSUtils gpsUtils; - private boolean locationPermission; private GmapFragment gmapFragment; private PersonalFragment personalFragment; private SettingsFragment settingsFragment; private ExploreFragment exploreFragment; private Toolbar toolbar; - public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; private ImageView menu_avatar; private MainActivity self; 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 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.self = this; - toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitle("Personal Notes"); - setSupportActionBar(toolbar); - gmapFragment = new GmapFragment(); - personalFragment = new PersonalFragment(); - settingsFragment = new SettingsFragment(); - exploreFragment = new ExploreFragment(); + this.toolbar = (Toolbar) findViewById(R.id.toolbar); + this.toolbar.setTitle("Personal Notes"); + this.setSupportActionBar(toolbar); + this.gmapFragment = new GmapFragment(); + this.personalFragment = new PersonalFragment(); + this.settingsFragment = new SettingsFragment(); + this.exploreFragment = new ExploreFragment(); + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); @@ -99,7 +76,6 @@ public class MainActivity extends AppCompatActivity //Change Layout Log.d(TAG, "Changing Fragment to Personal Activity"); -// PersonalFragment personalFragment = new PersonalFragment(); personalFragment.setArguments(b); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.fragment_container, personalFragment); @@ -129,15 +105,18 @@ public class MainActivity extends AppCompatActivity 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 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(); - Log.d(TAG, "onOptionsItemSelected: id -> "+id); - //noinspection SimplifiableIfStatement + // Settings if (id == R.id.action_settings) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); toolbar.setTitle("Settings"); @@ -146,17 +125,19 @@ public class MainActivity extends AppCompatActivity ft.commit(); return true; } - return super.onOptionsItemSelected(item); } + /** + * This function will be called when an item is selected from the nav bar. + * @param item + * @return + */ @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - int id = item.getItemId(); - if (id == R.id.nav_explore) { toolbar.setTitle("Explore"); setSupportActionBar(toolbar); @@ -193,16 +174,17 @@ public class MainActivity extends AppCompatActivity finish(); } + // Close the drawer DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } + public GPSUtils getGPSUtils() { return this.gpsUtils; } - public User getUser() { return user; } @@ -211,6 +193,12 @@ public class MainActivity extends AppCompatActivity return user.getId(); } + /** + * Permittion handlers + * @param requestCode + * @param permissions + * @param grantResults + */ @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { @@ -248,6 +236,9 @@ public class MainActivity extends AppCompatActivity } + /** + * Update the Navbar avatar + */ public void updateNavAvatar() { //Change The Avatar Utils.URLtoImageView(menu_avatar, user.getAvatar()); diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java index bb173fd..5f4090a 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java @@ -1,10 +1,10 @@ package com.android_app.matan.ara.sagi.thesocialnotework; -import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; /** * Created by JERLocal on 7/8/2016. + * This class will hold information about a Mark on the Map. */ public class MarkerNoteStruct { private Note note; diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java index c43b66d..dc97dad 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java @@ -10,211 +10,220 @@ import java.util.Date; /** * Created by JERLocal on 7/1/2016. + * A Note Class - Represents a note Object */ public class Note implements Parcelable { - protected int likes; - protected ArrayList tags; - protected float lat, lon; - protected String id, address, title, body, timestamp, avatar, ownerId; - protected boolean isPublic; + protected int likes; + protected ArrayList tags; + protected float lat, lon; + protected String id, address, title, body, timestamp, avatar, ownerId; + protected boolean isPublic; - public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, String avatar, String ownerId, ArrayList tags) { - this.id = id; - this.lat = lat; - this.lon = lon; - this.address = address; - - this.title = title; - this.body = body; - this.timestamp = timestamp; - this.isPublic = isPublic; - this.likes = likes; - this.tags = tags; - this.avatar = avatar; - this.ownerId = ownerId; - } + public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, String avatar, String ownerId, ArrayList tags) { + this.id = id; + this.lat = lat; + this.lon = lon; + this.address = address; + this.title = title; + this.body = body; + this.timestamp = timestamp; + this.isPublic = isPublic; + this.likes = likes; + this.tags = tags; + this.avatar = avatar; + this.ownerId = ownerId; + } - protected Note(Parcel in) { - likes = in.readInt(); - tags = in.createStringArrayList(); - lat = in.readFloat(); - lon = in.readFloat(); - - id = in.readString(); - address = in.readString(); - title = in.readString(); - body = in.readString(); - timestamp = in.readString(); - avatar = in.readString(); - ownerId = in.readString(); - isPublic = in.readByte() != 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public Note createFromParcel(Parcel in) { - return new Note(in); - } - - @Override - public Note[] newArray(int size) { - return new Note[size]; - } - }; - + protected Note(Parcel in) { + likes = in.readInt(); + tags = in.createStringArrayList(); + lat = in.readFloat(); + lon = in.readFloat(); + id = in.readString(); + address = in.readString(); + title = in.readString(); + body = in.readString(); + timestamp = in.readString(); + avatar = in.readString(); + ownerId = in.readString(); + isPublic = in.readByte() != 0; + } + public static final Creator CREATOR = new Creator() { @Override - public String toString() { - return "Note{" + - "id=" + id + - ", lat=" + lat + - ", lon=" + lon + - - ", address='" + address + '\'' + - ", title='" + title + '\'' + - ", body='" + body + '\'' + - ", timestamp=" + timestamp + - ", isPublic=" + isPublic + - ", avatar=" + avatar + - ", ownerId=" + ownerId + - '}'; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public float getLat() { - return lat; - } - - public void setLat(float lat) { - this.lat = lat; - } - - public float getLon() { - return lon; - } - - public void setLon(float lon) { - this.lon = lon; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public String getTimestamp() { - return timestamp; - } - - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } - - public boolean isPublic() { - return isPublic; - } - - public void setPublic(boolean aPublic) { - isPublic = aPublic; - } - - public String getLocationAndTime() { - return getTimestamp() + " at " + getAddress(); - } - - public int getLikes() { - return likes; - } - - public void setLikes(int likes) { - this.likes = likes; - } - - public ArrayList getTags() { - return tags; - } - - public void setTags(ArrayList tags) { - this.tags = tags; - } - - public String getAvatar() { - return avatar; - } - - public void setAvatar(String avatar) { - this.avatar = avatar; - } - - public String getOwnerId() { - return ownerId; - } - - public void setOwnerId(String ownerId) { - this.ownerId = ownerId; - } - - - @Override - public int describeContents() { - return 0; + public Note createFromParcel(Parcel in) { + return new Note(in); } @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(likes); - dest.writeList(tags); - dest.writeFloat(lat); - dest.writeFloat(lon); - dest.writeString(id); - dest.writeString(address); - dest.writeString(title); - dest.writeString(body); - dest.writeString(timestamp); - dest.writeString(avatar); - dest.writeString(ownerId); - dest.writeByte((byte) (isPublic ? 1 : 0)); + public Note[] newArray(int size) { + return new Note[size]; } + }; - public String getTime() { - Date d = new Date(timestamp); - DateFormat format = new SimpleDateFormat("HH:mm"); - return format.format(d); - } - public String getDate() { - Date d = new Date(timestamp); - DateFormat format = new SimpleDateFormat("dd MMM yyy"); - return format.format(d); - } + @Override + public String toString() { + return "Note{" + + "id=" + id + + ", lat=" + lat + + ", lon=" + lon + + + ", address='" + address + '\'' + + ", title='" + title + '\'' + + ", body='" + body + '\'' + + ", timestamp=" + timestamp + + ", isPublic=" + isPublic + + ", avatar=" + avatar + + ", ownerId=" + ownerId + + '}'; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public float getLat() { + return lat; + } + + public void setLat(float lat) { + this.lat = lat; + } + + public float getLon() { + return lon; + } + + public void setLon(float lon) { + this.lon = lon; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public boolean isPublic() { + return isPublic; + } + + public void setPublic(boolean aPublic) { + isPublic = aPublic; + } + + public String getLocationAndTime() { + return getTimestamp() + " at " + getAddress(); + } + + public int getLikes() { + return likes; + } + + public void setLikes(int likes) { + this.likes = likes; + } + + public ArrayList getTags() { + return tags; + } + + public void setTags(ArrayList tags) { + this.tags = tags; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getOwnerId() { + return ownerId; + } + + public void setOwnerId(String ownerId) { + this.ownerId = ownerId; + } + + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(likes); + dest.writeList(tags); + dest.writeFloat(lat); + dest.writeFloat(lon); + dest.writeString(id); + dest.writeString(address); + dest.writeString(title); + dest.writeString(body); + dest.writeString(timestamp); + dest.writeString(avatar); + dest.writeString(ownerId); + dest.writeByte((byte) (isPublic ? 1 : 0)); + } + + /** + * Get a Simplified Readable Time (Creation of the note) + * + * @return String + */ + public String getTime() { + Date d = new Date(timestamp); + DateFormat format = new SimpleDateFormat("HH:mm"); + return format.format(d); + } + + /** + * Get a Simplified Readable Date (Creation of the note) + * + * @return String + */ + public String getDate() { + Date d = new Date(timestamp); + DateFormat format = new SimpleDateFormat("dd MMM yyy"); + return format.format(d); + } } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java index 863307a..a54a8e4 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java @@ -5,18 +5,10 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; 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.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -36,8 +28,6 @@ import android.widget.TextView; import android.widget.Toast; 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.JSONException; @@ -54,558 +44,534 @@ import java.util.List; * to handle interaction events. */ public class PersonalFragment extends Fragment { + protected ListView noteList; + private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; + private GPSUtils gpsUtils; + private List listOfNotes, presentedNotes; + private ListAdapter noteListAdapter; + private String userId; + private final String TAG = "[TSN/PersonalFragment]"; + private MainActivity activity; + private final int FINE_PERM = 0; + private int userFilterSelection; + private Long dateFilterSelection; + private ImageButton dateFilter; + private ImageButton userFilter; + private Button map_small_filter; + private Button map_medium_filter; + private Button map_large_filter; + private LinearLayout personalSpaceFilters; + private boolean dateFilterIsVisible = false; + private boolean userFilterIsVisible = false; - protected ListView noteList; - private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; - private GPSUtils gpsUtils; - private List listOfNotes, presentedNotes; - private ListAdapter noteListAdapter; - private String userId; - private final String TAG = "[TSN/PersonalFragment]"; - private MainActivity activity; - private final int FINE_PERM = 0, CAMERA_PERM = 1; - private int userFilterSelection; - private Long dateFilterSelection; + public PersonalFragment() { + // Required empty public constructor + } - private ImageButton dateFilter; - private ImageButton userFilter; - private Button map_small_filter; - private Button map_medium_filter; - private Button map_large_filter; - private LinearLayout personalSpaceFilters; - private boolean dateFilterIsVisible = false; - private boolean userFilterIsVisible = false; - - public PersonalFragment() { - // Required empty public constructor - } + @Override + 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 + this.activity = (MainActivity) getActivity(); + Bundle bundle = getArguments(); + this.userId = activity.getUserId(); + Log.d(TAG, "onCreateView: userID: " + userId); + //set default values for filters + dateFilterSelection = Utils.MONTH_MILI; + userFilterSelection = 3; - @Override - 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(); - Bundle bundle = getArguments(); - this.userId = activity.getUserId(); - Log.d(TAG, "onCreateView: userID: " + userId); - //set default values for filters - dateFilterSelection = Utils.MONTH_MILI; - userFilterSelection = 3; + ActivityCompat.requestPermissions(activity, new String[]{ + android.Manifest.permission.ACCESS_FINE_LOCATION, + android.Manifest.permission.CAMERA, + Manifest.permission.WRITE_EXTERNAL_STORAGE + }, + FINE_PERM + ); - ActivityCompat.requestPermissions(activity, new String[]{ - android.Manifest.permission.ACCESS_FINE_LOCATION, - android.Manifest.permission.CAMERA, - Manifest.permission.WRITE_EXTERNAL_STORAGE - }, - FINE_PERM - ); + this.noteList = (ListView) view.findViewById(R.id.ps_list_listview); + gpsUtils = activity.getGPSUtils(); + gpsUtils.getLocation(); + listOfNotes = new ArrayList<>(); + presentedNotes = new ArrayList<>(); + noteListAdapter = new ListAdapter(getContext(), presentedNotes); + noteList.setAdapter(noteListAdapter); + noteList.setOnItemClickListener(new ItemClickedListener()); + Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes"); - this.noteList = (ListView) view.findViewById(R.id.ps_list_listview); - gpsUtils = activity.getGPSUtils(); - gpsUtils.getLocation(); - listOfNotes = new ArrayList<>(); - presentedNotes = new ArrayList<>(); + dateFilter = (ImageButton) view.findViewById(R.id.personalSpace_date_filter); + userFilter = (ImageButton) view.findViewById(R.id.personalSpace_premission_filter); - noteListAdapter = new ListAdapter(getContext(), presentedNotes); - noteList.setAdapter(noteListAdapter); - noteList.setOnItemClickListener(new ItemClickedListener()); - Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes"); + map_small_filter = (Button) view.findViewById(R.id.personalSpace_small_filter); + map_medium_filter = (Button) view.findViewById(R.id.personalSpace_medium_filter); + Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); - dateFilter = (ImageButton) view.findViewById(R.id.personalSpace_date_filter); - userFilter = (ImageButton) view.findViewById(R.id.personalSpace_premission_filter); + map_large_filter = (Button) view.findViewById(R.id.personalSpace_large_filter); - map_small_filter = (Button) view.findViewById(R.id.personalSpace_small_filter); - map_medium_filter = (Button) view.findViewById(R.id.personalSpace_medium_filter); - Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); + map_small_filter.setOnClickListener(button1ClickListener); + map_medium_filter.setOnClickListener(button2ClickListener); + map_large_filter.setOnClickListener(button3ClickListener); - map_large_filter = (Button) view.findViewById(R.id.personalSpace_large_filter); + personalSpaceFilters = (LinearLayout) view.findViewById(R.id.personalSpace_filter_options); - map_small_filter.setOnClickListener(button1ClickListener); - map_medium_filter.setOnClickListener(button2ClickListener); - map_large_filter.setOnClickListener(button3ClickListener); + // Date Filter Listener + dateFilter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + Log.d(TAG, "onClick: dateFilter pressed"); + if (dateFilterIsVisible) { + dateFilterIsVisible = false; + personalSpaceFilters.setVisibility(View.GONE); + } else { + personalSpaceFilters.setVisibility(View.VISIBLE); + dateFilterIsVisible = true; + userFilterIsVisible = false; - personalSpaceFilters = (LinearLayout) view.findViewById(R.id.personalSpace_filter_options); + // set text button in the right filter string + map_small_filter.setText(R.string.day); + map_medium_filter.setText(R.string.week); + map_large_filter.setText(R.string.month); + } + setButtonsColor(); - dateFilter.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - Log.d(TAG, "onClick: dateFilter pressed"); - if (dateFilterIsVisible) { - dateFilterIsVisible = false; - personalSpaceFilters.setVisibility(View.GONE); - } else { - personalSpaceFilters.setVisibility(View.VISIBLE); - dateFilterIsVisible = true; - userFilterIsVisible = false; + } + }); + // User Filter Listener + userFilter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d(TAG, "onClick: userFilter pressed"); + //if pressed same filter twice - close filters. + if (userFilterIsVisible) { + userFilterIsVisible = false; + personalSpaceFilters.setVisibility(View.GONE); + } else { + personalSpaceFilters.setVisibility(View.VISIBLE); + userFilterIsVisible = true; + dateFilterIsVisible = false; - // set text button in the right filter string - map_small_filter.setText(R.string.day); - map_medium_filter.setText(R.string.week); - map_large_filter.setText(R.string.month); - } - setButtonsColor(); + // set text button in the right filter string + map_small_filter.setText(R.string.privateNote); + map_medium_filter.setText(R.string.publicNote); + map_large_filter.setText(R.string.privateAndPublic); + } + setButtonsColor(); - } - }); + } + }); - userFilter.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Log.d(TAG, "onClick: userFilter pressed"); - //if pressed same filter twice - close filters. - if (userFilterIsVisible) { - userFilterIsVisible = false; - personalSpaceFilters.setVisibility(View.GONE); - } else { - personalSpaceFilters.setVisibility(View.VISIBLE); - userFilterIsVisible = true; - dateFilterIsVisible = false; + VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); + // The New "Add Button" - Floating Fab Button + FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); + fab.setOnClickListener(addNewNoteDialog); + return view; + } - // set text button in the right filter string - map_small_filter.setText(R.string.privateNote); - map_medium_filter.setText(R.string.publicNote); - map_large_filter.setText(R.string.privateAndPublic); - } - setButtonsColor(); + @Override + public void onAttach(Context context) { + super.onAttach(context); + Utils.dismissLoadingDialog(); + Log.d(TAG, "onAttach"); + } - } - }); + @Override + public void onDetach() { + super.onDetach(); + Utils.dismissLoadingDialog(); + } - // get all notes according to some default filter ? // TODO: Aran? - VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); +// public void getAllNotes() { +// Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId); +// VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); +// } -// getAllNotes(); + // New Note Dialog (View) + private View.OnClickListener addNewNoteDialog = new View.OnClickListener() { + public void onClick(View v) { + //create and configure dialog + final Dialog dialog = new Dialog(getActivity()); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setContentView(R.layout.note_view_full); + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.MATCH_PARENT; + lp.height = WindowManager.LayoutParams.MATCH_PARENT; + dialog.setCancelable(false); + dialog.show(); + dialog.getWindow().setAttributes(lp); - -//https://thesocialnotework-api.appspot.com/api/note/all?uid= - // The New "Add Button" - FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); - fab.setOnClickListener(addNewNoteDialog); - - return view; - } - - - @Override - public void onAttach(Context context) { - super.onAttach(context); - Utils.dismissLoadingDialog(); - Log.d(TAG, "onAttach"); - } - - @Override - public void onDetach() { - super.onDetach(); - Utils.dismissLoadingDialog(); - } - - public void getAllNotes() { - Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId); - VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); - } - - private View.OnClickListener addNewNoteDialog = new View.OnClickListener() { + //get note_view_full layout elements + final Switch permissionSwitch = (Switch) dialog.findViewById(R.id.nvf_note_permission); + final EditText newTitle = (EditText) dialog.findViewById(R.id.nvf_note_title); + final EditText newBody = (EditText) dialog.findViewById(R.id.nvf_note_content); + Button saveBtn = (Button) dialog.findViewById(R.id.nvf_note_submit_btn); + Button cancelBtn = (Button) dialog.findViewById(R.id.nvf_note_cancel_btn); + cancelBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + dialog.dismiss(); + } + }); + saveBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - //create and configure dialog - final Dialog dialog = new Dialog(getActivity()); - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialog.setContentView(R.layout.note_view_full); - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.MATCH_PARENT; - dialog.setCancelable(false); - dialog.show(); - dialog.getWindow().setAttributes(lp); - - - //get note_view_full layout elements - final Switch permissionSwitch = (Switch) dialog.findViewById(R.id.nvf_note_permission); - final EditText newTitle = (EditText) dialog.findViewById(R.id.nvf_note_title); - final EditText newBody = (EditText) dialog.findViewById(R.id.nvf_note_content); - Button saveBtn = (Button) dialog.findViewById(R.id.nvf_note_submit_btn); - Button cancelBtn = (Button) dialog.findViewById(R.id.nvf_note_cancel_btn); - - cancelBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - dialog.dismiss(); - } - }); - - saveBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - - //title too short - if (newTitle.getText().length() == 0) { - Toast toast = Toast.makeText(getActivity(), "Title too short.", Toast.LENGTH_LONG); - toast.show(); - return; - } - - //title too long - if (newTitle.getText().length() > 20) { - Toast toast = Toast.makeText(getActivity(), "Title too long.\n Use up to 20 notes.", Toast.LENGTH_LONG); - toast.show(); - return; - } - //volley post - final JSONObject noteJson = new JSONObject(); - try { - - //TODO need to get owner id from login screen - noteJson.put("owner_id", userId); - noteJson.put("title", newTitle.getText()); - noteJson.put("lat", gpsUtils.getLatitude()); - noteJson.put("lng", gpsUtils.getLongitude()); - noteJson.put("address", gpsUtils.getAddress()); - noteJson.put("body", newBody.getText()); - noteJson.put("is_public", permissionSwitch.isChecked()); -// noteJson.put("tags",); - Log.d(TAG, "Json: " + noteJson.toString()); - - - } catch (Exception e) { - Log.d(TAG, "saveBtn: " + e.toString()); - } - - //send request and close dialog - VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener); - dialog.dismiss(); - } - }); - - //change text of switch according to state. - permissionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) - permissionSwitch.setText(R.string.nvf_public_label); - else - permissionSwitch.setText(R.string.nvf_private_label); - } - }); + //title too short + if (newTitle.getText().length() == 0) { + Toast toast = Toast.makeText(getActivity(), "Title too short.", Toast.LENGTH_LONG); + toast.show(); + return; + } + //title too long + if (newTitle.getText().length() > 20) { + Toast toast = Toast.makeText(getActivity(), "Title too long.\n Use up to 20 notes.", Toast.LENGTH_LONG); + toast.show(); + return; + } + if (newBody.getText().length() < 1) { + Toast.makeText(getActivity(), "Cant Submit an empty body", Toast.LENGTH_LONG).show(); + return; + } + //volley post + final JSONObject noteJson = new JSONObject(); + try { + //TODO need to get owner id from login screen + noteJson.put("owner_id", userId); + noteJson.put("title", newTitle.getText()); + noteJson.put("lat", gpsUtils.getLatitude()); + noteJson.put("lng", gpsUtils.getLongitude()); + noteJson.put("address", gpsUtils.getAddress()); + noteJson.put("body", newBody.getText()); + noteJson.put("is_public", permissionSwitch.isChecked()); + Log.d(TAG, "Json: " + noteJson.toString()); + } catch (Exception e) { + Log.d(TAG, "saveBtn: " + e.toString()); + } + //send request and close dialog + VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener); + dialog.dismiss(); } - }; - - //response listener for adding new note - Response.Listener newNoteSuccessListener = new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "newNoteSuccess: response - " + response.toString()); - try { - Date time = new Date(); - JSONObject noteObject = response.getJSONObject("note"); - time.setTime(noteObject.getLong("created_at")); - addNoteFromJsonObj(noteObject, time,0); - updateShowedNotes(); - -// presentedNotes = listOfNotes; -// noteList.setAdapter(noteListAdapter); - } catch (Exception e) { - Log.e(TAG, "newNoteSuccess:" + e.getMessage()); - } - + }); + //change text of switch according to state. + permissionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) + permissionSwitch.setText(R.string.nvf_public_label); + else + permissionSwitch.setText(R.string.nvf_private_label); } - }; + }); + } + }; + + //response listener for adding new note + Response.Listener newNoteSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "newNoteSuccess: response - " + response.toString()); + try { + Date time = new Date(); + JSONObject noteObject = response.getJSONObject("note"); + time.setTime(noteObject.getLong("created_at")); + addNoteFromJsonObj(noteObject, time, 0); + updateShowedNotes(); + } catch (Exception e) { + Log.e(TAG, "newNoteSuccess:" + e.getMessage()); + } + + } + }; -// //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 getNotesSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "getNotesSuccessListener: " + response.toString()); + Utils.dismissLoadingDialog(); + try { + //need to get all notes and add to listOfNotes + JSONArray noteObjectsArray = response.getJSONArray("notes"); + activity.getUser().setNumber_of_notes(noteObjectsArray.length()); + Date time = new Date(); + for (int i = 0; i < noteObjectsArray.length(); i++) { + JSONObject noteObject = noteObjectsArray.getJSONObject(i); + time.setTime(noteObject.getLong("created_at")); + + addNoteFromJsonObj(noteObject, time, -1); + } + updateShowedNotes(); + } catch (Exception e) { + Log.e(TAG, "newNoteSuccess:" + e.getMessage()); + } + + } + }; + + /** + * Converts JSON Array to A Java String ArrayList + * @param jArray JSONArray Object + * @return ArrayList + */ + private ArrayList jsonArrayToStringArray(JSONArray jArray) { + ArrayList stringArray = new ArrayList(); + 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; + } - //response listener for getting all user notes - Response.Listener getNotesSuccessListener = new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "getNotesSuccessListener: " + response.toString()); - Utils.dismissLoadingDialog(); - try { - //need to get all notes and add to listOfNotes - JSONArray noteObjectsArray = response.getJSONArray("notes"); - activity.getUser().setNumber_of_notes(noteObjectsArray.length()); - Date time = new Date(); - for (int i = 0; i < noteObjectsArray.length(); i++) { - JSONObject noteObject = noteObjectsArray.getJSONObject(i); - time.setTime(noteObject.getLong("created_at")); + /** + * 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 { + Note addNote = 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"), + noteObject.getString("avatar"), + noteObject.getString("owner_id"), + jsonArrayToStringArray(noteObject.getJSONArray("tags")) + ); + Log.d(TAG, "addNoteFromJsonObj: " + addNote.getDate() + " " + addNote.getTime()); + if (position != 0) + listOfNotes.add(addNote); + else + listOfNotes.add(position, addNote); - addNoteFromJsonObj(noteObject, time,-1); + + } + + /** + * The ListView Item Listener + */ + class ItemClickedListener implements AdapterView.OnItemClickListener { + @Override + public void onItemClick(AdapterView parent, View view, final int position, long id) { + //create and configure dialog + final Note note = presentedNotes.get(position); + final Dialog noteViewDialog = new Dialog(getActivity()); + noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + noteViewDialog.setContentView(R.layout.note_display_full); + + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(noteViewDialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.MATCH_PARENT; + lp.height = WindowManager.LayoutParams.MATCH_PARENT; + noteViewDialog.show(); + + + //get note_view_full layout elements + final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview); + final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview); + final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_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 likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); + final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); + final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); + final ImageView avatar = (RoundAvatarImageView) noteViewDialog.findViewById(R.id.note_user_avatar); + + + title.setText(note.getTitle()); + body.setText(note.getBody()); + date.setText(note.getDate()); + time.setText(note.getTime()); + location.setText(note.getAddress()); + if (likes != null) likes.setText("" + note.getLikes()); + permission.setText("" + (note.isPublic() ? "Public" : "Private")); + Utils.URLtoImageView(avatar, note.getAvatar()); + // DElete Button Listener + deleteBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + //Put up the Yes/No message box + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder + .setTitle("Delete Note") + .setMessage("Are you sure you want to delete the note?") + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton("Yes", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Yes button clicked, do something + Toast.makeText(getActivity(), "Item Deleted!", + Toast.LENGTH_SHORT).show(); + JSONObject delNote = new JSONObject(); + try { + delNote.put("uid", userId); + delNote.put("nid", note.getId()); + VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener); + listOfNotes.remove(presentedNotes.get(position)); + presentedNotes.remove(position); + } catch (JSONException e) { + Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); + e.printStackTrace(); } updateShowedNotes(); -// presentedNotes = listOfNotes; -// noteList.setAdapter(noteListAdapter); - } catch (Exception e) { - Log.e(TAG, "newNoteSuccess:" + e.getMessage()); - } - + noteViewDialog.dismiss(); + } + }) + .setNegativeButton("No", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Yes button clicked, do something + Toast.makeText(getActivity(), "Canceled", + Toast.LENGTH_SHORT).show(); + noteViewDialog.dismiss(); + } + }) //Do nothing on no + .show(); } - }; - - private ArrayList jsonArrayToStringArray(JSONArray jArray) { - ArrayList stringArray = new ArrayList(); - 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; - } - - - private void addNoteFromJsonObj(JSONObject noteObject, Date time, int position) throws JSONException { - Note addNote = 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"), - noteObject.getString("avatar"), - noteObject.getString("owner_id"), - jsonArrayToStringArray(noteObject.getJSONArray("tags")) - ); - Log.d(TAG, "addNoteFromJsonObj: "+ addNote.getDate() + " " + addNote.getTime()); - if (position != 0) - listOfNotes.add(addNote); - else - listOfNotes.add(position,addNote); - + }); } + } - // click on listView item - class ItemClickedListener implements AdapterView.OnItemClickListener { - @Override - public void onItemClick(AdapterView parent, View view, final int position, long id) { - //create and configure dialog - final Note note = presentedNotes.get(position); - final Dialog noteViewDialog = new Dialog(getActivity()); - noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - noteViewDialog.setContentView(R.layout.note_display_full); -// noteViewDialog.setTitle("You wrote..."); + //all buttons listener + public View.OnClickListener button1ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + //user filters + if (userFilterIsVisible) { + userFilterSelection = 1; + } + //date filters + else { + dateFilterSelection = Utils.DAY_MILI; - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(noteViewDialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.MATCH_PARENT; - noteViewDialog.show(); -// dialog.getWindow().setAttributes(lp); + } + setButtonsColor(); + updateShowedNotes(); + } + }; + //all buttons listener + public View.OnClickListener button2ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + //user filters + if (userFilterIsVisible) { + userFilterSelection = 2; + } + //date filters + else { + dateFilterSelection = Utils.WEEK_MILI; + } + setButtonsColor(); + updateShowedNotes(); + + } + }; + //all buttons listener + public View.OnClickListener button3ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //user filters + if (userFilterIsVisible) { + userFilterSelection = 3; + } + //date filters + else { + dateFilterSelection = Utils.MONTH_MILI; + + } + setButtonsColor(); + + updateShowedNotes(); + + } + }; - //get note_view_full layout elements - final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview); - final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview); - final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_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 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 ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); - final ImageView avatar = (RoundAvatarImageView) noteViewDialog.findViewById(R.id.note_user_avatar); + /** + * Update The Shown Notes (FIlters) + */ + public void updateShowedNotes() { + presentedNotes = new ArrayList<>(); + long timeDifference; + Date now = new Date(); + Date targetDate; + for (Note note : listOfNotes) { + //get note location and date + targetDate = new Date(note.getTimestamp()); + //get time and date differences + timeDifference = now.getTime() - targetDate.getTime(); + //add to currently presented list according to filters. + if (timeDifference <= dateFilterSelection + && ((!note.isPublic && userFilterSelection == 1) || (note.isPublic && userFilterSelection == 2) || (userFilterSelection == 3))) { + presentedNotes.add(note); + } + } + noteListAdapter.updateList(presentedNotes); + noteList.setAdapter(noteListAdapter); + } - title.setText(note.getTitle()); - body.setText(note.getBody()); - date.setText(note.getDate()); - time.setText(note.getTime()); - location.setText(note.getAddress()); - if (likes != null) likes.setText("" + note.getLikes()); -// tags.setText("Tags: "+ note.getTags().toString()); - permission.setText("" + (note.isPublic() ? "Public" : "Private")); - Utils.URLtoImageView(avatar, note.getAvatar()); + /** + * Set The Filter Button Colors + */ + private void setButtonsColor() { - deleteBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - //Put up the Yes/No message box - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder - .setTitle("Delete Note") - .setMessage("Are you sure you want to delete the note?") - .setIcon(android.R.drawable.ic_dialog_alert) - .setPositiveButton("Yes", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - //Yes button clicked, do something - Toast.makeText(getActivity(), "Item Deleted!", - Toast.LENGTH_SHORT).show(); - //TODO send delete - JSONObject delNote = new JSONObject(); - try { - delNote.put("uid", userId); - delNote.put("nid", note.getId()); - VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener); - listOfNotes.remove(presentedNotes.get(position)); - presentedNotes.remove(position); + Log.d(TAG, "setButtonsColor: start"); + //set date filter colors + if (dateFilterIsVisible) { + Log.d(TAG, "setButtonsColor: dateselection :" + dateFilterSelection); - } catch (JSONException e) { - Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); - e.printStackTrace(); - } - updateShowedNotes(); -// noteList.setAdapter(noteListAdapter); - noteViewDialog.dismiss(); - } - }) - .setNegativeButton("No", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - //Yes button clicked, do something - Toast.makeText(getActivity(), "Canceled", - Toast.LENGTH_SHORT).show(); - noteViewDialog.dismiss(); - } - }) //Do nothing on no - .show(); - } - }); - - } + dateFilter.setBackgroundColor(Utils.filterColor); + if (dateFilterSelection == Utils.DAY_MILI) { + map_small_filter.setBackgroundColor(Utils.filterColor); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else if (dateFilterSelection == Utils.WEEK_MILI) { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundColor(Utils.filterColor); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundColor(Utils.filterColor); + } + } else { + dateFilter.setBackgroundResource(android.R.drawable.btn_default); } - - //all buttons listener - public View.OnClickListener button1ClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - //user filters - if (userFilterIsVisible) { - userFilterSelection = 1; - } - //date filters - else { - dateFilterSelection = Utils.DAY_MILI; - - } - setButtonsColor(); - updateShowedNotes(); - } - }; - //all buttons listener - public View.OnClickListener button2ClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - //user filters - if (userFilterIsVisible) { - userFilterSelection = 2; - } - //date filters - else { - dateFilterSelection = Utils.WEEK_MILI; - } - setButtonsColor(); - updateShowedNotes(); - - } - }; - //all buttons listener - public View.OnClickListener button3ClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - - //user filters - if (userFilterIsVisible) { - userFilterSelection = 3; - } - //date filters - else { - dateFilterSelection = Utils.MONTH_MILI; - - } - setButtonsColor(); - - updateShowedNotes(); - - } - }; - - - public void updateShowedNotes() { - presentedNotes = new ArrayList<>(); - long timeDifference; -// Location currLocation = new Location(gpsUtils.getLocation()); - Date now = new Date(); -// Location targetLocation = new Location("");//provider name is unecessary - Date targetDate; - for (Note note : listOfNotes) { - //get note location and date -// targetLocation.setLatitude(note.getLat());//your coords of course -// targetLocation.setLongitude(note.getLon()); - targetDate = new Date(note.getTimestamp()); - //get time and date differences - timeDifference = now.getTime() - targetDate.getTime(); -// distance = currLocation.distanceTo(targetLocation); - //add to currently presented list according to filters. - if (timeDifference <= dateFilterSelection - && ((!note.isPublic && userFilterSelection == 1) || (note.isPublic && userFilterSelection == 2) || (userFilterSelection == 3))) { - presentedNotes.add(note); - } - - } - noteListAdapter.updateList(presentedNotes); - noteList.setAdapter(noteListAdapter); - } - - //set secondery filter colors filter colors - private void setButtonsColor() { - - Log.d(TAG, "setButtonsColor: start"); - //set date filter colors - if (dateFilterIsVisible) { - Log.d(TAG, "setButtonsColor: dateselection :"+ dateFilterSelection); - - dateFilter.setBackgroundColor(Utils.filterColor); - if (dateFilterSelection == Utils.DAY_MILI) { - map_small_filter.setBackgroundColor(Utils.filterColor); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else if (dateFilterSelection == Utils.WEEK_MILI) { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundColor(Utils.filterColor); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundColor(Utils.filterColor); - } - } else { - dateFilter.setBackgroundResource(android.R.drawable.btn_default); - } - - //set date filter colors - if (userFilterIsVisible) { - Log.d(TAG, "setButtonsColor: userFilter: "+ userFilterSelection); - userFilter.setBackgroundColor(Utils.filterColor); - if (userFilterSelection == 1) { - map_small_filter.setBackgroundColor(Utils.filterColor); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else if (userFilterSelection == 2) { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundColor(Utils.filterColor); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundColor(Utils.filterColor); - } - } else { - userFilter.setBackgroundResource(android.R.drawable.btn_default); - } + //set date filter colors + if (userFilterIsVisible) { + Log.d(TAG, "setButtonsColor: userFilter: " + userFilterSelection); + userFilter.setBackgroundColor(Utils.filterColor); + if (userFilterSelection == 1) { + map_small_filter.setBackgroundColor(Utils.filterColor); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else if (userFilterSelection == 2) { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundColor(Utils.filterColor); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundColor(Utils.filterColor); + } + } else { + userFilter.setBackgroundResource(android.R.drawable.btn_default); } + } }