Match drawer clock preview line breaks
This commit is contained in:
@@ -125,7 +125,8 @@ public final class ClockFragment extends Fragment {
|
|||||||
SbtSettings.KEY_CLOCK_CUSTOM_FORMAT,
|
SbtSettings.KEY_CLOCK_CUSTOM_FORMAT,
|
||||||
customFormatEnabledValue,
|
customFormatEnabledValue,
|
||||||
customFormatValue,
|
customFormatValue,
|
||||||
18f);
|
18f,
|
||||||
|
true);
|
||||||
bindCustomFormat(
|
bindCustomFormat(
|
||||||
prefs,
|
prefs,
|
||||||
drawerClockCustomFormatEnabled,
|
drawerClockCustomFormatEnabled,
|
||||||
@@ -136,7 +137,8 @@ public final class ClockFragment extends Fragment {
|
|||||||
SbtSettings.KEY_DRAWER_CLOCK_CUSTOM_FORMAT,
|
SbtSettings.KEY_DRAWER_CLOCK_CUSTOM_FORMAT,
|
||||||
drawerClockCustomFormatEnabledValue,
|
drawerClockCustomFormatEnabledValue,
|
||||||
drawerClockCustomFormatValue,
|
drawerClockCustomFormatValue,
|
||||||
24f);
|
24f,
|
||||||
|
false);
|
||||||
bindCustomFormat(
|
bindCustomFormat(
|
||||||
prefs,
|
prefs,
|
||||||
drawerDateCustomFormatEnabled,
|
drawerDateCustomFormatEnabled,
|
||||||
@@ -147,7 +149,8 @@ public final class ClockFragment extends Fragment {
|
|||||||
SbtSettings.KEY_DRAWER_DATE_CUSTOM_FORMAT,
|
SbtSettings.KEY_DRAWER_DATE_CUSTOM_FORMAT,
|
||||||
drawerDateCustomFormatEnabledValue,
|
drawerDateCustomFormatEnabledValue,
|
||||||
drawerDateCustomFormatValue,
|
drawerDateCustomFormatValue,
|
||||||
16f);
|
16f,
|
||||||
|
false);
|
||||||
updateCustomFormatHelpVisibility(customFormatHelpContainer, customFormatHelpToggle, false);
|
updateCustomFormatHelpVisibility(customFormatHelpContainer, customFormatHelpToggle, false);
|
||||||
applyBulletText(customFormatHelpCommon);
|
applyBulletText(customFormatHelpCommon);
|
||||||
applyBulletText(customFormatHelpStyling);
|
applyBulletText(customFormatHelpStyling);
|
||||||
@@ -186,7 +189,8 @@ public final class ClockFragment extends Fragment {
|
|||||||
String formatKey,
|
String formatKey,
|
||||||
boolean enabled,
|
boolean enabled,
|
||||||
String format,
|
String format,
|
||||||
float previewTextSizeSp) {
|
float previewTextSizeSp,
|
||||||
|
boolean multilinePreview) {
|
||||||
if (enabledView == null || input == null) {
|
if (enabledView == null || input == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -198,7 +202,7 @@ public final class ClockFragment extends Fragment {
|
|||||||
previewTextSizeSp);
|
previewTextSizeSp);
|
||||||
}
|
}
|
||||||
updateCustomFormatVisibility(container, enabled);
|
updateCustomFormatVisibility(container, enabled);
|
||||||
PreviewBinding binding = new PreviewBinding(enabledView, input, preview);
|
PreviewBinding binding = new PreviewBinding(enabledView, input, preview, multilinePreview);
|
||||||
previewBindings.add(binding);
|
previewBindings.add(binding);
|
||||||
updatePreview(binding);
|
updatePreview(binding);
|
||||||
enabledView.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
enabledView.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
@@ -247,12 +251,37 @@ public final class ClockFragment extends Fragment {
|
|||||||
binding.preview.getContext(),
|
binding.preview.getContext(),
|
||||||
pattern,
|
pattern,
|
||||||
binding.preview.getPreviewTextColor());
|
binding.preview.getPreviewTextColor());
|
||||||
|
if (!binding.multilinePreview) {
|
||||||
|
result = flattenRows(result);
|
||||||
|
}
|
||||||
binding.preview.setPreview(result);
|
binding.preview.setPreview(result);
|
||||||
binding.preview.setVisibility(result.rows().isEmpty() ? View.GONE : View.VISIBLE);
|
binding.preview.setVisibility(result.rows().isEmpty() ? View.GONE : View.VISIBLE);
|
||||||
binding.preview.setContentDescription(result.contentDescription());
|
binding.preview.setContentDescription(result.contentDescription());
|
||||||
return result.containsSeconds();
|
return result.containsSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ClockPatternPreviewRenderer.Result flattenRows(ClockPatternPreviewRenderer.Result result) {
|
||||||
|
if (result == null || result.rows() == null || result.rows().size() <= 1) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
SpannableStringBuilder text = new SpannableStringBuilder();
|
||||||
|
StringBuilder description = new StringBuilder();
|
||||||
|
for (int i = 0; i < result.rows().size(); i++) {
|
||||||
|
ClockPatternPreviewRenderer.Row row = result.rows().get(i);
|
||||||
|
if (i > 0) {
|
||||||
|
text.append(' ');
|
||||||
|
description.append(' ');
|
||||||
|
}
|
||||||
|
if (row != null && row.text() != null) {
|
||||||
|
text.append(row.text());
|
||||||
|
description.append(row.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrayList<ClockPatternPreviewRenderer.Row> rows = new ArrayList<>();
|
||||||
|
rows.add(new ClockPatternPreviewRenderer.Row(text, "", "", 0, 0));
|
||||||
|
return new ClockPatternPreviewRenderer.Result(rows, description.toString(), result.containsSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
private void schedulePreviewTickerIfNeeded() {
|
private void schedulePreviewTickerIfNeeded() {
|
||||||
View view = getView();
|
View view = getView();
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
@@ -446,7 +475,7 @@ public final class ClockFragment extends Fragment {
|
|||||||
view.setText(builder);
|
view.setText(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record PreviewBinding(CheckBox enabled, EditText input, ClockPatternPreviewView preview) {
|
private record PreviewBinding(CheckBox enabled, EditText input, ClockPatternPreviewView preview, boolean multilinePreview) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class FontFamilyAdapter extends BaseAdapter {
|
private static final class FontFamilyAdapter extends BaseAdapter {
|
||||||
|
|||||||
Reference in New Issue
Block a user