Skip to content

Feature/mvvm refactor - #6

Merged
ThanhTrunggDEV merged 17 commits into
masterfrom
feature/mvvm-refactor
Feb 3, 2026
Merged

Feature/mvvm refactor#6
ThanhTrunggDEV merged 17 commits into
masterfrom
feature/mvvm-refactor

Conversation

@ThanhTrunggDEV

Copy link
Copy Markdown
Collaborator

No description provided.

- Add Core/ViewModelBase.cs - INotifyPropertyChanged implementation
- Add Core/RelayCommand.cs - Command pattern for WPF
- Add Core/Mediator/ - Event Aggregator for ViewModel communication
- Add Core/DI/ServiceLocator.cs - Lightweight DI container
- Add Core/Bootstrapper.cs - Composition root for DI registration
- Add Core/ServiceAdapters.cs - Adapter pattern for existing services
- Add Interfaces/IServices.cs - Service interfaces (SOLID)
- Add ViewModels/ - Separated ViewModels for each tab:
  * HunterViewModel - Content Hunter tab
  * DownloadViewModel - YouTube/TikTok download tab
  * BilibiliViewModel - Bilibili download tab
  * EditorViewModel - Video editor tab
  * ReviewViewModel - Auto review tab
  * AIToolsViewModel - AI tools tab
  * MainViewModel - Main window coordinator

Design Patterns applied:
- MVVM (Model-View-ViewModel)
- Mediator Pattern (Event Aggregator)
- Command Pattern (RelayCommand)
- Adapter Pattern (ServiceAdapters)
- Service Locator Pattern (DI Container)
- Singleton Pattern (EventAggregator)

SOLID Principles:
- Single Responsibility: Each ViewModel handles one tab
- Open/Closed: Adapters extend without modifying
- Interface Segregation: Separate service interfaces
- Dependency Inversion: ViewModels depend on abstractions
- Fixed ServiceLocator generic constraints for proper DI registration
- Created simplified ViewModels that match actual Service APIs
- ViewModels: Hunter, Download, Bilibili, Editor, Review, AITools, Main
- Core: ViewModelBase, RelayCommand<T>, AsyncRelayCommand<T>
- Mediator: EventAggregator for cross-ViewModel communication
- ServiceAdapters: Adapter pattern wrapping existing services
- Interfaces: IServices matching actual service contracts
- Bootstrapper: Composition root with proper service registration

Design Patterns Used:
- MVVM (Model-View-ViewModel)
- Command Pattern (RelayCommand, AsyncRelayCommand)
- Adapter Pattern (ServiceAdapters)
- Mediator Pattern (EventAggregator)
- Service Locator (lightweight DI)
- Facade Pattern (MainViewModel)

SOLID Principles Applied:
- Single Responsibility: Each ViewModel handles one tab
- Interface Segregation: Separate interfaces per service
- Dependency Inversion: ViewModels depend on abstractions
- Update App.xaml.cs: Initialize Bootstrapper on startup, cleanup on exit
- Update MainWindowPro.xaml.cs: Add ViewModel property and set DataContext
- MVVM infrastructure is now properly initialized and connected to the view
- Existing code-behind continues to work alongside the new MVVM pattern
- Add Views folder with UserControl for each tab:
  - BilibiliView: Bilibili download with data binding
  - HunterView: Content hunting with ObservableCollection
  - DownloadView: General download with progress binding
  - EditorView: Video editing with trim/extract features
  - ReviewView: Auto review with progress tracking
  - AIToolsView: TTS and STT with command binding
- Add MainShell.xaml: New MVVM main window with tab navigation
- Update App.xaml: StartupUri now points to Views/MainShell.xaml
- All Views use ViewModels via ServiceLocator.Resolve
- Commands bound to AsyncRelayCommand for async operations
- Progress bars bound to ViewModel properties
- Status text bound with INotifyPropertyChanged
- Fixed XAML parse error: Token is not valid
- Background gradient is already defined in Button.Style
- App now compiles and starts without XAML errors
- Keep original UI/frontend (2105 lines XAML)
- MainWindowPro already has ViewModel wired in constructor
- MVVM infrastructure (ViewModels, Commands, DI) remains intact
- Next: Add data binding to existing XAML controls
- Created Views/Tabs/BilibiliTab.xaml with original UI design (160 lines)
- BilibiliTab.xaml.cs exposes all controls via public properties
- Updated MainWindowPro.xaml to use BilibiliTab UserControl
- Added xmlns:tabs namespace for UserControls
- Changed Bilibili event handlers from private to public in MainWindowPro.xaml.cs
- MainWindowPro uses helper properties to access BilibiliTab controls
- Successfully built and tested - app runs correctly
- Reduced MainWindowPro.xaml from 2105 lines (still long but first tab extracted)

This is the first step in splitting the monolithic MainWindowPro.xaml.
Next: Extract remaining tabs (YouTube, TikTok, Hunter, etc.)
Created UserControls:
- Views/Tabs/YouTubeTab.xaml (140 lines) with 17 control properties
- Views/Tabs/TikTokTab.xaml (170 lines) with 15 control properties

Changes in MainWindowPro.xaml:
- Replaced YouTube TabItem content with YouTubeTab UserControl
- Replaced TikTok TabItem content with TikTokTab UserControl
- Reduced MainWindowPro.xaml by ~400 lines (from 1959 to ~1600 lines)

Changes in MainWindowPro.xaml.cs:
- Added 37 helper properties for YouTube and TikTok controls
- Changed 9 event handlers from private to public (YouTubeParse_Click, YouTubeDownload_Click, YouTubeBrowse_Click, YouTubeCancel_Click, TikTokUrl_GotFocus, TikTokParse_Click, TikTokDownload_Click, TikTokBrowse_Click, TikTokCancel_Click)

Build: Successful (0 errors, 14 warnings)
Status: 3/8 tabs refactored (Bilibili, YouTube, TikTok)
Next: Hunter, Download, Editor, Review, AI Tools tabs
- Thêm method GetPageCountAsync() để đếm số tập của mỗi URL
- Thêm event EpisodeStarted để theo dõi progress từng tập
- Sửa logic download để phân tích tất cả URL trước khi tải
- Cập nhật progress bar hiển thị đúng số tập thực tế thay vì số URL
- Fix null reference warning trong ServiceAdapters.cs

Ví dụ: 2 URL (5 tập + 3 tập) = hiển thị 'Video 1/8' thay vì 'Video 1/2'
@ThanhTrunggDEV
ThanhTrunggDEV merged commit 3224b34 into master Feb 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant