Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor for performance, readability and maintainability (#210)
* chore: Use string interpolation instead of concatenation * Refactor code for improved readability and maintainability Several changes were made to the codebase to improve code readability and maintainability. These include the restructuring of multiple conditional statements, improved logger messaging, deletion of unnecessary comments and spaces, modification of class and method visibility, and alteration of class structure and parameters for better performance and clarity. * refactor: code quality and maintainability issues * Refactor code for better readability and async treatment Several synchronous methods have been transformed into asynchronous tasks across ViewModel and utilities. All the constructors in the classes ListItem and PickedListItem were refactored into property initialization for better readability. Also, localization strings now use the LangProvider directly for language access. These significant changes will improve the codebase's maintainability. * Refactor: Simplify SearchResult data load method Refactored the LoadData method in SearchResultViewModel.cs for better readability and logical flow. Extracted complex search result checks into a separate private method, HasSearchResult(). This makes the code cleaner and more maintainable by avoiding nested ternary operations and deep if conditions. * Refactor media type string properties and detail-fetching logic The commit alters properties in the MediaTypes class to be constants rather than static getters. In the FileUtils class, it refactors the multipart conditional logic for fetching media details into a switch expression and separate helper methods for cleaner, more maintainable code. * Refactor: Simplify Search method in MainWindowViewModel Previously, item processing was complex and involved many nested conditions. This made it difficult to understand and maintain. Now, item processing is simplified by extracting it into separate methods: `ProcessItemAsync`, `ProcessResultsAsync`, `AddToFinalList`, and `ProcessSubfolders`. This change improves the code's readability and maintainability. * Refactor search result processing in ProSearchResultViewModel This update simplifies the result processing code in ProSearchResultViewModel by extracting reusable logic into separate methods. It also improves readability by breaking down complex conditions and loops into more manageable chunks. The handling of no results, processing of search results, and individual result items are now handled in their own methods. * Refactor: Make GetClientAccessTokenAsync private and awaitable Changed the GetClientAccessTokenAsync method from public to private as it does not need to be openly available. This method is now properly awaited in all calls to ensure sequential execution and prevent potential issues related to concurrency or incomplete tasks. * refactor: Implement auto-scroll behavior in ScrollViewers Extract auto-scroll logic into ScrollViewerBehavior and update XAML to use this new behavior. This cleaning encapsulates the auto-scroll functionality and removes redundant code, improving maintainability and readability. * fix total poster count * fix: Refactor file validation logic Simplify the file validation process by moving exclusion logic to `FileUtils`. Combined multiple conditions into a single method for clarity and maintainability. * refactor: Use MediaTypes constants for media type strings Replaced hardcoded media type strings with `MediaTypes` constants across the entire codebase for better maintainability and consistency. This change affects various modules including ProcessUtils, MainWindowViewModel, SearchResultViewModel, TmdbDataTransformer, DataUtils, TMDBService, and IgdbDataTransformer. * refactor: Segregate methods to simplify ResultPicked logic Separated complex logic within the `ResultPicked` method into smaller methods to improve code readability and maintainability. Introduced `PrepareRating`, `PickResult`, `SelectMtvType`, `CastResult`, and `AddToPickedList` methods. * refactor: Refactor image URL generation created a utility method to generate poster url for IGDB, also fix the issue of poster preview not working in game mode * refactor: Unified image handling with a new IImage interface Replaced direct image handling with `IImage` interface to streamline processing. Introduced `ArtworkWrapper` and `ImageDataWrapper` classes for better abstraction. Enhanced loading and processing logic for improved code clarity and maintainability. * refactor: Simplify media type handling in PosterPickerViewModel Refactored PosterPickerViewModel to streamline media type handling by extracting methods for different media types. Improved readability and maintainability by reducing redundancy. * refactor: modularize SearchAndMakeMethod in MainWindowViewModel Refactored SearchAndMakeMethod by extracting validation and initialization logic into separate helper methods. Improved code readability and maintainability by organizing related functionalities and reducing method complexity. * refactor for code quality * fix: Remove async/await from sync methods and add static modifier Refactored methods in PosterPickerViewModel to remove unnecessary async/await usage for synchronous operations. Made ProcessSubfolders method in MainWindowViewModel static to align it with its usage context. Added an async keyword to SearchAgainMethod to correctly await StartSearch execution in SearchResultViewModel. * refactor: Apply various code improvements and fixes Refined method visibility, improved formatting, and fixed minor logical issues. Specifically, adjusted method access modifiers to `static`, used concise collection initializations, and corrected string formatting issues. Reorganized namespaces and fixed inconsistency in the handling of media types and file attributes. * refactor: readability and code style Replaced switch with if-else in MainWindowViewModel for readability. Added exception for invalid search mode in TMDBService. Improved readability in FileUtils by adding braces around conditional return. * refactor: Extract dialog logic to ShowSearchResultDialog method Refactored dialog handling for search results into a separate method to reduce code duplication and improve readability. This change affects the processing of zero, single, and multiple result cases. * feature: Refactor and centralize PosterIcon code Unified PosterIcon classes into a base class to avoid code duplication and simplify maintenance. Updated class for different PosterIcon variants to extend from the new PosterIconBase class. * refactor: Centralize image opening logic Refactored the image opening logic by creating a centralized `ShowImageBrowser` method in `UiUtil` class. This reduces redundancy and improves maintainability across the `ProSearchResultViewModel`, `PosterPickerViewModel`, and `ManualExplorerViewModel` classes. * refactor: refactor data extraction to use a common method Consolidate the logic for creating ListItem instances by introducing the TransformDetailsIntoListItem method. This reduces code duplication and simplifies updates. * chore: Move ShowImageBrowser method to UiUtils Moved `UiUtil.ShowImageBrowser` method to `UiUtils` and updated all references to use the new location. * refactor: Move ListView sort logic to behavior class Moved ListView sorting logic from code-behind to a new behavior class `ListViewClickSortBehavior`. * chore: Remove unused using directives, and move most used directives to GlobalUsing pattern Unnecessary using directives have been removed across multiple files to clean up the codebase and move frequently used directives to Usings.cs to reduce clutter * fix: Improve error handling and remove unnecessary async Enhanced error handling in `ProcessUtils.cs` by adding detailed error messages and throwing `InvalidOperationException`. Removed the unnecessary ` async ` keyword from `LoadGameData` in `PosterPickerViewModel.cs` as the method does not contain any async operations. * refactor: Refactor TMDB data handling to use SearchResultData class Refactored TmdbDataTransformer to encapsulate result details into a new SearchResultData class. This change simplifies the method signatures and improves code readability by reducing parameter count. Added SearchResultData.cs to define the new data structure. * fix: add braces around if * refactor: Simplify MainWindowViewModel constructor Refactored MainWindowViewModel constructor by extracting property tracking, culture setup, and command line processing into separate methods for better readability and maintainability. Removed redundant initialization code and reorganized method calls for logical flow. * fix: Replace `ProgressInfo` with `ProgressBarData` Updated the codebase to replace the `ProgressInfo` class with `ProgressBarData`. This change affects all instances where progress information is handled, including UI bindings and method parameters. Additionally, added an attribute `[Localizable(false)]` to `IconUtils`. * chore: Add braces around if
- Loading branch information