-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We are now showing the character's birthday
- Loading branch information
Showing
35 changed files
with
309 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class LanguageModel { | ||
final String code; | ||
final String countryCode; | ||
|
||
LanguageModel(this.code, this.countryCode) | ||
: assert(code != null), | ||
assert(countryCode != null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:genshindb/domain/enums/enums.dart'; | ||
import 'package:genshindb/domain/models/models.dart'; | ||
|
||
abstract class LocaleService { | ||
LanguageModel getLocaleWithoutLang(); | ||
|
||
LanguageModel getLocale(AppLanguageType language); | ||
|
||
String getFormattedLocale(AppLanguageType language); | ||
|
||
DateTime getCharBirthDate(String birthday); | ||
|
||
String formatCharBirthDate(String birthday); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:genshindb/domain/enums/enums.dart'; | ||
import 'package:genshindb/domain/extensions/string_extensions.dart'; | ||
import 'package:genshindb/domain/models/models.dart'; | ||
import 'package:genshindb/domain/services/locale_service.dart'; | ||
import 'package:genshindb/domain/services/settings_service.dart'; | ||
import 'package:intl/intl.dart'; | ||
|
||
class LocaleServiceImpl implements LocaleService { | ||
final SettingsService _settingsService; | ||
|
||
LocaleServiceImpl(this._settingsService); | ||
|
||
@override | ||
DateTime getCharBirthDate(String birthday) { | ||
if (birthday.isNullEmptyOrWhitespace) { | ||
throw Exception('Character birthday must not be null'); | ||
} | ||
final locale = getFormattedLocale(_settingsService.language); | ||
final format = DateFormat('MM/dd', locale); | ||
return format.parse(birthday); | ||
} | ||
|
||
@override | ||
String formatCharBirthDate(String birthday) { | ||
if (birthday.isNullEmptyOrWhitespace) { | ||
return ''; | ||
} | ||
final locale = getFormattedLocale(_settingsService.language); | ||
final birthdayDate = getCharBirthDate(birthday); | ||
return toBeginningOfSentenceCase(DateFormat('MMMM d', locale).format(birthdayDate)); | ||
} | ||
|
||
@override | ||
String getFormattedLocale(AppLanguageType language) { | ||
final locale = getLocale(language); | ||
return '${locale.code}_${locale.countryCode}'; | ||
} | ||
|
||
@override | ||
LanguageModel getLocaleWithoutLang() { | ||
return getLocale(_settingsService.language); | ||
} | ||
|
||
@override | ||
LanguageModel getLocale(AppLanguageType language) { | ||
var langCode = 'en'; | ||
var countryCode = 'US'; | ||
switch (language) { | ||
case AppLanguageType.spanish: | ||
langCode = 'es'; | ||
countryCode = 'ES'; | ||
break; | ||
case AppLanguageType.french: | ||
langCode = 'fr'; | ||
countryCode = 'FR'; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return LanguageModel(langCode, countryCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.