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 f9cc6e5c..3a1c1d67 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 @@ -6,7 +6,6 @@ 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.widget.ProgressBar; import android.widget.Toast; @@ -22,8 +21,8 @@ import javax.net.ssl.SSLHandshakeException; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseActivity; -import gr.thmmy.mthmmy.data.Board; -import gr.thmmy.mthmmy.data.Topic; +import gr.thmmy.mthmmy.model.Board; +import gr.thmmy.mthmmy.model.Topic; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; import okhttp3.Request; @@ -46,10 +45,14 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo private MaterialProgressBar progressBar; private BoardTask boardTask; + private BoardAdapter boardAdapter; private final ArrayList parsedSubBoards = new ArrayList<>(); private final ArrayList parsedTopics = new ArrayList<>(); + private String boardUrl; + private String boardTitle; + private int numberOfPages = -1; private int pagesLoaded = 0; private boolean isLoadingMore; @@ -62,12 +65,13 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo setContentView(R.layout.activity_board); Bundle extras = getIntent().getExtras(); - final String boardTitle = extras.getString(BUNDLE_BOARD_TITLE); + boardTitle = extras.getString(BUNDLE_BOARD_TITLE); boardUrl = extras.getString(BUNDLE_BOARD_URL); //Initializes graphics toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitle(boardTitle); + if (boardTitle != null && !Objects.equals(boardTitle, "")) toolbar.setTitle(boardTitle); + else toolbar.setTitle("Board"); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -172,6 +176,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo } private boolean parseBoard(Document boardPage) { + if (boardTitle == null || Objects.equals(boardTitle, "")) + boardTitle = boardPage.select("div.nav a.nav").last().text(); + //Removes loading item if (isLoadingMore) { if (parsedTopics.size() > 0) parsedTopics.remove(parsedTopics.size() - 1); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java index cae5688b..c03882c4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java @@ -17,8 +17,8 @@ import java.util.ArrayList; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.topic.TopicActivity; -import gr.thmmy.mthmmy.data.Board; -import gr.thmmy.mthmmy.data.Topic; +import gr.thmmy.mthmmy.model.Board; +import gr.thmmy.mthmmy.model.Topic; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; @@ -28,7 +28,7 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; /** - * {@link RecyclerView.Adapter} that can display a {@link gr.thmmy.mthmmy.data.Board}. + * {@link RecyclerView.Adapter} that can display a {@link gr.thmmy.mthmmy.model.Board}. */ class BoardAdapter extends RecyclerView.Adapter { private static final String TAG = "BoardAdapter"; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index 95e1268e..cb9981b1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -17,8 +17,8 @@ import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; import gr.thmmy.mthmmy.activities.topic.TopicActivity; -import gr.thmmy.mthmmy.data.Board; -import gr.thmmy.mthmmy.data.TopicSummary; +import gr.thmmy.mthmmy.model.Board; +import gr.thmmy.mthmmy.model.TopicSummary; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java index d455f8be..896078e8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java @@ -16,9 +16,9 @@ import java.util.List; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseFragment; -import gr.thmmy.mthmmy.data.Board; -import gr.thmmy.mthmmy.data.Category; -import gr.thmmy.mthmmy.data.TopicSummary; +import gr.thmmy.mthmmy.model.Board; +import gr.thmmy.mthmmy.model.Category; +import gr.thmmy.mthmmy.model.TopicSummary; /** diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index e586d931..9b51c3af 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java @@ -26,8 +26,8 @@ import java.util.List; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseFragment; -import gr.thmmy.mthmmy.data.Board; -import gr.thmmy.mthmmy.data.Category; +import gr.thmmy.mthmmy.model.Board; +import gr.thmmy.mthmmy.model.Category; import gr.thmmy.mthmmy.session.SessionManager; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java index 8e039862..beb22697 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java @@ -12,7 +12,7 @@ import java.util.List; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseFragment; -import gr.thmmy.mthmmy.data.TopicSummary; +import gr.thmmy.mthmmy.model.TopicSummary; /** diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 5cbfd621..8b5d14b1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -24,7 +24,7 @@ import java.util.regex.Pattern; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseFragment; -import gr.thmmy.mthmmy.data.TopicSummary; +import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CustomRecyclerView; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 1659665b..92e505cb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -38,7 +38,7 @@ import gr.thmmy.mthmmy.activities.profile.latestPosts.LatestPostsFragment; import gr.thmmy.mthmmy.activities.profile.stats.StatsFragment; import gr.thmmy.mthmmy.activities.profile.summary.SummaryFragment; import gr.thmmy.mthmmy.activities.topic.TopicActivity; -import gr.thmmy.mthmmy.data.PostSummary; +import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.utils.CircleTransform; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; @@ -66,15 +66,17 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment public static final String BUNDLE_PROFILE_URL = "PROFILE_URL"; /** * The key to use when putting user's thumbnail url String to {@link ProfileActivity}'s Bundle. - * If user doesn't have a thumbnail put an empty string. + * If user doesn't have a thumbnail put an empty string or leave it null. */ public static final String BUNDLE_THUMBNAIL_URL = "THUMBNAIL_URL"; /** * The key to use when putting username String to {@link ProfileActivity}'s Bundle. + * If username is not available put an empty string or leave it null. */ public static final String BUNDLE_USERNAME = "USERNAME"; private static final int THUMBNAIL_SIZE = 200; + private TextView usernameView; private TextView personalTextView; private MaterialProgressBar progressBar; private FloatingActionButton replyFAB; @@ -83,6 +85,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment private ProfileTask profileTask; private String personalText; private String profileUrl; + private String username; @Override protected void onCreate(Bundle savedInstanceState) { @@ -92,7 +95,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment Bundle extras = getIntent().getExtras(); String thumbnailUrl = extras.getString(BUNDLE_THUMBNAIL_URL); if (thumbnailUrl == null) thumbnailUrl = ""; - String username = extras.getString(BUNDLE_USERNAME); + username = extras.getString(BUNDLE_USERNAME); profileUrl = extras.getString(BUNDLE_PROFILE_URL); //Initializes graphic elements @@ -121,8 +124,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment , R.drawable.ic_default_user_thumbnail, null)) .transform(new CircleTransform()) .into(thumbnailView); - TextView usernameView = (TextView) findViewById(R.id.profile_activity_username); - usernameView.setText(username); + usernameView = (TextView) findViewById(R.id.profile_activity_username); + if (username == null || Objects.equals(username, "")) usernameView.setText("Username"); + else usernameView.setText(username); personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text); viewPager = (ViewPager) findViewById(R.id.profile_tab_container); @@ -209,6 +213,13 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment try { Response response = client.newCall(request).execute(); profilePage = Jsoup.parse(response.body().string()); + //Finds username if missing + if (username == null || Objects.equals(username, "")) { + username = profilePage. + select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"). + first().text(); + } + { //Finds personal text Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); if (tmpEl != null) { @@ -239,12 +250,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment //Parse was successful progressBar.setVisibility(ProgressBar.INVISIBLE); - if (personalText != null) { - personalTextView.setVisibility(View.VISIBLE); - personalTextView.setText(personalText); - } else { - personalTextView.setVisibility(View.GONE); - } + if (usernameView.getText() != username) usernameView.setText(username); + if (personalText != null) personalTextView.setText(personalText); setupViewPager(viewPager, profilePage); TabLayout tabLayout = (TabLayout) findViewById(R.id.profile_tabs); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index 4e60e949..9709acfb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseFragment; -import gr.thmmy.mthmmy.data.PostSummary; -import gr.thmmy.mthmmy.data.TopicSummary; +import gr.thmmy.mthmmy.model.PostSummary; +import gr.thmmy.mthmmy.model.TopicSummary; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; /** diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index dbe83af3..99b52db1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -23,7 +23,8 @@ import javax.net.ssl.SSLHandshakeException; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseFragment; -import gr.thmmy.mthmmy.data.PostSummary; +import gr.thmmy.mthmmy.model.PostSummary; +import gr.thmmy.mthmmy.utils.ParseHelpers; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; import okhttp3.Request; @@ -229,33 +230,8 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap pTopicUrl = rowHeader.first().select("a").last().attr("href"); pDateTime = rowHeader.last().text(); } - pPost = row.select("div.post").first().outerHtml(); + pPost = ParseHelpers.youtubeEmbeddedFix(row.select("div.post").first()); - { //Fixes embedded videos - Elements noembedTag = row.select("div").select(".post").first().select("noembed"); - ArrayList embededVideosUrls = new ArrayList<>(); - - for (Element _noembed : noembedTag) { - embededVideosUrls.add(_noembed.text().substring(_noembed.text() - .indexOf("href=\"https://www.youtube.com/watch?") + 38 - , _noembed.text().indexOf("target") - 2)); - } - - int tmp_counter = 0; - while (pPost.contains(" embededVideosUrls.size()) - break; - pPost = pPost.replace( - pPost.substring(pPost.indexOf("") + 9) - , "
" - + "" - + "\"\"" - + "" - + "
"); - } - } //Add stuff to make it work in WebView //style.css pPost = ("" + pPost); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java index 6ff199fb..ba1f966e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Objects; import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.utils.ParseHelpers; import mthmmy.utils.Report; @@ -148,35 +149,7 @@ public class SummaryFragment extends Fragment { pHtml = ""; else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { //This needs special handling since it may have css - { //Fix embedded videos - Elements noembedTag = summaryRow.select("noembed"); - ArrayList embededVideosUrls = new ArrayList<>(); - - for (Element _noembed : noembedTag) { - embededVideosUrls.add(_noembed.text().substring(_noembed.text() - .indexOf("href=\"https://www.youtube.com/watch?") + 38 - , _noembed.text().indexOf("target") - 2)); - } - - pHtml = summaryRow.html(); - - int tmp_counter = 0; - while (pHtml.contains(" embededVideosUrls.size()) - break; - pHtml = pHtml.replace( - pHtml.substring(pHtml.indexOf("") + 9) - , "
" - + "" - + "\"\"" - + "" - //+ "" - + "
"); - } - } - + pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow); //Add stuff to make it work in WebView //style.css pHtml = ("\n" + 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 d9cd670c..85766993 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 @@ -29,7 +29,7 @@ import java.util.Objects; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.base.BaseActivity; -import gr.thmmy.mthmmy.data.Post; +import gr.thmmy.mthmmy.model.Post; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; import okhttp3.Request; @@ -384,6 +384,7 @@ public class TopicActivity extends BaseActivity { case SUCCESS: progressBar.setVisibility(ProgressBar.INVISIBLE); + recyclerView.swapAdapter(new TopicAdapter(getApplicationContext(), progressBar, postsList, new TopicTask()), false); 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 bebfb695..64278cab 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 @@ -42,14 +42,18 @@ import java.util.List; import java.util.Objects; import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; -import gr.thmmy.mthmmy.data.Post; +import gr.thmmy.mthmmy.model.LinkTarget; +import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.utils.CircleTransform; import gr.thmmy.mthmmy.utils.FileManager.ThmmyFile; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_THUMBNAIL_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_USERNAME; @@ -513,35 +517,50 @@ class TopicAdapter extends RecyclerView.Adapter { @SuppressWarnings("SameReturnValue") private boolean handleUri(final Uri uri) { - final String host = uri.getHost(); final String uriString = uri.toString(); - //Checks if app can handle this url - if (Objects.equals(host, "www.thmmy.gr")) { - if (uriString.contains("topic=")) { //This url points to a topic - //Checks if this is the current topic - if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), base_url)) { - //Gets uri's targeted message's index number - String msgIndexReq = uriString.substring(uriString.indexOf("msg") + 3); - if (msgIndexReq.contains("#")) - msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf("#")); - else - msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf(";")); - - //Checks if this post is in the current topic's page - for (Post post : postsList) { - if (post.getPostIndex() == Integer.parseInt(msgIndexReq)) { - //Don't restart Activity - //Just change post focus - //TODO - return true; - } + LinkTarget.Target target = LinkTarget.resolveLinkTarget(uri); + if (LinkTarget.targetEqual(target, LinkTarget.Target.TOPIC)) { + //This url points to a topic + //Checks if this is the current topic + if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), base_url)) { + //Gets uri's targeted message's index number + String msgIndexReq = uriString.substring(uriString.indexOf("msg") + 3); + if (msgIndexReq.contains("#")) + msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf("#")); + else + msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf(";")); + + //Checks if this post is in the current topic's page + for (Post post : postsList) { + if (post.getPostIndex() == Integer.parseInt(msgIndexReq)) { + //Don't restart Activity + //Just change post focus + //TODO + return true; } } - topicTask.execute(uri.toString()); } - return true; + topicTask.execute(uri.toString()); + } else if (LinkTarget.targetEqual(target, LinkTarget.Target.BOARD)) { + Intent intent = new Intent(context, BoardActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_BOARD_URL, uriString); + extras.putString(BUNDLE_BOARD_TITLE, ""); + intent.putExtras(extras); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } else if (LinkTarget.targetEqual(target, LinkTarget.Target.PROFILE)) { + Intent intent = new Intent(context, ProfileActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_PROFILE_URL, uriString); + extras.putString(BUNDLE_THUMBNAIL_URL, ""); + extras.putString(BUNDLE_USERNAME, ""); + intent.putExtras(extras); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); } + Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.setFlags(FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index 787fe1d0..34066a3c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -14,8 +14,9 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import gr.thmmy.mthmmy.data.Post; +import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.utils.FileManager.ThmmyFile; +import gr.thmmy.mthmmy.utils.ParseHelpers; import mthmmy.utils.Report; /** @@ -193,36 +194,7 @@ class TopicParser { p_subject = thisRow.select("div[id^=subject_]").first().select("a").first().text(); //Finds post's text - p_post = thisRow.select("div").select(".post").first().outerHtml(); - - { //Fixes embedded videos - Elements noembedTag = thisRow.select("div").select(".post").first().select("noembed"); - ArrayList embededVideosUrls = new ArrayList<>(); - - for (Element _noembed : noembedTag) { - embededVideosUrls.add(_noembed.text().substring(_noembed.text() - .indexOf("href=\"https://www.youtube.com/watch?") + 38 - , _noembed.text().indexOf("target") - 2)); - } - - int tmp_counter = 0; - while (p_post.contains(" embededVideosUrls.size()) - break; - p_post = p_post.replace( - p_post.substring(p_post.indexOf("") + 9) - , ""); - } - } + p_post = ParseHelpers.youtubeEmbeddedFix(thisRow.select("div").select(".post").first()); //Add stuff to make it work in WebView //style.css diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Board.java b/app/src/main/java/gr/thmmy/mthmmy/model/Board.java similarity index 95% rename from app/src/main/java/gr/thmmy/mthmmy/data/Board.java rename to app/src/main/java/gr/thmmy/mthmmy/model/Board.java index 72b8b64d..4934e759 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Board.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Board.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.data; +package gr.thmmy.mthmmy.model; public class Board { private final String url, title, mods, stats, lastPost, lastPostUrl; diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Category.java b/app/src/main/java/gr/thmmy/mthmmy/model/Category.java similarity index 97% rename from app/src/main/java/gr/thmmy/mthmmy/data/Category.java rename to app/src/main/java/gr/thmmy/mthmmy/model/Category.java index e66b2f41..648c0bb9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Category.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Category.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.data; +package gr.thmmy.mthmmy.model; import com.bignerdranch.expandablerecyclerview.model.Parent; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java b/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java new file mode 100644 index 00000000..ea283781 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java @@ -0,0 +1,50 @@ +package gr.thmmy.mthmmy.model; + +import android.net.Uri; + +import java.util.Objects; + +import mthmmy.utils.Report; + +public class LinkTarget { + private static final String TAG = "LinkTarget"; + + public enum Target { + NOT_THMMY, UNKNOWN_THMMY, TOPIC, BOARD, UNREAD_POSTS, PROFILE_SUMMARY, + PROFILE_LATEST_POSTS, PROFILE_STATS, PROFILE + } + + public static boolean isThmmy(Uri uri) { + return resolveLinkTarget(uri) != Target.NOT_THMMY; + } + + public static Target resolveLinkTarget(Uri uri) { + final String host = uri.getHost(); + final String uriString = uri.toString(); + + //Checks if app can handle this url + if (Objects.equals(host, "www.thmmy.gr")) { + if (uriString.contains("topic=")) return Target.TOPIC; + else if (uriString.contains("board=")) return Target.BOARD; + else if (uriString.contains("action=profile")) { + if (uriString.contains(";sa=showPosts")) + return Target.PROFILE_LATEST_POSTS; + else if (uriString.contains(";sa=statPanel")) + return Target.PROFILE_STATS; + else return Target.PROFILE_SUMMARY; + } else if (uriString.contains("action=unread")) + return Target.UNREAD_POSTS; + Report.v(TAG, "Unknown thmmy link found, link: " + uriString); + return Target.UNKNOWN_THMMY; + } + return Target.NOT_THMMY; + } + + public static boolean targetEqual(Target first, Target second) { + return first == Target.PROFILE && + (second == Target.PROFILE_LATEST_POSTS || + second == Target.PROFILE_STATS || + second == Target.PROFILE_SUMMARY) + || first == second; + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java similarity index 99% rename from app/src/main/java/gr/thmmy/mthmmy/data/Post.java rename to app/src/main/java/gr/thmmy/mthmmy/model/Post.java index 9ce37162..454ee890 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.data; +package gr.thmmy.mthmmy.model; import java.util.ArrayList; diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/PostSummary.java b/app/src/main/java/gr/thmmy/mthmmy/model/PostSummary.java similarity index 95% rename from app/src/main/java/gr/thmmy/mthmmy/data/PostSummary.java rename to app/src/main/java/gr/thmmy/mthmmy/model/PostSummary.java index 1259eb74..cf27691d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/PostSummary.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/PostSummary.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.data; +package gr.thmmy.mthmmy.model; public class PostSummary { private final String topicUrl; diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Topic.java b/app/src/main/java/gr/thmmy/mthmmy/model/Topic.java similarity index 97% rename from app/src/main/java/gr/thmmy/mthmmy/data/Topic.java rename to app/src/main/java/gr/thmmy/mthmmy/model/Topic.java index 714485c4..87e70a2f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Topic.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Topic.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.data; +package gr.thmmy.mthmmy.model; public class Topic extends TopicSummary { private final String lastPostUrl, stats; diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/TopicSummary.java b/app/src/main/java/gr/thmmy/mthmmy/model/TopicSummary.java similarity index 95% rename from app/src/main/java/gr/thmmy/mthmmy/data/TopicSummary.java rename to app/src/main/java/gr/thmmy/mthmmy/model/TopicSummary.java index 486d7ac2..dc9e4098 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/TopicSummary.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/TopicSummary.java @@ -1,4 +1,4 @@ -package gr.thmmy.mthmmy.data; +package gr.thmmy.mthmmy.model; public class TopicSummary { final String topicUrl; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java new file mode 100644 index 00000000..24fb958e --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java @@ -0,0 +1,42 @@ +package gr.thmmy.mthmmy.utils; + +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.util.ArrayList; + +public class ParseHelpers { + private static final String TAG = "ParseHelpers"; + + public static String youtubeEmbeddedFix(Element html) { + //Fixes embedded videos + Elements noembedTag = html.select("noembed"); + ArrayList embededVideosUrls = new ArrayList<>(); + + for (Element _noembed : noembedTag) { + embededVideosUrls.add(_noembed.text().substring(_noembed.text() + .indexOf("href=\"https://www.youtube.com/watch?") + 38 + , _noembed.text().indexOf("target") - 2)); + } + + String fixed = html.outerHtml(); + int tmp_counter = 0; + while (fixed.contains(" embededVideosUrls.size()) + break; + fixed = fixed.replace( + fixed.substring(fixed.indexOf("") + 9) + , ""); + } + return fixed; + } +}