Skip to content

Commit

Permalink
Add Localizable attribute and improve encapsulation
Browse files Browse the repository at this point in the history
Added the `[Localizable(false)]` attribute to various classes to exclude them from localization. Improved encapsulation by modifying access modifiers for properties and fields, ensuring private or protected access where appropriate. These changes help in better resource management and code maintainability.
  • Loading branch information
DineshSolanki committed Jul 29, 2024
1 parent 76c39ff commit 8ab08ac
Show file tree
Hide file tree
Showing 36 changed files with 97 additions and 67 deletions.
2 changes: 1 addition & 1 deletion FoliCon/Models/Constants/GlobalVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IconOverlay IconOverlayType()
};
}

public static readonly string MediaInfoFile = "info.folicon";
public const string MediaInfoFile = "info.folicon";

private static string IconOverlayTypeString =>
Services.Tracker.Store.GetData("PosterIconConfigViewModel")["p.IconOverlay"].ToString();
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Configuration/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.Configuration;

[Localizable(false)]
internal static class AssemblyInfo
{
public static string GetVersion()
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Convertor/BoolToPermissionTextConvertor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.Convertor;

[Localizable(false)]
public class BoolToPermissionTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Convertor/ImageCacheConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// Converts an image path to a BitmapImage with caching to improve performance and thread safety.
/// CREDIT: https://stackoverflow.com/a/37652158/8076598
/// </summary>
[Localizable(false)]
public class ImageCacheConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
15 changes: 8 additions & 7 deletions FoliCon/Modules/DeviantArt/DArt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

namespace FoliCon.Modules.DeviantArt;

[Localizable(false)]
public class DArt : BindableBase
{
private string _clientAccessToken;
private string _clientSecret;
private string _clientId;
private readonly string _clientId;

private readonly MemoryCache _cache = new(new MemoryCacheOptions());

private static readonly JsonSerializerSettings SerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore };
public string ClientId

private string ClientId
{
get => _clientId;
set => SetProperty(ref _clientId, value);
init => SetProperty(ref _clientId, value);
}

public string ClientSecret
private string ClientSecret
{
get => _clientSecret;
set => SetProperty(ref _clientSecret, value);
init => SetProperty(ref _clientSecret, value);
}

public string ClientAccessToken
private string ClientAccessToken
{
get => _clientAccessToken;
set => SetProperty(ref _clientAccessToken, value);
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Extension/BindingPathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FoliCon.Modules.Extension;

[Localizable(false)]
public static class BindingPathExtensions
{
private static readonly ImageCacheConverter ImageCacheConverter = new ();
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Extension/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.Extension;

[Localizable(false)]
public static class DialogServiceExtensions
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Extension/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.Extension;

[Localizable(false)]
public static class Extensions
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Extension/StreamExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace FoliCon.Modules.Extension;

[Localizable(false)]
public static class StreamExtensions
{
private static readonly ReaderOptions ReaderOptions = new() { ArchiveEncoding =
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/IGDB/IgdbDataTransformer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.IGDB;

[Localizable(false)]
public class IgdbDataTransformer(ref List<PickedListItem> listDataTable, ref List<ImageToDownload> imgDownloadList)
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
3 changes: 2 additions & 1 deletion FoliCon/Modules/IGDB/IgdbService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.IGDB;

[Localizable(false)]
public class IgdbService(ref IGDBClient serviceClient)
{
private const string ServiceClientIsNotInitialized = "Service Client is not initialized.";
Expand All @@ -19,7 +20,7 @@ public async Task<ResultResponse> SearchGameAsync(string query)
}

var r = await _serviceClient.QueryAsync<Game>(IGDBClient.Endpoints.Games,
$"search \"{query}\"; fields artworks.image_id, name,first_release_date,total_rating,summary,cover.*;");
$"""search "{query}"; fields artworks.image_id, name,first_release_date,total_rating,summary,cover.*;""");

return new ResultResponse
{
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/LangProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FoliCon.Properties.Langs;

[Localizable(false)]
public class LangProvider : INotifyPropertyChanged
{
private static string _cultureInfoStr;
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/Media/PngToIcoService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.Media;

[Localizable(false)]
public static class PngToIcoService
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
5 changes: 3 additions & 2 deletions FoliCon/Modules/TMDB/TMDBService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace FoliCon.Modules.TMDB;

[Localizable(false)]
internal class TmdbService
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down Expand Up @@ -114,8 +115,8 @@ public async Task<ResultResponse> SearchWithParamsAsync(ParsedTitle parsedTitle,
{
Logger.Debug("Searching for {ParsedTitle} in {SearchMode}", parsedTitle, searchMode);

var mediaType = "";
object? searchResult = null;
string mediaType;
object? searchResult;

switch (searchMode)
{
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/UI/CustomMessageBox.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.UI;

[Localizable(false)]
internal static class CustomMessageBox
{
public static MessageBoxInfo Ask(string messageBoxText, string caption)
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Modules/UI/FolderDragDropHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static void Control_DragOver(object sender, DragEventArgs e)
var dt = e.Data.GetData(DataFormats.FileDrop);
var data = (dt as Array)?.GetValue(0)?.ToString();

Logger.Trace("Control_DragOver: Data: {Data}", data ?? "null");
Logger.Trace("Control_DragOver: Data: {Data}", data);

e.Effects = Directory.Exists(data) ? DragDropEffects.Link : DragDropEffects.None;
e.Handled = true;
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/UI/HandyWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace FoliCon.Modules.UI;

[Localizable(false)]
public class HandyWindow : Window, IDialogWindow
{
static HandyWindow()
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Modules/UI/ListViewClickSortBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void OnClick(object sender, RoutedEventArgs e)
? Application.Current.Resources["HeaderTemplateArrowUp"] as DataTemplate
: Application.Current.Resources["HeaderTemplateArrowDown"] as DataTemplate;

// Remove arrow from previously sorted header
// Remove arrow from the previously sorted header
if (_lastHeaderClicked != null && _lastHeaderClicked != headerClicked)
{
_lastHeaderClicked.Column.HeaderTemplate = null;
Expand Down
25 changes: 13 additions & 12 deletions FoliCon/Modules/utils/CultureUtils.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
namespace FoliCon.Modules.utils;

[Localizable(false)]
public static class CultureUtils
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private static readonly Dictionary<Languages, string> LanguageCodes = new()
{
{ Languages.English, "en-US" },
{ Languages.Spanish, "es-MX" },
{ Languages.Arabic, "ar-SA" },
{ Languages.Russian, "ru-RU" },
{ Languages.Hindi, "hi-IN" },
{ Languages.Portuguese, "pt-PT" }
};

public static CultureInfo GetCultureInfoByLanguage(Languages language)
{
Logger.Debug("Getting CultureInfo by Language: {Language}", language);

var languageCodes = new Dictionary<Languages, string>
{
{ Languages.English, "en-US" },
{ Languages.Spanish, "es-MX" },
{ Languages.Arabic, "ar-SA" },
{ Languages.Russian, "ru-RU" },
{ Languages.Hindi, "hi-IN" },
{ Languages.Portuguese, "pt-PT" }
};

var langCode = languageCodes.GetValueOrDefault(language, "en-US");

var langCode = LanguageCodes.GetValueOrDefault(language, "en-US");
ConfigHelper.Instance.SetLang(langCode.Split("-")[0]);

return new CultureInfo(langCode);
Expand Down
5 changes: 3 additions & 2 deletions FoliCon/Modules/utils/DataUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.utils;

[Localizable(false)]
public static class DataUtils
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand All @@ -24,10 +25,10 @@ public static int GetResultCount(bool isPickedById, dynamic result, string searc
/// <returns>Formatted Rating value.</returns>
public static string FormatRating(double ratingInput)
{
Logger.Debug("Start FormatRatingString() - Input received : {RatingInput}", ratingInput);
Logger.Trace("Start FormatRatingString() - Input received : {RatingInput}", ratingInput);
var decimalPart = ratingInput % 1;
var formattedRatingValue = decimalPart > 0 ? ratingInput.ToString("0.##") : ratingInput.ToString("0");
Logger.Debug("End FormatRatingString() - Formatted Rating : {FormattedRatingValue}", formattedRatingValue);
Logger.Trace("End FormatRatingString() - Formatted Rating : {FormattedRatingValue}", formattedRatingValue);
return formattedRatingValue;
}

Expand Down
5 changes: 1 addition & 4 deletions FoliCon/Modules/utils/DialogUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public static VistaFolderBrowserDialog NewFolderBrowserDialog(string description
};
return folderBrowser;
}
public static VistaOpenFileDialog NewOpenFileDialog(string description)
{
return NewOpenFileDialog(description, "All files (*.*)|*.*");
}

public static VistaOpenFileDialog NewOpenFileDialog(string description, string filter)
{
Logger.Debug("Creating New Open File Dialog");
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/utils/StaTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace FoliCon.Modules.utils;

//Taken from-https://stackoverflow.com/a/16722767/8076598
[Localizable(false)]
public static class StaTask
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/utils/TitleCleaner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.Modules.utils;

[Localizable(false)]
internal static class TitleCleaner
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
1 change: 1 addition & 0 deletions FoliCon/ViewModels/AboutBoxViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace FoliCon.ViewModels;

[Localizable(false)]
public class AboutBoxViewModel : BindableBase, IDialogAware
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/ViewModels/ApiConfigurationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ApiConfigurationViewModel : BindableBase, IDialogAware
{
private string _title = "API Configuration";
private string _title = Lang.APIKeysConfiguration;
private string _dartClient;
private string _dartClientId;
private string _tmdbKey;
Expand Down
13 changes: 7 additions & 6 deletions FoliCon/ViewModels/CustomIconControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FoliCon.ViewModels;

[Localizable(false)]
public class CustomIconControlViewModel : BindableBase, IDialogAware, IFileDragDropTarget
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down Expand Up @@ -54,7 +55,7 @@ public bool IsUndoEnable
set => SetProperty(ref _isUndoEnable, value);
}

public string SelectedDirectory
private string SelectedDirectory
{
get => _selectedDirectory;
set
Expand All @@ -69,7 +70,7 @@ public string SelectedDirectory
}
}

public string SelectedIconsDirectory
private string SelectedIconsDirectory
{
get => _selectedIconsDirectory;
set
Expand All @@ -88,17 +89,17 @@ public string SelectedIconsDirectory
public ObservableCollection<string> Directories
{
get => _directories;
set => SetProperty(ref _directories, value);
private set => SetProperty(ref _directories, value);
}

public ObservableCollection<string> Icons
{
get => _icons;
set => SetProperty(ref _icons, value);
private set => SetProperty(ref _icons, value);
}
public int Index { get => _index; set => SetProperty(ref _index, value); }
public int TotalIcons { get => _totalIcons; set => SetProperty(ref _totalIcons, value); }
public bool StopSearch { get => _stopSearch; set => SetProperty(ref _stopSearch, value); }
private bool StopSearch { get => _stopSearch; set => SetProperty(ref _stopSearch, value); }
#region Declare Delegates

public DelegateCommand LoadDirectory { get; set; }
Expand Down Expand Up @@ -201,7 +202,7 @@ protected virtual void CloseDialog(string parameter)
RaiseRequestClose(new DialogResult(result));
}

public virtual void RaiseRequestClose(IDialogResult dialogResult) =>
protected virtual void RaiseRequestClose(IDialogResult dialogResult) =>
RequestClose?.Invoke(dialogResult);

public virtual bool CanCloseDialog() => true;
Expand Down
6 changes: 3 additions & 3 deletions FoliCon/ViewModels/DialogControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class DialogControlViewModel : BindableBase, IDialogAware
public string Message
{
get => _message;
set => SetProperty(ref _message, value);
private set => SetProperty(ref _message, value);
}

private string _title = "Notification";

public string Title
{
get => _title;
set => SetProperty(ref _title, value);
private set => SetProperty(ref _title, value);
}

public event Action<IDialogResult> RequestClose;
Expand All @@ -39,7 +39,7 @@ protected virtual void CloseDialog(string parameter)
RaiseRequestClose(new DialogResult(result));
}

public virtual void RaiseRequestClose(IDialogResult dialogResult)
protected virtual void RaiseRequestClose(IDialogResult dialogResult)
{
RequestClose?.Invoke(dialogResult);
}
Expand Down
Loading

0 comments on commit 8ab08ac

Please sign in to comment.