This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reads the html because there is no api endpoint for it. adds a new `archive` boolean to the Board model.
- Loading branch information
Showing
19 changed files
with
723 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Clover/app/src/main/java/org/floens/chan/core/model/Archive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.floens.chan.core.model; | ||
|
||
import java.util.List; | ||
|
||
public class Archive { | ||
public final List<ArchiveItem> items; | ||
|
||
public static Archive fromItems(List<ArchiveItem> items) { | ||
return new Archive(items); | ||
} | ||
|
||
private Archive(List<ArchiveItem> items) { | ||
this.items = items; | ||
} | ||
|
||
public static class ArchiveItem { | ||
public final String description; | ||
|
||
public final int id; | ||
|
||
public static ArchiveItem fromDescriptionId(String description, int id) { | ||
return new ArchiveItem(description, id); | ||
} | ||
|
||
private ArchiveItem(String description, int id) { | ||
this.description = description; | ||
this.id = id; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Clover/app/src/main/java/org/floens/chan/core/net/HtmlReaderRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.floens.chan.core.net; | ||
|
||
import com.android.volley.NetworkResponse; | ||
import com.android.volley.Request; | ||
import com.android.volley.Response; | ||
import com.android.volley.Response.Listener; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.HttpHeaderParser; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
public abstract class HtmlReaderRequest<T> extends Request<T> { | ||
protected final Listener<T> listener; | ||
|
||
public HtmlReaderRequest(String url, Listener<T> listener, Response.ErrorListener errorListener) { | ||
super(Request.Method.GET, url, errorListener); | ||
|
||
this.listener = listener; | ||
} | ||
|
||
@Override | ||
protected void deliverResponse(T response) { | ||
listener.onResponse(response); | ||
} | ||
|
||
@Override | ||
protected Response<T> parseNetworkResponse(NetworkResponse response) { | ||
try { | ||
Document document = Jsoup.parse(new ByteArrayInputStream(response.data), | ||
HttpHeaderParser.parseCharset(response.headers), getUrl()); | ||
|
||
T result = readDocument(document); | ||
|
||
return Response.success(result, HttpHeaderParser.parseCacheHeaders(response)); | ||
} catch (IOException e) { | ||
return Response.error(new VolleyError(e)); | ||
} | ||
} | ||
|
||
public abstract T readDocument(Document document) throws IOException; | ||
} |
138 changes: 138 additions & 0 deletions
138
Clover/app/src/main/java/org/floens/chan/core/presenter/ArchivePresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.floens.chan.core.presenter; | ||
|
||
import org.floens.chan.core.database.DatabaseManager; | ||
import org.floens.chan.core.model.Archive; | ||
import org.floens.chan.core.model.orm.Board; | ||
import org.floens.chan.core.model.orm.Loadable; | ||
import org.floens.chan.core.site.SiteActions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static android.text.TextUtils.isEmpty; | ||
|
||
public class ArchivePresenter implements SiteActions.ArchiveListener { | ||
private DatabaseManager databaseManager; | ||
|
||
private Callback callback; | ||
private Board board; | ||
|
||
private boolean inRequest = false; | ||
|
||
private String filter; | ||
private List<Archive.ArchiveItem> items = new ArrayList<>(); | ||
private List<Archive.ArchiveItem> filteredItems = new ArrayList<>(); | ||
|
||
@Inject | ||
public ArchivePresenter(DatabaseManager databaseManager) { | ||
this.databaseManager = databaseManager; | ||
} | ||
|
||
public void create(Callback callback, Board board) { | ||
this.callback = callback; | ||
this.board = board; | ||
|
||
loadArchive(); | ||
} | ||
|
||
public void onRefresh() { | ||
if (!inRequest) { | ||
loadArchive(); | ||
} | ||
} | ||
|
||
private void loadArchive() { | ||
inRequest = true; | ||
callback.showError(false); | ||
board.site.actions().archive(board, this); | ||
} | ||
|
||
public void onSearchEntered(String query) { | ||
filterArchive(query); | ||
} | ||
|
||
public void onSearchVisibility(boolean visible) { | ||
if (!visible) { | ||
filterArchive(null); | ||
} | ||
} | ||
|
||
public void onItemClicked(Archive.ArchiveItem item) { | ||
Loadable loadable = databaseManager.getDatabaseLoadableManager() | ||
.get(Loadable.forThread(board.site, board, item.id)); | ||
|
||
callback.openThread(loadable); | ||
} | ||
|
||
@Override | ||
public void onArchive(Archive archive) { | ||
inRequest = false; | ||
callback.hideRefreshing(); | ||
callback.showList(); | ||
items = archive.items; | ||
updateWithFilter(); | ||
} | ||
|
||
@Override | ||
public void onArchiveError() { | ||
inRequest = false; | ||
callback.hideRefreshing(); | ||
callback.showError(true); | ||
} | ||
|
||
private void filterArchive(String query) { | ||
filter = query; | ||
updateWithFilter(); | ||
} | ||
|
||
private void updateWithFilter() { | ||
filteredItems.clear(); | ||
if (isEmpty(filter)) { | ||
filteredItems.addAll(items); | ||
} else { | ||
for (Archive.ArchiveItem item : items) { | ||
if (filterApplies(item, filter)) { | ||
filteredItems.add(item); | ||
} | ||
} | ||
} | ||
|
||
callback.setArchiveItems(filteredItems); | ||
} | ||
|
||
private boolean filterApplies(Archive.ArchiveItem item, String filter) { | ||
return item.description.toLowerCase(Locale.ENGLISH).contains(filter.toLowerCase()); | ||
} | ||
|
||
public interface Callback { | ||
void setArchiveItems(List<Archive.ArchiveItem> items); | ||
|
||
void hideRefreshing(); | ||
|
||
void showList(); | ||
|
||
void showError(boolean show); | ||
|
||
void openThread(Loadable loadable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
9c4f433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this api endpoint not the one you are looking for?
"A list of archived thread IDs can be found here:
http(s)://a.4cdn.org/board/archive.json"
9c4f433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bitti09 that endpoint only contains the thread nos, and we need more information for the archive to be useful. See the related issue #173
9c4f433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its complicate cause:
Example:
https://a.4cdn.org/c/archive.json
first thread from it must be fetched via
https://a.4cdn.org/c/thread/3034542.json
to get informations about it without using http scraper.
and yes they arent included in catalog.json&threads.json