Browse Source

Topic reply refreshes topic, bookmarks go to last topic's page

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
41fcbd1d2e
  1. 4
      app/build.gradle
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java
  3. 263
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java
  4. 44
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/ReplyParser.java
  5. 30
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  6. 228
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

4
app/build.gradle

@ -20,8 +20,8 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
debug { debug {
//def date = new Date().format('ddMMyy_HHmm'); def date = new Date().format('ddMMyy_HHmm');
def date = 1; //def date = 1;
archivesBaseName = archivesBaseName + "-$date" archivesBaseName = archivesBaseName + "-$date"
} }
} }

2
app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java

@ -114,7 +114,7 @@ public class BookmarkActivity extends BaseActivity {
Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class); Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic=" extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic="
+ bookmarkedTopic.getId() + ".0"); + bookmarkedTopic.getId() + "." + 2147483647);
extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle()); extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle());
intent.putExtras(extras); intent.putExtras(extras);
startActivity(intent); startActivity(intent);

263
app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java

@ -0,0 +1,263 @@
package gr.thmmy.mthmmy.activities.topic;
import android.util.Log;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import okhttp3.Response;
class Posting {
enum REPLY_STATUS {
SUCCESSFUL, NO_SUBJECT, EMPTY_BODY, NEW_REPLY_WHILE_POSTING, NOT_FOUND, SESSION_ENDED, OTHER_ERROR
}
static REPLY_STATUS replyStatus(Response response) throws IOException {
if (response.code() == 404) return REPLY_STATUS.NOT_FOUND;
if (response.code() < 200 || response.code() >= 400) return REPLY_STATUS.OTHER_ERROR;
String finalUrl = response.request().url().toString();
if (finalUrl.contains("action=post")) {
Document postErrorPage = Jsoup.parse(response.body().string());
String[] errors = postErrorPage.select("tr[id=errors] div[id=error_list]").first()
.toString().split("<br>");
for (int i = 0; i < errors.length; ++i) { //TODO test
Log.d("TAG", String.valueOf(i));
Log.d("TAG", errors[i]);
}
for (String error : errors) {
if (error.contains("Your session timed out while posting") ||
error.contains("Υπερβήκατε τον μέγιστο χρόνο σύνδεσης κατά την αποστολή"))
return REPLY_STATUS.SESSION_ENDED;
if (error.contains("No subject was filled in")
|| error.contains("Δεν δόθηκε τίτλος"))
return REPLY_STATUS.NO_SUBJECT;
if (error.contains("The message body was left empty")
|| error.contains("Δεν δόθηκε κείμενο για το μήνυμα"))
return REPLY_STATUS.EMPTY_BODY;
}
return REPLY_STATUS.NEW_REPLY_WHILE_POSTING;
}
return REPLY_STATUS.SUCCESSFUL;
}
static String htmlToBBcode(String html) {
Map<String, String> bbMap = new HashMap<>();
Map<String, String> smileysMap1 = new HashMap<>();
Map<String, String> smileysMap2 = new HashMap<>();
smileysMap1.put("Smiley", ":)");
smileysMap1.put("Wink", ";)");
smileysMap1.put("Cheesy", ":D");
smileysMap1.put("Grin", ";D");
smileysMap1.put("Angry", ">:(");
smileysMap1.put("Sad", ":(");
smileysMap1.put("Shocked", ":o");
smileysMap1.put("Cool", "8))");
smileysMap1.put("Huh", ":???:");
smileysMap1.put("Roll Eyes", "::)");
smileysMap1.put("Tongue", ":P");
smileysMap1.put("Embarrassed", ":-[");
smileysMap1.put("Lips Sealed", ":-X");
smileysMap1.put("Kiss", ":-*");
smileysMap1.put("Cry", ":'(");
smileysMap1.put("heart", "<3");
smileysMap1.put("kleidaria", "^locked^");
smileysMap1.put("roll_over", "^rollover^");
smileysMap1.put("redface", "^redface^");
smileysMap1.put("confused", "^confused^");
smileysMap1.put("innocent", "^innocent^");
smileysMap1.put("sleep", "^sleep^");
smileysMap1.put("lips_sealed", "^sealed^");
smileysMap1.put("cool", "^cool^");
smileysMap1.put("crazy", "^crazy^");
smileysMap1.put("mad", "^mad^");
smileysMap1.put("wav", "^wav^");
smileysMap1.put("BinkyBaby", "^binkybaby^");
smileysMap1.put("DontKnow", "^dontknow^");
smileysMap1.put("angry4", ":angry4:");
smileysMap1.put("angryAndHot", "^angryhot^");
smileysMap1.put("angry", "^angry^");
smileysMap1.put("bang_head", "^banghead^");
smileysMap1.put("CryBaby", "^crybaby^");
smileysMap1.put("Hello", "^hello^");
smileysMap1.put("jerk", "^jerk^");
smileysMap1.put("NoNo", "^nono^");
smileysMap1.put("NotWorthy", "^notworthy^");
smileysMap1.put("Off-topic", "^off-topic^");
smileysMap1.put("Puke", "^puke^");
smileysMap1.put("Shout", "^shout^");
smileysMap1.put("Slurp", "^slurp^");
smileysMap1.put("SuperConfused", "^superconfused^");
smileysMap1.put("SuperInnocent", "^superinnocent^");
smileysMap1.put("CellPhone", "^cellPhone^");
smileysMap1.put("Idiot", "^idiot^");
smileysMap1.put("Knuppel", "^knuppel^");
smileysMap1.put("TickedOff", "^tickedOff^");
smileysMap1.put("Peace", "^peace^");
smileysMap1.put("Suspicious", "^suspicious^");
smileysMap1.put("Caffine", "^caffine^");
smileysMap1.put("argue", "^argue^");
smileysMap1.put("banned2", "^banned2^");
smileysMap1.put("banned", "^banned^");
smileysMap1.put("bath", "^bath^");
smileysMap1.put("beg", "^beg^");
smileysMap1.put("bluescreen", "^bluescreen^");
smileysMap1.put("boil", "^boil^");
smileysMap1.put("bye", "^bye^");
smileysMap1.put("callmerip", "^callmerip^");
smileysMap1.put("carnaval", "^carnaval^");
smileysMap1.put("clap", "^clap^");
smileysMap1.put("coffepot", "^coffepot^");
smileysMap1.put("crap", "^crap^");
smileysMap1.put("curses", "^curses^");
smileysMap1.put("funny", "^funny^");
smileysMap1.put("guitar", "^guitar^");
smileysMap1.put("kissy", "^kissy^");
smileysMap1.put("band", "^band^");
smileysMap1.put("ivres", "^ivres^");
smileysMap1.put("kaloe", "^kaloe^");
smileysMap1.put("kremala", "^kremala^");
smileysMap1.put("moon", "^moon^");
smileysMap1.put("mopping", "^mopping^");
smileysMap1.put("mountza", "^mountza^");
smileysMap1.put("pcsleep", "^pcsleep^");
smileysMap1.put("pinokio", "^pinokio^");
smileysMap1.put("poke", "^poke^");
smileysMap1.put("seestars", "^seestars^");
smileysMap1.put("sfyri", "^sfyri^");
smileysMap1.put("spam", "^spam^");
smileysMap1.put("super", "^super^");
smileysMap1.put("tafos", "^tafos^");
smileysMap1.put("tomato", "^tomato^");
smileysMap1.put("ytold", "^ytold^");
smileysMap1.put("beer", "^beer^");
smileysMap1.put("ο fritz!!!", "^fritz^");
smileysMap1.put("o Wade!!!", "^wade^");
smileysMap1.put("bonjour", "^hat^");
smileysMap1.put("bonjour2", "^miss^");
smileysMap1.put("question", "^que^");
smileysMap1.put("shifty", "^shifty^");
smileysMap1.put("shy", "^shy^");
smileysMap1.put("music_listenning", "^music_listen^");
smileysMap1.put("bag_face", "^bagface^");
smileysMap1.put("rotation", "^rotate^");
smileysMap1.put("love", "^love^");
smileysMap1.put("speech", "^speech^");
smileysMap1.put("shocked", "^shocked^");
smileysMap1.put("extremely_shocked", "^ex_shocked^");
smileysMap1.put("smurf", "^smurf^");
smileysMap1.put("monster", "^monster^");
smileysMap1.put("pig", "^pig^");
smileysMap1.put("lol", "^lol^");
smileysMap2.put("Police", "^Police^");
smileysMap2.put("foyska", "^fouska^");
smileysMap2.put("nista", "^nysta^");
smileysMap2.put("10_7_3", "^sfinaki^");
smileysMap2.put("yu", "^yue^");
smileysMap2.put("a-eatpaper", "^eatpaper^");
smileysMap2.put("lypi", "^lypi^");
smileysMap2.put("megashok1wq", "^aytoxeir^");
smileysMap2.put("victory", "^victory^");
smileysMap2.put("filarakia", "^filarakia^");
smileysMap2.put("rofl", "^rolfmao^");
smileysMap2.put("locked", "^lock^");
smileysMap2.put("facepalm", "^facepalm^");
//html stuff on the beginning
bbMap.put("<link rel=.+\">\n ", "");
//quotes and code headers
bbMap.put("\n\\s+?<div class=\"quoteheader\">\n (.+?)\n </div>", "");
bbMap.put("\n\\s+?<div class=\"codeheader\">\n (.+?)\n </div>", "");
bbMap.put("\n\\s+?<div class=\"quote\">\n (.+?)\n </div>", "");
bbMap.put("<br>", "\n");
//bold
bbMap.put("\n\\s+?<b>(.+?)</b>", "\\[b\\]$1\\[/b\\]");
//italics
bbMap.put("\n\\s+?<i>(.+?)</i>", "\\[i\\]$1\\[/i\\]");
//underline
bbMap.put("\n\\s+?<span style=\"text-decoration: underline;\">(.+?)</span>", "\\[u\\]$1\\[/u\\]");
//deleted
bbMap.put("\n\\s+?<del>(.+?)</del>", "\\[s\\]$1\\[/s\\]");
//text color
bbMap.put("\n\\s+?<span style=\"color: (.+?);\">(.+?)</span>", "\\[color=$1\\]$2\\[/color\\]");
//glow
bbMap.put("\n\\s+?<span style=\"background-color: (.+?);\">(.+?)</span>", "\\[glow=$1,2,300\\]$2\\[/glow\\]");
//shadow
bbMap.put("\n\\s+?<span style=\"text-shadow: (.+?) (.+?)\">(.+?)</span>", "\\[shadow=$1,$2\\]$3\\[/shadow\\]");
//running text
bbMap.put("\\s+?<marquee>\n (.+?)\n </marquee>", "\\[move\\]$1\\[/move\\]");
//alignment
bbMap.put("\n\\s+?<div align=\"center\">\n (.+?)\n </div>", "\\[center\\]$1\\[/center\\]");
bbMap.put("\n\\s+?<div style=\"text-align: (.+?);\">\n (.+?)\n </div>", "\\[$1\\]$2\\[/$1\\]");
//preformated
bbMap.put("\n\\s+?<pre>(.+?)</pre>", "\\[pre\\]$1\\[/pre\\]");
//horizontal rule
bbMap.put("\n\\s+?<hr>", "\\[hr\\]");
//resize
bbMap.put("\n\\s+?<span style=\"font-size: (.+?);(.+?)\">(.+?)</span>", "\\[size=$1\\]$3\\[/size\\]");
//font
bbMap.put("\n\\s+?<span style=\"font-family: (.+?);\">(.+?)</span>", "\\[font=$1\\]$2\\[/font\\]");
//lists
bbMap.put("\\s+<li>(.+?)</li>", "\\[li\\]$1\\[/li\\]");
bbMap.put("\n\\s+<ul style=\"margin-top: 0; margin-bottom: 0;\">([\\S\\s]+?)\n\\s+</ul>",
"\\[list\\]\n$1\n\\[/list\\]");
//latex code
bbMap.put("\n\\s+?<img src=\".+?eq=(.+?)\" .+?\">", "\\[tex\\]$1\\[/tex\\]");
//code
bbMap.put("\n\\s+?<div class=\"code\">\n (.+?)\n </div>", "\\[code\\]$1\\[/code\\]");
//teletype
bbMap.put("\n\\s+?<tt>(.+?)</tt>", "\\[tt\\]$1\\[/tt\\]");
//superscript/subscript
bbMap.put("\n\\s+?<sub>(.+?)</sub>", "\\[sub\\]$1\\[/sub\\]");
bbMap.put("\n\\s+?<sup>(.+?)</sup>", "\\[sup\\]$1\\[/sup\\]");
//tables
bbMap.put("\\s+?<td.+?>([\\S\\s]+?)</td>", "\\[td\\]$1\\[/td\\]");
bbMap.put("<tr>([\\S\\s]+?)\n </tr>", "\\[tr\\]$1\\[/tr\\]");
bbMap.put("\n\\s+?<table style=\"(.+?)\">\n <tbody>\n ([\\S\\s]+?)\n </tbody>\n </table>"
, "\\[table\\]$2\\[/table\\]");
//videos
bbMap.put("\n\\s+?<div class=\"yt\"><a href=\".+?watch\\?v=(.+?)\"((.|\\n)*?)\\/div>\n",
"[youtube]https://www.youtube.com/watch?v=$1[/youtube]");
//ftp
bbMap.put("<a href=\"ftp:(.+?)\" .+?>([\\S\\s]+?)</a>", "\\[fpt=ftp:$1\\]$2\\[/ftp\\]");
//mailto
bbMap.put("\n\\s+?<a href=\"mailto:(.+?)\">([\\S\\s]+?)</a>", "\\[email\\]$2\\[/email\\]");
//links
bbMap.put("\n\\s+?<a href=\"(.+?)\" .+?>([\\S\\s]+?)</a>", "\\[url=$1\\]$2\\[/url\\]");
//smileys
for (Map.Entry entry : smileysMap1.entrySet()) {
bbMap.put("\n <img src=\"(.+?)//www.thmmy.gr/smf/Smileys/default_dither/(.+?) alt=\""
+ entry.getKey().toString() + "\" .+?\">", entry.getValue().toString());
}
for (Map.Entry entry : smileysMap2.entrySet()) { //Those that have empty alt tag
bbMap.put("\n <img src=\"(.+?)//www.thmmy.gr/smf/Smileys/default_dither/"
+ entry.getKey().toString() + ".gif\" .+?\">", entry.getValue().toString());
}
bbMap.put("\n <img src=\"(.+?)//www.thmmy.gr/smf/Smileys/default_dither/undecided.gif\" alt=\"Undecided\" border=\"0\">"
, Matcher.quoteReplacement(":-\\"));
//html stuff on the end
bbMap.put("\n</div>", "");
for (Map.Entry entry : bbMap.entrySet()) {
html = html.replaceAll(entry.getKey().toString(), entry.getValue().toString());
}
//img need to be done last or it messes up everything else
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? width=\"(.+?)\" .+? height=\"(.+?)\" .+?>",
"\\[img width=$2 height=$3\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? height=\"(.+?)\" .+? width=\"(.+?)\" .+?>",
"\\[img height=$2 width=$3\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? width=\"(.+?)\" .+?>", "\\[img width=$2\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? height=\"(.+?)\" .+?>", "\\[img height=$2\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\".+?>", "\\[img\\]$1\\[/img\\]");
return html;
}
}

44
app/src/main/java/gr/thmmy/mthmmy/activities/topic/ReplyParser.java

@ -1,44 +0,0 @@
package gr.thmmy.mthmmy.activities.topic;
import android.util.Log;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import okhttp3.Response;
class ReplyParser {
enum REPLY_STATUS {
SUCCESSFUL, NO_SUBJECT, EMPTY_BODY, NEW_REPLY_WHILE_POSTING, NOT_FOUND, SESSION_ENDED, OTHER_ERROR
}
static REPLY_STATUS replyStatus(Response response) throws IOException {
if (response.code() == 404) return REPLY_STATUS.NOT_FOUND;
if (response.code() < 200 || response.code() >= 400) return REPLY_STATUS.OTHER_ERROR;
String finalUrl = response.request().url().toString();
if (finalUrl.contains("action=post")) {
Document postErrorPage = Jsoup.parse(response.body().string());
String[] errors = postErrorPage.select("tr[id=errors] div[id=error_list]").first()
.toString().split("<br>");
for (int i = 0; i < errors.length; ++i) { //TODO test
Log.d("TAG", String.valueOf(i));
Log.d("TAG", errors[i]);
}
for (String error : errors) {
if (error.contains("Your session timed out while posting") ||
error.contains("Υπερβήκατε τον μέγιστο χρόνο σύνδεσης κατά την αποστολή"))
return REPLY_STATUS.SESSION_ENDED;
if (error.contains("No subject was filled in")
|| error.contains("Δεν δόθηκε τίτλος"))
return REPLY_STATUS.NO_SUBJECT;
if (error.contains("The message body was left empty")
|| error.contains("Δεν δόθηκε κείμενο για το μήνυμα"))
return REPLY_STATUS.EMPTY_BODY;
}
return REPLY_STATUS.NEW_REPLY_WHILE_POSTING;
}
return REPLY_STATUS.SUCCESSFUL;
}
}

30
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.topic; package gr.thmmy.mthmmy.activities.topic;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
@ -17,12 +18,14 @@ import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod; import android.text.method.ScrollingMovementMethod;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -60,7 +63,7 @@ import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.topic.ReplyParser.replyStatus; import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus;
/** /**
* Activity for topics. When creating an Intent of this activity you need to bundle a <b>String</b> * Activity for topics. When creating an Intent of this activity you need to bundle a <b>String</b>
@ -117,6 +120,7 @@ public class TopicActivity extends BaseActivity {
private String parsedTitle; private String parsedTitle;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private String loadedPageUrl = ""; private String loadedPageUrl = "";
private boolean reloadingPage = false;
@Override @Override
@ -480,7 +484,7 @@ public class TopicActivity extends BaseActivity {
} }
} }
//Checks if the page to be loaded is the one already shown //Checks if the page to be loaded is the one already shown
if (!Objects.equals(loadedPageUrl, "") && loadedPageUrl.contains(base_url)) { if (!reloadingPage && !Objects.equals(loadedPageUrl, "") && loadedPageUrl.contains(base_url)) {
if (newPageUrl.contains("topicseen#new") || newPageUrl.contains("#new")) if (newPageUrl.contains("topicseen#new") || newPageUrl.contains("#new"))
if (thisPage == numberOfPages) if (thisPage == numberOfPages)
return SAME_PAGE; return SAME_PAGE;
@ -497,6 +501,7 @@ public class TopicActivity extends BaseActivity {
} else if (Integer.parseInt(newPageUrl.substring(base_url.length() + 1)) / 15 + 1 == thisPage) //TODO fix bug } else if (Integer.parseInt(newPageUrl.substring(base_url.length() + 1)) / 15 + 1 == thisPage) //TODO fix bug
return SAME_PAGE; return SAME_PAGE;
} else if (!Objects.equals(loadedPageUrl, "")) topicTitle = null; } else if (!Objects.equals(loadedPageUrl, "")) topicTitle = null;
if (reloadingPage) reloadingPage = !reloadingPage;
loadedPageUrl = newPageUrl; loadedPageUrl = newPageUrl;
replyPageUrl = null; replyPageUrl = null;
@ -735,13 +740,34 @@ public class TopicActivity extends BaseActivity {
@Override @Override
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
View view = getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
postsList.remove(postsList.size() - 1);
topicAdapter.notifyItemRemoved(postsList.size());
progressBar.setVisibility(ProgressBar.GONE); progressBar.setVisibility(ProgressBar.GONE);
replyFAB.setVisibility(View.VISIBLE); replyFAB.setVisibility(View.VISIBLE);
bottomNavBar.setVisibility(View.VISIBLE); bottomNavBar.setVisibility(View.VISIBLE);
if (!result) if (!result)
Toast.makeText(TopicActivity.this, "Post failed!", Toast.LENGTH_SHORT).show(); Toast.makeText(TopicActivity.this, "Post failed!", Toast.LENGTH_SHORT).show();
paginationEnabled(true); paginationEnabled(true);
replyFAB.setEnabled(true); replyFAB.setEnabled(true);
if (result) {
topicTask = new TopicTask();
if ((postsList.get(postsList.size() - 1).getPostNumber() + 1) % 15 == 0)
topicTask.execute(base_url + "." + 2147483647);
else {
reloadingPage = true;
topicTask.execute(loadedPageUrl);
}
Log.d("TAG", "sent");
}
} }
} }
} }

228
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -42,12 +42,9 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Matcher;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity;
@ -66,6 +63,7 @@ import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.topic.Posting.htmlToBBcode;
import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager;
/** /**
@ -144,6 +142,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
} else if (viewType == VIEW_TYPE_QUICK_REPLY) { } else if (viewType == VIEW_TYPE_QUICK_REPLY) {
View view = LayoutInflater.from(parent.getContext()). View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.activity_topic_quick_reply_row, parent, false); inflate(R.layout.activity_topic_quick_reply_row, parent, false);
view.findViewById(R.id.quick_reply_submit).setEnabled(true);
//Default post subject //Default post subject
replyDataHolder[replySubject] = "Re: " + topicTitle; replyDataHolder[replySubject] = "Re: " + topicTitle;
//Build quotes //Build quotes
@ -467,9 +466,14 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.submitButton.setOnClickListener(new View.OnClickListener() { holder.submitButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (holder.quickReplySubject.getText().toString().isEmpty()) return;
if (holder.quickReply.getText().toString().isEmpty()) return; if (holder.quickReply.getText().toString().isEmpty()) return;
holder.submitButton.setEnabled(false); holder.submitButton.setEnabled(false);
replyTask.execute(holder.quickReply.getText().toString()); replyTask.execute(holder.quickReplySubject.getText().toString(),
holder.quickReply.getText().toString());
replyDataHolder[replySubject] = "Re: " + topicTitle;
replyDataHolder[replyText] = "";
holder.quickReply.setText("");
} }
}); });
} }
@ -782,222 +786,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
return null; return null;
} }
private String htmlToBBcode(String html) {
Map<String, String> bbMap = new HashMap<>();
Map<String, String> smileysMap1 = new HashMap<>();
Map<String, String> smileysMap2 = new HashMap<>();
smileysMap1.put("Smiley", ":)");
smileysMap1.put("Wink", ";)");
smileysMap1.put("Cheesy", ":D");
smileysMap1.put("Grin", ";D");
smileysMap1.put("Angry", ">:(");
smileysMap1.put("Sad", ":(");
smileysMap1.put("Shocked", ":o");
smileysMap1.put("Cool", "8))");
smileysMap1.put("Huh", ":???:");
smileysMap1.put("Roll Eyes", "::)");
smileysMap1.put("Tongue", ":P");
smileysMap1.put("Embarrassed", ":-[");
smileysMap1.put("Lips Sealed", ":-X");
smileysMap1.put("Kiss", ":-*");
smileysMap1.put("Cry", ":'(");
smileysMap1.put("heart", "<3");
smileysMap1.put("kleidaria", "^locked^");
smileysMap1.put("roll_over", "^rollover^");
smileysMap1.put("redface", "^redface^");
smileysMap1.put("confused", "^confused^");
smileysMap1.put("innocent", "^innocent^");
smileysMap1.put("sleep", "^sleep^");
smileysMap1.put("lips_sealed", "^sealed^");
smileysMap1.put("cool", "^cool^");
smileysMap1.put("crazy", "^crazy^");
smileysMap1.put("mad", "^mad^");
smileysMap1.put("wav", "^wav^");
smileysMap1.put("BinkyBaby", "^binkybaby^");
smileysMap1.put("DontKnow", "^dontknow^");
smileysMap1.put("angry4", ":angry4:");
smileysMap1.put("angryAndHot", "^angryhot^");
smileysMap1.put("angry", "^angry^");
smileysMap1.put("bang_head", "^banghead^");
smileysMap1.put("CryBaby", "^crybaby^");
smileysMap1.put("Hello", "^hello^");
smileysMap1.put("jerk", "^jerk^");
smileysMap1.put("NoNo", "^nono^");
smileysMap1.put("NotWorthy", "^notworthy^");
smileysMap1.put("Off-topic", "^off-topic^");
smileysMap1.put("Puke", "^puke^");
smileysMap1.put("Shout", "^shout^");
smileysMap1.put("Slurp", "^slurp^");
smileysMap1.put("SuperConfused", "^superconfused^");
smileysMap1.put("SuperInnocent", "^superinnocent^");
smileysMap1.put("CellPhone", "^cellPhone^");
smileysMap1.put("Idiot", "^idiot^");
smileysMap1.put("Knuppel", "^knuppel^");
smileysMap1.put("TickedOff", "^tickedOff^");
smileysMap1.put("Peace", "^peace^");
smileysMap1.put("Suspicious", "^suspicious^");
smileysMap1.put("Caffine", "^caffine^");
smileysMap1.put("argue", "^argue^");
smileysMap1.put("banned2", "^banned2^");
smileysMap1.put("banned", "^banned^");
smileysMap1.put("bath", "^bath^");
smileysMap1.put("beg", "^beg^");
smileysMap1.put("bluescreen", "^bluescreen^");
smileysMap1.put("boil", "^boil^");
smileysMap1.put("bye", "^bye^");
smileysMap1.put("callmerip", "^callmerip^");
smileysMap1.put("carnaval", "^carnaval^");
smileysMap1.put("clap", "^clap^");
smileysMap1.put("coffepot", "^coffepot^");
smileysMap1.put("crap", "^crap^");
smileysMap1.put("curses", "^curses^");
smileysMap1.put("funny", "^funny^");
smileysMap1.put("guitar", "^guitar^");
smileysMap1.put("kissy", "^kissy^");
smileysMap1.put("band", "^band^");
smileysMap1.put("ivres", "^ivres^");
smileysMap1.put("kaloe", "^kaloe^");
smileysMap1.put("kremala", "^kremala^");
smileysMap1.put("moon", "^moon^");
smileysMap1.put("mopping", "^mopping^");
smileysMap1.put("mountza", "^mountza^");
smileysMap1.put("pcsleep", "^pcsleep^");
smileysMap1.put("pinokio", "^pinokio^");
smileysMap1.put("poke", "^poke^");
smileysMap1.put("seestars", "^seestars^");
smileysMap1.put("sfyri", "^sfyri^");
smileysMap1.put("spam", "^spam^");
smileysMap1.put("super", "^super^");
smileysMap1.put("tafos", "^tafos^");
smileysMap1.put("tomato", "^tomato^");
smileysMap1.put("ytold", "^ytold^");
smileysMap1.put("beer", "^beer^");
smileysMap1.put("ο fritz!!!", "^fritz^");
smileysMap1.put("o Wade!!!", "^wade^");
smileysMap1.put("bonjour", "^hat^");
smileysMap1.put("bonjour2", "^miss^");
smileysMap1.put("question", "^que^");
smileysMap1.put("shifty", "^shifty^");
smileysMap1.put("shy", "^shy^");
smileysMap1.put("music_listenning", "^music_listen^");
smileysMap1.put("bag_face", "^bagface^");
smileysMap1.put("rotation", "^rotate^");
smileysMap1.put("love", "^love^");
smileysMap1.put("speech", "^speech^");
smileysMap1.put("shocked", "^shocked^");
smileysMap1.put("extremely_shocked", "^ex_shocked^");
smileysMap1.put("smurf", "^smurf^");
smileysMap1.put("monster", "^monster^");
smileysMap1.put("pig", "^pig^");
smileysMap1.put("lol", "^lol^");
smileysMap2.put("Police", "^Police^");
smileysMap2.put("foyska", "^fouska^");
smileysMap2.put("nista", "^nysta^");
smileysMap2.put("10_7_3", "^sfinaki^");
smileysMap2.put("yu", "^yue^");
smileysMap2.put("a-eatpaper", "^eatpaper^");
smileysMap2.put("lypi", "^lypi^");
smileysMap2.put("megashok1wq", "^aytoxeir^");
smileysMap2.put("victory", "^victory^");
smileysMap2.put("filarakia", "^filarakia^");
smileysMap2.put("rofl", "^rolfmao^");
smileysMap2.put("locked", "^lock^");
smileysMap2.put("facepalm", "^facepalm^");
//html stuff on the beginning
bbMap.put("<link rel=.+\">\n ", "");
//quotes and code headers
bbMap.put("\n\\s+?<div class=\"quoteheader\">\n (.+?)\n </div>", "");
bbMap.put("\n\\s+?<div class=\"codeheader\">\n (.+?)\n </div>", "");
bbMap.put("\n\\s+?<div class=\"quote\">\n (.+?)\n </div>", "");
bbMap.put("<br>", "\n");
//bold
bbMap.put("\n\\s+?<b>(.+?)</b>", "\\[b\\]$1\\[/b\\]");
//italics
bbMap.put("\n\\s+?<i>(.+?)</i>", "\\[i\\]$1\\[/i\\]");
//underline
bbMap.put("\n\\s+?<span style=\"text-decoration: underline;\">(.+?)</span>", "\\[u\\]$1\\[/u\\]");
//deleted
bbMap.put("\n\\s+?<del>(.+?)</del>", "\\[s\\]$1\\[/s\\]");
//text color
bbMap.put("\n\\s+?<span style=\"color: (.+?);\">(.+?)</span>", "\\[color=$1\\]$2\\[/color\\]");
//glow
bbMap.put("\n\\s+?<span style=\"background-color: (.+?);\">(.+?)</span>", "\\[glow=$1,2,300\\]$2\\[/glow\\]");
//shadow
bbMap.put("\n\\s+?<span style=\"text-shadow: (.+?) (.+?)\">(.+?)</span>", "\\[shadow=$1,$2\\]$3\\[/shadow\\]");
//running text
bbMap.put("\\s+?<marquee>\n (.+?)\n </marquee>", "\\[move\\]$1\\[/move\\]");
//alignment
bbMap.put("\n\\s+?<div align=\"center\">\n (.+?)\n </div>", "\\[center\\]$1\\[/center\\]");
bbMap.put("\n\\s+?<div style=\"text-align: (.+?);\">\n (.+?)\n </div>", "\\[$1\\]$2\\[/$1\\]");
//preformated
bbMap.put("\n\\s+?<pre>(.+?)</pre>", "\\[pre\\]$1\\[/pre\\]");
//horizontal rule
bbMap.put("\n\\s+?<hr>", "\\[hr\\]");
//resize
bbMap.put("\n\\s+?<span style=\"font-size: (.+?);(.+?)\">(.+?)</span>", "\\[size=$1\\]$3\\[/size\\]");
//font
bbMap.put("\n\\s+?<span style=\"font-family: (.+?);\">(.+?)</span>", "\\[font=$1\\]$2\\[/font\\]");
//lists
bbMap.put("\\s+<li>(.+?)</li>", "\\[li\\]$1\\[/li\\]");
bbMap.put("\n\\s+<ul style=\"margin-top: 0; margin-bottom: 0;\">([\\S\\s]+?)\n\\s+</ul>",
"\\[list\\]\n$1\n\\[/list\\]");
//latex code
bbMap.put("\n\\s+?<img src=\".+?eq=(.+?)\" .+?\">", "\\[tex\\]$1\\[/tex\\]");
//code
bbMap.put("\n\\s+?<div class=\"code\">\n (.+?)\n </div>", "\\[code\\]$1\\[/code\\]");
//teletype
bbMap.put("\n\\s+?<tt>(.+?)</tt>", "\\[tt\\]$1\\[/tt\\]");
//superscript/subscript
bbMap.put("\n\\s+?<sub>(.+?)</sub>", "\\[sub\\]$1\\[/sub\\]");
bbMap.put("\n\\s+?<sup>(.+?)</sup>", "\\[sup\\]$1\\[/sup\\]");
//tables
bbMap.put("\\s+?<td.+?>([\\S\\s]+?)</td>", "\\[td\\]$1\\[/td\\]");
bbMap.put("<tr>([\\S\\s]+?)\n </tr>", "\\[tr\\]$1\\[/tr\\]");
bbMap.put("\n\\s+?<table style=\"(.+?)\">\n <tbody>\n ([\\S\\s]+?)\n </tbody>\n </table>"
, "\\[table\\]$2\\[/table\\]");
//videos
bbMap.put("\n\\s+?<div class=\"yt\"><a href=\".+?watch\\?v=(.+?)\"((.|\\n)*?)\\/div>\n",
"[youtube]https://www.youtube.com/watch?v=$1[/youtube]");
//ftp
bbMap.put("<a href=\"ftp:(.+?)\" .+?>([\\S\\s]+?)</a>", "\\[fpt=ftp:$1\\]$2\\[/ftp\\]");
//mailto
bbMap.put("\n\\s+?<a href=\"mailto:(.+?)\">([\\S\\s]+?)</a>", "\\[email\\]$2\\[/email\\]");
//links
bbMap.put("\n\\s+?<a href=\"(.+?)\" .+?>([\\S\\s]+?)</a>", "\\[url=$1\\]$2\\[/url\\]");
//smileys
for (Map.Entry entry : smileysMap1.entrySet()) {
bbMap.put("\n <img src=\"(.+?)//www.thmmy.gr/smf/Smileys/default_dither/(.+?) alt=\""
+ entry.getKey().toString() + "\" .+?\">", entry.getValue().toString());
}
for (Map.Entry entry : smileysMap2.entrySet()) { //Those that have empty alt tag
bbMap.put("\n <img src=\"(.+?)//www.thmmy.gr/smf/Smileys/default_dither/"
+ entry.getKey().toString() + ".gif\" .+?\">", entry.getValue().toString());
}
bbMap.put("\n <img src=\"(.+?)//www.thmmy.gr/smf/Smileys/default_dither/undecided.gif\" alt=\"Undecided\" border=\"0\">"
, Matcher.quoteReplacement(":-\\"));
//html stuff on the end
bbMap.put("\n</div>", "");
for (Map.Entry entry : bbMap.entrySet()) {
html = html.replaceAll(entry.getKey().toString(), entry.getValue().toString());
}
//img need to be done last or it messes up everything else
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? width=\"(.+?)\" .+? height=\"(.+?)\" .+?>",
"\\[img width=$2 height=$3\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? height=\"(.+?)\" .+? width=\"(.+?)\" .+?>",
"\\[img height=$2 width=$3\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? width=\"(.+?)\" .+?>", "\\[img width=$2\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? height=\"(.+?)\" .+?>", "\\[img height=$2\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\".+?>", "\\[img\\]$1\\[/img\\]");
return html;
}
/** /**
* Returns a String with a single FontAwesome typeface character corresponding to this file's * Returns a String with a single FontAwesome typeface character corresponding to this file's
* extension. * extension.

Loading…
Cancel
Save