Skip to content
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

Added global time element #1232

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -680,5 +680,9 @@
"emojiPickerSearchEmoji": "Search emoji",
"@emojiPickerSearchEmoji": {
"description": "Hint text for the emoji picker search text field."
},
"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
Expand Up @@ -1014,6 +1014,12 @@ abstract class ZulipLocalizations {
/// In en, this message translates to:
/// **'Search emoji'**
String get emojiPickerSearchEmoji;

/// 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> {
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,7 @@ class ZulipLocalizationsAr extends ZulipLocalizations {

@override
String get emojiPickerSearchEmoji => 'Search emoji';

@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
Expand Up @@ -537,4 +537,7 @@ class ZulipLocalizationsEn extends ZulipLocalizations {

@override
String get emojiPickerSearchEmoji => 'Search emoji';

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

@override
String get emojiPickerSearchEmoji => 'Search emoji';

@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
Expand Up @@ -537,4 +537,7 @@ class ZulipLocalizationsJa extends ZulipLocalizations {

@override
String get emojiPickerSearchEmoji => 'Search emoji';

@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
Expand Up @@ -537,4 +537,7 @@ class ZulipLocalizationsPl extends ZulipLocalizations {

@override
String get emojiPickerSearchEmoji => 'Search emoji';

@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
Expand Up @@ -537,4 +537,7 @@ class ZulipLocalizationsRu extends ZulipLocalizations {

@override
String get emojiPickerSearchEmoji => 'Search emoji';

@override
String get composeBoxAttachGlobalTimeTooltip => 'Attach a global time';
}
62 changes: 61 additions & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -865,6 +865,65 @@ 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 {
// Store the context's mounted status before async operations
final BuildContext currentContext = context;

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

// Check if the widget is still mounted before continuing
if (!currentContext.mounted) return [];

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

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

// Check mounted status again after second async operation
if (!currentContext.mounted) return [];

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

final DateTime fullDateTime = DateTime(
pickedDate.year,
pickedDate.month,
pickedDate.day,
pickedTime.hour,
pickedTime.minute,
);

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

controller.content.text += timeMarkup;

return [];
}
}

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

Expand Down Expand Up @@ -1099,6 +1158,7 @@ abstract class _ComposeBoxBody extends StatelessWidget {
_AttachFileButton(controller: controller),
_AttachMediaButton(controller: controller),
_AttachFromCameraButton(controller: controller),
_AttachGlobalTimeButton(controller: controller)
];

final topicInput = buildTopicInput();
Expand Down