feat: implement epub service, navigation service, and global error boundary with updated reader UI layouts
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
namespace NexusReader.UI.Shared.Services;
|
||||
|
||||
public interface IReaderNavigationService
|
||||
{
|
||||
int CurrentChapterIndex { get; }
|
||||
int TotalChapters { get; }
|
||||
string ChapterTitle { get; }
|
||||
|
||||
event Action OnNavigationChanged;
|
||||
|
||||
void GoToChapter(int index);
|
||||
void GoToNextChapter();
|
||||
void GoToPreviousChapter();
|
||||
void UpdateMetadata(int currentIndex, int totalChapters, string title);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace NexusReader.UI.Shared.Services;
|
||||
|
||||
public class ReaderNavigationService : IReaderNavigationService
|
||||
{
|
||||
public int CurrentChapterIndex { get; private set; } = 0;
|
||||
public int TotalChapters { get; private set; } = 1;
|
||||
public string ChapterTitle { get; private set; } = "Loading...";
|
||||
|
||||
public event Action? OnNavigationChanged;
|
||||
|
||||
public void GoToChapter(int index)
|
||||
{
|
||||
if (index < 0 || index >= TotalChapters) return;
|
||||
|
||||
CurrentChapterIndex = index;
|
||||
OnNavigationChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void GoToNextChapter()
|
||||
{
|
||||
if (CurrentChapterIndex < TotalChapters - 1)
|
||||
{
|
||||
GoToChapter(CurrentChapterIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void GoToPreviousChapter()
|
||||
{
|
||||
if (CurrentChapterIndex > 0)
|
||||
{
|
||||
GoToChapter(CurrentChapterIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMetadata(int currentIndex, int totalChapters, string title)
|
||||
{
|
||||
bool changed = false;
|
||||
if (CurrentChapterIndex != currentIndex) { CurrentChapterIndex = currentIndex; changed = true; }
|
||||
if (TotalChapters != totalChapters) { TotalChapters = totalChapters; changed = true; }
|
||||
if (ChapterTitle != title) { ChapterTitle = title; changed = true; }
|
||||
|
||||
if (changed)
|
||||
{
|
||||
OnNavigationChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user