From 5ed0ad7a40927f49b3387f75cc76891648fc0de7 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Tue, 28 Dec 2021 13:29:09 +0200 Subject: [PATCH] Changed string representation of opening hours in long-click copy menu and in editor UI. Signed-off-by: S. Kozyr --- .../maps/editor/EditorFragment.java | 3 +- .../maps/editor/data/TimeFormatUtils.java | 38 ++++++------------- .../maps/widget/placepage/PlacePageView.java | 2 +- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/android/src/com/mapswithme/maps/editor/EditorFragment.java b/android/src/com/mapswithme/maps/editor/EditorFragment.java index 428e898b3d..c5600439f5 100644 --- a/android/src/com/mapswithme/maps/editor/EditorFragment.java +++ b/android/src/com/mapswithme/maps/editor/EditorFragment.java @@ -439,7 +439,8 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe { final Timetable[] timetables = OpeningHours.nativeTimetablesFromString(openingHours); String content = timetables == null ? openingHours - : TimeFormatUtils.formatTimetables(requireContext(), + : TimeFormatUtils.formatTimetables(getResources(), + openingHours, timetables); UiUtils.hide(mEmptyOpeningHours); UiUtils.setTextAndShow(mOpeningHours, content); diff --git a/android/src/com/mapswithme/maps/editor/data/TimeFormatUtils.java b/android/src/com/mapswithme/maps/editor/data/TimeFormatUtils.java index d174e03889..64e0c77782 100644 --- a/android/src/com/mapswithme/maps/editor/data/TimeFormatUtils.java +++ b/android/src/com/mapswithme/maps/editor/data/TimeFormatUtils.java @@ -72,30 +72,6 @@ public class TimeFormatUtils return builder.toString(); } - public static String formatTimetables(@NonNull Context context, @NonNull Timetable[] timetables) - { - final Resources resources = MwmApplication.from(context).getResources(); - - if (timetables[0].isFullWeek()) - { - return timetables[0].isFullday ? resources.getString(R.string.twentyfour_seven) - : resources.getString(R.string.daily) + " " + timetables[0].workingTimespan; - } - - final StringBuilder builder = new StringBuilder(); - for (Timetable tt : timetables) - { - String workingTime = tt.isFullday ? resources.getString(R.string.editor_time_allday) - : tt.workingTimespan.toString(); - - builder.append(String.format(Locale.getDefault(), "%-21s", formatWeekdays(tt))).append(" ") - .append(workingTime) - .append("\n"); - } - - return builder.toString(); - } - public static String formatNonBusinessTime(Timespan[] closedTimespans, String hoursClosedLabel) { StringBuilder closedTextBuilder = new StringBuilder(); @@ -111,7 +87,7 @@ public class TimeFormatUtils return closedTextBuilder.toString(); } - public static String generateCopyText(Resources resources, String ohStr, Timetable[] timetables) + public static String formatTimetables(@NonNull Resources resources, String ohStr, Timetable[] timetables) { if (timetables == null || timetables.length == 0) return ohStr; @@ -122,12 +98,16 @@ public class TimeFormatUtils Timetable tt = timetables[0]; if (tt.isFullday) return resources.getString(R.string.twentyfour_seven); - return resources.getString(R.string.daily) + " " + tt.workingTimespan.toWideString(); + if (tt.closedTimespans == null || tt.closedTimespans.length == 0) + return resources.getString(R.string.daily) + " " + tt.workingTimespan.toWideString(); + return resources.getString(R.string.daily) + " " + tt.workingTimespan.toWideString() + + "\n" + formatNonBusinessTime(tt.closedTimespans, resources.getString(R.string.editor_hours_closed)); } // Generate full week multiline string. E.g. // "Mon-Fri HH:MM - HH:MM - // Sat HH:MM - HH:MM" + // Sat HH:MM - HH:MM + // Non-business Hours HH:MM - HH:MM" StringBuilder weekSchedule = new StringBuilder(); boolean firstRow = true; for (Timetable tt : timetables) @@ -141,6 +121,10 @@ public class TimeFormatUtils tt.workingTimespan.toWideString(); weekSchedule.append(weekdays).append(' ').append(openTime); + if (tt.closedTimespans != null && tt.closedTimespans.length > 0) + weekSchedule.append('\n') + .append(formatNonBusinessTime(tt.closedTimespans, resources.getString(R.string.editor_hours_closed))); + firstRow = false; } diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 0f6140f8d5..9a06451abc 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -1475,7 +1475,7 @@ public class PlacePageView extends NestedScrollViewClickFixed case R.id.ll__place_schedule: final String ohStr = mMapObject.getMetadata(Metadata.MetadataType.FMD_OPEN_HOURS); final Timetable[] timetables = OpeningHours.nativeTimetablesFromString(ohStr); - items.add(TimeFormatUtils.generateCopyText(getResources(), ohStr, timetables)); + items.add(TimeFormatUtils.formatTimetables(getResources(), ohStr, timetables)); break; case R.id.ll__place_operator: items.add(mTvOperator.getText().toString());