Skip to content

Commit

Permalink
Merge pull request #118 from Suwayomi/Suwayomi-exclusive-tracking
Browse files Browse the repository at this point in the history
Suwayomi exclusive tracking
  • Loading branch information
aless2003 authored May 21, 2024
2 parents 682b4af + 731a05a commit 214e95d
Show file tree
Hide file tree
Showing 25 changed files with 1,134 additions and 636 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}

group = 'online.hatsunemiku'
version = '1.7.0'
version = '1.8.0'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<summary>Desktop client for Tachidesk</summary>
<description>
<p>
Tachidesk-VaadinUI is a UI for the Tachidesk Server. It is written in Java and uses Vaadin as UI framework.
Tachidesk-VaadinUI is a Manga reader using Suwayomi.
</p>
</description>
<launchable type="desktop-id">online.hatsune_miku.tachidesk-vaadinui.desktop</launchable>
Expand Down Expand Up @@ -42,9 +42,10 @@
</screenshot>
</screenshots>
<releases>
<release version="1.6.1" date="2024-04-09">
<release version="1.8.0" date="2024-05-20">
<description>
<p>Fixed a bug with AniList import authentication</p>
<p>Returned to Suwayomi Tracking method</p>
<p>MAL has been disabled for certain versions of Suwayomi. Use AniList Instead.</p>
</description>
</release>
</releases>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import online.hatsunemiku.tachideskvaadinui.component.dialog.tracking.provider.TrackerProvider;
import online.hatsunemiku.tachideskvaadinui.data.tachidesk.TrackerType;
import online.hatsunemiku.tachideskvaadinui.data.tracking.Tracker;
import online.hatsunemiku.tachideskvaadinui.data.tracking.search.TrackerSearchResult;
import online.hatsunemiku.tachideskvaadinui.services.TrackingDataService;
import org.jetbrains.annotations.NotNull;
Expand All @@ -28,26 +30,31 @@

/** Represents a dialog for choosing and tracking a manga. */
public class TrackingMangaChoiceDialog extends Dialog {

/**
* Constructs a {@link TrackingMangaChoiceDialog}.
*
* @param mangaName the name of the manga to search
* @param mangaId the ID of the manga on Suwayomi
* @param trackerProvider the {@link TrackerProvider} to use for tracking activities.
* @param dataService the {@link TrackingDataService} to use for saving tracking data.
* @param trackerType the {@link TrackerType} to use for tracking.
*/
public TrackingMangaChoiceDialog(
String mangaName,
int mangaId,
TrackerProvider trackerProvider,
TrackingDataService dataService) {
TrackingDataService dataService,
TrackerType trackerType) {

this.setClassName("tracking-manga-choice-dialog");

TextField searchField = new TextField("Search Manga");
searchField.setValue(mangaName);

var mangaList = trackerProvider.search(mangaName);
Tracker mangaTracker = dataService.getTracker(mangaId);

var mangaList = trackerProvider.search(mangaName, trackerType);

AtomicReference<TrackerSearchResult> selectedManga = new AtomicReference<>();

Expand Down Expand Up @@ -83,7 +90,7 @@ public TrackingMangaChoiceDialog(
return;
}

var results = trackerProvider.search(value);
var results = trackerProvider.search(value, trackerType);
mangaList.clear();

mangaList.addAll(results);
Expand Down Expand Up @@ -121,15 +128,15 @@ public TrackingMangaChoiceDialog(

boolean isPrivate = trackerProvider.canSetPrivate() && privateCheckbox.getValue();

trackerProvider.submitToTracker(isPrivate, mangaId, manga.getRemoteId());
trackerProvider.submitToTracker(isPrivate, mangaId, manga.getRemoteId(), trackerType);

switch (trackerProvider.getTrackerType()) {
case MAL -> dataService.getTracker(mangaId).setMalId(remoteId);
case ANILIST -> dataService.getTracker(mangaId).setAniListId(remoteId);
switch (trackerType) {
case MAL -> mangaTracker.setMalId(remoteId);
case ANILIST -> mangaTracker.setAniListId(remoteId);
default -> throw new IllegalArgumentException("Invalid tracker type");
}

dataService.getTracker(mangaId).setPrivate(isPrivate);
mangaTracker.setPrivate(isPrivate);

close();
});
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import java.util.List;
import lombok.AllArgsConstructor;
import online.hatsunemiku.tachideskvaadinui.component.dialog.tracking.provider.TrackerProvider;
import online.hatsunemiku.tachideskvaadinui.data.tachidesk.Status;
import online.hatsunemiku.tachideskvaadinui.data.tachidesk.TrackRecord;
import online.hatsunemiku.tachideskvaadinui.data.tachidesk.TrackerType;
import online.hatsunemiku.tachideskvaadinui.data.tracking.Tracker;
import online.hatsunemiku.tachideskvaadinui.data.tracking.search.TrackerSearchResult;
import online.hatsunemiku.tachideskvaadinui.data.tracking.statistics.MangaStatistics;
import online.hatsunemiku.tachideskvaadinui.services.tracker.SuwayomiTrackingService;

/**
Expand All @@ -18,7 +23,7 @@
* It implements the {@link TrackerProvider} interface.
*/
@AllArgsConstructor
public abstract class SuwayomiProvider implements TrackerProvider {
public class SuwayomiProvider implements TrackerProvider {

protected SuwayomiTrackingService suwayomiAPI;

Expand All @@ -27,17 +32,91 @@ public boolean canSetPrivate() {
return false;
}

@Override
public List<TrackerSearchResult> search(String query) {
return suwayomiAPI.searchMAL(query);
/**
* Searches for trackers based on the provided query and tracker type.
*
* @param query The search query.
* @param type The {@link TrackerType} to search through.
* @return A list of {@link TrackerSearchResult} objects representing the search results. If the
* tracker type is neither MAL nor AniList, it <b>returns an empty list</b>.
*/
public List<TrackerSearchResult> search(String query, TrackerType type) {
if (type == TrackerType.MAL) {
return suwayomiAPI.searchMAL(query);
} else if (type == TrackerType.ANILIST) {
return suwayomiAPI.searchAniList(query);
} else {
return List.of();
}
}

@Override
public void submitToTracker(boolean isPrivate, int mangaId, int externalId) {
public void submitToTracker(
boolean isPrivate, int mangaId, int externalId, TrackerType trackerType) {
if (isPrivate) {
throw new IllegalArgumentException("Suwayomi does not support private entries");
}

suwayomiAPI.trackOnMAL(mangaId, externalId);
if (trackerType == TrackerType.MAL) {
suwayomiAPI.trackOnMAL(mangaId, externalId);
} else if (trackerType == TrackerType.ANILIST) {
suwayomiAPI.trackOnAniList(mangaId, externalId);
}
}

@Override
public MangaStatistics getStatistics(Tracker tracker) {
TrackRecord record = getTrackRecord(tracker);

if (record == null) {
throw new IllegalArgumentException("No record found for tracker");
}

return suwayomiAPI.getStatistics(record);
}

@Override
public Integer getMaxChapter(Tracker tracker) {
TrackRecord record = getTrackRecord(tracker);

if (record == null) {
throw new IllegalArgumentException("No record found for tracker");
}

return record.getTotalChapters();
}

/**
* Retrieves the tracking record for a given tracker.
*
* @param tracker The {@link Tracker} for which to retrieve the tracking record.
* @return The {@link TrackRecord} for the provided tracker, or {@code null} if the tracker does
* not have a MAL ID or an AniList ID.
*/
private TrackRecord getTrackRecord(Tracker tracker) {
if (tracker.hasMalId()) {
return suwayomiAPI.getTrackRecordMAL(tracker.getMangaId());
} else if (tracker.hasAniListId()) {
return suwayomiAPI.getTrackRecordAniList(tracker.getMangaId());
} else {
return null;
}
}

/**
* Retrieves the list of statuses for a given tracker.
*
* @param tracker The {@link Tracker} for which to retrieve the statuses.
* @return A list of {@link Status} objects representing the statuses for the tracker.
* @throws IllegalArgumentException if no tracking record is found for the provided tracker.
*/
public List<Status> getTrackerStatuses(Tracker tracker) {
TrackRecord record = getTrackRecord(tracker);

if (record == null) {
throw new IllegalArgumentException("No record found for tracker");
}

return suwayomiAPI.getStatuses(record);
}
}
Loading

0 comments on commit 214e95d

Please sign in to comment.