Skip to content

Commit

Permalink
ИКОНКИ ИКОНОЧКИ
Browse files Browse the repository at this point in the history
  • Loading branch information
A-So-Nya committed Aug 18, 2021
1 parent 9c7fc87 commit e824900
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 1 deletion.
Binary file added res/raw/anon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raw/bnet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raw/gosdep.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raw/isaac.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raw/shizik.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raw/souseiseki.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/raw/suiseiseki.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/com/mishiranu/dashchan/chan/synch/SynchChanConfiguration.java
@@ -1,5 +1,7 @@
package com.mishiranu.dashchan.chan.synch;

import android.util.Pair;

import chan.content.ChanConfiguration;

public class SynchChanConfiguration extends ChanConfiguration {
Expand Down Expand Up @@ -32,6 +34,47 @@ public Posting obtainPostingConfiguration(String boardName, boolean newThread) {
posting.attachmentMimeTypes.add("audio/*");
posting.attachmentMimeTypes.add("application/*");
posting.attachmentSpoiler = true;
posting.userIcons.add(Pair.create("green","GREEN"));
posting.userIcons.add(Pair.create("yellow","YELLOW"));
posting.userIcons.add(Pair.create("red","RED"));
posting.userIcons.add(Pair.create("anon","Anonymous"));
posting.userIcons.add(Pair.create("doge","DOGE"));
posting.userIcons.add(Pair.create("kappa","KAPPA"));
posting.userIcons.add(Pair.create("mlg","MLG"));
posting.userIcons.add(Pair.create("wwe","WWE"));
posting.userIcons.add(Pair.create("dota2","DOTA"));
posting.userIcons.add(Pair.create("isaac","Isaac"));
posting.userIcons.add(Pair.create("bnet","Battle.net"));
posting.userIcons.add(Pair.create("steam","Steam"));
posting.userIcons.add(Pair.create("lenny","( ͡° ͜ʖ ͡°)"));
posting.userIcons.add(Pair.create("psi","Psi"));
posting.userIcons.add(Pair.create("psialt","Psi Alt"));
posting.userIcons.add(Pair.create("allah","Аллах Акбар"));
posting.userIcons.add(Pair.create("bindera","Бiндєра"));
posting.userIcons.add(Pair.create("sovok","Совок"));
posting.userIcons.add(Pair.create("gosdep","Госдеп"));
posting.userIcons.add(Pair.create("wehrmacht","Wehrmacht"));
posting.userIcons.add(Pair.create("liberator","Liberator"));
posting.userIcons.add(Pair.create("shizik","Шизик"));
posting.userIcons.add(Pair.create("guadel","Гваделупа"));
posting.userIcons.add(Pair.create("poni","Poni"));
posting.userIcons.add(Pair.create("suiseiseki","Suiseiseki"));
posting.userIcons.add(Pair.create("souseiseki","Souseiseki"));
posting.userIcons.add(Pair.create("kamina","Kamina"));
posting.userIcons.add(Pair.create("mushroom","Kinoko Nasu"));
posting.userIcons.add(Pair.create("mando","Mandalorian"));
posting.userIcons.add(Pair.create("mando2","Mandalorian Alt"));
posting.userIcons.add(Pair.create("synchtube","Synchtube"));
posting.userIcons.add(Pair.create("stalt","Synchtube Alt"));
posting.userIcons.add(Pair.create("archlinux","Arch"));
posting.userIcons.add(Pair.create("debian","Debian"));
posting.userIcons.add(Pair.create("vk","Facebook"));
posting.userIcons.add(Pair.create("skype","Skype"));
posting.userIcons.add(Pair.create("konfa","КОНФОГНИЛЬ"));
posting.userIcons.add(Pair.create("cola","Coca-Cola"));
posting.userIcons.add(Pair.create("pepsi","Pepsi"));
posting.userIcons.add(Pair.create("mtndew","Mtn Dew"));

return posting;
}

Expand Down
3 changes: 3 additions & 0 deletions src/com/mishiranu/dashchan/chan/synch/SynchChanMarkup.java
Expand Up @@ -23,6 +23,9 @@ public SynchChanMarkup() {
addTag("span", "style", "text-decoration: underline", TAG_UNDERLINE);
addTag("span", "style", "text-decoration: line-through", TAG_STRIKE);
addPreformatted("code", true);
addColorable("font");
addColorable("span");
addColorable("div");
}

@Override
Expand Down
21 changes: 21 additions & 0 deletions src/com/mishiranu/dashchan/chan/synch/SynchChanPerformer.java
@@ -1,17 +1,21 @@
package com.mishiranu.dashchan.chan.synch;

import java.util.ArrayList;
import java.util.Arrays;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.net.Uri;
import android.util.Log;
import android.util.Pair;

import chan.content.ApiException;
import chan.content.ChanLocator;
import chan.content.ChanPerformer;
import chan.content.InvalidResponseException;
import chan.content.model.Icon;
import chan.content.model.Post;
import chan.content.model.Posts;
import chan.http.HttpException;
Expand All @@ -24,6 +28,9 @@
import chan.util.StringUtils;

public class SynchChanPerformer extends ChanPerformer {

private final String[] iconsNoUrl = {"shizik", "suiseiseki", "souseiseki", "gosdep", "bnet", "isaac", "anon"};

private static final HttpRequest.RedirectHandler NOT_FOUND_REDIRECT_HANDLER =
(responseCode, requestedUri, redirectedUri, holder) -> {
if (redirectedUri.toString().contains("/arch/")) {
Expand Down Expand Up @@ -86,13 +93,26 @@ public ReadPostsResult onReadPosts(ReadPostsData data) throws HttpException, Inv
Uri uri = locator.buildPath(data.boardName, "res", data.threadNumber + ".json");
JSONObject jsonObject = new HttpRequest(uri, data.holder, data).setValidator(data.validator)
.setRedirectHandler(NOT_FOUND_REDIRECT_HANDLER).read().getJsonObject();
Uri uriIcons = locator.buildPath(data.boardName, "res", data.threadNumber + ".html");
String responseText = new HttpRequest(uriIcons, data).setValidator(data.validator).setRedirectHandler(NOT_FOUND_REDIRECT_HANDLER).read().getString();
if (jsonObject != null) {
try {
JSONArray jsonArray = jsonObject.getJSONArray("posts");
if (jsonArray.length() > 0) {
Post[] posts = new Post[jsonArray.length()];
for (int i = 0; i < posts.length; i++) {
posts[i] = SynchModelMapper.createPost(jsonArray.getJSONObject(i), locator, data.boardName);
Pair<String, String> icon = new SynchPostsParser(responseText, posts[i].getPostNumber()).convertSinglePost();
if(icon != null ){
if(Arrays.asList(iconsNoUrl).contains(icon.first)) {
posts[i].setIcons(new Icon(locator, Uri.parse("chan:///res/raw/" + icon.first), icon.second));
}
else {
posts[i].setIcons(new Icon(locator, Uri.parse("https://static.syn-ch.com/flags/b/" + icon.first + ".png"), icon.second));
}
} else{
posts[i].setIcons();
}
}
return new ReadPostsResult(posts);
}
Expand Down Expand Up @@ -150,6 +170,7 @@ public SendPostResult onSendPost(SendPostData data) throws HttpException, ApiExc
}
}
entity.add("json_response", "1");
entity.add("user_flag", data.userIcon);

SynchChanLocator locator = ChanLocator.get(this);
Uri contentUri = data.threadNumber != null ? locator.createThreadUri(data.boardName, data.threadNumber)
Expand Down
5 changes: 4 additions & 1 deletion src/com/mishiranu/dashchan/chan/synch/SynchModelMapper.java
Expand Up @@ -17,6 +17,7 @@
import chan.content.model.Icon;
import chan.content.model.Post;
import chan.content.model.Posts;
import chan.http.HttpRequest;
import chan.util.CommonUtils;
import chan.util.StringUtils;

Expand All @@ -38,7 +39,7 @@ public static FileAttachment createFileAttachment(JSONObject jsonObject, SynchCh
FileAttachment attachment = new FileAttachment();
String tim = CommonUtils.getJsonString(jsonObject, "tim");
String filename = CommonUtils.getJsonString(jsonObject, "filename");
String ext = CommonUtils.getJsonString(jsonObject, "ext");
String ext = CommonUtils.getJsonString(jsonObject, "ext").toLowerCase();
String thumb = CommonUtils.getJsonString(jsonObject, "thumb");
attachment.setSize(jsonObject.optInt("fsize"));
attachment.setWidth(jsonObject.optInt("h"));
Expand Down Expand Up @@ -102,6 +103,8 @@ public static Post createPost(JSONObject jsonObject, SynchChanLocator locator, S
if (com != null) {
// Vichan JSON API bug, sometimes comment is broken
com = com.replace("<a ", "<a ").replaceAll("href=\"\\?", "href=\"");
com = com.replace("class=\"public_ban\"", "style=\"color: red\"");
com = com.replace("class=\"irony\"", "style=\"color: #FF00FF\"");
post.setComment(com);
}
ArrayList<Attachment> attachments = null;
Expand Down
60 changes: 60 additions & 0 deletions src/com/mishiranu/dashchan/chan/synch/SynchPostsParser.java
@@ -0,0 +1,60 @@
package com.mishiranu.dashchan.chan.synch;

import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.annotation.SuppressLint;
import android.text.Html;
import android.util.Log;
import android.util.Pair;

import chan.content.ChanConfiguration;
import chan.content.ChanLocator;
import chan.content.model.FileAttachment;
import chan.content.model.Post;
import chan.content.model.Posts;
import chan.text.ParseException;
import chan.text.TemplateParser;
import chan.util.StringUtils;

@SuppressLint("SimpleDateFormat")
public class SynchPostsParser
{
private String mSource;

private String mPostNumber;

// private static final Pattern FLAG = Pattern.compile("<span class=\"flag flag-(.*?)\"");



public SynchPostsParser(String source, String postNumber)
{
mSource = source;
mPostNumber = postNumber;
}

public Pair<String, String> convertSinglePost() {
Pattern FLAG = Pattern.compile("<label for=\"delete_" + mPostNumber + "\">(.*?)<span class=\"flag flag-(.*?)\"(.*?)title=\"(.*?)\" ></span>(.*?)</label>");
Pattern NOT_NEEDED = Pattern.compile("<label for=\"delete_(.*?)\"");
Matcher matcher = FLAG.matcher(mSource);
if(matcher.find()){
Matcher matcher1 = NOT_NEEDED.matcher(matcher.group(1));
if(!matcher1.find()){
Log.d("benis", "found" + matcher.group(2));
Log.d("benis", matcher.group(4));
Pair<String, String> toIcon = new Pair<String, String>(matcher.group(2), StringUtils.unescapeHtml(matcher.group(4)));
return toIcon;
} else {
return null;
}
} else{
return null;
}
}
}

0 comments on commit e824900

Please sign in to comment.