Browse Source

Bookmarks refresh on activity resume, fixed quote, embedded video overlay image and recyclerView bugs. Made activities SingeInstance.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
c79b1204f4
  1. 5
      app/src/main/AndroidManifest.xml
  2. BIN
      app/src/main/assets/YouTube_light_color_icon.png
  3. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  4. 121
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java
  5. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  6. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  7. 26
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  8. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java

5
app/src/main/AndroidManifest.xml

@ -48,8 +48,7 @@
android:host="thmmy.gr"
android:scheme="https" />
<data
android:host="thmmy.gr"/>
<data android:host="thmmy.gr" />
</intent-filter>
</activity>
<activity
@ -61,6 +60,7 @@
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".activities.AboutActivity"
android:launchMode="singleInstance"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
@ -90,6 +90,7 @@
</activity>
<activity
android:name=".activities.downloads.DownloadsActivity"
android:launchMode="singleInstance"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data

BIN
app/src/main/assets/YouTube_light_color_icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

8
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -8,6 +8,7 @@ import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ProgressBar;
@ -161,6 +162,13 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
}
}
@Override
public void onResume() {
super.onResume();
Log.d("Boardaa", "onResume called!");
refreshBoardBookmark((ImageButton) findViewById(R.id.bookmark));
}
@Override
public void onDestroy() {
super.onDestroy();

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

@ -1,5 +1,7 @@
package gr.thmmy.mthmmy.activities.topic;
import android.util.Log;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@ -11,11 +13,52 @@ import java.util.regex.Matcher;
import okhttp3.Response;
import timber.log.Timber;
/**
* This is a utility class containing a collection of static methods to help with topic replying.
*/
class Posting {
/**
* {@link REPLY_STATUS} enum defines the different possible outcomes of a topic reply request.
*/
enum REPLY_STATUS {
SUCCESSFUL, NO_SUBJECT, EMPTY_BODY, NEW_REPLY_WHILE_POSTING, NOT_FOUND, SESSION_ENDED, OTHER_ERROR
/**
* The request was successful
*/
SUCCESSFUL,
/**
* Request was lacking a subject
*/
NO_SUBJECT,
/**
* Request had empty body
*/
EMPTY_BODY,
/**
* There were new topic replies while making the request
*/
NEW_REPLY_WHILE_POSTING,
/**
* Error 404, page was not found
*/
NOT_FOUND,
/**
* User session ended while posting the reply
*/
SESSION_ENDED,
/**
* Other undefined of unidentified error
*/
OTHER_ERROR
}
/**
* This method can be used to check whether a topic post request was successful or not and if
* not maybe get the reason why.
*
* @param response {@link okhttp3.Response} of the request
* @return a {@link REPLY_STATUS} that describes the response status
* @throws IOException method relies to {@link org.jsoup.Jsoup#parse(String)}
*/
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;
@ -44,10 +87,19 @@ class Posting {
return REPLY_STATUS.SUCCESSFUL;
}
/**
* This is a fucked up method.. Just don't waste your time here unless you have suicidal
* tendencies.
*
* @param html the html string to be transformed to BBcode
* @return the BBcode string
*/
static String htmlToBBcode(String html) {
Log.d("Cancer", 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");
@ -170,64 +222,66 @@ class Posting {
//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");
bbMap.put("\\s*?<div class=\"quoteheader\">(.*?(\\n))*?.*?<\\/div>", "");
bbMap.put("\\s*?<div class=\"codeheader\">(.*?(\\n))+?.*?<\\/div>", "");
bbMap.put("\\s*?<div class=\"quote\">(.*?(\\n))+?.*?<\\/div>", "");
bbMap.put("<br>", "\\\n");
//Non-breaking space
bbMap.put("&nbsp;", " ");
//bold
bbMap.put("\n\\s+?<b>(.+?)</b>", "\\[b\\]$1\\[/b\\]");
bbMap.put("\\s*?<b>([\\S\\s]+?)<\\/b>", "\\[b\\]$1\\[/b\\]");
//italics
bbMap.put("\n\\s+?<i>(.+?)</i>", "\\[i\\]$1\\[/i\\]");
bbMap.put("\\s*?<i>([\\S\\s]+?)<\\/i>", "\\[i\\]$1\\[/i\\]");
//underline
bbMap.put("\n\\s+?<span style=\"text-decoration: underline;\">(.+?)</span>", "\\[u\\]$1\\[/u\\]");
bbMap.put("\\s*?<span style=\"text-decoration: underline;\">([\\S\\s]+?)<\\/span>", "\\[u\\]$1\\[/u\\]");
//deleted
bbMap.put("\n\\s+?<del>(.+?)</del>", "\\[s\\]$1\\[/s\\]");
bbMap.put("\\s*?<del>([\\S\\s]+?)<\\/del>", "\\[s\\]$1\\[/s\\]");
//text color
bbMap.put("\n\\s+?<span style=\"color: (.+?);\">(.+?)</span>", "\\[color=$1\\]$2\\[/color\\]");
bbMap.put("\\s*?<span style=\"color: (.+?);\">([\\S\\s]+?)<\\/span>", "\\[color=$1\\]$2\\[/color\\]");
//glow
bbMap.put("\n\\s+?<span style=\"background-color: (.+?);\">(.+?)</span>", "\\[glow=$1,2,300\\]$2\\[/glow\\]");
bbMap.put("\\s*?<span style=\"background-color: (.+?);\">([\\S\\s]+?)<\\/span>", "\\[glow=$1,2,300\\]$2\\[/glow\\]");
//shadow
bbMap.put("\n\\s+?<span style=\"text-shadow: (.+?) (.+?)\">(.+?)</span>", "\\[shadow=$1,$2\\]$3\\[/shadow\\]");
bbMap.put("\\s*?<span style=\"text-shadow: (.+?) (.+?)\">([\\S\\s]+?)<\\/span>", "\\[shadow=$1,$2\\]$3\\[/shadow\\]");
//running text
bbMap.put("\\s+?<marquee>\n (.+?)\n </marquee>", "\\[move\\]$1\\[/move\\]");
bbMap.put("\\s*?<marquee>\n ([\\S\\s]+?)\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\\]");
bbMap.put("\\s*?<div align=\"center\">\n ([\\S\\s]+?)\n <\\/div>", "\\[center\\]$1\\[/center\\]");
bbMap.put("\\s*?<div style=\"text-align: (.+?);\">\n ([\\S\\s]+?)\n <\\/div>", "\\[$1\\]$2\\[/$1\\]");
//preformated
bbMap.put("\n\\s+?<pre>(.+?)</pre>", "\\[pre\\]$1\\[/pre\\]");
bbMap.put("\\s*?<pre>([\\S\\s]+?)<\\/pre>", "\\[pre\\]$1\\[/pre\\]");
//horizontal rule
bbMap.put("\n\\s+?<hr>", "\\[hr\\]");
bbMap.put("\\s*?<hr>", "\\[hr\\]");
//resize
bbMap.put("\n\\s+?<span style=\"font-size: (.+?);(.+?)\">(.+?)</span>", "\\[size=$1\\]$3\\[/size\\]");
bbMap.put("\\s*?<span style=\"font-size: (.+?);(.+?)\">([\\S\\s]+?)<\\/span>", "\\[size=$1\\]$3\\[/size\\]");
//font
bbMap.put("\n\\s+?<span style=\"font-family: (.+?);\">(.+?)</span>", "\\[font=$1\\]$2\\[/font\\]");
bbMap.put("\\s*?<span style=\"font-family: (.+?);\">([\\S\\s]+?)<\\/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>",
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\\]");
bbMap.put("\\s*?<img src=\".+?eq=([\\S\\s]+?)\" .+?\">", "\\[tex\\]$1\\[/tex\\]");
//code
bbMap.put("\n\\s+?<div class=\"code\">\n (.+?)\n </div>", "\\[code\\]$1\\[/code\\]");
bbMap.put("\\s*?<div class=\"code\">((.*?(\\n))+?.*?)<\\/div>", "\\[code\\]$1\\[/code\\]");
//teletype
bbMap.put("\n\\s+?<tt>(.+?)</tt>", "\\[tt\\]$1\\[/tt\\]");
bbMap.put("\\s*?<tt>([\\S\\s]+?)<\\/tt>", "\\[tt\\]$1\\[/tt\\]");
//superscript/subscript
bbMap.put("\n\\s+?<sub>(.+?)</sub>", "\\[sub\\]$1\\[/sub\\]");
bbMap.put("\n\\s+?<sup>(.+?)</sup>", "\\[sup\\]$1\\[/sup\\]");
bbMap.put("\\s*?<sub>([\\S\\s]+?)<\\/sub>", "\\[sub\\]$1\\[/sub\\]");
bbMap.put("\\s*?<sup>([\\S\\s]+?)<\\/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>"
bbMap.put("\\s*?<td.+?>([\\S\\s]+?)<\\/td>", "\\[td\\]$1\\[/td\\]");
bbMap.put("<tr>([\\S\\s]+?)\n <\\/tr>", "\\[tr\\]$1\\[/tr\\]");
bbMap.put("\\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",
bbMap.put("\\s*?<div class=\"yt\">.+?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\\]");
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\\]");
bbMap.put("\\s*?<a href=\"mailto:(.+?)\">([\\S\\s]+?)<\\/a>", "\\[email\\]$2\\[/email\\]");
//links
bbMap.put("\n\\s+?<a href=\"(.+?)\" .+?>([\\S\\s]+?)</a>", "\\[url=$1\\]$2\\[/url\\]");
bbMap.put("\\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=\""
@ -257,6 +311,7 @@ class Posting {
html = html.replaceAll("\\s+<img src=\"(.+?)\" .+? height=\"(.+?)\" .+?>", "\\[img height=$2\\]$1\\[/img\\]");
html = html.replaceAll("\\s+<img src=\"(.+?)\".+?>", "\\[img\\]$1\\[/img\\]");
Log.d("Cancer", html);
return html;
}
}

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

@ -226,6 +226,7 @@ public class TopicActivity extends BaseActivity {
// Inflates the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.topic_menu, menu);
setTopicBookmark(menu.getItem(0));
super.onCreateOptionsMenu(menu);
return true;
}
@ -269,8 +270,9 @@ public class TopicActivity extends BaseActivity {
@Override
protected void onResume() {
drawer.setSelection(-1);
super.onResume();
refreshTopicBookmark();
drawer.setSelection(-1);
}
@Override

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

@ -181,6 +181,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
//Post's WebView parameters
holder.post.setClickable(true);
holder.post.setWebViewClient(new LinkLauncher());
holder.post.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
//Avoids errors about layout having 0 width/height
holder.thumbnail.setMinimumWidth(1);

26
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -422,6 +422,18 @@ public abstract class BaseActivity extends AppCompatActivity {
}
}
protected void refreshTopicBookmark() {
if (thisPageBookmarkMenuButton == null) {
return;
}
loadSavedBookmarks();
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(bookmarked);
} else {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
}
}
protected void topicMenuBookmarkClick() {
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
@ -455,6 +467,17 @@ public abstract class BaseActivity extends AppCompatActivity {
});
}
protected void refreshBoardBookmark(final ImageButton thisPageBookmarkImageButton) {
if (thisPageBookmarkImageButton == null)
return;
loadSavedBookmarks();
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
} else {
thisPageBookmarkImageButton.setImageDrawable(notBookmarked);
}
}
private void loadSavedBookmarks() {
String tmpString = bookmarksFile.getString(BOOKMARKED_TOPICS_KEY, null);
if (tmpString != null)
@ -568,8 +591,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
//----------------------------------MISC----------------------
protected void setMainActivity(MainActivity mainActivity)
{
protected void setMainActivity(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}

2
app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java

@ -156,7 +156,7 @@ public class ParseHelpers {
+ "<a href=\"https://www.youtube.com/watch?v="
+ embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">"
+ "<img class=\"embedded-video-play\" "
+ "src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\">"
+ "src=\"YouTube_light_color_icon.png\">"
+ "</a>"
+ "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter)

Loading…
Cancel
Save