Merge remote-tracking branch 'inorichi/master'

This commit is contained in:
Yuri Revich 2015-11-30 20:49:42 +03:00
commit 82f1e694e8
15 changed files with 524 additions and 187 deletions

View file

@ -4,6 +4,7 @@ import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
import eu.kanade.mangafeed.data.database.tables.ChapterTable; import eu.kanade.mangafeed.data.database.tables.ChapterTable;
import eu.kanade.mangafeed.util.UrlUtil;
@StorIOSQLiteType(table = ChapterTable.TABLE) @StorIOSQLiteType(table = ChapterTable.TABLE)
public class Chapter { public class Chapter {
@ -44,6 +45,10 @@ public class Chapter {
public Chapter() {} public Chapter() {}
public void setUrl(String url) {
this.url = UrlUtil.getPath(url);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View file

@ -4,6 +4,7 @@ import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
import eu.kanade.mangafeed.data.database.tables.MangaTable; import eu.kanade.mangafeed.data.database.tables.MangaTable;
import eu.kanade.mangafeed.util.UrlUtil;
@StorIOSQLiteType(table = MangaTable.TABLE) @StorIOSQLiteType(table = MangaTable.TABLE)
public class Manga { public class Manga {
@ -57,6 +58,10 @@ public class Manga {
public Manga() {} public Manga() {}
public void setUrl(String url) {
this.url = UrlUtil.getPath(url);
}
public static void copyFromNetwork(Manga local, Manga network) { public static void copyFromNetwork(Manga local, Manga network) {
if (network.title != null) if (network.title != null)
local.title = network.title; local.title = network.title;

View file

@ -8,6 +8,7 @@ import java.util.List;
import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.source.base.Source;
import eu.kanade.mangafeed.data.source.online.english.Batoto; import eu.kanade.mangafeed.data.source.online.english.Batoto;
import eu.kanade.mangafeed.data.source.online.english.Kissmanga;
import eu.kanade.mangafeed.data.source.online.english.Mangafox; import eu.kanade.mangafeed.data.source.online.english.Mangafox;
import eu.kanade.mangafeed.data.source.online.english.Mangahere; import eu.kanade.mangafeed.data.source.online.english.Mangahere;
@ -16,6 +17,7 @@ public class SourceManager {
public static final int BATOTO = 1; public static final int BATOTO = 1;
public static final int MANGAHERE = 2; public static final int MANGAHERE = 2;
public static final int MANGAFOX = 3; public static final int MANGAFOX = 3;
public static final int KISSMANGA = 4;
private HashMap<Integer, Source> mSourcesMap; private HashMap<Integer, Source> mSourcesMap;
private Context context; private Context context;
@ -42,6 +44,8 @@ public class SourceManager {
return new Mangahere(context); return new Mangahere(context);
case MANGAFOX: case MANGAFOX:
return new Mangafox(context); return new Mangafox(context);
case KISSMANGA:
return new Kissmanga(context);
} }
return null; return null;
@ -51,6 +55,7 @@ public class SourceManager {
mSourcesMap.put(BATOTO, createSource(BATOTO)); mSourcesMap.put(BATOTO, createSource(BATOTO));
mSourcesMap.put(MANGAHERE, createSource(MANGAHERE)); mSourcesMap.put(MANGAHERE, createSource(MANGAHERE));
mSourcesMap.put(MANGAFOX, createSource(MANGAFOX)); mSourcesMap.put(MANGAFOX, createSource(MANGAFOX));
mSourcesMap.put(KISSMANGA, createSource(KISSMANGA));
} }
public List<Source> getSources() { public List<Source> getSources() {

View file

@ -20,6 +20,9 @@ public abstract class BaseSource {
// Id of the source (must be declared and obtained from SourceManager to avoid conflicts) // Id of the source (must be declared and obtained from SourceManager to avoid conflicts)
public abstract int getSourceId(); public abstract int getSourceId();
// Base url of the source, like: http://example.com
public abstract String getBaseUrl();
// True if the source requires a login // True if the source requires a login
public abstract boolean isLoginRequired(); public abstract boolean isLoginRequired();
@ -76,7 +79,7 @@ public abstract class BaseSource {
} }
// Get the URL of the first page that contains a source image and the page list // Get the URL of the first page that contains a source image and the page list
protected String overrideChapterPageUrl(String defaultPageUrl) { protected String overrideChapterUrl(String defaultPageUrl) {
return defaultPageUrl; return defaultPageUrl;
} }

View file

@ -2,6 +2,7 @@ package eu.kanade.mangafeed.data.source.base;
import android.content.Context; import android.content.Context;
import com.bumptech.glide.load.model.LazyHeaders;
import com.squareup.okhttp.Headers; import com.squareup.okhttp.Headers;
import com.squareup.okhttp.Response; import com.squareup.okhttp.Response;
@ -9,6 +10,7 @@ import org.jsoup.Jsoup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
@ -25,14 +27,16 @@ import rx.schedulers.Schedulers;
public abstract class Source extends BaseSource { public abstract class Source extends BaseSource {
@Inject protected NetworkHelper mNetworkService; @Inject protected NetworkHelper networkService;
@Inject protected CacheManager mCacheManager; @Inject protected CacheManager cacheManager;
@Inject protected PreferencesHelper prefs; @Inject protected PreferencesHelper prefs;
protected Headers mRequestHeaders; protected Headers requestHeaders;
protected LazyHeaders glideHeaders;
public Source(Context context) { public Source(Context context) {
App.get(context).getComponent().inject(this); App.get(context).getComponent().inject(this);
mRequestHeaders = headersBuilder().build(); requestHeaders = headersBuilder().build();
glideHeaders = glideHeadersBuilder().build();
} }
// Get the most popular mangas from the source // Get the most popular mangas from the source
@ -40,8 +44,8 @@ public abstract class Source extends BaseSource {
if (page.page == 1) if (page.page == 1)
page.url = getInitialPopularMangasUrl(); page.url = getInitialPopularMangasUrl();
return mNetworkService return networkService
.getStringResponse(page.url, mRequestHeaders, null) .getStringResponse(page.url, requestHeaders, null)
.map(Jsoup::parse) .map(Jsoup::parse)
.doOnNext(doc -> page.mangas = parsePopularMangasFromHtml(doc)) .doOnNext(doc -> page.mangas = parsePopularMangasFromHtml(doc))
.doOnNext(doc -> page.nextPageUrl = parseNextPopularMangasUrl(doc, page)) .doOnNext(doc -> page.nextPageUrl = parseNextPopularMangasUrl(doc, page))
@ -53,8 +57,8 @@ public abstract class Source extends BaseSource {
if (page.page == 1) if (page.page == 1)
page.url = getInitialSearchUrl(query); page.url = getInitialSearchUrl(query);
return mNetworkService return networkService
.getStringResponse(page.url, mRequestHeaders, null) .getStringResponse(page.url, requestHeaders, null)
.map(Jsoup::parse) .map(Jsoup::parse)
.doOnNext(doc -> page.mangas = parseSearchFromHtml(doc)) .doOnNext(doc -> page.mangas = parseSearchFromHtml(doc))
.doOnNext(doc -> page.nextPageUrl = parseNextSearchUrl(doc, page, query)) .doOnNext(doc -> page.nextPageUrl = parseNextSearchUrl(doc, page, query))
@ -63,21 +67,21 @@ public abstract class Source extends BaseSource {
// Get manga details from the source // Get manga details from the source
public Observable<Manga> pullMangaFromNetwork(final String mangaUrl) { public Observable<Manga> pullMangaFromNetwork(final String mangaUrl) {
return mNetworkService return networkService
.getStringResponse(overrideMangaUrl(mangaUrl), mRequestHeaders, null) .getStringResponse(getBaseUrl() + overrideMangaUrl(mangaUrl), requestHeaders, null)
.flatMap(unparsedHtml -> Observable.just(parseHtmlToManga(mangaUrl, unparsedHtml))); .flatMap(unparsedHtml -> Observable.just(parseHtmlToManga(mangaUrl, unparsedHtml)));
} }
// Get chapter list of a manga from the source // Get chapter list of a manga from the source
public Observable<List<Chapter>> pullChaptersFromNetwork(String mangaUrl) { public Observable<List<Chapter>> pullChaptersFromNetwork(final String mangaUrl) {
return mNetworkService return networkService
.getStringResponse(mangaUrl, mRequestHeaders, null) .getStringResponse(getBaseUrl() + mangaUrl, requestHeaders, null)
.flatMap(unparsedHtml -> .flatMap(unparsedHtml ->
Observable.just(parseHtmlToChapters(unparsedHtml))); Observable.just(parseHtmlToChapters(unparsedHtml)));
} }
public Observable<List<Page>> getCachedPageListOrPullFromNetwork(final String chapterUrl) { public Observable<List<Page>> getCachedPageListOrPullFromNetwork(final String chapterUrl) {
return mCacheManager.getPageUrlsFromDiskCache(chapterUrl) return cacheManager.getPageUrlsFromDiskCache(getChapterCacheKey(chapterUrl))
.onErrorResumeNext(throwable -> { .onErrorResumeNext(throwable -> {
return pullPageListFromNetwork(chapterUrl); return pullPageListFromNetwork(chapterUrl);
}) })
@ -85,8 +89,8 @@ public abstract class Source extends BaseSource {
} }
public Observable<List<Page>> pullPageListFromNetwork(final String chapterUrl) { public Observable<List<Page>> pullPageListFromNetwork(final String chapterUrl) {
return mNetworkService return networkService
.getStringResponse(overrideChapterPageUrl(chapterUrl), mRequestHeaders, null) .getStringResponse(getBaseUrl() + overrideChapterUrl(chapterUrl), requestHeaders, null)
.flatMap(unparsedHtml -> { .flatMap(unparsedHtml -> {
List<String> pageUrls = parseHtmlToPageUrls(unparsedHtml); List<String> pageUrls = parseHtmlToPageUrls(unparsedHtml);
return Observable.just(getFirstImageFromPageUrls(pageUrls, unparsedHtml)); return Observable.just(getFirstImageFromPageUrls(pageUrls, unparsedHtml));
@ -102,8 +106,8 @@ public abstract class Source extends BaseSource {
public Observable<Page> getImageUrlFromPage(final Page page) { public Observable<Page> getImageUrlFromPage(final Page page) {
page.setStatus(Page.LOAD_PAGE); page.setStatus(Page.LOAD_PAGE);
return mNetworkService return networkService
.getStringResponse(overridePageUrl(page.getUrl()), mRequestHeaders, null) .getStringResponse(overridePageUrl(page.getUrl()), requestHeaders, null)
.flatMap(unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml))) .flatMap(unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml)))
.onErrorResumeNext(e -> { .onErrorResumeNext(e -> {
page.setStatus(Page.ERROR); page.setStatus(Page.ERROR);
@ -123,13 +127,13 @@ public abstract class Source extends BaseSource {
return pageObservable return pageObservable
.flatMap(p -> { .flatMap(p -> {
if (!mCacheManager.isImageInCache(page.getImageUrl())) { if (!cacheManager.isImageInCache(page.getImageUrl())) {
return cacheImage(page); return cacheImage(page);
} }
return Observable.just(page); return Observable.just(page);
}) })
.flatMap(p -> { .flatMap(p -> {
page.setImagePath(mCacheManager.getImagePath(page.getImageUrl())); page.setImagePath(cacheManager.getImagePath(page.getImageUrl()));
page.setStatus(Page.READY); page.setStatus(Page.READY);
return Observable.just(page); return Observable.just(page);
}) })
@ -143,7 +147,7 @@ public abstract class Source extends BaseSource {
page.setStatus(Page.DOWNLOAD_IMAGE); page.setStatus(Page.DOWNLOAD_IMAGE);
return getImageProgressResponse(page) return getImageProgressResponse(page)
.flatMap(resp -> { .flatMap(resp -> {
if (!mCacheManager.putImageToDiskCache(page.getImageUrl(), resp)) { if (!cacheManager.putImageToDiskCache(page.getImageUrl(), resp)) {
throw new IllegalStateException("Unable to save image"); throw new IllegalStateException("Unable to save image");
} }
return Observable.just(page); return Observable.just(page);
@ -151,12 +155,12 @@ public abstract class Source extends BaseSource {
} }
public Observable<Response> getImageProgressResponse(final Page page) { public Observable<Response> getImageProgressResponse(final Page page) {
return mNetworkService.getProgressResponse(page.getImageUrl(), mRequestHeaders, page); return networkService.getProgressResponse(page.getImageUrl(), requestHeaders, page);
} }
public void savePageList(String chapterUrl, List<Page> pages) { public void savePageList(String chapterUrl, List<Page> pages) {
if (pages != null) if (pages != null)
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); cacheManager.putPageUrlsToDiskCache(getChapterCacheKey(chapterUrl), pages);
} }
protected List<Page> convertToPages(List<String> pageUrls) { protected List<Page> convertToPages(List<String> pageUrls) {
@ -174,4 +178,21 @@ public abstract class Source extends BaseSource {
return pages; return pages;
} }
protected String getChapterCacheKey(String chapterUrl) {
return getSourceId() + chapterUrl;
}
protected LazyHeaders.Builder glideHeadersBuilder() {
LazyHeaders.Builder builder = new LazyHeaders.Builder();
for (Map.Entry<String, List<String>> entry : requestHeaders.toMultimap().entrySet()) {
builder.addHeader(entry.getKey(), entry.getValue().get(0));
}
return builder;
}
public LazyHeaders getGlideHeaders() {
return glideHeaders;
}
} }

View file

@ -1,6 +1,7 @@
package eu.kanade.mangafeed.data.source.online.english; package eu.kanade.mangafeed.data.source.online.english;
import android.content.Context; import android.content.Context;
import android.net.Uri;
import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.Headers; import com.squareup.okhttp.Headers;
@ -33,13 +34,12 @@ public class Batoto extends Source {
public static final String NAME = "Batoto (EN)"; public static final String NAME = "Batoto (EN)";
public static final String BASE_URL = "http://bato.to"; public static final String BASE_URL = "http://bato.to";
public static final String INITIAL_POPULAR_MANGAS_URL = public static final String POPULAR_MANGAS_URL = BASE_URL + "/search_ajax?order_cond=views&order=desc&p=%d";
"http://bato.to/search_ajax?order_cond=views&order=desc&p="; public static final String SEARCH_URL = BASE_URL + "/search_ajax?name=%s&p=%s";
public static final String INITIAL_SEARCH_URL = "http://bato.to/search_ajax?"; public static final String CHAPTER_URL = "/areader?id=%s&p=1";
public static final String INITIAL_PAGE_URL = "http://bato.to/areader?"; public static final String PAGE_URL = BASE_URL + "/areader?id=%s&p=%s";
public static final String LOGIN_URL = public static final String MANGA_URL = "/comic_pop?id=%s";
"https://bato.to/forums/index.php?app=core&module=global&section=login"; public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global&section=login";
public Batoto(Context context) { public Batoto(Context context) {
super(context); super(context);
@ -50,6 +50,16 @@ public class Batoto extends Source {
return NAME; return NAME;
} }
@Override
public int getSourceId() {
return SourceManager.BATOTO;
}
@Override
public String getBaseUrl() {
return BASE_URL;
}
@Override @Override
protected Headers.Builder headersBuilder() { protected Headers.Builder headersBuilder() {
Headers.Builder builder = super.headersBuilder(); Headers.Builder builder = super.headersBuilder();
@ -103,11 +113,6 @@ public class Batoto extends Source {
return Observable.just(genres); return Observable.just(genres);
} }
@Override
public int getSourceId() {
return SourceManager.BATOTO;
}
@Override @Override
public boolean isLoginRequired() { public boolean isLoginRequired() {
return true; return true;
@ -115,24 +120,24 @@ public class Batoto extends Source {
@Override @Override
public String getInitialPopularMangasUrl() { public String getInitialPopularMangasUrl() {
return INITIAL_POPULAR_MANGAS_URL + "1"; return String.format(POPULAR_MANGAS_URL, 1);
} }
@Override @Override
public String getInitialSearchUrl(String query) { public String getInitialSearchUrl(String query) {
return INITIAL_SEARCH_URL + "name=" + query + "&p=1"; return String.format(SEARCH_URL, Uri.encode(query), 1);
} }
@Override @Override
protected String overrideMangaUrl(String defaultMangaUrl) { protected String overrideMangaUrl(String defaultMangaUrl) {
String mangaId = defaultMangaUrl.substring(defaultMangaUrl.lastIndexOf("r") + 1); String mangaId = defaultMangaUrl.substring(defaultMangaUrl.lastIndexOf("r") + 1);
return "http://bato.to/comic_pop?id=" + mangaId; return String.format(MANGA_URL, mangaId);
} }
@Override @Override
protected String overrideChapterPageUrl(String defaultPageUrl) { protected String overrideChapterUrl(String defaultPageUrl) {
String id = defaultPageUrl.substring(defaultPageUrl.indexOf("#") + 1); String id = defaultPageUrl.substring(defaultPageUrl.indexOf("#") + 1);
return INITIAL_PAGE_URL + "id=" + id + "&p=1"; return String.format(CHAPTER_URL, id);
} }
@Override @Override
@ -140,7 +145,7 @@ public class Batoto extends Source {
int start = defaultPageUrl.indexOf("#") + 1; int start = defaultPageUrl.indexOf("#") + 1;
int end = defaultPageUrl.indexOf("_", start); int end = defaultPageUrl.indexOf("_", start);
String id = defaultPageUrl.substring(start, end); String id = defaultPageUrl.substring(start, end);
return INITIAL_PAGE_URL + "id=" + id + "&p=" + defaultPageUrl.substring(end+1); return String.format(PAGE_URL, id, defaultPageUrl.substring(end+1));
} }
@Override @Override
@ -167,7 +172,7 @@ public class Batoto extends Source {
if (next == null) if (next == null)
return null; return null;
return INITIAL_POPULAR_MANGAS_URL + (page.page + 1); return String.format(POPULAR_MANGAS_URL, page.page + 1);
} }
@Override @Override
@ -192,22 +197,16 @@ public class Batoto extends Source {
Manga mangaFromHtmlBlock = new Manga(); Manga mangaFromHtmlBlock = new Manga();
Element urlElement = htmlBlock.select("a[href^=http://bato.to]").first(); Element urlElement = htmlBlock.select("a[href^=http://bato.to]").first();
Element nameElement = urlElement;
Element updateElement = htmlBlock.select("td").get(5); Element updateElement = htmlBlock.select("td").get(5);
mangaFromHtmlBlock.source = getSourceId(); mangaFromHtmlBlock.source = getSourceId();
if (urlElement != null) { if (urlElement != null) {
String fieldUrl = urlElement.attr("href"); mangaFromHtmlBlock.setUrl(urlElement.attr("href"));
mangaFromHtmlBlock.url = fieldUrl; mangaFromHtmlBlock.title = urlElement.text().trim();
}
if (nameElement != null) {
String fieldName = nameElement.text().trim();
mangaFromHtmlBlock.title = fieldName;
} }
if (updateElement != null) { if (updateElement != null) {
long fieldUpdate = parseUpdateFromElement(updateElement); mangaFromHtmlBlock.last_update = parseUpdateFromElement(updateElement);
mangaFromHtmlBlock.last_update = fieldUpdate;
} }
return mangaFromHtmlBlock; return mangaFromHtmlBlock;
@ -219,7 +218,7 @@ public class Batoto extends Source {
if (next == null) if (next == null)
return null; return null;
return INITIAL_SEARCH_URL + "name=" + query + "&p=" + (page.page + 1); return String.format(SEARCH_URL, query, page.page + 1);
} }
private long parseUpdateFromElement(Element updateElement) { private long parseUpdateFromElement(Element updateElement) {
@ -257,8 +256,7 @@ public class Batoto extends Source {
} }
} }
if (descriptionElement != null) { if (descriptionElement != null) {
String fieldDescription = descriptionElement.text().substring("Description:".length()).trim(); newManga.description = descriptionElement.text().substring("Description:".length()).trim();
newManga.description = fieldDescription;
} }
if (genreElements != null) { if (genreElements != null) {
String fieldGenres = ""; String fieldGenres = "";
@ -274,8 +272,7 @@ public class Batoto extends Source {
newManga.genre = fieldGenres; newManga.genre = fieldGenres;
} }
if (thumbnailUrlElement != null) { if (thumbnailUrlElement != null) {
String fieldThumbnailUrl = thumbnailUrlElement.attr("src"); newManga.thumbnail_url = thumbnailUrlElement.attr("src");
newManga.thumbnail_url = fieldThumbnailUrl;
} }
boolean fieldCompleted = unparsedHtml.contains("<td>Complete</td>"); boolean fieldCompleted = unparsedHtml.contains("<td>Complete</td>");
@ -309,20 +306,16 @@ public class Batoto extends Source {
Chapter newChapter = Chapter.create(); Chapter newChapter = Chapter.create();
Element urlElement = chapterElement.select("a[href^=http://bato.to/reader").first(); Element urlElement = chapterElement.select("a[href^=http://bato.to/reader").first();
Element nameElement = urlElement;
Element dateElement = chapterElement.select("td").get(4); Element dateElement = chapterElement.select("td").get(4);
if (urlElement != null) { if (urlElement != null) {
String fieldUrl = urlElement.attr("href"); String fieldUrl = urlElement.attr("href");
newChapter.url = fieldUrl; newChapter.setUrl(fieldUrl);
} newChapter.name = urlElement.text().trim();
if (nameElement != null) {
String fieldName = nameElement.text().trim();
newChapter.name = fieldName;
} }
if (dateElement != null) { if (dateElement != null) {
long fieldDate = parseDateFromElement(dateElement); newChapter.date_upload = parseDateFromElement(dateElement);
newChapter.date_upload = fieldDate;
} }
newChapter.date_fetch = new Date().getTime(); newChapter.date_fetch = new Date().getTime();
@ -357,12 +350,8 @@ public class Batoto extends Source {
} }
} else { } else {
// For webtoons in one page // For webtoons in one page
Element page = parsedDocument.select("div > a").first();
String url = page.attr("href");
url = BASE_URL + "/reader" + url.substring(0, url.length() - 1) + "f";
for (int i = 0; i < parsedDocument.select("div > img").size(); i++) { for (int i = 0; i < parsedDocument.select("div > img").size(); i++) {
pageUrlList.add(url); pageUrlList.add("");
} }
} }
@ -401,7 +390,7 @@ public class Batoto extends Source {
@Override @Override
public Observable<Boolean> login(String username, String password) { public Observable<Boolean> login(String username, String password) {
return mNetworkService.getStringResponse(LOGIN_URL, mRequestHeaders, null) return networkService.getStringResponse(LOGIN_URL, requestHeaders, null)
.flatMap(response -> doLogin(response, username, password)) .flatMap(response -> doLogin(response, username, password))
.map(this::isAuthenticationSuccessful); .map(this::isAuthenticationSuccessful);
} }
@ -420,7 +409,7 @@ public class Batoto extends Source {
formBody.add("invisible", "1"); formBody.add("invisible", "1");
formBody.add("rememberMe", "1"); formBody.add("rememberMe", "1");
return mNetworkService.postData(postUrl, formBody.build(), mRequestHeaders); return networkService.postData(postUrl, formBody.build(), requestHeaders);
} }
@Override @Override
@ -431,7 +420,7 @@ public class Batoto extends Source {
@Override @Override
public boolean isLogged() { public boolean isLogged() {
try { try {
for ( HttpCookie cookie : mNetworkService.getCookies().get(new URI(BASE_URL)) ) { for ( HttpCookie cookie : networkService.getCookies().get(new URI(BASE_URL)) ) {
if (cookie.getName().equals("pass_hash")) if (cookie.getName().equals("pass_hash"))
return true; return true;
} }

View file

@ -0,0 +1,257 @@
package eu.kanade.mangafeed.data.source.online.english;
import android.content.Context;
import android.net.Uri;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.Headers;
import com.squareup.okhttp.Response;
import org.jsoup.Jsoup;
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.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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;
import eu.kanade.mangafeed.data.source.model.Page;
import rx.Observable;
public class Kissmanga extends Source {
public static final String NAME = "Kissmanga (EN)";
public static final String HOST = "kissmanga.com";
public static final String IP = "93.174.95.110";
public static final String BASE_URL = "http://" + IP;
public static final String POPULAR_MANGAS_URL = BASE_URL + "/MangaList/MostPopular?page=%s";
public Kissmanga(Context context) {
super(context);
}
@Override
protected Headers.Builder headersBuilder() {
Headers.Builder builder = super.headersBuilder();
builder.add("Host", HOST);
return builder;
}
@Override
public String getName() {
return NAME;
}
@Override
public int getSourceId() {
return SourceManager.KISSMANGA;
}
@Override
public String getBaseUrl() {
return BASE_URL;
}
@Override
public boolean isLoginRequired() {
return false;
}
@Override
protected String getInitialPopularMangasUrl() {
return String.format(POPULAR_MANGAS_URL, 1);
}
@Override
protected String getInitialSearchUrl(String query) {
return null;
}
@Override
protected List<Manga> parsePopularMangasFromHtml(Document parsedHtml) {
List<Manga> mangaList = new ArrayList<>();
Elements mangaHtmlBlocks = parsedHtml.select("table.listing tr:gt(1)");
for (Element currentHtmlBlock : mangaHtmlBlocks) {
Manga currentManga = constructPopularMangaFromHtmlBlock(currentHtmlBlock);
mangaList.add(currentManga);
}
return mangaList;
}
private Manga constructPopularMangaFromHtmlBlock(Element htmlBlock) {
Manga mangaFromHtmlBlock = new Manga();
mangaFromHtmlBlock.source = getSourceId();
Element urlElement = htmlBlock.select("td a:eq(0)").first();
if (urlElement != null) {
mangaFromHtmlBlock.setUrl(urlElement.attr("href"));
mangaFromHtmlBlock.title = urlElement.text();
}
return mangaFromHtmlBlock;
}
@Override
protected String parseNextPopularMangasUrl(Document parsedHtml, MangasPage page) {
Element next = parsedHtml.select("li > a:contains( Next)").first();
if (next == null)
return null;
return String.format(POPULAR_MANGAS_URL, next.attr("href"));
}
@Override
protected List<Manga> parseSearchFromHtml(Document parsedHtml) {
return null;
}
@Override
protected String parseNextSearchUrl(Document parsedHtml, MangasPage page, String query) {
return null;
}
@Override
protected Manga parseHtmlToManga(String mangaUrl, String unparsedHtml) {
Document parsedDocument = Jsoup.parse(unparsedHtml);
Element infoElement = parsedDocument.select("div.barContent").first();
Element titleElement = infoElement.select("a.bigChar").first();
Element authorElement = infoElement.select("p:has(span:contains(Author:)) > a").first();
Element genreElement = infoElement.select("p:has(span:contains(Genres:)) > *:gt(0)").first();
Elements descriptionElement = infoElement.select("p:has(span:contains(Summary:)) ~ p");
Element thumbnailUrlElement = parsedDocument.select(".rightBox:eq(0) img").first();
Manga newManga = new Manga();
newManga.url = mangaUrl;
if (titleElement != null) {
newManga.title = titleElement.text();
}
if (authorElement != null) {
newManga.author = authorElement.text();
}
if (descriptionElement != null) {
newManga.description = descriptionElement.text();
}
if (genreElement != null) {
newManga.genre = genreElement.text();
}
if (thumbnailUrlElement != null) {
newManga.thumbnail_url = Uri.parse(thumbnailUrlElement.attr("src"))
.buildUpon().authority(IP).toString();
}
// if (statusElement != null) {
// boolean fieldCompleted = statusElement.text().contains("Completed");
// newManga.status = fieldCompleted + "";
// }
newManga.initialized = true;
return newManga;
}
@Override
protected List<Chapter> parseHtmlToChapters(String unparsedHtml) {
Document parsedDocument = Jsoup.parse(unparsedHtml);
List<Chapter> chapterList = new ArrayList<>();
Elements chapterElements = parsedDocument.select("table.listing tr:gt(1)");
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").first();
Element dateElement = chapterElement.select("td:eq(1)").first();
if (urlElement != null) {
newChapter.setUrl(urlElement.attr("href"));
newChapter.name = urlElement.text();
}
if (dateElement != null) {
try {
newChapter.date_upload = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).parse(dateElement.text()).getTime();
} catch (ParseException e) {
// Do Nothing.
}
}
newChapter.date_fetch = new Date().getTime();
return newChapter;
}
public Observable<List<Page>> pullPageListFromNetwork(final String chapterUrl) {
FormEncodingBuilder builder = new FormEncodingBuilder();
return networkService
.postData(getBaseUrl() + overrideChapterUrl(chapterUrl), builder.build(), requestHeaders)
.flatMap(networkService::mapResponseToString)
.flatMap(unparsedHtml -> {
List<String> pageUrls = parseHtmlToPageUrls(unparsedHtml);
return Observable.just(getFirstImageFromPageUrls(pageUrls, unparsedHtml));
});
}
@Override
protected List<String> parseHtmlToPageUrls(String unparsedHtml) {
Document parsedDocument = Jsoup.parse(unparsedHtml);
List<String> pageUrlList = new ArrayList<>();
int numImages = parsedDocument.select("#divImage img").size();
for (int i = 0; i < numImages; i++) {
pageUrlList.add("");
}
return pageUrlList;
}
@Override
protected List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
List<Page> pages = convertToPages(pageUrls);
Pattern p = Pattern.compile("lstImages.push\\(\"(.+?)\"");
Matcher m = p.matcher(unparsedHtml);
List<String> imageUrls = new ArrayList<>();
while (m.find()) {
imageUrls.add(m.group(1));
}
for (int i = 0; i < pages.size(); i++) {
pages.get(i).setImageUrl(imageUrls.get(i));
}
return pages;
}
@Override
protected String parseHtmlToImageUrl(String unparsedHtml) {
return null;
}
@Override
public Observable<Response> getImageProgressResponse(final Page page) {
return networkService.getProgressResponse(page.getImageUrl(), null, page);
}
}

View file

@ -1,6 +1,7 @@
package eu.kanade.mangafeed.data.source.online.english; package eu.kanade.mangafeed.data.source.online.english;
import android.content.Context; import android.content.Context;
import android.net.Uri;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -25,9 +26,9 @@ public class Mangafox extends Source {
public static final String NAME = "Mangafox (EN)"; public static final String NAME = "Mangafox (EN)";
public static final String BASE_URL = "http://mangafox.me"; public static final String BASE_URL = "http://mangafox.me";
public static final String INITIAL_POPULAR_MANGAS_URL = "http://mangafox.me/directory/"; public static final String POPULAR_MANGAS_URL = BASE_URL + "/directory/%s";
public static final String INITIAL_SEARCH_URL = public static final String SEARCH_URL =
"http://mangafox.me/search.php?name_method=cw&advopts=1&order=az&sort=name"; BASE_URL + "/search.php?name_method=cw&advopts=1&order=az&sort=name&name=%s&page=%s";
public Mangafox(Context context) { public Mangafox(Context context) {
super(context); super(context);
@ -43,6 +44,11 @@ public class Mangafox extends Source {
return SourceManager.MANGAFOX; return SourceManager.MANGAFOX;
} }
@Override
public String getBaseUrl() {
return BASE_URL;
}
@Override @Override
public boolean isLoginRequired() { public boolean isLoginRequired() {
return false; return false;
@ -50,12 +56,12 @@ public class Mangafox extends Source {
@Override @Override
protected String getInitialPopularMangasUrl() { protected String getInitialPopularMangasUrl() {
return INITIAL_POPULAR_MANGAS_URL; return String.format(POPULAR_MANGAS_URL, "");
} }
@Override @Override
protected String getInitialSearchUrl(String query) { protected String getInitialSearchUrl(String query) {
return INITIAL_SEARCH_URL + "&name=" + query + "&page=1"; return String.format(SEARCH_URL, Uri.encode(query), 1);
} }
@Override @Override
@ -78,7 +84,7 @@ public class Mangafox extends Source {
Element urlElement = htmlBlock.select("a.title").first(); Element urlElement = htmlBlock.select("a.title").first();
if (urlElement != null) { if (urlElement != null) {
mangaFromHtmlBlock.url = urlElement.attr("href"); mangaFromHtmlBlock.setUrl(urlElement.attr("href"));
mangaFromHtmlBlock.title = urlElement.text(); mangaFromHtmlBlock.title = urlElement.text();
} }
@ -91,7 +97,7 @@ public class Mangafox extends Source {
if (next == null) if (next == null)
return null; return null;
return INITIAL_POPULAR_MANGAS_URL + next.attr("href"); return String.format(POPULAR_MANGAS_URL, next.attr("href"));
} }
@Override @Override
@ -114,7 +120,7 @@ public class Mangafox extends Source {
Element urlElement = htmlBlock.select("a.series_preview").first(); Element urlElement = htmlBlock.select("a.series_preview").first();
if (urlElement != null) { if (urlElement != null) {
mangaFromHtmlBlock.url = urlElement.attr("href"); mangaFromHtmlBlock.setUrl(urlElement.attr("href"));
mangaFromHtmlBlock.title = urlElement.text(); mangaFromHtmlBlock.title = urlElement.text();
} }
@ -153,24 +159,19 @@ public class Mangafox extends Source {
newManga.title = title; newManga.title = title;
} }
if (artistElement != null) { if (artistElement != null) {
String fieldArtist = artistElement.text(); newManga.artist = artistElement.text();
newManga.artist = fieldArtist;
} }
if (authorElement != null) { if (authorElement != null) {
String fieldAuthor = authorElement.text(); newManga.author = authorElement.text();
newManga.author = fieldAuthor;
} }
if (descriptionElement != null) { if (descriptionElement != null) {
String fieldDescription = descriptionElement.text(); newManga.description = descriptionElement.text();
newManga.description = fieldDescription;
} }
if (genreElement != null) { if (genreElement != null) {
String fieldGenre = genreElement.text(); newManga.genre = genreElement.text();
newManga.genre = fieldGenre;
} }
if (thumbnailUrlElement != null) { if (thumbnailUrlElement != null) {
String fieldThumbnailUrl = thumbnailUrlElement.attr("src"); newManga.thumbnail_url = thumbnailUrlElement.attr("src");
newManga.thumbnail_url = fieldThumbnailUrl;
} }
// if (statusElement != null) { // if (statusElement != null) {
// boolean fieldCompleted = statusElement.text().contains("Completed"); // boolean fieldCompleted = statusElement.text().contains("Completed");
@ -206,7 +207,7 @@ public class Mangafox extends Source {
Element dateElement = chapterElement.select("span.date").first(); Element dateElement = chapterElement.select("span.date").first();
if (urlElement != null) { if (urlElement != null) {
newChapter.url = urlElement.attr("href"); newChapter.setUrl(urlElement.attr("href"));
} }
if (nameElement != null) { if (nameElement != null) {
newChapter.name = nameElement.text(); newChapter.name = nameElement.text();

View file

@ -1,6 +1,7 @@
package eu.kanade.mangafeed.data.source.online.english; package eu.kanade.mangafeed.data.source.online.english;
import android.content.Context; import android.content.Context;
import android.net.Uri;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -26,9 +27,8 @@ public class Mangahere extends Source {
public static final String NAME = "Mangahere (EN)"; public static final String NAME = "Mangahere (EN)";
public static final String BASE_URL = "http://www.mangahere.co"; public static final String BASE_URL = "http://www.mangahere.co";
public static final String POPULAR_MANGAS_URL = BASE_URL + "/directory/%s";
private static final String INITIAL_POPULAR_MANGAS_URL = "http://www.mangahere.co/directory/"; public static final String SEARCH_URL = BASE_URL + "/search.php?name=%s&page=%s";
private static final String INITIAL_SEARCH_URL = "http://www.mangahere.co/search.php?";
public Mangahere(Context context) { public Mangahere(Context context) {
super(context); super(context);
@ -44,6 +44,11 @@ public class Mangahere extends Source {
return SourceManager.MANGAHERE; return SourceManager.MANGAHERE;
} }
@Override
public String getBaseUrl() {
return BASE_URL;
}
@Override @Override
public boolean isLoginRequired() { public boolean isLoginRequired() {
return false; return false;
@ -51,12 +56,12 @@ public class Mangahere extends Source {
@Override @Override
protected String getInitialPopularMangasUrl() { protected String getInitialPopularMangasUrl() {
return INITIAL_POPULAR_MANGAS_URL; return String.format(POPULAR_MANGAS_URL, "");
} }
@Override @Override
protected String getInitialSearchUrl(String query) { protected String getInitialSearchUrl(String query) {
return INITIAL_SEARCH_URL + "name=" + query + "&page=1"; return String.format(SEARCH_URL, Uri.encode(query), 1);
} }
public Observable<List<String>> getGenres() { public Observable<List<String>> getGenres() {
@ -117,7 +122,7 @@ public class Mangahere extends Source {
Element urlElement = htmlBlock.select("div.title > a").first(); Element urlElement = htmlBlock.select("div.title > a").first();
if (urlElement != null) { if (urlElement != null) {
mangaFromHtmlBlock.url = urlElement.attr("href"); mangaFromHtmlBlock.setUrl(urlElement.attr("href"));
mangaFromHtmlBlock.title = urlElement.attr("title"); mangaFromHtmlBlock.title = urlElement.attr("title");
} }
@ -130,7 +135,7 @@ public class Mangahere extends Source {
if (next == null) if (next == null)
return null; return null;
return INITIAL_POPULAR_MANGAS_URL + next.attr("href"); return String.format(POPULAR_MANGAS_URL, next.attr("href"));
} }
@Override @Override
@ -153,7 +158,7 @@ public class Mangahere extends Source {
Element urlElement = htmlBlock.select("a.manga_info").first(); Element urlElement = htmlBlock.select("a.manga_info").first();
if (urlElement != null) { if (urlElement != null) {
mangaFromHtmlBlock.url = urlElement.attr("href"); mangaFromHtmlBlock.setUrl(urlElement.attr("href"));
mangaFromHtmlBlock.title = urlElement.text(); mangaFromHtmlBlock.title = urlElement.text();
} }
@ -231,20 +236,16 @@ public class Mangahere extends Source {
newManga.url = mangaUrl; newManga.url = mangaUrl;
if (artistElement != null) { if (artistElement != null) {
String fieldArtist = artistElement.text(); newManga.artist = artistElement.text();
newManga.artist = fieldArtist;
} }
if (authorElement != null) { if (authorElement != null) {
String fieldAuthor = authorElement.text(); newManga.author = authorElement.text();
newManga.author = fieldAuthor;
} }
if (descriptionElement != null) { if (descriptionElement != null) {
String fieldDescription = descriptionElement.text().substring(0, descriptionElement.text().length() - "Show less".length()); newManga.description = descriptionElement.text().substring(0, descriptionElement.text().length() - "Show less".length());
newManga.description = fieldDescription;
} }
if (genreElement != null) { if (genreElement != null) {
String fieldGenre = genreElement.text().substring("Genre(s):".length()); newManga.genre = genreElement.text().substring("Genre(s):".length());
newManga.genre = fieldGenre;
} }
if (statusElement != null) { if (statusElement != null) {
boolean fieldCompleted = statusElement.text().contains("Completed"); boolean fieldCompleted = statusElement.text().contains("Completed");
@ -258,8 +259,7 @@ public class Mangahere extends Source {
Element thumbnailUrlElement = parsedDocument.select("img").first(); Element thumbnailUrlElement = parsedDocument.select("img").first();
if (thumbnailUrlElement != null) { if (thumbnailUrlElement != null) {
String fieldThumbnailUrl = thumbnailUrlElement.attr("src"); newManga.thumbnail_url = thumbnailUrlElement.attr("src");
newManga.thumbnail_url = fieldThumbnailUrl;
} }
newManga.initialized = true; newManga.initialized = true;
@ -295,16 +295,13 @@ public class Mangahere extends Source {
Element dateElement = chapterElement.select("span.right").first(); Element dateElement = chapterElement.select("span.right").first();
if (urlElement != null) { if (urlElement != null) {
String fieldUrl = urlElement.attr("href"); newChapter.setUrl(urlElement.attr("href"));
newChapter.url = fieldUrl;
} }
if (nameElement != null) { if (nameElement != null) {
String fieldName = nameElement.text(); newChapter.name = nameElement.text();
newChapter.name = fieldName;
} }
if (dateElement != null) { if (dateElement != null) {
long fieldDate = parseDateFromElement(dateElement); newChapter.date_upload = parseDateFromElement(dateElement);
newChapter.date_upload = fieldDate;
} }
newChapter.date_fetch = new Date().getTime(); newChapter.date_fetch = new Date().getTime();

View file

@ -0,0 +1,78 @@
package eu.kanade.mangafeed.ui.catalogue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import java.util.ArrayList;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.models.Manga;
public class CatalogueAdapter extends ArrayAdapter<Manga> {
private CatalogueFragment fragment;
private LayoutInflater inflater;
public CatalogueAdapter(CatalogueFragment fragment) {
super(fragment.getActivity(), 0, new ArrayList<>());
this.fragment = fragment;
inflater = fragment.getActivity().getLayoutInflater();
}
@Override
public View getView(int position, View view, ViewGroup parent) {
Manga manga = getItem(position);
ViewHolder holder;
if (view != null) {
holder = (ViewHolder) view.getTag();
} else {
view = inflater.inflate(R.layout.item_catalogue, parent, false);
holder = new ViewHolder(view, fragment);
view.setTag(holder);
}
holder.onSetValues(manga);
return view;
}
static class ViewHolder {
@Bind(R.id.title) TextView title;
@Bind(R.id.author) TextView author;
@Bind(R.id.thumbnail) ImageView thumbnail;
CatalogueFragment fragment;
public ViewHolder(View view, CatalogueFragment fragment) {
this.fragment = fragment;
ButterKnife.bind(this, view);
}
public void onSetValues(Manga manga) {
title.setText(manga.title);
author.setText(manga.author);
if (manga.thumbnail_url != null) {
GlideUrl url = new GlideUrl(manga.thumbnail_url,
fragment.getPresenter().getSource().getGlideHeaders());
Glide.with(fragment)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.centerCrop()
.into(thumbnail);
} else {
thumbnail.setImageResource(android.R.color.transparent);
}
}
}
}

View file

@ -14,6 +14,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import java.util.List; import java.util.List;
@ -27,19 +28,16 @@ import eu.kanade.mangafeed.ui.manga.MangaActivity;
import eu.kanade.mangafeed.util.PageBundle; import eu.kanade.mangafeed.util.PageBundle;
import eu.kanade.mangafeed.widget.EndlessScrollListener; import eu.kanade.mangafeed.widget.EndlessScrollListener;
import nucleus.factory.RequiresPresenter; import nucleus.factory.RequiresPresenter;
import uk.co.ribot.easyadapter.EasyAdapter;
@RequiresPresenter(CataloguePresenter.class) @RequiresPresenter(CataloguePresenter.class)
public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> { public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
@Bind(R.id.gridView) GridView manga_list; @Bind(R.id.gridView) GridView gridView;
@Bind(R.id.progress) ProgressBar progress; @Bind(R.id.progress) ProgressBar progress;
@Bind(R.id.progress_grid) ProgressBar progressGrid;
@Bind(R.id.progress_grid) ProgressBar progress_grid; private CatalogueAdapter adapter;
private EndlessScrollListener scrollListener;
private EasyAdapter<Manga> adapter;
private EndlessScrollListener scroll_listener;
private String search; private String search;
public final static String SOURCE_ID = "source_id"; public final static String SOURCE_ID = "source_id";
@ -107,13 +105,9 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
} }
} }
public EasyAdapter<Manga> getAdapter() {
return adapter;
}
public void initializeAdapter() { public void initializeAdapter() {
adapter = new EasyAdapter<>(getActivity(), CatalogueHolder.class); adapter = new CatalogueAdapter(this);
manga_list.setAdapter(adapter); gridView.setAdapter(adapter);
} }
@OnItemClick(R.id.gridView) @OnItemClick(R.id.gridView)
@ -126,8 +120,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
} }
public void initializeScrollListener() { public void initializeScrollListener() {
scroll_listener = new EndlessScrollListener(this::requestNext); scrollListener = new EndlessScrollListener(this::requestNext);
manga_list.setOnScrollListener(scroll_listener); gridView.setOnScrollListener(scrollListener);
} }
public void requestNext() { public void requestNext() {
@ -140,21 +134,22 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
} }
public void showGridProgressBar() { public void showGridProgressBar() {
progress_grid.setVisibility(ProgressBar.VISIBLE); progressGrid.setVisibility(ProgressBar.VISIBLE);
} }
public void hideProgressBar() { public void hideProgressBar() {
progress.setVisibility(ProgressBar.GONE); progress.setVisibility(ProgressBar.GONE);
progress_grid.setVisibility(ProgressBar.GONE); progressGrid.setVisibility(ProgressBar.GONE);
} }
public void onAddPage(PageBundle<List<Manga>> page) { public void onAddPage(PageBundle<List<Manga>> page) {
hideProgressBar(); hideProgressBar();
if (page.page == 0) { if (page.page == 0) {
adapter.getItems().clear(); gridView.setSelection(0);
scroll_listener.resetScroll(); adapter.clear();
scrollListener.resetScroll();
} }
adapter.addItems(page.data); adapter.addAll(page.data);
} }
private int getMangaIndex(Manga manga) { private int getMangaIndex(Manga manga) {
@ -170,8 +165,8 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
if (position == -1) if (position == -1)
return null; return null;
View v = manga_list.getChildAt(position - View v = gridView.getChildAt(position -
manga_list.getFirstVisiblePosition()); gridView.getFirstVisiblePosition());
if(v == null) if(v == null)
return null; return null;
@ -182,8 +177,11 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
public void updateImage(Manga manga) { public void updateImage(Manga manga) {
ImageView imageView = getImageView(getMangaIndex(manga)); ImageView imageView = getImageView(getMangaIndex(manga));
if (imageView != null) { if (imageView != null) {
GlideUrl url = new GlideUrl(manga.thumbnail_url,
getPresenter().getSource().getGlideHeaders());
Glide.with(this) Glide.with(this)
.load(manga.thumbnail_url) .load(url)
.centerCrop() .centerCrop()
.into(imageView); .into(imageView);
} }

View file

@ -1,47 +0,0 @@
package eu.kanade.mangafeed.ui.catalogue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import java.util.Objects;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.models.Manga;
import uk.co.ribot.easyadapter.ItemViewHolder;
import uk.co.ribot.easyadapter.PositionInfo;
import uk.co.ribot.easyadapter.annotations.LayoutId;
import uk.co.ribot.easyadapter.annotations.ViewId;
@LayoutId(R.layout.item_catalogue)
public class CatalogueHolder extends ItemViewHolder<Manga> {
@ViewId(R.id.title) TextView title;
@ViewId(R.id.author) TextView author;
@ViewId(R.id.thumbnail) ImageView thumbnail;
public CatalogueHolder(View view) {
super(view);
}
@Override
public void onSetValues(Manga manga, PositionInfo positionInfo) {
title.setText(manga.title);
author.setText(manga.author);
if (manga.thumbnail_url != null) {
Glide.with(getContext())
.load(manga.thumbnail_url)
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.centerCrop()
.into(thumbnail);
} else {
thumbnail.setImageResource(android.R.color.transparent);
}
}
}

View file

@ -201,4 +201,8 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
restartRequest(); restartRequest();
} }
public Source getSource() {
return selectedSource;
}
} }

View file

@ -0,0 +1,21 @@
package eu.kanade.mangafeed.util;
import java.net.URI;
import java.net.URISyntaxException;
public class UrlUtil {
public static String getPath(String s) {
try {
URI uri = new URI(s);
String out = uri.getPath();
if (uri.getQuery() != null)
out += "?" + uri.getQuery();
if (uri.getFragment() != null)
out += "#" + uri.getFragment();
return out;
} catch (URISyntaxException e) {
return s;
}
}
}

View file

@ -7,7 +7,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="50dp"
tools:text="New Text" tools:text="New Text"
android:id="@+id/source_name" android:id="@+id/source_name"
android:gravity="center_vertical" android:gravity="center_vertical"