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 2ba8dc2..9852c8d 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 @@ -97,7 +97,8 @@ public class PersonalFragment extends Fragment { Bundle bundle = getArguments(); this.userId = activity.getUserId(); Log.d(TAG, "onCreateView: userID: " + userId); - dateFilterSelection = 2592000000L; + //set default values for filters + dateFilterSelection = Utils.MONTH_MILI; userFilterSelection = 3; @@ -126,7 +127,7 @@ public class PersonalFragment extends Fragment { 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); + Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); map_large_filter = (Button) view.findViewById(R.id.personalSpace_large_filter); @@ -153,6 +154,8 @@ public class PersonalFragment extends Fragment { map_medium_filter.setText(week); map_large_filter.setText(month); } + setButtonsColor(); + } }); @@ -174,6 +177,8 @@ public class PersonalFragment extends Fragment { map_medium_filter.setText(publicNote); map_large_filter.setText(privateAndPublic); } + setButtonsColor(); + } }); @@ -192,23 +197,23 @@ public class PersonalFragment extends Fragment { } - @Override - public void onAttach(Context context) { - super.onAttach(context); - Utils.dismissLoadingDialog(); - Log.d(TAG, "onAttach"); - } + @Override + public void onAttach(Context context) { + super.onAttach(context); + Utils.dismissLoadingDialog(); + Log.d(TAG, "onAttach"); + } - @Override - public void onDetach() { - super.onDetach(); - Utils.dismissLoadingDialog(); - } + @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); - } + 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() { public void onClick(View v) { @@ -498,30 +503,30 @@ public class PersonalFragment extends Fragment { } - //all buttons listener public View.OnClickListener button1ClickListener = new View.OnClickListener() { @Override public void onClick(final View v) { - Log.d(TAG, "onClick: start"); - Log.d(TAG, "onClick: v id: "+ v.getId()); - Log.d(TAG, "onClick: map_small_filter id: "+ R.id.map_small_filter); - Log.d(TAG, "onCreateView: personalSpace_filter_options = "+R.id.personalSpace_filter_options); +// Log.d(TAG, "onClick: start"); +// Log.d(TAG, "onClick: v id: " + v.getId()); +// Log.d(TAG, "onClick: map_small_filter id: " + R.id.map_small_filter); +// Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); +// +// Log.d(TAG, "onClick: are equal? " + (v.getId() == R.id.map_small_filter)); +// +// Log.d(TAG, "onClick: case map_small_filter"); + //user filters + if (userFilterIsVisible) { + userFilterSelection = 1; + } + //date filters + else { + dateFilterSelection = Utils.WEEK_MILI; - Log.d(TAG, "onClick: are equal? "+ (v.getId() ==R.id.map_small_filter)); - - Log.d(TAG, "onClick: case map_small_filter"); - //user filters - if (userFilterIsVisible) { - userFilterSelection = 1; - } - //date filters - else { - dateFilterSelection = 86400000L; - - } - updateShowedNotes(); + } + setButtonsColor(); + updateShowedNotes(); } }; //all buttons listener @@ -529,16 +534,15 @@ public class PersonalFragment extends Fragment { @Override public void onClick(final View v) { - Log.d(TAG, "onClick: start"); - Log.d(TAG, "onClick: v id: " + v.getId()); - Log.d(TAG, "onClick: map_small_filter id: " + R.id.map_small_filter); - Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); - - Log.d(TAG, "onClick: are equal? " + (v.getId() == R.id.map_small_filter)); - - - Log.d(TAG, "onClick: case map_medium_filter"); - v.setBackgroundColor(Color.BLUE); +// Log.d(TAG, "onClick: start"); +// Log.d(TAG, "onClick: v id: " + v.getId()); +// Log.d(TAG, "onClick: map_small_filter id: " + R.id.map_small_filter); +// Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); +// +// Log.d(TAG, "onClick: are equal? " + (v.getId() == R.id.map_small_filter)); +// +// +// Log.d(TAG, "onClick: case map_medium_filter"); //user filters if (userFilterIsVisible) { @@ -547,10 +551,13 @@ public class PersonalFragment extends Fragment { } //date filters else { - dateFilterSelection = 604800000L; + dateFilterSelection = Utils.WEEK_MILI; } + setButtonsColor(); + updateShowedNotes(); + } }; //all buttons listener @@ -558,14 +565,14 @@ public class PersonalFragment extends Fragment { @Override public void onClick(final View v) { - Log.d(TAG, "onClick: start"); - Log.d(TAG, "onClick: v id: "+ v.getId()); - Log.d(TAG, "onClick: map_small_filter id: "+ R.id.map_small_filter); - Log.d(TAG, "onCreateView: personalSpace_filter_options = "+R.id.personalSpace_filter_options); - - Log.d(TAG, "onClick: are equal? "+ (v.getId() ==R.id.map_small_filter)); - - Log.d(TAG, "onClick: case map_large_filter"); +// Log.d(TAG, "onClick: start"); +// Log.d(TAG, "onClick: v id: " + v.getId()); +// Log.d(TAG, "onClick: map_small_filter id: " + R.id.map_small_filter); +// Log.d(TAG, "onCreateView: personalSpace_filter_options = " + R.id.personalSpace_filter_options); +// +// Log.d(TAG, "onClick: are equal? " + (v.getId() == R.id.map_small_filter)); +// +// Log.d(TAG, "onClick: case map_large_filter"); //user filters if (userFilterIsVisible) { @@ -573,9 +580,11 @@ public class PersonalFragment extends Fragment { } //date filters else { - dateFilterSelection = 2592000000L; + dateFilterSelection = Utils.MONTH_MILI; } + setButtonsColor(); + updateShowedNotes(); } @@ -644,16 +653,14 @@ public class PersonalFragment extends Fragment { // }; - - public void updateShowedNotes() { presentedNotes = new ArrayList<>(); long timeDifference; // float distance; - Log.d(TAG, "updateShowedNotes: start"); - Log.d(TAG, "updateShowedNotes: userPrefFilter = "+userFilterSelection); - Log.d(TAG, "updateShowedNotes: timeDifferencePerf = "+dateFilterSelection); - Log.d(TAG, "updateShowedNotes: +++++++++++++++++++++++++++++++++++++++++++++++++"); +// Log.d(TAG, "updateShowedNotes: start"); +// Log.d(TAG, "updateShowedNotes: userPrefFilter = " + userFilterSelection); +// Log.d(TAG, "updateShowedNotes: timeDifferencePerf = " + dateFilterSelection); +// Log.d(TAG, "updateShowedNotes: +++++++++++++++++++++++++++++++++++++++++++++++++"); // Location currLocation = new Location(gpsUtils.getLocation()); @@ -661,8 +668,8 @@ public class PersonalFragment extends Fragment { // Location targetLocation = new Location("");//provider name is unecessary Date targetDate; - for (Note note : listOfNotes){ - Log.d(TAG, "updateShowedNotes: chekcing note with title: "+ note.title); + for (Note note : listOfNotes) { +// Log.d(TAG, "updateShowedNotes: checkcing note with title: " + note.title); //get note location and date // targetLocation.setLatitude(note.getLat());//your coords of course // targetLocation.setLongitude(note.getLon()); @@ -672,19 +679,67 @@ public class PersonalFragment extends Fragment { timeDifference = now.getTime() - targetDate.getTime(); // distance = currLocation.distanceTo(targetLocation); - Log.d(TAG, "updateShowedNotes: time difference = "+ timeDifference); +// Log.d(TAG, "updateShowedNotes: time difference = " + timeDifference); //add to currently presented list according to filters. - if(timeDifference <= dateFilterSelection - && ((!note.isPublic && userFilterSelection==1) || (note.isPublic && userFilterSelection == 2) || (userFilterSelection == 3))){ + if (timeDifference <= dateFilterSelection + && ((!note.isPublic && userFilterSelection == 1) || (note.isPublic && userFilterSelection == 2) || (userFilterSelection == 3))) { presentedNotes.add(note); } - Log.d(TAG, "updateShowedNotes: ======================================"); +// Log.d(TAG, "updateShowedNotes: ======================================"); } - Log.d(TAG, "updateShowedNotes: presentedNotes size = "+ presentedNotes.size()); +// Log.d(TAG, "updateShowedNotes: presentedNotes size = " + presentedNotes.size()); noteListAdapter.updateList(presentedNotes); noteList.setAdapter(noteListAdapter); } + //set main 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); + } + } + } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java index c6a0369..05261f8 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; @@ -47,6 +48,9 @@ public class Utils { private static boolean mLocationPermission = false; private static boolean mCameraPermission = false; private static SharedPreferences prefs; + public static int filterColor = Color.parseColor("#33adff"); + public static final long DAY_MILI = 86400000L,WEEK_MILI = 604800000L,MONTH_MILI = 2592000000L; + public static Bitmap getBitmapFromURL(String url) {