Add check before display date

This commit is contained in:
PavelRatushnyi 2017-09-24 11:13:04 +03:00
parent bcc8192cf6
commit fe195a238d
2 changed files with 26 additions and 14 deletions

View file

@ -213,8 +213,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
itemViewHolder.title.setText(marker.getName(app)); itemViewHolder.title.setText(marker.getName(app));
boolean noGroup = marker.groupName == null; boolean noGroup = marker.groupName == null;
boolean early = false; boolean createdEarly = false;
if (noGroup) { if (noGroup && !markerInHistory) {
Calendar currentDateCalendar = Calendar.getInstance(); Calendar currentDateCalendar = Calendar.getInstance();
currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); currentDateCalendar.setTimeInMillis(System.currentTimeMillis());
int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR);
@ -223,22 +223,23 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
markerCalendar.setTimeInMillis(System.currentTimeMillis()); markerCalendar.setTimeInMillis(System.currentTimeMillis());
int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR);
int markerYear = markerCalendar.get(Calendar.YEAR); int markerYear = markerCalendar.get(Calendar.YEAR);
early = currentDay - markerDay >= 2 || currentYear != markerYear; createdEarly = currentDay - markerDay >= 2 || currentYear != markerYear;
} }
if (markerInHistory || createdEarly) {
itemViewHolder.point.setVisibility(View.VISIBLE);
itemViewHolder.description.setVisibility(View.VISIBLE);
Date date;
if (markerInHistory) { if (markerInHistory) {
itemViewHolder.point.setVisibility(View.VISIBLE); date = new Date(marker.visitedDate);
itemViewHolder.description.setVisibility(View.VISIBLE); } else {
itemViewHolder.description.setText(app.getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(marker.visitedDate)))); date = new Date(marker.creationDate);
} else if (noGroup && early) { }
itemViewHolder.point.setVisibility(View.VISIBLE);
itemViewHolder.description.setVisibility(View.VISIBLE);
Date date = new Date(marker.creationDate);
String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date); String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
if (month.length() > 1) { if (month.length() > 1) {
month = Character.toUpperCase(month.charAt(0)) + month.substring(1); month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
} }
String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date); String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
itemViewHolder.description.setText(month + " " + day); itemViewHolder.description.setText(app.getString(R.string.passed, month + " " + day));
} else { } else {
itemViewHolder.point.setVisibility(View.GONE); itemViewHolder.point.setVisibility(View.GONE);
itemViewHolder.description.setVisibility(View.GONE); itemViewHolder.description.setVisibility(View.GONE);
@ -428,7 +429,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
Date date = new Date(); Date date = new Date();
date.setMonth(month); date.setMonth(month);
String monthStr = dateFormat.format(date); String monthStr = dateFormat.format(date);
return Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1); if (monthStr.length() > 1) {
monthStr = Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1);
}
return monthStr;
} }
private int getLastDisplayItemIndexOfGroup(MapMarkersGroup group) { private int getLastDisplayItemIndexOfGroup(MapMarkersGroup group) {

View file

@ -9,7 +9,6 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -125,7 +124,13 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
itemViewHolder.title.setText(marker.getName(app)); itemViewHolder.title.setText(marker.getName(app));
itemViewHolder.description.setText(app.getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(marker.visitedDate)))); Date date = new Date(marker.visitedDate);
String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
if (month.length() > 1) {
month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
}
String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
itemViewHolder.description.setText(app.getString(R.string.passed, month + " " + day));
itemViewHolder.optionsBtn.setBackgroundDrawable(app.getResources().getDrawable(night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset)); itemViewHolder.optionsBtn.setBackgroundDrawable(app.getResources().getDrawable(night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reset_to_default_dark)); itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
@ -219,7 +224,10 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
Date date = new Date(); Date date = new Date();
date.setMonth(month); date.setMonth(month);
String monthStr = dateFormat.format(date); String monthStr = dateFormat.format(date);
return Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1); if (monthStr.length() > 1) {
monthStr = Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1);
}
return monthStr;
} }
public interface MapMarkersHistoryAdapterListener { public interface MapMarkersHistoryAdapterListener {