Skip to content

Insert time element global #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -870,5 +870,9 @@
"zulipAppTitle": "Zulip",
"@zulipAppTitle": {
"description": "The name of Zulip. This should be either 'Zulip' or a transliteration."
},
"composeBoxAttachGlobalTimeTooltip": "Attach a global time",
"@composeBoxAttachGlobalTimeTooltip": {
"description": "Tooltip for the button to attach a global time to the compose box."
}
}
6 changes: 6 additions & 0 deletions lib/generated/l10n/zulip_localizations.dart
Original file line number Diff line number Diff line change
@@ -1274,6 +1274,12 @@ abstract class ZulipLocalizations {
/// In en, this message translates to:
/// **'Zulip'**
String get zulipAppTitle;

/// Tooltip for the button to attach a global time to the compose box.
///
/// In en, this message translates to:
/// **'Attach a global time'**
String get composeBoxAttachGlobalTimeTooltip;
}

class _ZulipLocalizationsDelegate extends LocalizationsDelegate<ZulipLocalizations> {
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ar.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsAr extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_en.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsEn extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ja.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsJa extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_nb.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsNb extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_pl.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsPl extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ru.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsRu extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_sk.dart
Original file line number Diff line number Diff line change
@@ -678,4 +678,7 @@ class ZulipLocalizationsSk extends ZulipLocalizations {

@override
String get zulipAppTitle => 'Zulip';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
65 changes: 64 additions & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import 'package:app_settings/app_settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mime/mime.dart';

import 'package:intl/intl.dart';
import '../api/exception.dart';
import '../api/model/model.dart';
import '../api/route/messages.dart';
@@ -1034,6 +1034,68 @@ class _AttachFromCameraButton extends _AttachUploadsButton {
}
}

class _AttachGlobalTimeButton extends _AttachUploadsButton {
const _AttachGlobalTimeButton({required super.controller});

@override
IconData get icon => ZulipIcons.clock;

@override
String tooltip(ZulipLocalizations zulipLocalizations) =>
zulipLocalizations.composeBoxAttachGlobalTimeTooltip;

@override
Future<Iterable<_File>> getFiles(BuildContext context) async {
// Ensure the context is still valid
if (!context.mounted) return [];

// Request a date and time from the user.
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2100),
);

// Recheck context after async operation
if (!context.mounted) return [];

if (pickedDate == null) {
return []; // User canceled, no action needed.
}

final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);

// Recheck context after async operation
if (!context.mounted) return [];

if (pickedTime == null) {
return [];
}

// Combine the picked date and time.
final DateTime fullDateTime = DateTime(
pickedDate.year,
pickedDate.month,
pickedDate.day,
pickedTime.hour,
pickedTime.minute,
);

// Format the date-time for the new markup.
final String timeMarkup =
"<time:${DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(fullDateTime.toUtc())}>";

// Safely update the content controller
controller.content.text += timeMarkup;

return [];
}
}

class _SendButton extends StatefulWidget {
const _SendButton({required this.controller, required this.getDestination});

@@ -1270,6 +1332,7 @@ abstract class _ComposeBoxBody extends StatelessWidget {
_AttachFileButton(controller: controller),
_AttachMediaButton(controller: controller),
_AttachFromCameraButton(controller: controller),
_AttachGlobalTimeButton(controller: controller),
];

final topicInput = buildTopicInput();