mirror of https://github.com/kurisufriend/Clover
parent
345c22de7f
commit
08df656d05
After Width: | Height: | Size: 411 B |
@ -0,0 +1,109 @@ |
||||
/* |
||||
* 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.manager.BoardManager; |
||||
import org.floens.chan.core.model.orm.Board; |
||||
import org.floens.chan.core.site.Site; |
||||
import org.floens.chan.core.site.Sites; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import javax.inject.Inject; |
||||
|
||||
import static org.floens.chan.Chan.getGraph; |
||||
|
||||
public class BoardSetupPresenter { |
||||
private Callback callback; |
||||
|
||||
private final List<Site> sites = new ArrayList<>(); |
||||
|
||||
@Inject |
||||
BoardManager boardManager; |
||||
|
||||
private List<Board> savedBoards; |
||||
|
||||
@Inject |
||||
public BoardSetupPresenter() { |
||||
getGraph().inject(this); |
||||
} |
||||
|
||||
public void create(Callback callback) { |
||||
this.callback = callback; |
||||
|
||||
sites.addAll(Sites.allSites()); |
||||
|
||||
loadSavedBoards(); |
||||
callback.setSavedBoards(savedBoards); |
||||
} |
||||
|
||||
public void addFromSuggestion(BoardSuggestion suggestion) { |
||||
Board board = Board.fromSiteNameCode(suggestion.site, suggestion.key, suggestion.key); |
||||
|
||||
boardManager.saveBoard(board); |
||||
|
||||
loadSavedBoards(); |
||||
callback.setSavedBoards(savedBoards); |
||||
} |
||||
|
||||
public void move(int from, int to) { |
||||
Board item = savedBoards.remove(from); |
||||
savedBoards.add(to, item); |
||||
|
||||
callback.setSavedBoards(savedBoards); |
||||
} |
||||
|
||||
public void remove(int position) { |
||||
Board board = savedBoards.remove(position); |
||||
|
||||
boardManager.unsaveBoard(board); |
||||
|
||||
loadSavedBoards(); |
||||
callback.setSavedBoards(savedBoards); |
||||
} |
||||
|
||||
public List<BoardSuggestion> getSuggestionsForQuery(String query) { |
||||
List<BoardSuggestion> suggestions = new ArrayList<>(); |
||||
|
||||
for (Site site : sites) { |
||||
suggestions.add(new BoardSuggestion(query, site)); |
||||
} |
||||
|
||||
return suggestions; |
||||
} |
||||
|
||||
private void loadSavedBoards() { |
||||
savedBoards = new ArrayList<>(boardManager.getSavedBoards()); |
||||
} |
||||
|
||||
public interface Callback { |
||||
void setSavedBoards(List<Board> savedBoards); |
||||
} |
||||
|
||||
public static class BoardSuggestion { |
||||
public final String key; |
||||
public final Site site; |
||||
|
||||
public BoardSuggestion(String key, Site site) { |
||||
this.key = key; |
||||
this.site = site; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,254 @@ |
||||
/* |
||||
* 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.site.sites.chan8; |
||||
|
||||
|
||||
import android.support.annotation.Nullable; |
||||
import android.webkit.WebView; |
||||
|
||||
import org.floens.chan.chan.ChanLoaderRequest; |
||||
import org.floens.chan.chan.ChanLoaderRequestParams; |
||||
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.Resolvable; |
||||
import org.floens.chan.core.site.Site; |
||||
import org.floens.chan.core.site.SiteAuthentication; |
||||
import org.floens.chan.core.site.SiteBase; |
||||
import org.floens.chan.core.site.SiteEndpoints; |
||||
import org.floens.chan.core.site.SiteIcon; |
||||
import org.floens.chan.core.site.SiteRequestModifier; |
||||
import org.floens.chan.core.site.common.ChanReaderRequest; |
||||
import org.floens.chan.core.site.http.DeleteRequest; |
||||
import org.floens.chan.core.site.http.HttpCall; |
||||
import org.floens.chan.core.site.http.LoginRequest; |
||||
import org.floens.chan.core.site.http.Reply; |
||||
|
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
import okhttp3.HttpUrl; |
||||
import okhttp3.Request; |
||||
|
||||
public class Chan8 extends SiteBase { |
||||
public static final Resolvable RESOLVABLE = new Resolvable() { |
||||
@Override |
||||
public ResolveResult resolve(String value) { |
||||
if (value.equals("8chan")) { |
||||
return ResolveResult.NAME_MATCH; |
||||
} else if (value.equals("https://8ch.net/")) { |
||||
return ResolveResult.FULL_MATCH; |
||||
} else { |
||||
return ResolveResult.NO; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends Site> getSiteClass() { |
||||
return Chan8.class; |
||||
} |
||||
}; |
||||
|
||||
private final SiteEndpoints endpoints = new SiteEndpoints() { |
||||
private final HttpUrl root = new HttpUrl.Builder() |
||||
.scheme("https") |
||||
.host("8ch.net") |
||||
.build(); |
||||
|
||||
private final HttpUrl media = new HttpUrl.Builder() |
||||
.scheme("https") |
||||
.host("media.8ch.net") |
||||
.build(); |
||||
|
||||
@Override |
||||
public HttpUrl catalog(Board board) { |
||||
return root.newBuilder() |
||||
.addPathSegment(board.code) |
||||
.addPathSegment("catalog.json") |
||||
.build(); |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl thread(Board board, Loadable loadable) { |
||||
return root.newBuilder() |
||||
.addPathSegment(board.code) |
||||
.addPathSegment("res") |
||||
.addPathSegment(loadable.no + ".json") |
||||
.build(); |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl imageUrl(Post.Builder post, Map<String, String> arg) { |
||||
return root.newBuilder() |
||||
.addPathSegment("file_store") |
||||
.addPathSegment(arg.get("tim") + "." + arg.get("ext")) |
||||
.build(); |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl thumbnailUrl(Post.Builder post, boolean spoiler, Map<String, String> arg) { |
||||
return root.newBuilder() |
||||
.addPathSegment("file_store") |
||||
.addPathSegment("thumb") |
||||
.addPathSegment(arg.get("tim") + "." + arg.get("ext")) |
||||
.build(); |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl icon(Post.Builder post, String icon, Map<String, String> arg) { |
||||
HttpUrl.Builder stat = root.newBuilder().addPathSegment("static"); |
||||
|
||||
switch (icon) { |
||||
case "country": |
||||
stat.addPathSegment("flags"); |
||||
stat.addPathSegment(arg.get("country_code").toLowerCase(Locale.ENGLISH) + ".png"); |
||||
break; |
||||
} |
||||
|
||||
return stat.build(); |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl boards() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl reply(Loadable loadable) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl delete(Post post) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl report(Post post) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public HttpUrl login() { |
||||
return null; |
||||
} |
||||
}; |
||||
|
||||
private SiteRequestModifier siteRequestModifier = new SiteRequestModifier() { |
||||
@Override |
||||
public void modifyHttpCall(HttpCall httpCall, Request.Builder requestBuilder) { |
||||
} |
||||
|
||||
@SuppressWarnings("deprecation") |
||||
@Override |
||||
public void modifyWebView(WebView webView) { |
||||
} |
||||
}; |
||||
|
||||
private SiteAuthentication authentication = new SiteAuthentication() { |
||||
@Override |
||||
public boolean requireAuthentication(AuthenticationRequestType type) { |
||||
return false; |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
public String name() { |
||||
return "8chan"; |
||||
} |
||||
|
||||
@Override |
||||
public SiteIcon icon() { |
||||
return SiteIcon.fromAssets("icons/8chan.png"); |
||||
} |
||||
|
||||
@Override |
||||
public boolean feature(Feature feature) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean boardFeature(BoardFeature boardFeature, Board board) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public SiteEndpoints endpoints() { |
||||
return endpoints; |
||||
} |
||||
|
||||
@Override |
||||
public SiteRequestModifier requestModifier() { |
||||
return siteRequestModifier; |
||||
} |
||||
|
||||
@Override |
||||
public SiteAuthentication authentication() { |
||||
return authentication; |
||||
} |
||||
|
||||
@Override |
||||
public BoardsType boardsType() { |
||||
return BoardsType.INFINITE; |
||||
} |
||||
|
||||
@Override |
||||
public String desktopUrl(Loadable loadable, @Nullable Post post) { |
||||
return "https://8ch.net/"; |
||||
} |
||||
|
||||
@Override |
||||
public void boards(BoardsListener boardsListener) { |
||||
} |
||||
|
||||
@Override |
||||
public Board board(String code) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public ChanLoaderRequest loaderRequest(ChanLoaderRequestParams request) { |
||||
return new ChanLoaderRequest(new ChanReaderRequest(request)); |
||||
} |
||||
|
||||
@Override |
||||
public void post(Reply reply, PostListener postListener) { |
||||
} |
||||
|
||||
@Override |
||||
public void delete(DeleteRequest deleteRequest, DeleteListener deleteListener) { |
||||
} |
||||
|
||||
@Override |
||||
public void login(LoginRequest loginRequest, LoginListener loginListener) { |
||||
} |
||||
|
||||
@Override |
||||
public void logout() { |
||||
} |
||||
|
||||
@Override |
||||
public boolean isLoggedIn() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public LoginRequest getLoginDetails() { |
||||
return null; |
||||
} |
||||
} |
@ -1,82 +0,0 @@ |
||||
/* |
||||
* 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.ui.drawable; |
||||
|
||||
import android.graphics.Canvas; |
||||
import android.graphics.ColorFilter; |
||||
import android.graphics.Paint; |
||||
import android.graphics.Path; |
||||
import android.graphics.PixelFormat; |
||||
import android.graphics.drawable.Drawable; |
||||
|
||||
import static org.floens.chan.utils.AndroidUtils.dp; |
||||
|
||||
public class ThumbDrawable extends Drawable { |
||||
private Paint paint = new Paint(); |
||||
private Path path = new Path(); |
||||
private int width; |
||||
private int height; |
||||
|
||||
public ThumbDrawable() { |
||||
width = dp(40); |
||||
height = dp(40); |
||||
|
||||
paint.setStrokeWidth(dp(2)); |
||||
paint.setStyle(Paint.Style.STROKE); |
||||
paint.setStrokeCap(Paint.Cap.BUTT); |
||||
paint.setColor(0xff757575); |
||||
|
||||
path.reset(); |
||||
for (int i = 0; i < 3; i++) { |
||||
int top = (int) (getMinimumHeight() / 2f + (i - 1) * dp(6)); |
||||
path.moveTo(dp(8), top); |
||||
path.lineTo(getMinimumWidth() - dp(8), top); |
||||
} |
||||
path.close(); |
||||
} |
||||
|
||||
@Override |
||||
public void draw(Canvas canvas) { |
||||
canvas.drawPath(path, paint); |
||||
} |
||||
|
||||
@Override |
||||
public int getIntrinsicWidth() { |
||||
return width; |
||||
} |
||||
|
||||
@Override |
||||
public int getIntrinsicHeight() { |
||||
return height; |
||||
} |
||||
|
||||
@Override |
||||
public void setAlpha(int alpha) { |
||||
paint.setAlpha(alpha); |
||||
} |
||||
|
||||
@Override |
||||
public void setColorFilter(ColorFilter cf) { |
||||
paint.setColorFilter(cf); |
||||
} |
||||
|
||||
@Override |
||||
public int getOpacity() { |
||||
return PixelFormat.TRANSLUCENT; |
||||
} |
||||
} |
After Width: | Height: | Size: 107 B |
After Width: | Height: | Size: 82 B |
After Width: | Height: | Size: 101 B |
After Width: | Height: | Size: 113 B |
After Width: | Height: | Size: 116 B |
@ -0,0 +1,42 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
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/>. |
||||
--> |
||||
<LinearLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="48dp" |
||||
android:background="?attr/backcolor" |
||||
android:orientation="horizontal"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/image" |
||||
android:layout_width="48dp" |
||||
android:layout_height="48dp" |
||||
android:padding="8dp" |
||||
android:scaleType="fitCenter"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/text" |
||||
android:layout_width="0dp" |
||||
android:layout_height="48dp" |
||||
android:layout_weight="1" |
||||
android:gravity="center_vertical" |
||||
android:maxLines="1" |
||||
android:textColor="?text_color_primary" |
||||
android:textSize="14sp"/> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue