diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8a57fcbc..8e78f4e6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,12 +1,12 @@ + package="gr.thmmy.mthmmy" + android:installLocation="auto"> - - - - + + + + - + - + - + - - + + + android:scheme="http" /> + android:scheme="http" /> + android:scheme="https" /> + android:scheme="https" /> - + + android:windowSoftInputMode="adjustPan" /> + android:value=".activities.main.MainActivity" /> + android:value=".activities.main.MainActivity" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:value=".activities.main.MainActivity" /> + android:value=".activities.main.MainActivity" /> + android:value=".activities.main.MainActivity" /> + android:resource="@xml/provider_paths" /> + android:exported="false" /> - - + + diff --git a/app/src/main/assets/YouTube_light_color_icon.png b/app/src/main/assets/YouTube_light_color_icon.png new file mode 100644 index 00000000..bfd6db39 Binary files /dev/null and b/app/src/main/assets/YouTube_light_color_icon.png differ diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java index 565b587a..633ab6ec 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java +++ b/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(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java index f0220f82..3fe99911 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/Posting.java +++ b/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 bbMap = new HashMap<>(); Map smileysMap1 = new HashMap<>(); Map 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("\n ", ""); //quotes and code headers - bbMap.put("\n\\s+?
\n (.+?)\n
", ""); - bbMap.put("\n\\s+?
\n (.+?)\n
", ""); - bbMap.put("\n\\s+?
\n (.+?)\n
", ""); - bbMap.put("
", "\n"); + bbMap.put("\\s*?
(.*?(\\n))*?.*?<\\/div>", ""); + bbMap.put("\\s*?
(.*?(\\n))+?.*?<\\/div>", ""); + bbMap.put("\\s*?
(.*?(\\n))+?.*?<\\/div>", ""); + bbMap.put("
", "\\\n"); + //Non-breaking space + bbMap.put(" ", " "); //bold - bbMap.put("\n\\s+?(.+?)", "\\[b\\]$1\\[/b\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/b>", "\\[b\\]$1\\[/b\\]"); //italics - bbMap.put("\n\\s+?(.+?)", "\\[i\\]$1\\[/i\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/i>", "\\[i\\]$1\\[/i\\]"); //underline - bbMap.put("\n\\s+?(.+?)", "\\[u\\]$1\\[/u\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/span>", "\\[u\\]$1\\[/u\\]"); //deleted - bbMap.put("\n\\s+?(.+?)", "\\[s\\]$1\\[/s\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/del>", "\\[s\\]$1\\[/s\\]"); //text color - bbMap.put("\n\\s+?(.+?)", "\\[color=$1\\]$2\\[/color\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/span>", "\\[color=$1\\]$2\\[/color\\]"); //glow - bbMap.put("\n\\s+?(.+?)", "\\[glow=$1,2,300\\]$2\\[/glow\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/span>", "\\[glow=$1,2,300\\]$2\\[/glow\\]"); //shadow - bbMap.put("\n\\s+?(.+?)", "\\[shadow=$1,$2\\]$3\\[/shadow\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/span>", "\\[shadow=$1,$2\\]$3\\[/shadow\\]"); //running text - bbMap.put("\\s+?\n (.+?)\n ", "\\[move\\]$1\\[/move\\]"); + bbMap.put("\\s*?\n ([\\S\\s]+?)\n <\\/marquee>", "\\[move\\]$1\\[/move\\]"); //alignment - bbMap.put("\n\\s+?
\n (.+?)\n
", "\\[center\\]$1\\[/center\\]"); - bbMap.put("\n\\s+?
\n (.+?)\n
", "\\[$1\\]$2\\[/$1\\]"); + bbMap.put("\\s*?
\n ([\\S\\s]+?)\n <\\/div>", "\\[center\\]$1\\[/center\\]"); + bbMap.put("\\s*?
\n ([\\S\\s]+?)\n <\\/div>", "\\[$1\\]$2\\[/$1\\]"); //preformated - bbMap.put("\n\\s+?
(.+?)
", "\\[pre\\]$1\\[/pre\\]"); + bbMap.put("\\s*?
([\\S\\s]+?)<\\/pre>", "\\[pre\\]$1\\[/pre\\]");
         //horizontal rule
-        bbMap.put("\n\\s+?
", "\\[hr\\]"); + bbMap.put("\\s*?
", "\\[hr\\]"); //resize - bbMap.put("\n\\s+?(.+?)", "\\[size=$1\\]$3\\[/size\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/span>", "\\[size=$1\\]$3\\[/size\\]"); //font - bbMap.put("\n\\s+?(.+?)", "\\[font=$1\\]$2\\[/font\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/span>", "\\[font=$1\\]$2\\[/font\\]"); //lists - bbMap.put("\\s+
  • (.+?)
  • ", "\\[li\\]$1\\[/li\\]"); - bbMap.put("\n\\s+
      ([\\S\\s]+?)\n\\s+
    ", + bbMap.put("\\s+
  • (.+?)<\\/li>", "\\[li\\]$1\\[/li\\]"); + bbMap.put("\n\\s+
      ([\\S\\s]+?)\n\\s+<\\/ul>", "\\[list\\]\n$1\n\\[/list\\]"); //latex code - bbMap.put("\n\\s+?", "\\[tex\\]$1\\[/tex\\]"); + bbMap.put("\\s*?", "\\[tex\\]$1\\[/tex\\]"); //code - bbMap.put("\n\\s+?
      \n (.+?)\n
      ", "\\[code\\]$1\\[/code\\]"); + bbMap.put("\\s*?
      ((.*?(\\n))+?.*?)<\\/div>", "\\[code\\]$1\\[/code\\]"); //teletype - bbMap.put("\n\\s+?(.+?)", "\\[tt\\]$1\\[/tt\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/tt>", "\\[tt\\]$1\\[/tt\\]"); //superscript/subscript - bbMap.put("\n\\s+?(.+?)", "\\[sub\\]$1\\[/sub\\]"); - bbMap.put("\n\\s+?(.+?)", "\\[sup\\]$1\\[/sup\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/sub>", "\\[sub\\]$1\\[/sub\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/sup>", "\\[sup\\]$1\\[/sup\\]"); //tables - bbMap.put("\\s+?([\\S\\s]+?)", "\\[td\\]$1\\[/td\\]"); - bbMap.put("([\\S\\s]+?)\n ", "\\[tr\\]$1\\[/tr\\]"); - bbMap.put("\n\\s+?\n \n ([\\S\\s]+?)\n \n
      " + bbMap.put("\\s*?([\\S\\s]+?)<\\/td>", "\\[td\\]$1\\[/td\\]"); + bbMap.put("([\\S\\s]+?)\n <\\/tr>", "\\[tr\\]$1\\[/tr\\]"); + bbMap.put("\\s*?\n \n ([\\S\\s]+?)\n <\\/tbody>\n <\\/table>" , "\\[table\\]$2\\[/table\\]"); //videos - bbMap.put("\n\\s+?
      \n", + bbMap.put("\\s*?
      .+?watch\\?v=(.+?)\"((.|\\n)*?)/div>\n", "[youtube]https://www.youtube.com/watch?v=$1[/youtube]"); //ftp - bbMap.put("([\\S\\s]+?)", "\\[fpt=ftp:$1\\]$2\\[/ftp\\]"); + bbMap.put("([\\S\\s]+?)<\\/a>", "\\[fpt=ftp:$1\\]$2\\[/ftp\\]"); //mailto - bbMap.put("\n\\s+?([\\S\\s]+?)", "\\[email\\]$2\\[/email\\]"); + bbMap.put("\\s*?([\\S\\s]+?)<\\/a>", "\\[email\\]$2\\[/email\\]"); //links - bbMap.put("\n\\s+?([\\S\\s]+?)", "\\[url=$1\\]$2\\[/url\\]"); + bbMap.put("\\s*?([\\S\\s]+?)", "\\[url=$1\\]$2\\[/url\\]"); //smileys for (Map.Entry entry : smileysMap1.entrySet()) { bbMap.put("\n \""", "\\[img height=$2\\]$1\\[/img\\]"); html = html.replaceAll("\\s+", "\\[img\\]$1\\[/img\\]"); + Log.d("Cancer", html); return html; } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 8cb77d90..5c170204 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/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 diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index b37ec5e4..aa17b311 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -181,6 +181,7 @@ class TopicAdapter extends RecyclerView.Adapter { //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); diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index f43d603f..f844573d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -337,7 +337,7 @@ public abstract class BaseActivity extends AppCompatActivity { drawer = drawerBuilder.build(); - if(!(BaseActivity.this instanceof MainActivity)) + if (!(BaseActivity.this instanceof MainActivity)) drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); drawer.setOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() { @@ -396,7 +396,7 @@ public abstract class BaseActivity extends AppCompatActivity { protected void onPostExecute(Integer result) { Toast.makeText(getBaseContext(), "Logged out successfully!", Toast.LENGTH_LONG).show(); updateDrawer(); - if(mainActivity!=null) + if (mainActivity != null) mainActivity.updateTabs(); progressDialog.dismiss(); } @@ -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; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java index 75a9fa72..a2e80cca 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java @@ -156,7 +156,7 @@ public class ParseHelpers { + "" + "" + + "src=\"YouTube_light_color_icon.png\">" + "" + "