Complete Mangafox and other minor changes

This commit is contained in:
inorichi 2015-11-22 01:35:26 +01:00
parent 9dd9c995a8
commit 9b504126d0
3 changed files with 114 additions and 25 deletions

View File

@ -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<Chapter> parseHtmlToChapters(String unparsedHtml) {
return null;
Document parsedDocument = Jsoup.parse(unparsedHtml);
List<Chapter> chapterList = new ArrayList<Chapter>();
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<String> parseHtmlToPageUrls(String unparsedHtml) {
return null;
Document parsedDocument = Jsoup.parse(unparsedHtml);
List<String> 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");
}
}

View File

@ -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));

View File

@ -27,7 +27,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp">
android:layout_height="?attr/actionBarSize">
<TextView
android:id="@+id/current_page"
@ -66,11 +66,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp">
android:layout_height="?attr/actionBarSize">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/lock_orientation"
android:src="@drawable/ic_screen_rotation"
@ -78,13 +78,13 @@
android:background="?android:selectableItemBackground" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:background="?android:selectableItemBackground" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/reader_selector"
android:src="@drawable/ic_view_carousel"
@ -92,7 +92,7 @@
android:background="?android:selectableItemBackground" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/reader_extra_settings"
android:src="@drawable/ic_more_vert"