From ad0c79877c9b0609621c6b30458ec11ca06c21f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20K=C3=BCpper?= Date: Mon, 5 Feb 2024 08:26:15 -0500 Subject: [PATCH] send UiLanguage as http header (#532) * send UiLanguage as http header * remove translate locally since it's done on the server. * add to PlaybackOrigin if a playlist is shared or owned --- .../Clients/Contracts/IDiscoverClient.cs | 2 +- .../Clients/Contracts/IPlaylistClient.cs | 2 +- .../Clients/Contracts/IStatisticsClient.cs | 8 +-- .../Implementation/Clients/DiscoverClient.cs | 3 +- .../Implementation/Clients/PlaylistClient.cs | 3 +- .../Clients/StatisticsClient.cs | 20 ++----- .../Implementation/Constants/HeaderNames.cs | 1 + BMM.Core/App.cs | 1 + BMM.Core/Extensions/TranslationsExtensions.cs | 8 --- .../Achievements/PrepareAchievementsAction.cs | 8 +-- ...kAndShowAchievementUnlockedScreenAction.cs | 6 +-- ...nitializeBibleStudyRulesViewModelAction.cs | 9 +--- .../InitializeBibleStudyViewModelAction.cs | 6 +-- .../Interfaces/ITranslateDocsAction.cs | 10 ---- .../Documents/TranslateDocsAction.cs | 53 ------------------- .../Player/UpdateExternalRelationsAction.cs | 12 ----- .../CachedDiscoverClientDecorator.cs | 4 +- .../CachedPlaylistClientDecorator.cs | 4 +- .../ApiClients/HttpHeaderProviders.cs | 6 ++- .../ApiClients/UiLanguageHeaderProvider.cs | 20 +++++++ .../Downloading/GlobalMediaDownloader.cs | 7 +-- .../Languages/AppLanguageProvider.cs | 3 -- .../ViewModels/BrowseDetailsListViewModel.cs | 7 +-- BMM.Core/ViewModels/BrowseViewModel.cs | 8 +-- .../ViewModels/CuratedPlaylistsViewModel.cs | 22 ++------ BMM.Core/ViewModels/ExploreNewestViewModel.cs | 21 +------- .../ViewModels/TrackCollectionViewModel.cs | 5 +- .../Downloading/GlobalMediaDownloaderTests.cs | 5 +- 28 files changed, 62 insertions(+), 202 deletions(-) delete mode 100644 BMM.Core/GuardedActions/Documents/Interfaces/ITranslateDocsAction.cs delete mode 100644 BMM.Core/GuardedActions/Documents/TranslateDocsAction.cs create mode 100644 BMM.Core/Implementations/ApiClients/UiLanguageHeaderProvider.cs diff --git a/BMM.Api/Implementation/Clients/Contracts/IDiscoverClient.cs b/BMM.Api/Implementation/Clients/Contracts/IDiscoverClient.cs index 8cf783f9d..5ad17686b 100644 --- a/BMM.Api/Implementation/Clients/Contracts/IDiscoverClient.cs +++ b/BMM.Api/Implementation/Clients/Contracts/IDiscoverClient.cs @@ -8,6 +8,6 @@ namespace BMM.Api.Implementation.Clients.Contracts { public interface IDiscoverClient { - Task> GetDocuments(string lang, int? age, AppTheme theme, CachePolicy cachePolicy); + Task> GetDocuments(int? age, AppTheme theme, CachePolicy cachePolicy); } } \ No newline at end of file diff --git a/BMM.Api/Implementation/Clients/Contracts/IPlaylistClient.cs b/BMM.Api/Implementation/Clients/Contracts/IPlaylistClient.cs index 4f5aab527..ca10af563 100644 --- a/BMM.Api/Implementation/Clients/Contracts/IPlaylistClient.cs +++ b/BMM.Api/Implementation/Clients/Contracts/IPlaylistClient.cs @@ -14,7 +14,7 @@ public interface IPlaylistClient Task GetCover(int podcastId); - Task GetDocuments(string lang, int? age, CachePolicy cachePolicy); + Task GetDocuments(int? age, CachePolicy cachePolicy); Task> GetTracks(int podcastId, CachePolicy cachePolicy); } diff --git a/BMM.Api/Implementation/Clients/Contracts/IStatisticsClient.cs b/BMM.Api/Implementation/Clients/Contracts/IStatisticsClient.cs index a374ce84e..c5774731f 100644 --- a/BMM.Api/Implementation/Clients/Contracts/IStatisticsClient.cs +++ b/BMM.Api/Implementation/Clients/Contracts/IStatisticsClient.cs @@ -73,15 +73,15 @@ public interface IStatisticsClient Task> GetYearInReview(); - Task GetProjectProgress(string lang, AppTheme theme); + Task GetProjectProgress(AppTheme theme); - Task GetProjectRules(string lang, int projectId); + Task GetProjectRules(int projectId); Task AchievementAcknowledge(string achievementType); Task DeleteAchievements(); Task PostListeningEvents(IList listeningEvents); - Task GetAchievements(string lang, AppTheme theme); - Task> GetAchievementsToAcknowledge(string lang, AppTheme theme); + Task GetAchievements(AppTheme theme); + Task> GetAchievementsToAcknowledge(AppTheme theme); } } \ No newline at end of file diff --git a/BMM.Api/Implementation/Clients/DiscoverClient.cs b/BMM.Api/Implementation/Clients/DiscoverClient.cs index 59d13495e..a1ab2b5fe 100644 --- a/BMM.Api/Implementation/Clients/DiscoverClient.cs +++ b/BMM.Api/Implementation/Clients/DiscoverClient.cs @@ -16,10 +16,9 @@ public class DiscoverClient : BaseClient, IDiscoverClient public DiscoverClient(IRequestHandler handler, ApiBaseUri baseUri, ILogger logger) : base(handler, baseUri, logger) { } - public async Task> GetDocuments(string lang, int? age, AppTheme theme, CachePolicy cachePolicy) + public async Task> GetDocuments(int? age, AppTheme theme, CachePolicy cachePolicy) { var uri = new UriTemplate(ApiUris.Discover); - uri.SetParameter("lang", lang); if (age.HasValue) uri.SetParameter("age", age.Value); uri.SetParameter("theme", theme); diff --git a/BMM.Api/Implementation/Clients/PlaylistClient.cs b/BMM.Api/Implementation/Clients/PlaylistClient.cs index b7bd186f5..36e0edf4c 100644 --- a/BMM.Api/Implementation/Clients/PlaylistClient.cs +++ b/BMM.Api/Implementation/Clients/PlaylistClient.cs @@ -36,10 +36,9 @@ public async Task GetCover(int podcastId) return await GetCoverBase(podcastId, ApiUris.PlaylistCover); } - public Task GetDocuments(string lang, int? age, CachePolicy cachePolicy) + public Task GetDocuments(int? age, CachePolicy cachePolicy) { var uri = new UriTemplate(ApiUris.PlaylistDocuments); - uri.SetParameter("lang", lang); uri.SetParameter("age", age); return Get(uri); } diff --git a/BMM.Api/Implementation/Clients/StatisticsClient.cs b/BMM.Api/Implementation/Clients/StatisticsClient.cs index 31803f74f..e723d522a 100644 --- a/BMM.Api/Implementation/Clients/StatisticsClient.cs +++ b/BMM.Api/Implementation/Clients/StatisticsClient.cs @@ -124,46 +124,34 @@ public Task> GetYearInReview() return Get>(uri); } - public async Task GetAchievements(string lang, AppTheme theme) + public async Task GetAchievements(AppTheme theme) { var uri = new UriTemplate(ApiUris.Achievements); - uri.SetParameter("lang", lang); uri.SetParameter("theme", theme); return await Get(uri); } - public Task> GetAchievementsToAcknowledge(string lang, AppTheme theme) + public Task> GetAchievementsToAcknowledge(AppTheme theme) { var uri = new UriTemplate(ApiUris.AchievementsToAcknowledge); - uri.SetParameter("lang", lang); uri.SetParameter("theme", theme); return Get>(uri); } - public Task GetProjectProgress(string lang, AppTheme theme) + public Task GetProjectProgress(AppTheme theme) { var uri = new UriTemplate(ApiUris.ProjectProgress); - uri.SetParameter("lang", lang); uri.SetParameter("theme", theme); return Get(uri); } - public Task GetProjectRules(string lang, int projectId) + public Task GetProjectRules(int projectId) { var uri = new UriTemplate(ApiUris.ProjectRules); uri.SetParameter("projectId", projectId); - uri.SetParameter("lang", lang); return Get(uri); } - // public Task GetAchievements(string lang, AppTheme theme) - // { - // var uri = new UriTemplate(ApiUris.StatisticsAchievements); - // uri.SetParameter("lang", lang); - // uri.SetParameter("theme", theme); - // return Get(uri); - // } - // public Task AchievementAcknowledge(string achievementType) { var uri = new UriTemplate(ApiUris.AchievementAcknowledge); diff --git a/BMM.Api/Implementation/Constants/HeaderNames.cs b/BMM.Api/Implementation/Constants/HeaderNames.cs index fb95cab3d..8bba186d2 100644 --- a/BMM.Api/Implementation/Constants/HeaderNames.cs +++ b/BMM.Api/Implementation/Constants/HeaderNames.cs @@ -13,5 +13,6 @@ public static class HeaderNames public const string Accept = "Accept"; public const string MobileDownloadAllowed = "MobileDownloadAllowed"; public const string Authorization = "Authorization"; + public const string UiLanguage = "UiLanguage"; } } \ No newline at end of file diff --git a/BMM.Core/App.cs b/BMM.Core/App.cs index ffd1e7255..545732908 100644 --- a/BMM.Core/App.cs +++ b/BMM.Core/App.cs @@ -194,6 +194,7 @@ public override void Initialize() Mvx.IoCProvider.RegisterType(); Mvx.IoCProvider.RegisterType(); Mvx.IoCProvider.RegisterType(); + Mvx.IoCProvider.RegisterType(); Mvx.IoCProvider.RegisterType(); Mvx.IoCProvider.RegisterType(); Mvx.IoCProvider.RegisterType(); diff --git a/BMM.Core/Extensions/TranslationsExtensions.cs b/BMM.Core/Extensions/TranslationsExtensions.cs index 0ae417788..a107412a9 100644 --- a/BMM.Core/Extensions/TranslationsExtensions.cs +++ b/BMM.Core/Extensions/TranslationsExtensions.cs @@ -1,6 +1,3 @@ -using System; -using BMM.Api.Implementation.Models; -using BMM.Api.Implementation.Models.Interfaces; using BMM.Core.Translation; using MvvmCross.Localization; @@ -16,11 +13,6 @@ public static string ConvertPlaylistAuthorToLabel(this IMvxLanguageBinder mvxLan return string.Format(mvxLanguageBinder.GetText(Translations.MyContentViewModel_ByFormat), authorName); } - public static string GetTranslationKey(this ITranslationDetailsHolder translationDetailsHolder) - { - return $"{translationDetailsHolder.TranslationParent}_{translationDetailsHolder.TranslationId}"; - } - public static string GetTranslationKey(this Type basicType, string key) { return $"{basicType.Name}_{key}"; diff --git a/BMM.Core/GuardedActions/Achievements/PrepareAchievementsAction.cs b/BMM.Core/GuardedActions/Achievements/PrepareAchievementsAction.cs index bb8d3760c..596f6307e 100644 --- a/BMM.Core/GuardedActions/Achievements/PrepareAchievementsAction.cs +++ b/BMM.Core/GuardedActions/Achievements/PrepareAchievementsAction.cs @@ -4,7 +4,6 @@ using BMM.Core.GuardedActions.Achievements.Interfaces; using BMM.Core.GuardedActions.Base; using BMM.Core.Implementations.Device; -using BMM.Core.Implementations.Languages; using BMM.Core.Models.POs.Base; using BMM.Core.Models.POs.BibleStudy; using BMM.Core.Models.POs.Other; @@ -18,18 +17,15 @@ public class PrepareAchievementsAction IPrepareAchievementsAction { private readonly IStatisticsClient _statisticsClient; - private readonly IAppLanguageProvider _appLanguageProvider; private readonly IDeviceInfo _deviceInfo; private readonly IMvxNavigationService _mvxNavigationService; public PrepareAchievementsAction( IStatisticsClient statisticsClient, - IAppLanguageProvider appLanguageProvider, IDeviceInfo deviceInfo, IMvxNavigationService mvxNavigationService) { _statisticsClient = statisticsClient; - _appLanguageProvider = appLanguageProvider; _deviceInfo = deviceInfo; _mvxNavigationService = mvxNavigationService; } @@ -38,9 +34,7 @@ public PrepareAchievementsAction( protected override async Task Execute() { - var achievementHolder = await _statisticsClient.GetAchievements( - _appLanguageProvider.GetAppLanguage(), - await _deviceInfo.GetCurrentTheme()); + var achievementHolder = await _statisticsClient.GetAchievements(await _deviceInfo.GetCurrentTheme()); var elementsList = new List(); diff --git a/BMM.Core/GuardedActions/BibleStudy/CheckAndShowAchievementUnlockedScreenAction.cs b/BMM.Core/GuardedActions/BibleStudy/CheckAndShowAchievementUnlockedScreenAction.cs index 03a3e1017..2bbc9152c 100644 --- a/BMM.Core/GuardedActions/BibleStudy/CheckAndShowAchievementUnlockedScreenAction.cs +++ b/BMM.Core/GuardedActions/BibleStudy/CheckAndShowAchievementUnlockedScreenAction.cs @@ -5,7 +5,6 @@ using BMM.Core.GuardedActions.BibleStudy.Interfaces; using BMM.Core.Helpers.PresentationHints; using BMM.Core.Implementations.Device; -using BMM.Core.Implementations.Languages; using BMM.Core.Messages; using BMM.Core.Models.POs.BibleStudy; using BMM.Core.Utils; @@ -22,26 +21,23 @@ public class CheckAndShowAchievementUnlockedScreenAction : GuardedAction, ICheck private readonly IStatisticsClient _statisticsClient; private readonly IMvxNavigationService _mvxNavigationService; private readonly IMvxMessenger _mvxMessenger; - private readonly IAppLanguageProvider _appLanguageProvider; private readonly IDeviceInfo _deviceInfo; public CheckAndShowAchievementUnlockedScreenAction( IStatisticsClient statisticsClient, IMvxNavigationService mvxNavigationService, IMvxMessenger mvxMessenger, - IAppLanguageProvider appLanguageProvider, IDeviceInfo deviceInfo) { _statisticsClient = statisticsClient; _mvxNavigationService = mvxNavigationService; _mvxMessenger = mvxMessenger; - _appLanguageProvider = appLanguageProvider; _deviceInfo = deviceInfo; } protected override async Task Execute() { - var achievements = await _statisticsClient.GetAchievementsToAcknowledge(_appLanguageProvider.GetAppLanguage(), await _deviceInfo.GetCurrentTheme()); + var achievements = await _statisticsClient.GetAchievementsToAcknowledge(await _deviceInfo.GetCurrentTheme()); if (!achievements.Any()) return; diff --git a/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyRulesViewModelAction.cs b/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyRulesViewModelAction.cs index 9db4c9b5c..eae483b90 100644 --- a/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyRulesViewModelAction.cs +++ b/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyRulesViewModelAction.cs @@ -5,7 +5,6 @@ using BMM.Core.GuardedActions.TrackInfo.Interfaces; using BMM.Core.Helpers; using BMM.Core.Implementations.Factories.Streak; -using BMM.Core.Implementations.Languages; using BMM.Core.Implementations.UI; using BMM.Core.Models.POs.Base.Interfaces; using BMM.Core.Models.POs.BibleStudy; @@ -20,21 +19,17 @@ namespace BMM.Core.GuardedActions.BibleStudy; public class InitializeBibleStudyRulesViewModelAction : GuardedActionWithParameter, IInitializeBibleStudyRulesViewModelAction { private readonly IStatisticsClient _statisticsClient; - private readonly IAppLanguageProvider _appLanguageProvider; private IBibleStudyRulesViewModel DataContext => this.GetDataContext(); - public InitializeBibleStudyRulesViewModelAction( - IStatisticsClient statisticsClient, - IAppLanguageProvider appLanguageProvider) + public InitializeBibleStudyRulesViewModelAction(IStatisticsClient statisticsClient) { _statisticsClient = statisticsClient; - _appLanguageProvider = appLanguageProvider; } protected override async Task Execute(int projectId) { - var projectRules = await _statisticsClient.GetProjectRules(_appLanguageProvider.GetAppLanguage(), projectId); + var projectRules = await _statisticsClient.GetProjectRules(projectId); var items = new List(); DataContext.Title = projectRules.PageTitle; diff --git a/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyViewModelAction.cs b/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyViewModelAction.cs index 67e9de102..4e457b365 100644 --- a/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyViewModelAction.cs +++ b/BMM.Core/GuardedActions/BibleStudy/InitializeBibleStudyViewModelAction.cs @@ -7,7 +7,6 @@ using BMM.Core.Helpers; using BMM.Core.Implementations.Device; using BMM.Core.Implementations.Factories.Streak; -using BMM.Core.Implementations.Languages; using BMM.Core.Implementations.UI; using BMM.Core.Models.POs.BibleStudy; using BMM.Core.Models.POs.Other; @@ -27,7 +26,6 @@ public class InitializeBibleStudyViewModelAction : GuardedAction, IInitializeBib private readonly IMvxNavigationService _mvxNavigationService; private readonly IDeepLinkHandler _deepLinkHandler; private readonly IUriOpener _uriOpener; - private readonly IAppLanguageProvider _appLanguageProvider; private readonly IDeviceInfo _deviceInfo; private readonly IMediaPlayer _mediaPlayer; @@ -41,7 +39,6 @@ public InitializeBibleStudyViewModelAction( IMvxNavigationService mvxNavigationService, IDeepLinkHandler deepLinkHandler, IUriOpener uriOpener, - IAppLanguageProvider appLanguageProvider, IDeviceInfo deviceInfo, IMediaPlayer mediaPlayer) { @@ -52,14 +49,13 @@ public InitializeBibleStudyViewModelAction( _mvxNavigationService = mvxNavigationService; _deepLinkHandler = deepLinkHandler; _uriOpener = uriOpener; - _appLanguageProvider = appLanguageProvider; _deviceInfo = deviceInfo; _mediaPlayer = mediaPlayer; } protected override async Task Execute() { - var projectProgress = await _statisticsClient.GetProjectProgress(_appLanguageProvider.GetAppLanguage(), await _deviceInfo.GetCurrentTheme()); + var projectProgress = await _statisticsClient.GetProjectProgress(await _deviceInfo.GetCurrentTheme()); UpdateUnlockedAchievements(projectProgress); diff --git a/BMM.Core/GuardedActions/Documents/Interfaces/ITranslateDocsAction.cs b/BMM.Core/GuardedActions/Documents/Interfaces/ITranslateDocsAction.cs deleted file mode 100644 index 7ce83d4c1..000000000 --- a/BMM.Core/GuardedActions/Documents/Interfaces/ITranslateDocsAction.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using BMM.Api.Implementation.Models; -using BMM.Core.GuardedActions.Base.Interfaces; - -namespace BMM.Core.GuardedActions.Documents.Interfaces -{ - public interface ITranslateDocsAction : IGuardedActionWithParameterAndResult, IList> - { - } -} \ No newline at end of file diff --git a/BMM.Core/GuardedActions/Documents/TranslateDocsAction.cs b/BMM.Core/GuardedActions/Documents/TranslateDocsAction.cs deleted file mode 100644 index a3246de8a..000000000 --- a/BMM.Core/GuardedActions/Documents/TranslateDocsAction.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using BMM.Api.Implementation.Models; -using BMM.Core.Extensions; -using BMM.Core.GuardedActions.Base; -using BMM.Core.GuardedActions.Documents.Interfaces; -using BMM.Core.Implementations.Localization.Interfaces; - -namespace BMM.Core.GuardedActions.Documents -{ - public class TranslateDocsAction - : GuardedActionWithParameterAndResult, IList>, - ITranslateDocsAction - { - private readonly IBMMLanguageBinder _bmmLanguageBinder; - - public TranslateDocsAction(IBMMLanguageBinder bmmLanguageBinder) - { - _bmmLanguageBinder = bmmLanguageBinder; - } - - protected override async Task> Execute(IList docs) - { - await Task.CompletedTask; - var adjustedDocs = docs.ToList(); - - foreach (var document in adjustedDocs) - { - HandleDiscoverSection(document); - HandleInfoMessage(document); - } - - return adjustedDocs; - } - - private void HandleDiscoverSection(Document document) - { - if (!(document is DiscoverSectionHeader sectionHeader)) - return; - - sectionHeader.Title = _bmmLanguageBinder.GetTranslationsSafe(sectionHeader.GetTranslationKey(), sectionHeader.Title); - } - - private void HandleInfoMessage(Document document) - { - if (!(document is InfoMessage infoMessage)) - return; - - infoMessage.MessageText = _bmmLanguageBinder.GetTranslationsSafe(infoMessage.GetTranslationKey(), infoMessage.TranslatedMessage); - } - } -} \ No newline at end of file diff --git a/BMM.Core/GuardedActions/Player/UpdateExternalRelationsAction.cs b/BMM.Core/GuardedActions/Player/UpdateExternalRelationsAction.cs index 0a10cc6ea..2cd82cea3 100644 --- a/BMM.Core/GuardedActions/Player/UpdateExternalRelationsAction.cs +++ b/BMM.Core/GuardedActions/Player/UpdateExternalRelationsAction.cs @@ -1,14 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Threading.Tasks; using BMM.Api.Abstraction; using BMM.Api.Implementation.Models; using BMM.Api.Utils; -using BMM.Core.Constants; using BMM.Core.Extensions; using BMM.Core.GuardedActions.Base; using BMM.Core.GuardedActions.Player.Interfaces; @@ -16,13 +8,9 @@ using BMM.Core.Implementations.FirebaseRemoteConfig; using BMM.Core.Implementations.Languages; using BMM.Core.Implementations.Region.Interfaces; -using BMM.Core.Implementations.UI; using BMM.Core.Models.Enums; -using BMM.Core.Translation; using BMM.Core.Utils; using BMM.Core.ViewModels.Interfaces; -using MvvmCross; -using Newtonsoft.Json; namespace BMM.Core.GuardedActions.Player { diff --git a/BMM.Core/Implementations/ApiClients/CachedDiscoverClientDecorator.cs b/BMM.Core/Implementations/ApiClients/CachedDiscoverClientDecorator.cs index 85eafe1ce..f0732f1dc 100644 --- a/BMM.Core/Implementations/ApiClients/CachedDiscoverClientDecorator.cs +++ b/BMM.Core/Implementations/ApiClients/CachedDiscoverClientDecorator.cs @@ -20,10 +20,10 @@ public CachedDiscoverClientDecorator(IDiscoverClient client, IClientCache client _clientCache = clientCache; } - public Task> GetDocuments(string lang, int? age, AppTheme theme, CachePolicy cachePolicy) + public Task> GetDocuments(int? age, AppTheme theme, CachePolicy cachePolicy) { return _clientCache.Get( - () => _client.GetDocuments(lang, age, theme, cachePolicy), + () => _client.GetDocuments(age, theme, cachePolicy), cachePolicy, TimeSpan.FromMinutes(30), CacheKeys.DiscoverGetDocuments diff --git a/BMM.Core/Implementations/ApiClients/CachedPlaylistClientDecorator.cs b/BMM.Core/Implementations/ApiClients/CachedPlaylistClientDecorator.cs index 381f9bf98..bd48ed3ea 100644 --- a/BMM.Core/Implementations/ApiClients/CachedPlaylistClientDecorator.cs +++ b/BMM.Core/Implementations/ApiClients/CachedPlaylistClientDecorator.cs @@ -43,10 +43,10 @@ public Task GetCover(int podcastId) return _client.GetCover(podcastId); } - public Task GetDocuments(string lang, int? age, CachePolicy cachePolicy) + public Task GetDocuments(int? age, CachePolicy cachePolicy) { return _clientCache.Get(() => - _client.GetDocuments(lang, age, cachePolicy), + _client.GetDocuments(age, cachePolicy), cachePolicy, TimeSpan.FromHours(1), CacheKeys.PlaylistGetDocument); diff --git a/BMM.Core/Implementations/ApiClients/HttpHeaderProviders.cs b/BMM.Core/Implementations/ApiClients/HttpHeaderProviders.cs index ba5d078c2..6a5881679 100644 --- a/BMM.Core/Implementations/ApiClients/HttpHeaderProviders.cs +++ b/BMM.Core/Implementations/ApiClients/HttpHeaderProviders.cs @@ -23,7 +23,8 @@ public IList GetProviders() Mvx.IoCProvider.Resolve(), Mvx.IoCProvider.Resolve(), Mvx.IoCProvider.Resolve(), - Mvx.IoCProvider.Resolve() + Mvx.IoCProvider.Resolve(), + Mvx.IoCProvider.Resolve() }; } } @@ -40,7 +41,8 @@ public IList GetProviders() Mvx.IoCProvider.Resolve(), Mvx.IoCProvider.Resolve(), Mvx.IoCProvider.Resolve(), - Mvx.IoCProvider.Resolve() + Mvx.IoCProvider.Resolve(), + Mvx.IoCProvider.Resolve() }; } } diff --git a/BMM.Core/Implementations/ApiClients/UiLanguageHeaderProvider.cs b/BMM.Core/Implementations/ApiClients/UiLanguageHeaderProvider.cs new file mode 100644 index 000000000..057a67f1c --- /dev/null +++ b/BMM.Core/Implementations/ApiClients/UiLanguageHeaderProvider.cs @@ -0,0 +1,20 @@ +using BMM.Api.Abstraction; +using BMM.Api.Implementation.Constants; +using BMM.Core.Implementations.Languages; + +namespace BMM.Core.Implementations.ApiClients; + +public class UiLanguageHeaderProvider : IHeaderProvider +{ + private readonly IAppLanguageProvider _appLanguageProvider; + + public UiLanguageHeaderProvider(IAppLanguageProvider appLanguageProvider) + { + _appLanguageProvider = appLanguageProvider; + } + + public async Task?> GetHeader() + { + return new KeyValuePair(HeaderNames.UiLanguage, _appLanguageProvider.GetAppLanguage()); + } +} \ No newline at end of file diff --git a/BMM.Core/Implementations/Downloading/GlobalMediaDownloader.cs b/BMM.Core/Implementations/Downloading/GlobalMediaDownloader.cs index 2bbbe540c..8dc34e3a3 100644 --- a/BMM.Core/Implementations/Downloading/GlobalMediaDownloader.cs +++ b/BMM.Core/Implementations/Downloading/GlobalMediaDownloader.cs @@ -18,7 +18,6 @@ using BMM.Core.Implementations.Exceptions; using BMM.Core.Implementations.FileStorage; using BMM.Core.Implementations.FirebaseRemoteConfig; -using BMM.Core.Implementations.Languages; using BMM.Core.Implementations.Security; using BMM.Core.Messages; using MvvmCross.Plugin.Messenger; @@ -33,7 +32,6 @@ public class GlobalMediaDownloader : IGlobalMediaDownloader private readonly IDownloadQueue _downloadQueue; private readonly IAppContentLogger _appContentLogger; private readonly IGlobalTrackProvider _globalTrackProvider; - private readonly IAppLanguageProvider _appLanguageProvider; private readonly IExceptionHandler _exceptionHandler; private readonly IMvxMessenger _messenger; private readonly INetworkSettings _networkSettings; @@ -53,7 +51,6 @@ public GlobalMediaDownloader(IStorageManager storageManager, IDownloadQueue downloadQueue, IAppContentLogger appContentLogger, IGlobalTrackProvider globalTrackProvider, - IAppLanguageProvider appLanguageProvider, IUserStorage user, IFirebaseRemoteConfig config, IDeviceInfo deviceInfo) @@ -68,7 +65,6 @@ public GlobalMediaDownloader(IStorageManager storageManager, _downloadQueue = downloadQueue; _appContentLogger = appContentLogger; _globalTrackProvider = globalTrackProvider; - _appLanguageProvider = appLanguageProvider; _user = user; _config = config; _deviceInfo = deviceInfo; @@ -143,8 +139,7 @@ private async Task RunSynchronizationTask(Func synchronizationTask, [Calle private async Task UpdateHomescreen() { var age = _config.SendAgeToDiscover ? _user.GetUser().Age : null; - await _client.Discover.GetDocuments(_appLanguageProvider.GetAppLanguage(), - age, + await _client.Discover.GetDocuments(age, await _deviceInfo.GetCurrentTheme(), CachePolicy.UseCacheAndWaitForUpdates); } diff --git a/BMM.Core/Implementations/Languages/AppLanguageProvider.cs b/BMM.Core/Implementations/Languages/AppLanguageProvider.cs index ca55bc9ab..6d30ae818 100644 --- a/BMM.Core/Implementations/Languages/AppLanguageProvider.cs +++ b/BMM.Core/Implementations/Languages/AppLanguageProvider.cs @@ -1,7 +1,4 @@ using System.Globalization; -using System.Linq; -using System.Reactive.Linq; -using Akavache; using BMM.Core.Constants; using BMM.Core.Helpers; using BMM.Core.Implementations.Localization; diff --git a/BMM.Core/ViewModels/BrowseDetailsListViewModel.cs b/BMM.Core/ViewModels/BrowseDetailsListViewModel.cs index 8dc59380c..22eac072e 100644 --- a/BMM.Core/ViewModels/BrowseDetailsListViewModel.cs +++ b/BMM.Core/ViewModels/BrowseDetailsListViewModel.cs @@ -1,12 +1,7 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using BMM.Api.Abstraction; -using BMM.Api.Implementation.Models; using BMM.Core.Constants; -using BMM.Core.Extensions; using BMM.Core.Implementations.Factories; using BMM.Core.Implementations.Factories.Tracks; -using BMM.Core.Models.POs.Base; using BMM.Core.Models.POs.Base.Interfaces; using BMM.Core.ViewModels.Base; using BMM.Core.ViewModels.Interfaces; @@ -34,7 +29,7 @@ public string Title public override async Task> LoadItems(int startIndex, int size, CachePolicy policy) { var response = await Client.Browse.GetDocuments(_path, startIndex, size); - Title = TextSource.GetTranslationsSafe(response.GetTranslationKey(), response.Title); + Title = response.Title; IsFullyLoaded = !response.SupportsPaging; return _documentsPOFactory.Create( response.Items, diff --git a/BMM.Core/ViewModels/BrowseViewModel.cs b/BMM.Core/ViewModels/BrowseViewModel.cs index d202542ac..f2109a2d3 100644 --- a/BMM.Core/ViewModels/BrowseViewModel.cs +++ b/BMM.Core/ViewModels/BrowseViewModel.cs @@ -12,24 +12,20 @@ public class BrowseViewModel : DocumentsViewModel { private readonly IDocumentsPOFactory _documentsPOFactory; private readonly IPrepareCoversCarouselItemsAction _prepareCoversCarouselItemsAction; - private readonly ITranslateDocsAction _translateDocsAction; public BrowseViewModel( IDocumentsPOFactory documentsPOFactory, - IPrepareCoversCarouselItemsAction prepareCoversCarouselItemsAction, - ITranslateDocsAction translateDocsAction) + IPrepareCoversCarouselItemsAction prepareCoversCarouselItemsAction) { _documentsPOFactory = documentsPOFactory; _prepareCoversCarouselItemsAction = prepareCoversCarouselItemsAction; - _translateDocsAction = translateDocsAction; } public override async Task> LoadItems(CachePolicy policy = CachePolicy.UseCacheAndRefreshOutdated) { var browseItems = await Client.Browse.Get(policy); - var translatedItems = await _translateDocsAction.ExecuteGuarded(browseItems.ToList()); - var carouselAdjustedItems = await _prepareCoversCarouselItemsAction.ExecuteGuarded(translatedItems); + var carouselAdjustedItems = await _prepareCoversCarouselItemsAction.ExecuteGuarded(browseItems.ToList()); var presentationItems = _documentsPOFactory.Create( carouselAdjustedItems, diff --git a/BMM.Core/ViewModels/CuratedPlaylistsViewModel.cs b/BMM.Core/ViewModels/CuratedPlaylistsViewModel.cs index 1a4936906..e5c3ba7c6 100644 --- a/BMM.Core/ViewModels/CuratedPlaylistsViewModel.cs +++ b/BMM.Core/ViewModels/CuratedPlaylistsViewModel.cs @@ -1,15 +1,9 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using BMM.Api.Abstraction; -using BMM.Api.Implementation.Models; +using BMM.Api.Abstraction; using BMM.Core.Extensions; using BMM.Core.GuardedActions.Documents.Interfaces; using BMM.Core.Implementations.Caching; using BMM.Core.Implementations.Factories; -using BMM.Core.Implementations.Languages; using BMM.Core.Implementations.Security; -using BMM.Core.Models.POs.Base; using BMM.Core.Models.POs.Base.Interfaces; using BMM.Core.Models.POs.Other; using BMM.Core.ViewModels.Base; @@ -18,23 +12,16 @@ namespace BMM.Core.ViewModels { public class CuratedPlaylistsViewModel : DocumentsViewModel { - private readonly IAppLanguageProvider _appLanguageProvider; private readonly IUserStorage _userStorage; - private readonly ITranslateDocsAction _translateDocsAction; private readonly IPrepareCoversCarouselItemsAction _prepareCoversCarouselItemsAction; private readonly IDocumentsPOFactory _documentsPOFactory; public override CacheKeys? CacheKey => CacheKeys.PlaylistGetAll; - public CuratedPlaylistsViewModel( - IAppLanguageProvider appLanguageProvider, - IUserStorage userStorage, - ITranslateDocsAction translateDocsAction, + public CuratedPlaylistsViewModel(IUserStorage userStorage, IPrepareCoversCarouselItemsAction prepareCoversCarouselItemsAction, IDocumentsPOFactory documentsPOFactory) { - _appLanguageProvider = appLanguageProvider; _userStorage = userStorage; - _translateDocsAction = translateDocsAction; _prepareCoversCarouselItemsAction = prepareCoversCarouselItemsAction; _documentsPOFactory = documentsPOFactory; } @@ -43,10 +30,9 @@ public override async Task> LoadItems(CachePolicy polic { var playlistsDocuments = await Client .Playlist - .GetDocuments(_appLanguageProvider.GetAppLanguage(), _userStorage.GetUser().Age, policy); + .GetDocuments(_userStorage.GetUser().Age, policy); - var translatedItems = await _translateDocsAction.ExecuteGuarded(playlistsDocuments.Items.ToList()); - var carouselAdjustedItems = await _prepareCoversCarouselItemsAction.ExecuteGuarded(translatedItems); + var carouselAdjustedItems = await _prepareCoversCarouselItemsAction.ExecuteGuarded(playlistsDocuments.Items.ToList()); var presentationItems = _documentsPOFactory.Create( carouselAdjustedItems, diff --git a/BMM.Core/ViewModels/ExploreNewestViewModel.cs b/BMM.Core/ViewModels/ExploreNewestViewModel.cs index 89ae46b22..c023f6179 100644 --- a/BMM.Core/ViewModels/ExploreNewestViewModel.cs +++ b/BMM.Core/ViewModels/ExploreNewestViewModel.cs @@ -1,13 +1,7 @@ -using System; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Linq; using BMM.Api.Abstraction; -using BMM.Api.Implementation.Clients.Contracts; using BMM.Api.Implementation.Models; using BMM.Core.Constants; using BMM.Core.Extensions; -using BMM.Core.GuardedActions.BibleStudy; using BMM.Core.GuardedActions.BibleStudy.Interfaces; using BMM.Core.GuardedActions.ContinueListening.Interfaces; using BMM.Core.GuardedActions.Documents.Interfaces; @@ -19,15 +13,11 @@ using BMM.Core.Implementations.Device; using BMM.Core.Implementations.Factories.Streak; using BMM.Core.Implementations.FirebaseRemoteConfig; -using BMM.Core.Implementations.Languages; using BMM.Core.Implementations.PlayObserver.Streak; using BMM.Core.Implementations.Security; using BMM.Core.Implementations.TrackInformation.Strategies; -using BMM.Core.Implementations.UI.StyledText; -using BMM.Core.Implementations.UI.StyledText.Enums; using BMM.Core.Messages; using BMM.Core.Messages.MediaPlayer; -using BMM.Core.Models.POs.Base; using BMM.Core.Models.POs.Base.Interfaces; using BMM.Core.Models.POs.Other; using BMM.Core.Models.POs.Tiles; @@ -46,8 +36,6 @@ public class ExploreNewestViewModel : DocumentsViewModel private readonly INavigateToViewModelAction _navigateToViewModelAction; private readonly IPrepareCoversCarouselItemsAction _prepareCoversCarouselItemsAction; private readonly IPrepareTileCarouselItemsAction _prepareTileCarouselItemsAction; - private readonly ITranslateDocsAction _translateDocsAction; - private readonly IAppLanguageProvider _appLanguageProvider; private readonly IUserStorage _user; private readonly IFirebaseRemoteConfig _config; private readonly IListeningStreakPOFactory _listeningStreakPOFactory; @@ -63,8 +51,6 @@ public ExploreNewestViewModel( INavigateToViewModelAction navigateToViewModelAction, IPrepareCoversCarouselItemsAction prepareCoversCarouselItemsAction, IPrepareTileCarouselItemsAction prepareTileCarouselItemsAction, - ITranslateDocsAction translateDocsAction, - IAppLanguageProvider appLanguageProvider, IUserStorage user, IFirebaseRemoteConfig config, IListeningStreakPOFactory listeningStreakPOFactory, @@ -77,8 +63,6 @@ public ExploreNewestViewModel( _navigateToViewModelAction = navigateToViewModelAction; _prepareCoversCarouselItemsAction = prepareCoversCarouselItemsAction; _prepareTileCarouselItemsAction = prepareTileCarouselItemsAction; - _translateDocsAction = translateDocsAction; - _appLanguageProvider = appLanguageProvider; _user = user; _config = config; _listeningStreakPOFactory = listeningStreakPOFactory; @@ -118,12 +102,11 @@ private void RefreshContinueListeningItems() public override async Task> LoadItems(CachePolicy policy = CachePolicy.UseCacheAndRefreshOutdated) { var age = _config.SendAgeToDiscover ? _user.GetUser().Age : null; - var docs = (await Client.Discover.GetDocuments(_appLanguageProvider.GetAppLanguage(), age, await _deviceInfo.GetCurrentTheme() , policy)).ToList(); + var docs = (await Client.Discover.GetDocuments(age, await _deviceInfo.GetCurrentTheme() , policy)).ToList(); await _streakObserver.UpdateStreakIfLocalVersionIsNewer(docs); bool hideStreak = await _settings.GetStreakHidden(); var filteredDocs = HideStreakInList(hideStreak, HideTeaserPodcastsInList(docs)); - var translatedDocs = await _translateDocsAction.ExecuteGuarded(filteredDocs); - var docsWithCoversCarousel = await _prepareCoversCarouselItemsAction.ExecuteGuarded(translatedDocs); + var docsWithCoversCarousel = await _prepareCoversCarouselItemsAction.ExecuteGuarded(filteredDocs); var presentationItems = await _prepareTileCarouselItemsAction.ExecuteGuarded(docsWithCoversCarousel); SetAdditionalElements(presentationItems); return presentationItems; diff --git a/BMM.Core/ViewModels/TrackCollectionViewModel.cs b/BMM.Core/ViewModels/TrackCollectionViewModel.cs index 0455a04b4..b7e1a0f4d 100644 --- a/BMM.Core/ViewModels/TrackCollectionViewModel.cs +++ b/BMM.Core/ViewModels/TrackCollectionViewModel.cs @@ -73,7 +73,10 @@ ITrackPOFactory trackPOFactory public override IEnumerable PlaybackOrigin() { - return new[] {MyCollection.Id.ToString(), MyCollection.Name}; + var owner = MyCollection.CanEdit + ? "Owner" + : "Shared"; + return new[] {MyCollection.Id.ToString(), MyCollection.Name, owner}; } protected override Task Initialization() diff --git a/BMM.Tests/BMM.Core.Test/Unit/Implementations/Downloading/GlobalMediaDownloaderTests.cs b/BMM.Tests/BMM.Core.Test/Unit/Implementations/Downloading/GlobalMediaDownloaderTests.cs index a6c4a5557..765311d12 100644 --- a/BMM.Tests/BMM.Core.Test/Unit/Implementations/Downloading/GlobalMediaDownloaderTests.cs +++ b/BMM.Tests/BMM.Core.Test/Unit/Implementations/Downloading/GlobalMediaDownloaderTests.cs @@ -38,7 +38,6 @@ public class GlobalMediaDownloaderTests private Mock _appContentLogger; private Mock _globalTrackProvider; private readonly FakeTrackFactory _fakeTrackFactory = new FakeTrackFactory(); - private Mock _appLanguageProvider; private List TrackOfflineTracks => new List { @@ -61,10 +60,9 @@ public void Init() _downloadQueue = new Mock(); _appContentLogger = new Mock(); _globalTrackProvider = new Mock(); - _appLanguageProvider = new Mock(); var discoverClient = new Mock(); - discoverClient.Setup(x => x.GetDocuments(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + discoverClient.Setup(x => x.GetDocuments(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(new List()); _client.Setup(x => x.Discover).Returns(discoverClient.Object); _connection.Setup(x => x.GetStatus()).Returns(ConnectionStatus.Online); @@ -91,7 +89,6 @@ public GlobalMediaDownloader CreateGlobalMediaDownloader() _downloadQueue.Object, _appContentLogger.Object, _globalTrackProvider.Object, - _appLanguageProvider.Object, userStorage.Object, config.Object, deviceInfo.Object