Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into independent
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 committed Sep 1, 2023
2 parents b3114c7 + 85076fc commit b252b3e
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 99 deletions.
112 changes: 109 additions & 3 deletions lib/data/holidays.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import "package:flutter/cupertino.dart";

class HolidayData {
final String name;
final int month;
final int day;

const HolidayData(this.name, {required this.month, required this.day});
HolidayData(this.name, {required this.month, required this.day});
}

// Based on the locale, this return holidays that have fixed date as per the
// Gregorian calendar. For example, Christmas is always on December 25th.
List<HolidayData> getHolidays(BuildContext context) {
final locale = Localizations.localeOf(context);
if (localeToHolidays.containsKey(locale.toLanguageTag())) {
return localeToHolidays[locale.toLanguageTag()]!;
} else if (localeToHolidays.containsKey(locale.languageCode)) {
return localeToHolidays[locale.languageCode]!;
}
return _defaultHolidays;
}

const List<HolidayData> allHolidays = [
List<HolidayData> _defaultHolidays = [
HolidayData('New Year', month: 1, day: 1),
HolidayData('Epiphany', month: 1, day: 6),
HolidayData('Pongal', month: 1, day: 14),
Expand All @@ -18,9 +32,101 @@ const List<HolidayData> allHolidays = [
HolidayData('May Day', month: 5, day: 1),
HolidayData('Midsummer\'s Eve', month: 6, day: 24),
HolidayData('Midsummer Day', month: 6, day: 25),
HolidayData('Christmas Eve', month: 12, day: 24),
HolidayData('Halloween', month: 10, day: 31),
HolidayData('Christmas Eve', month: 12, day: 24),
HolidayData('Christmas', month: 12, day: 25),
HolidayData('Boxing Day', month: 12, day: 26),
HolidayData('New Year\'s Eve', month: 12, day: 31),
];
Map<String, List<HolidayData>> localeToHolidays = {
'it': [
HolidayData('Capodanno', month: 1, day: 1),
// New Year's Day
HolidayData('Epifania', month: 1, day: 6),
// Epiphany
HolidayData('San Valentino', month: 2, day: 14),
// Valentine's Day
HolidayData('Festa della Liberazione', month: 4, day: 25),
// Liberation Day
HolidayData('Primo Maggio', month: 5, day: 1),
// Labor Day
HolidayData('Festa della Repubblica', month: 6, day: 2),
// Republic Day
HolidayData('Ferragosto', month: 8, day: 15),
// Assumption of Mary
HolidayData('Halloween', month: 10, day: 31),
// Halloween
HolidayData('Ognissanti', month: 11, day: 1),
// All Saints' Day
HolidayData('Immacolata Concezione', month: 12, day: 8),
// Immaculate Conception
HolidayData('Natale', month: 12, day: 25),
// Christmas Day
HolidayData('Vigilia di Capodanno', month: 12, day: 31),
// New Year's Eve
],
'fr': [
HolidayData('Jour de l\'An', month: 1, day: 1), // New Year's Day
HolidayData('Fête du Travail', month: 5, day: 1), // Labour Day
HolidayData('Fête Nationale', month: 7, day: 14), // Bastille Day
HolidayData('Assomption', month: 8, day: 15), // Assumption of Mary
HolidayData('Halloween', month: 10, day: 31), // Halloween
HolidayData('Toussaint', month: 11, day: 1), // All Saints' Day
HolidayData('Jour de l\'Armistice', month: 11, day: 11), // Armistice Day
HolidayData('Noël', month: 12, day: 25), // Christmas
HolidayData('Lendemain de Noël', month: 12, day: 26), // Boxing Day
HolidayData('Saint-Sylvestre', month: 12, day: 31), // New Year's Eve
],
'de': [
HolidayData('Neujahrstag', month: 1, day: 1),
// New Year
HolidayData('Valentinstag', month: 2, day: 14),
// Valentine's Day
HolidayData('Tag der Arbeit', month: 5, day: 1),
// Labor Day
HolidayData('Tag der Deutschen Einheit', month: 10, day: 3),
// German Unity Day
HolidayData('Halloween', month: 10, day: 31),
// Halloween
HolidayData('Erster Weihnachtstag', month: 12, day: 25),
// First Christmas Day
HolidayData('Zweiter Weihnachtstag', month: 12, day: 26),
// Second Christmas Day (Boxing Day)
HolidayData('Silvester', month: 12, day: 31),
// New Year's Eve
],
'nl': [
HolidayData('Nieuwjaarsdag', month: 1, day: 1), // New Year's Day
HolidayData('Valentijnsdag', month: 2, day: 14), // Valentine's Day
HolidayData('Koningsdag', month: 4, day: 27), // King's Day
HolidayData('Bevrijdingsdag', month: 5, day: 5), // Liberation Day
HolidayData('Hemelvaartsdag', month: 5, day: 26), // Ascension Day
HolidayData('Halloween', month: 10, day: 31), // Halloween
HolidayData('Sinterklaas', month: 12, day: 5), // Sinterklaas
HolidayData('Eerste Kerstdag', month: 12, day: 25), // First Christmas Day
HolidayData('Tweede Kerstdag', month: 12, day: 26), // Second Christmas Day
HolidayData('Oudejaarsdag', month: 12, day: 31), // New Year's Eve
],
'es': [
HolidayData('Año Nuevo', month: 1, day: 1),
// New Year's Day
HolidayData('San Valentín', month: 2, day: 14),
// Valentine's Day
HolidayData('Día del Trabajador', month: 5, day: 1),
// Labor Day
HolidayData('Día de la Hispanidad', month: 10, day: 12),
// Hispanic Day
HolidayData('Halloween', month: 10, day: 31),
// Halloween
HolidayData('Día de Todos los Santos', month: 11, day: 1),
// All Saints' Day
HolidayData('Día de la Constitución', month: 12, day: 6),
// Constitution Day
HolidayData('La Inmaculada Concepción', month: 12, day: 8),
// Immaculate Conception
HolidayData('Navidad', month: 12, day: 25),
// Christmas Day
HolidayData('Nochevieja', month: 12, day: 31),
// New Year's Eve
],
};
31 changes: 17 additions & 14 deletions lib/data/months.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
List<MonthData> allMonths = [
MonthData('January', 1),
MonthData('February', 2),
MonthData('March', 3),
MonthData('April', 4),
MonthData('May', 5),
MonthData('June', 6),
MonthData('July', 7),
MonthData('August', 8),
MonthData('September', 9),
MonthData('October', 10),
MonthData('November', 11),
MonthData('December', 12),
];
import "package:flutter/widgets.dart";
import "package:intl/intl.dart";

final Map<String, List<MonthData>> _cache = {};

List<MonthData> getMonthData(BuildContext context) {
final locale = Localizations.localeOf(context).toString();

if (!_cache.containsKey(locale)) {
final dateSymbols = DateFormat('MMMM', locale).dateSymbols;
_cache[locale] = List.generate(
12,
(index) => MonthData(dateSymbols.MONTHS[index], index + 1),
);
}
return _cache[locale]!;
}

class MonthData {
final String name;
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const List<Locale> appSupportedLocales = <Locale>[
Locale('en'),
Locale('es'),
Locale('de'),
Locale('fr'),
Locale('it'),
Locale("nl"),
Locale("zh", "CN"),
Expand Down
37 changes: 26 additions & 11 deletions lib/services/search_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:flutter/cupertino.dart";
import 'package:logging/logging.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/data/holidays.dart';
Expand Down Expand Up @@ -93,7 +94,8 @@ class SearchService {
final List<GenericSearchResult> searchResults = [];
for (var yearData in YearsData.instance.yearsData) {
if (yearData.year.startsWith(yearFromQuery)) {
final List<EnteFile> filesInYear = await _getFilesInYear(yearData.duration);
final List<EnteFile> filesInYear =
await _getFilesInYear(yearData.duration);
if (filesInYear.isNotEmpty) {
searchResults.add(
GenericSearchResult(
Expand All @@ -109,11 +111,16 @@ class SearchService {
}

Future<List<GenericSearchResult>> getHolidaySearchResults(
BuildContext context,
String query,
) async {
final List<GenericSearchResult> searchResults = [];
if (query.isEmpty) {
return searchResults;
}
final holidays = getHolidays(context);

for (var holiday in allHolidays) {
for (var holiday in holidays) {
if (holiday.name.toLowerCase().contains(query.toLowerCase())) {
final matchedFiles =
await FilesDB.instance.getFilesCreatedWithinDurations(
Expand Down Expand Up @@ -314,9 +321,12 @@ class SearchService {
return searchResults;
}

Future<List<GenericSearchResult>> getMonthSearchResults(String query) async {
Future<List<GenericSearchResult>> getMonthSearchResults(
BuildContext context,
String query,
) async {
final List<GenericSearchResult> searchResults = [];
for (var month in _getMatchingMonths(query)) {
for (var month in _getMatchingMonths(context, query)) {
final matchedFiles =
await FilesDB.instance.getFilesCreatedWithinDurations(
_getDurationsOfMonthInEveryYear(month.monthNumber),
Expand All @@ -337,10 +347,11 @@ class SearchService {
}

Future<List<GenericSearchResult>> getDateResults(
BuildContext context,
String query,
) async {
final List<GenericSearchResult> searchResults = [];
final potentialDates = _getPossibleEventDate(query);
final potentialDates = _getPossibleEventDate(context, query);

for (var potentialDate in potentialDates) {
final int day = potentialDate.item1;
Expand All @@ -365,8 +376,8 @@ class SearchService {
return searchResults;
}

List<MonthData> _getMatchingMonths(String query) {
return allMonths
List<MonthData> _getMatchingMonths(BuildContext context, String query) {
return getMonthData(context)
.where(
(monthData) =>
monthData.name.toLowerCase().startsWith(query.toLowerCase()),
Expand All @@ -391,7 +402,7 @@ class SearchService {
final int startYear = year ?? searchStartYear;
final int endYear = year ?? currentYear;
for (var yr = startYear; yr <= endYear; yr++) {
if (isValidDate(day: day, month: month, year: yr)) {
if (isValidGregorianDate(day: day, month: month, year: yr)) {
durationsOfHolidayInEveryYear.add([
DateTime(yr, month, day).microsecondsSinceEpoch,
DateTime(yr, month, day + 1).microsecondsSinceEpoch,
Expand All @@ -414,7 +425,10 @@ class SearchService {
return durationsOfMonthInEveryYear;
}

List<Tuple3<int, MonthData, int?>> _getPossibleEventDate(String query) {
List<Tuple3<int, MonthData, int?>> _getPossibleEventDate(
BuildContext context,
String query,
) {
final List<Tuple3<int, MonthData, int?>> possibleEvents = [];
if (query.trim().isEmpty) {
return possibleEvents;
Expand All @@ -434,8 +448,9 @@ class SearchService {
if (day == null || day < 1 || day > 31) {
return possibleEvents;
}
final List<MonthData> potentialMonth =
resultCount > 1 ? _getMatchingMonths(result[1]) : allMonths;
final List<MonthData> potentialMonth = resultCount > 1
? _getMatchingMonths(context, result[1])
: getMonthData(context);
final int? parsedYear = resultCount >= 3 ? int.tryParse(result[2]) : null;
final List<int> matchingYears = [];
if (parsedYear != null) {
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/home/preserve_footer_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import 'dart:async';
import "dart:io";

import 'package:flutter/material.dart';
import "package:flutter/services.dart";
import "package:logging/logging.dart";
import 'package:photo_manager/photo_manager.dart';
import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
import 'package:photos/services/local_sync_service.dart';
import 'package:photos/ui/common/gradient_button.dart';
Expand Down
7 changes: 6 additions & 1 deletion lib/ui/viewer/file/file_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/events/local_photos_updated_event.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
Expand Down Expand Up @@ -307,7 +308,11 @@ class FileAppBarState extends State<FileAppBar> {
}

Future<void> _download(EnteFile file) async {
final dialog = createProgressDialog(context, "Downloading...");
final dialog = createProgressDialog(
context,
context.l10n.downloading,
isDismissible: true,
);
await dialog.show();
try {
final FileType type = file.fileType;
Expand Down
13 changes: 11 additions & 2 deletions lib/ui/viewer/file/video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class _VideoWidgetState extends State<VideoWidget> {
getFileFromServer(
widget.file,
progressCallback: (count, total) {
if(!mounted) {
return;
}
_progressNotifier.value = count / (widget.file.fileSize ?? total);
if (_progressNotifier.value == 1) {
if (mounted) {
Expand All @@ -100,18 +103,24 @@ class _VideoWidgetState extends State<VideoWidget> {
}
},
).then((file) {
if (file != null) {
if (file != null && mounted) {
_setVideoPlayerController(file: file);
}
}).onError((error, stackTrace) {
showErrorDialog(context, "Error", S.of(context).failedToDownloadVideo);
if(mounted) {
showErrorDialog(context, "Error", S
.of(context).failedToDownloadVideo,);
}
});
}

@override
void dispose() {
removeCallBack(widget.file);
_videoPlayerController?.dispose();
_chewieController?.dispose();
_progressNotifier.dispose();

if (_wakeLockEnabledHere) {
unawaited(
WakelockPlus.enabled.then((isEnabled) {
Expand Down
Loading

0 comments on commit b252b3e

Please sign in to comment.