diff --git a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBActions.java b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBActions.java index fb446a6..973b114 100644 --- a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBActions.java +++ b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBActions.java @@ -1,96 +1,95 @@ - /* - * Clover - 4chan browser https://github.com/Floens/Clover/ - * Copyright (C) 2014 Floens - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.floens.chan.core.site.common.tinyib; +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.core.site.common.tinyib; - import static android.text.TextUtils.isEmpty; +import org.floens.chan.core.site.SiteAuthentication; +import org.floens.chan.core.site.common.CommonSite; +import org.floens.chan.core.site.common.MultipartHttpCall; +import org.floens.chan.core.site.http.Reply; +import org.floens.chan.core.site.http.ReplyResponse; +import org.jsoup.Jsoup; - import org.floens.chan.core.site.SiteAuthentication; - import org.floens.chan.core.site.common.CommonSite; - import org.floens.chan.core.site.common.MultipartHttpCall; - import org.floens.chan.core.site.http.Reply; - import org.floens.chan.core.site.http.ReplyResponse; - import org.jsoup.Jsoup; +import java.util.regex.Matcher; +import java.util.regex.Pattern; - import java.util.regex.Matcher; - import java.util.regex.Pattern; +import okhttp3.Response; - import okhttp3.Response; +import static android.text.TextUtils.isEmpty; - public class TinyIBActions extends CommonSite.CommonActions { - public TinyIBActions(CommonSite commonSite) { - super(commonSite); - } +public class TinyIBActions extends CommonSite.CommonActions { + public TinyIBActions(CommonSite commonSite) { + super(commonSite); + } - @Override - public void setupPost(Reply reply, MultipartHttpCall call) { - call.parameter("email", reply.options); + @Override + public void setupPost(Reply reply, MultipartHttpCall call) { + call.parameter("email", reply.options); - if (reply.file != null) { - call.fileParameter("file", reply.fileName, reply.file); - } + if (reply.file != null) { + call.fileParameter("file", reply.fileName, reply.file); + } - call.parameter("message", reply.comment); - call.parameter("name", reply.name); + call.parameter("message", reply.comment); + call.parameter("name", reply.name); - if (reply.loadable.isThreadMode()) { - call.parameter("parent", String.valueOf(reply.loadable.no)); - } + if (reply.loadable.isThreadMode()) { + call.parameter("parent", String.valueOf(reply.loadable.no)); + } - if (!isEmpty(reply.password)) { - call.parameter("password", reply.password); - } + if (!isEmpty(reply.password)) { + call.parameter("password", reply.password); + } - if (!isEmpty(reply.subject)) { - call.parameter("subject", reply.subject); - } - } + if (!isEmpty(reply.subject)) { + call.parameter("subject", reply.subject); + } + } - @Override - public void handlePost(ReplyResponse replyResponse, Response response, String result) { - // extract the data we need from matching the result - int threadNo = 0; - int postNo = 0; - Matcher res = resultPattern().matcher(result); - if (res.find()) { - threadNo = Integer.parseInt(res.group(1)); - postNo = Integer.parseInt(res.group(2)); - } - Matcher err = errorPattern().matcher(result); - if (err.find()) { - replyResponse.errorMessage = Jsoup.parse(err.group(1)).body().text(); - } else { - replyResponse.threadNo = threadNo; - replyResponse.postNo = postNo; - replyResponse.posted = true; - } - } + @Override + public void handlePost(ReplyResponse replyResponse, Response response, String result) { + // extract the data we need from matching the result + int threadNo = 0; + int postNo = 0; + Matcher res = resultPattern().matcher(result); + if (res.find()) { + threadNo = Integer.parseInt(res.group(1)); + postNo = Integer.parseInt(res.group(2)); + } + Matcher err = errorPattern().matcher(result); + if (err.find()) { + replyResponse.errorMessage = Jsoup.parse(err.group(1)).body().text(); + } else { + replyResponse.threadNo = threadNo; + replyResponse.postNo = postNo; + replyResponse.posted = true; + } + } - public Pattern resultPattern() { - return Pattern.compile(".+url=res/(\\d+).html#(\\d+)\">"); - } + public Pattern resultPattern() { + return Pattern.compile(".+url=res/(\\d+).html#(\\d+)\">"); + } + //TODO: match the error pattern + public Pattern errorPattern() { + return Pattern.compile("]*>Error.*]*>(.*?)"); + } - //TODO: match the error pattern - public Pattern errorPattern() { - return Pattern.compile("]*>Error.*]*>(.*?)"); - } - - @Override - public SiteAuthentication postAuthenticate() { - return SiteAuthentication.fromNone(); - } - } + @Override + public SiteAuthentication postAuthenticate() { + return SiteAuthentication.fromNone(); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBApi.java b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBApi.java index a04a223..3027e52 100644 --- a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBApi.java +++ b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBApi.java @@ -61,8 +61,7 @@ public void loadCatalog(JsonReader reader, ChanReaderProcessingQueue queue) thro reader.skipValue(); } } - - reader.endObject(); + reader.endObject(); } @Override @@ -86,7 +85,8 @@ public void readPostObject(JsonReader reader, ChanReaderProcessingQueue queue) t String thumbnailpath = null; String originalName = null; - /* prevent API parse error + /* prevent API parse error + resto is not available on opening board overview the first time so, we manually set the opId to 0, builder.op to true and builder.opId to 0 */ int opId = 0; @@ -183,9 +183,16 @@ public void readPostObject(JsonReader reader, ChanReaderProcessingQueue queue) t // The file from between the other values. if (file != null && file.length() > 0) { - fileName = file.substring(0, file.lastIndexOf(".")); - fileExt = file.substring(file.lastIndexOf(".") + 1); - Map args = makeArgument("path", file, + if (file.contains(" args = makeArgument("path", path, "thumbnailpath", thumbnail); PostImage image = new PostImage.Builder() .originalName(org.jsoup.parser.Parser.unescapeEntities(fileName, false)) @@ -293,9 +300,16 @@ private PostImage readPostImage(JsonReader reader, Post.Builder builder, reader.endObject(); if (file != null && file.length() > 0) { - fileName = file.substring(0, file.lastIndexOf(".")); - fileExt = file.substring(file.lastIndexOf(".") + 1); - Map args = makeArgument("path", file, + if (file.contains(" args = makeArgument("path", path, "thumbnailpath", thumbnail); return new PostImage.Builder() .originalName(org.jsoup.parser.Parser.unescapeEntities(fileName, false)) diff --git a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBCommentParser.java b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBCommentParser.java index 1aff370..b32a558 100644 --- a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBCommentParser.java +++ b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBCommentParser.java @@ -1,30 +1,30 @@ - /* - * Clover - 4chan browser https://github.com/Floens/Clover/ - * Copyright (C) 2014 Floens - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.floens.chan.core.site.common.tinyib; +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.core.site.common.tinyib; - import org.floens.chan.core.site.parser.CommentParser; +import org.floens.chan.core.site.parser.CommentParser; - import java.util.regex.Pattern; +import java.util.regex.Pattern; - public class TinyIBCommentParser extends CommentParser { - public TinyIBCommentParser() { - addDefaultRules(); - setQuotePattern(Pattern.compile(".*#(\\d+)")); - setFullQuotePattern(Pattern.compile("/(\\w+)/\\w+/(\\d+)\\.html#(\\d+)")); - } - } \ No newline at end of file +public class TinyIBCommentParser extends CommentParser { + public TinyIBCommentParser() { + addDefaultRules(); + setQuotePattern(Pattern.compile(".*#(\\d+)")); + setFullQuotePattern(Pattern.compile("/(\\w+)/\\w+/(\\d+)\\.html#(\\d+)")); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBEndpoints.java b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBEndpoints.java index 009e5f8..6fd24df 100644 --- a/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBEndpoints.java +++ b/app/src/main/java/org/floens/chan/core/site/common/tinyib/TinyIBEndpoints.java @@ -1,75 +1,91 @@ - /* - * Clover - 4chan browser https://github.com/Floens/Clover/ - * Copyright (C) 2014 Floens - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.floens.chan.core.site.common.tinyib; +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.core.site.common.tinyib; - import org.floens.chan.core.model.Post; - import org.floens.chan.core.model.orm.Board; - import org.floens.chan.core.model.orm.Loadable; - import org.floens.chan.core.site.common.CommonSite; +import org.floens.chan.core.model.Post; +import org.floens.chan.core.model.orm.Board; +import org.floens.chan.core.model.orm.Loadable; +import org.floens.chan.core.site.common.CommonSite; - import java.util.Locale; - import java.util.Map; +import java.util.Locale; +import java.util.Map; - import okhttp3.HttpUrl; +import okhttp3.HttpUrl; - public class TinyIBEndpoints extends CommonSite.CommonEndpoints { - protected final CommonSite.SimpleHttpUrl root; - protected final CommonSite.SimpleHttpUrl sys; +public class TinyIBEndpoints extends CommonSite.CommonEndpoints { + protected final CommonSite.SimpleHttpUrl root; + protected final CommonSite.SimpleHttpUrl sys; + protected final CommonSite.SimpleHttpUrl yt; - public TinyIBEndpoints(CommonSite commonSite, String rootUrl, String sysUrl) { - super(commonSite); - root = new CommonSite.SimpleHttpUrl(rootUrl); - sys = new CommonSite.SimpleHttpUrl(sysUrl); - } + public TinyIBEndpoints(CommonSite commonSite, String rootUrl, String sysUrl) { + super(commonSite); + root = new CommonSite.SimpleHttpUrl(rootUrl); + sys = new CommonSite.SimpleHttpUrl(sysUrl); + yt = new CommonSite.SimpleHttpUrl("https://youtu.be/"); + } - @Override - public HttpUrl catalog(Board board) { - return root.builder().s(board.code).s("catalog.json").url(); - } + @Override + public HttpUrl catalog(Board board) { + return root.builder().s(board.code).s("catalog.json").url(); + } - @Override - public HttpUrl thread(Board board, Loadable loadable) { - return root.builder().s(board.code).s("res").s(loadable.no + ".json").url(); - } + /*@Override + public HttpUrl boards() { + return root.builder().s("boards.json").url(); + }*/ - @Override - public HttpUrl thumbnailUrl(Post.Builder post, boolean spoiler, Map arg) { - return sys.builder().s(post.board.code).s("thumb").s(arg.get("thumbnailpath")).url(); - } + @Override + public HttpUrl thread(Board board, Loadable loadable) { + return root.builder().s(board.code).s("res").s(loadable.no + ".json").url(); + } - @Override - public HttpUrl imageUrl(Post.Builder post, Map arg) { - return sys.builder().s(post.board.code).s("src").s(arg.get("path")).url(); - } + @Override + public HttpUrl thumbnailUrl(Post.Builder post, boolean spoiler, Map arg) { + return sys.builder().s(post.board.code).s("thumb").s(arg.get("thumbnailpath")).url(); + } - @Override - public HttpUrl icon(Post.Builder post, String icon, Map arg) { - CommonSite.SimpleHttpUrl stat = sys.builder().s("static"); + @Override + public HttpUrl imageUrl(Post.Builder post, Map arg) { + if (arg.get("path").contains("youtube")) { + String youtubeId = arg.get("path"); + youtubeId = youtubeId.replaceAll("", ""); + return yt.builder().s(youtubeId).url(); + } else { + return sys.builder().s(post.board.code).s("src").s(arg.get("path")).url(); + } + } - if (icon.equals("country")) { - stat.s("flags").s(arg.get("country_code").toLowerCase(Locale.ENGLISH) + ".png"); - } + @Override + public HttpUrl icon(Post.Builder post, String icon, Map arg) { + CommonSite.SimpleHttpUrl stat = sys.builder().s("static"); - return stat.url(); - } + if (icon.equals("country")) { + stat.s("flags").s(arg.get("country_code").toLowerCase(Locale.ENGLISH) + ".png"); + } - @Override - public HttpUrl reply(Loadable loadable) { - return sys.builder().s(loadable.board.code).s("imgboard.php").url(); - } - } \ No newline at end of file + return stat.url(); + } + + + @Override + public HttpUrl reply(Loadable loadable) { + return sys.builder().s(loadable.board.code).s("imgboard.php").url(); + } +} diff --git a/app/src/main/java/org/floens/chan/core/site/sites/geechan/ChanGeeBoardsRequest.java b/app/src/main/java/org/floens/chan/core/site/sites/geechan/ChanGeeBoardsRequest.java index e9dac80..05cfa6f 100644 --- a/app/src/main/java/org/floens/chan/core/site/sites/geechan/ChanGeeBoardsRequest.java +++ b/app/src/main/java/org/floens/chan/core/site/sites/geechan/ChanGeeBoardsRequest.java @@ -1,94 +1,94 @@ - /* - * Clover - 4chan browser https://github.com/Floens/Clover/ - * Copyright (C) 2014 Floens - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.floens.chan.core.site.sites.geechan; - - import android.util.JsonReader; - import android.util.Log; - - import com.android.volley.Response.ErrorListener; - import com.android.volley.Response.Listener; - - import org.floens.chan.core.model.orm.Board; - import org.floens.chan.core.net.JsonReaderRequest; - import org.floens.chan.core.site.Site; - import org.floens.chan.utils.Logger; - - import java.io.IOException; - import java.util.ArrayList; - import java.util.List; - - public class ChanGeeBoardsRequest extends JsonReaderRequest> { - private final Site site; - - ChanGeeBoardsRequest(Site site, Listener> listener, ErrorListener errorListener) { - super(site.endpoints().boards().toString(), listener, errorListener); - this.site = site; - } - - @Override - public List readJson(JsonReader reader) throws Exception { - List list = new ArrayList<>(); - - reader.beginArray(); - while (reader.hasNext()) { - while (reader.hasNext()) { - Board board = readBoardEntry(reader); - if (board != null) { - list.add(board); - } - } - } - reader.endArray(); - - return list; - } - - private Board readBoardEntry(JsonReader reader) throws IOException { - reader.beginObject(); - - Board board = new Board(); - board.siteId = site.id(); - board.site = site; - - while (reader.hasNext()) { - String key = reader.nextName(); - - switch (key) { - case "title": - board.name = reader.nextString(); - break; - case "board": - board.code = reader.nextString(); - board.maxFileSize = 2048 * 1024; - break; - default: - reader.skipValue(); - break; - } - } - - reader.endObject(); - - if (!board.finish()) { - // Invalid data, ignore - return null; - } - - return board; - } - } \ No newline at end of file +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.core.site.sites.geechan; + +import android.util.JsonReader; +import android.util.Log; + +import com.android.volley.Response.ErrorListener; +import com.android.volley.Response.Listener; + +import org.floens.chan.core.model.orm.Board; +import org.floens.chan.core.net.JsonReaderRequest; +import org.floens.chan.core.site.Site; +import org.floens.chan.utils.Logger; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ChanGeeBoardsRequest extends JsonReaderRequest> { + private final Site site; + + ChanGeeBoardsRequest(Site site, Listener> listener, ErrorListener errorListener) { + super(site.endpoints().boards().toString(), listener, errorListener); + this.site = site; + } + + @Override + public List readJson(JsonReader reader) throws Exception { + List list = new ArrayList<>(); + + reader.beginArray(); + while (reader.hasNext()) { + while (reader.hasNext()) { + Board board = readBoardEntry(reader); + if (board != null) { + list.add(board); + } + } + } + reader.endArray(); + + return list; + } + + private Board readBoardEntry(JsonReader reader) throws IOException { + reader.beginObject(); + + Board board = new Board(); + board.siteId = site.id(); + board.site = site; + + while (reader.hasNext()) { + String key = reader.nextName(); + + switch (key) { + case "title": + board.name = reader.nextString(); + break; + case "board": + board.code = reader.nextString(); + board.maxFileSize = 2048 * 1024; + break; + default: + reader.skipValue(); + break; + } + } + + reader.endObject(); + + if (!board.finish()) { + // Invalid data, ignore + return null; + } + + return board; + } +} diff --git a/app/src/main/java/org/floens/chan/core/site/sites/geechan/Geechan.java b/app/src/main/java/org/floens/chan/core/site/sites/geechan/Geechan.java index c98a2e3..7ee4773 100644 --- a/app/src/main/java/org/floens/chan/core/site/sites/geechan/Geechan.java +++ b/app/src/main/java/org/floens/chan/core/site/sites/geechan/Geechan.java @@ -1,121 +1,121 @@ - /* - * Clover - 4chan browser https://github.com/Floens/Clover/ - * Copyright (C) 2014 Floens - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.floens.chan.core.site.sites.geechan; - - import androidx.annotation.Nullable; - - import org.floens.chan.core.model.Post; - import org.floens.chan.core.model.orm.Board; - import org.floens.chan.core.model.orm.Loadable; - import org.floens.chan.core.site.Boards; - import org.floens.chan.core.site.Site; - import org.floens.chan.core.site.SiteIcon; - import org.floens.chan.core.site.common.CommonSite; - import org.floens.chan.core.site.common.tinyib.TinyIBActions; - import org.floens.chan.core.site.common.tinyib.TinyIBApi; - import org.floens.chan.core.site.common.tinyib.TinyIBCommentParser; - import org.floens.chan.core.site.common.tinyib.TinyIBEndpoints; - import org.floens.chan.utils.Logger; - - import java.util.ArrayList; - import java.util.List; - - import okhttp3.HttpUrl; - - public class Geechan extends CommonSite { - private static final String TAG = "Geechan"; - - public static final CommonSiteUrlHandler URL_HANDLER = new CommonSiteUrlHandler() { - @Override - public Class getSiteClass() { - return Geechan.class; - } - - @Override - public HttpUrl getUrl() { - return HttpUrl.parse("http://www.geechan.tk"); - } - - @Override - public String[] getNames() { - return new String[]{"geechan"}; - } - - @Override - public String desktopUrl(Loadable loadable, @Nullable Post post) { - if (loadable.isCatalogMode()) { - return getUrl().newBuilder().addPathSegment(loadable.boardCode).toString(); - } else if (loadable.isThreadMode()) { - return getUrl().newBuilder() - .addPathSegment(loadable.boardCode).addPathSegment("res") - .addPathSegment(String.valueOf(loadable.no) + ".html") - .toString(); - } else { - return getUrl().toString(); - } - } - }; - - @Override - public void setup() { - setName("geechan"); - setIcon(SiteIcon.fromFavicon(HttpUrl.parse("http://www.geechan.tk/favicon.ico"))); - setBoardsType(BoardsType.DYNAMIC); - - setResolvable(URL_HANDLER); - - setConfig(new CommonConfig() { - @Override - public boolean feature(Feature feature) { - return feature == Feature.POSTING; - } - }); - - setEndpoints(new TinyIBEndpoints(this, - "http://www.geechan.tk", - "http://www.geechan.tk") { - - @Override - public HttpUrl boards() { - return new HttpUrl.Builder().scheme("http").host("www.geechan.tk").addPathSegment("boards.json").build(); - } - }); - - setActions(new TinyIBActions(this) { - @Override - public void boards(final BoardsListener listener) { - requestQueue.add(new ChanGeeBoardsRequest(Geechan.this, response -> { - listener.onBoardsReceived(new Boards(response)); - }, (error) -> { - Logger.e(TAG, "Failed to get boards from server", error); - - // API fail, provide some default boards - List list = new ArrayList<>(); - list.add(Board.fromSiteNameCode(Geechan.this, "Anime", "a")); - list.add(Board.fromSiteNameCode(Geechan.this, "Random", "b")); - list.add(Board.fromSiteNameCode(Geechan.this, "Technology", "g")); - list.add(Board.fromSiteNameCode(Geechan.this, "World of Warcraft", "wow")); - listener.onBoardsReceived(new Boards(list)); - })); - } - }); - - setApi(new TinyIBApi(this)); - setParser(new TinyIBCommentParser()); - } - } \ No newline at end of file +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.core.site.sites.geechan; + +import androidx.annotation.Nullable; + +import org.floens.chan.core.model.Post; +import org.floens.chan.core.model.orm.Board; +import org.floens.chan.core.model.orm.Loadable; +import org.floens.chan.core.site.Boards; +import org.floens.chan.core.site.Site; +import org.floens.chan.core.site.SiteIcon; +import org.floens.chan.core.site.common.CommonSite; +import org.floens.chan.core.site.common.tinyib.TinyIBActions; +import org.floens.chan.core.site.common.tinyib.TinyIBApi; +import org.floens.chan.core.site.common.tinyib.TinyIBCommentParser; +import org.floens.chan.core.site.common.tinyib.TinyIBEndpoints; +import org.floens.chan.utils.Logger; + +import java.util.ArrayList; +import java.util.List; + +import okhttp3.HttpUrl; + +public class Geechan extends CommonSite { + private static final String TAG = "Geechan"; + + public static final CommonSiteUrlHandler URL_HANDLER = new CommonSiteUrlHandler() { + @Override + public Class getSiteClass() { + return Geechan.class; + } + + @Override + public HttpUrl getUrl() { + return HttpUrl.parse("https://www.geechan.org"); + } + + @Override + public String[] getNames() { + return new String[]{"geechan"}; + } + + @Override + public String desktopUrl(Loadable loadable, @Nullable Post post) { + if (loadable.isCatalogMode()) { + return getUrl().newBuilder().addPathSegment(loadable.boardCode).toString(); + } else if (loadable.isThreadMode()) { + return getUrl().newBuilder() + .addPathSegment(loadable.boardCode).addPathSegment("res") + .addPathSegment(String.valueOf(loadable.no) + ".html") + .toString(); + } else { + return getUrl().toString(); + } + } + }; + + @Override + public void setup() { + setName("geechan"); + setIcon(SiteIcon.fromFavicon(HttpUrl.parse("https://www.geechan.org/favicon.ico"))); + setBoardsType(BoardsType.DYNAMIC); + + setResolvable(URL_HANDLER); + + setConfig(new CommonConfig() { + @Override + public boolean feature(Feature feature) { + return feature == Feature.POSTING; + } + }); + + setEndpoints(new TinyIBEndpoints(this, + "https://www.geechan.org", + "https://www.geechan.org") { + + @Override + public HttpUrl boards() { + return new HttpUrl.Builder().scheme("https").host("www.geechan.org").addPathSegment("boards.json").build(); + } + }); + + setActions(new TinyIBActions(this) { + @Override + public void boards(final BoardsListener listener) { + requestQueue.add(new ChanGeeBoardsRequest(Geechan.this, response -> { + listener.onBoardsReceived(new Boards(response)); + }, (error) -> { + Logger.e(TAG, "Failed to get boards from server", error); + + // API fail, provide some default boards + List list = new ArrayList<>(); + list.add(Board.fromSiteNameCode(Geechan.this, "Anime", "a")); + list.add(Board.fromSiteNameCode(Geechan.this, "Random", "b")); + list.add(Board.fromSiteNameCode(Geechan.this, "Technology", "g")); + list.add(Board.fromSiteNameCode(Geechan.this, "World of Warcraft", "wow")); + listener.onBoardsReceived(new Boards(list)); + })); + } + }); + + setApi(new TinyIBApi(this)); + setParser(new TinyIBCommentParser()); + } +}