From 9b504126d031205558e74ad28c05f67c95a484c4 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 22 Nov 2015 01:35:26 +0100 Subject: [PATCH] Complete Mangafox and other minor changes --- .../data/source/online/english/Mangafox.java | 106 +++++++++++++++++- .../mangafeed/ui/reader/ReaderMenu.java | 21 +--- app/src/main/res/layout/reader_menu.xml | 12 +- 3 files changed, 114 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java index ca36d79312..217c50d7b0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java @@ -7,12 +7,17 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; +import java.util.Locale; -import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.source.model.MangasPage; @@ -179,16 +184,109 @@ public class Mangafox extends Source { @Override protected List parseHtmlToChapters(String unparsedHtml) { - return null; + Document parsedDocument = Jsoup.parse(unparsedHtml); + + List chapterList = new ArrayList(); + + Elements chapterElements = parsedDocument.select("div#chapters li div"); + for (Element chapterElement : chapterElements) { + Chapter currentChapter = constructChapterFromHtmlBlock(chapterElement); + + chapterList.add(currentChapter); + } + + return chapterList; + } + + private Chapter constructChapterFromHtmlBlock(Element chapterElement) { + Chapter newChapter = Chapter.create(); + + Element urlElement = chapterElement.select("a.tips").first(); + Element nameElement = chapterElement.select("a.tips").first(); + Element dateElement = chapterElement.select("span.date").first(); + + if (urlElement != null) { + newChapter.url = urlElement.attr("href"); + } + if (nameElement != null) { + newChapter.name = nameElement.text(); + } + if (dateElement != null) { + newChapter.date_upload = parseUpdateFromElement(dateElement); + } + + newChapter.date_fetch = new Date().getTime(); + + return newChapter; + } + + private long parseUpdateFromElement(Element updateElement) { + String updatedDateAsString = updateElement.text(); + + if (updatedDateAsString.contains("Today")) { + Calendar today = Calendar.getInstance(); + today.set(Calendar.HOUR_OF_DAY, 0); + today.set(Calendar.MINUTE, 0); + today.set(Calendar.SECOND, 0); + today.set(Calendar.MILLISECOND, 0); + + try { + Date withoutDay = new SimpleDateFormat("h:mm a", Locale.ENGLISH).parse(updatedDateAsString.replace("Today", "")); + return today.getTimeInMillis() + withoutDay.getTime(); + } catch (ParseException e) { + return today.getTimeInMillis(); + } + } else if (updatedDateAsString.contains("Yesterday")) { + Calendar yesterday = Calendar.getInstance(); + yesterday.add(Calendar.DATE, -1); + yesterday.set(Calendar.HOUR_OF_DAY, 0); + yesterday.set(Calendar.MINUTE, 0); + yesterday.set(Calendar.SECOND, 0); + yesterday.set(Calendar.MILLISECOND, 0); + + try { + Date withoutDay = new SimpleDateFormat("h:mm a", Locale.ENGLISH).parse(updatedDateAsString.replace("Yesterday", "")); + return yesterday.getTimeInMillis() + withoutDay.getTime(); + } catch (ParseException e) { + return yesterday.getTimeInMillis(); + } + } else { + try { + Date specificDate = new SimpleDateFormat("MMM d, yyyy", Locale.ENGLISH).parse(updatedDateAsString); + + return specificDate.getTime(); + } catch (ParseException e) { + // Do Nothing. + } + } + + return 0; } @Override protected List parseHtmlToPageUrls(String unparsedHtml) { - return null; + Document parsedDocument = Jsoup.parse(unparsedHtml); + + List pageUrlList = new ArrayList<>(); + + Elements pageUrlElements = parsedDocument.select("select.m").first().select("option:not([value=0])"); + String baseUrl = parsedDocument.select("div#series a").first().attr("href").replace("1.html", ""); + int counter = 1; + for (Element pageUrlElement : pageUrlElements) { + if(counter < pageUrlElements.size()) { + pageUrlList.add(baseUrl + pageUrlElement.attr("value") + ".html"); + } + counter++; + } + + return pageUrlList; } @Override protected String parseHtmlToImageUrl(String unparsedHtml) { - return null; + Document parsedDocument = Jsoup.parse(unparsedHtml); + + Element imageElement = parsedDocument.getElementById("image"); + return imageElement.attr("src"); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java index 97ef1d8e61..32f7f88513 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java @@ -190,22 +190,13 @@ public class ReaderMenu { } private void initializePopupMenu() { - subscriptions.add(preferences.enableTransitions() - .asObservable() - .subscribe(enableTransitions::setChecked)); - - subscriptions.add(preferences.showPageNumber() - .asObservable() - .subscribe(showPageNumber::setChecked)); - - subscriptions.add(preferences.hideStatusBar() - .asObservable() - .subscribe(hideStatusBar::setChecked)); - - subscriptions.add(preferences.keepScreenOn() - .asObservable() - .subscribe(keepScreenOn::setChecked)); + // Load values from preferences + enableTransitions.setChecked(preferences.enableTransitions().get()); + showPageNumber.setChecked(preferences.showPageNumber().get()); + hideStatusBar.setChecked(preferences.hideStatusBar().get()); + keepScreenOn.setChecked(preferences.keepScreenOn().get()); + // Add a listener to change the corresponding setting enableTransitions.setOnCheckedChangeListener((view, isChecked) -> preferences.enableTransitions().set(isChecked)); diff --git a/app/src/main/res/layout/reader_menu.xml b/app/src/main/res/layout/reader_menu.xml index 707a405e68..e4c1351c32 100644 --- a/app/src/main/res/layout/reader_menu.xml +++ b/app/src/main/res/layout/reader_menu.xml @@ -27,7 +27,7 @@ + android:layout_height="?attr/actionBarSize"> + android:layout_height="?attr/actionBarSize">