Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for performance, readability and maintainability #210

Merged
merged 35 commits into from
Jul 27, 2024

Conversation

DineshSolanki
Copy link
Owner

No description provided.

@DineshSolanki DineshSolanki self-assigned this Jul 24, 2024
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.
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.
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.
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.
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.
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.
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.
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.
Simplify the file validation process by moving exclusion logic to `FileUtils`. Combined multiple conditions into a single method for clarity and maintainability.
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.
Separated complex logic within the `ResultPicked` method into smaller methods to improve code readability and maintainability. Introduced `PrepareRating`, `PickResult`, `SelectMtvType`, `CastResult`, and `AddToPickedList` methods.
created a utility method to generate poster url for IGDB, also fix the issue of poster preview not working in game mode
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.
Refactored PosterPickerViewModel to streamline media type handling by extracting methods for different media types. Improved readability and maintainability by reducing redundancy.
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.
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.
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.
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.
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.
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.
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.
Consolidate the logic for creating ListItem instances by introducing the TransformDetailsIntoListItem method. This reduces code duplication and simplifies updates.
Moved `UiUtil.ShowImageBrowser` method to `UiUtils` and updated all references to use the new location.
Moved ListView sorting logic from code-behind to a new behavior class `ListViewClickSortBehavior`.
…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
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.
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.
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.
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`.
Copy link

sonarcloud bot commented Jul 27, 2024

@DineshSolanki DineshSolanki added the enhancement New feature or request label Jul 27, 2024
@DineshSolanki DineshSolanki merged commit 7c54bda into master Jul 27, 2024
6 checks passed
@DineshSolanki DineshSolanki deleted the refactor branch July 27, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant