Browse Source

General fixes and cleanup

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
862912ff0e
  1. 17
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  4. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java
  5. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java
  7. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  8. 29
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  9. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java
  10. 30
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java
  11. 31
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  12. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  13. 33
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  14. 34
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  15. 2
      app/src/main/java/gr/thmmy/mthmmy/model/Board.java
  16. 2
      app/src/main/java/gr/thmmy/mthmmy/model/Category.java
  17. 50
      app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java
  18. 2
      app/src/main/java/gr/thmmy/mthmmy/model/Post.java
  19. 2
      app/src/main/java/gr/thmmy/mthmmy/model/PostSummary.java
  20. 2
      app/src/main/java/gr/thmmy/mthmmy/model/Topic.java
  21. 2
      app/src/main/java/gr/thmmy/mthmmy/model/TopicSummary.java
  22. 42
      app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java

17
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.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
@ -22,8 +21,8 @@ import javax.net.ssl.SSLHandshakeException;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.data.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.data.Topic; import gr.thmmy.mthmmy.model.Topic;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.Request; import okhttp3.Request;
@ -46,10 +45,14 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private BoardTask boardTask; private BoardTask boardTask;
private BoardAdapter boardAdapter; private BoardAdapter boardAdapter;
private final ArrayList<Board> parsedSubBoards = new ArrayList<>(); private final ArrayList<Board> parsedSubBoards = new ArrayList<>();
private final ArrayList<Topic> parsedTopics = new ArrayList<>(); private final ArrayList<Topic> parsedTopics = new ArrayList<>();
private String boardUrl; private String boardUrl;
private String boardTitle;
private int numberOfPages = -1; private int numberOfPages = -1;
private int pagesLoaded = 0; private int pagesLoaded = 0;
private boolean isLoadingMore; private boolean isLoadingMore;
@ -62,12 +65,13 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
setContentView(R.layout.activity_board); setContentView(R.layout.activity_board);
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
final String boardTitle = extras.getString(BUNDLE_BOARD_TITLE); boardTitle = extras.getString(BUNDLE_BOARD_TITLE);
boardUrl = extras.getString(BUNDLE_BOARD_URL); boardUrl = extras.getString(BUNDLE_BOARD_URL);
//Initializes graphics //Initializes graphics
toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(boardTitle); if (boardTitle != null && !Objects.equals(boardTitle, "")) toolbar.setTitle(boardTitle);
else toolbar.setTitle("Board");
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -172,6 +176,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
} }
private boolean parseBoard(Document boardPage) { private boolean parseBoard(Document boardPage) {
if (boardTitle == null || Objects.equals(boardTitle, ""))
boardTitle = boardPage.select("div.nav a.nav").last().text();
//Removes loading item //Removes loading item
if (isLoadingMore) { if (isLoadingMore) {
if (parsedTopics.size() > 0) parsedTopics.remove(parsedTopics.size() - 1); if (parsedTopics.size() > 0) parsedTopics.remove(parsedTopics.size() - 1);

6
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.R;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.data.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.data.Topic; import gr.thmmy.mthmmy.model.Topic;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 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; 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<RecyclerView.ViewHolder> { class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = "BoardAdapter"; private static final String TAG = "BoardAdapter";

4
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.forum.ForumFragment;
import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; import gr.thmmy.mthmmy.activities.main.recent.RecentFragment;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.data.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.data.TopicSummary; 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_TITLE;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;

6
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.R;
import gr.thmmy.mthmmy.activities.base.BaseFragment; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.data.Category; import gr.thmmy.mthmmy.model.Category;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.model.TopicSummary;
/** /**

4
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.R;
import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.activities.base.BaseFragment; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.data.Category; import gr.thmmy.mthmmy.model.Category;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;

2
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.R;
import gr.thmmy.mthmmy.activities.base.BaseFragment; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.model.TopicSummary;
/** /**

2
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.R;
import gr.thmmy.mthmmy.activities.base.BaseFragment; 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.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;

29
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.stats.StatsFragment;
import gr.thmmy.mthmmy.activities.profile.summary.SummaryFragment; import gr.thmmy.mthmmy.activities.profile.summary.SummaryFragment;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; 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 gr.thmmy.mthmmy.utils.CircleTransform;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;
@ -66,15 +66,17 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
public static final String BUNDLE_PROFILE_URL = "PROFILE_URL"; 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. * 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"; public static final String BUNDLE_THUMBNAIL_URL = "THUMBNAIL_URL";
/** /**
* The key to use when putting username String to {@link ProfileActivity}'s Bundle. * 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"; public static final String BUNDLE_USERNAME = "USERNAME";
private static final int THUMBNAIL_SIZE = 200; private static final int THUMBNAIL_SIZE = 200;
private TextView usernameView;
private TextView personalTextView; private TextView personalTextView;
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private FloatingActionButton replyFAB; private FloatingActionButton replyFAB;
@ -83,6 +85,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
private ProfileTask profileTask; private ProfileTask profileTask;
private String personalText; private String personalText;
private String profileUrl; private String profileUrl;
private String username;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -92,7 +95,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
String thumbnailUrl = extras.getString(BUNDLE_THUMBNAIL_URL); String thumbnailUrl = extras.getString(BUNDLE_THUMBNAIL_URL);
if (thumbnailUrl == null) thumbnailUrl = ""; if (thumbnailUrl == null) thumbnailUrl = "";
String username = extras.getString(BUNDLE_USERNAME); username = extras.getString(BUNDLE_USERNAME);
profileUrl = extras.getString(BUNDLE_PROFILE_URL); profileUrl = extras.getString(BUNDLE_PROFILE_URL);
//Initializes graphic elements //Initializes graphic elements
@ -121,8 +124,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
, R.drawable.ic_default_user_thumbnail, null)) , R.drawable.ic_default_user_thumbnail, null))
.transform(new CircleTransform()) .transform(new CircleTransform())
.into(thumbnailView); .into(thumbnailView);
TextView usernameView = (TextView) findViewById(R.id.profile_activity_username); usernameView = (TextView) findViewById(R.id.profile_activity_username);
usernameView.setText(username); if (username == null || Objects.equals(username, "")) usernameView.setText("Username");
else usernameView.setText(username);
personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text); personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text);
viewPager = (ViewPager) findViewById(R.id.profile_tab_container); viewPager = (ViewPager) findViewById(R.id.profile_tab_container);
@ -209,6 +213,13 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
profilePage = Jsoup.parse(response.body().string()); 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 { //Finds personal text
Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first();
if (tmpEl != null) { if (tmpEl != null) {
@ -239,12 +250,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
//Parse was successful //Parse was successful
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
if (personalText != null) { if (usernameView.getText() != username) usernameView.setText(username);
personalTextView.setVisibility(View.VISIBLE); if (personalText != null) personalTextView.setText(personalText);
personalTextView.setText(personalText);
} else {
personalTextView.setVisibility(View.GONE);
}
setupViewPager(viewPager, profilePage); setupViewPager(viewPager, profilePage);
TabLayout tabLayout = (TabLayout) findViewById(R.id.profile_tabs); TabLayout tabLayout = (TabLayout) findViewById(R.id.profile_tabs);

4
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.R;
import gr.thmmy.mthmmy.activities.base.BaseFragment; import gr.thmmy.mthmmy.activities.base.BaseFragment;
import gr.thmmy.mthmmy.data.PostSummary; import gr.thmmy.mthmmy.model.PostSummary;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.model.TopicSummary;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
/** /**

30
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.R;
import gr.thmmy.mthmmy.activities.base.BaseActivity; import gr.thmmy.mthmmy.activities.base.BaseActivity;
import gr.thmmy.mthmmy.activities.base.BaseFragment; 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 me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.Request; import okhttp3.Request;
@ -229,33 +230,8 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
pTopicUrl = rowHeader.first().select("a").last().attr("href"); pTopicUrl = rowHeader.first().select("a").last().attr("href");
pDateTime = rowHeader.last().text(); 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<String> 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("<embed")) {
if (tmp_counter > embededVideosUrls.size())
break;
pPost = pPost.replace(
pPost.substring(pPost.indexOf("<embed"), pPost.indexOf("/noembed>") + 9)
, "<div class=\"embedded-video\">"
+ "<a href=\"https://www.youtube.com/"
+ embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">"
+ "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter) + "/default.jpg\" alt=\"\" border=\"0\">"
+ "</a>"
+ "</div>");
}
}
//Add stuff to make it work in WebView //Add stuff to make it work in WebView
//style.css //style.css
pPost = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + pPost); pPost = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + pPost);

31
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 java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.utils.ParseHelpers;
import mthmmy.utils.Report; import mthmmy.utils.Report;
@ -148,35 +149,7 @@ public class SummaryFragment extends Fragment {
pHtml = ""; pHtml = "";
else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) {
//This needs special handling since it may have css //This needs special handling since it may have css
{ //Fix embedded videos pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow);
Elements noembedTag = summaryRow.select("noembed");
ArrayList<String> 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("<embed")) {
if (tmp_counter > embededVideosUrls.size())
break;
pHtml = pHtml.replace(
pHtml.substring(pHtml.indexOf("<embed"), pHtml.indexOf("/noembed>") + 9)
, "<div class=\"embedded-video\">"
+ "<a href=\"https://www.youtube.com/"
+ embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">"
+ "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter) + "/default.jpg\" alt=\"\" border=\"0\">"
+ "</a>"
//+ "<img class=\"embedded-video-play\" src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\">"
+ "</div>");
}
}
//Add stuff to make it work in WebView //Add stuff to make it work in WebView
//style.css //style.css
pHtml = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n" + pHtml = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n" +

3
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.R;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.base.BaseActivity; 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 me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import okhttp3.Request; import okhttp3.Request;
@ -384,6 +384,7 @@ public class TopicActivity extends BaseActivity {
case SUCCESS: case SUCCESS:
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
recyclerView.swapAdapter(new TopicAdapter(getApplicationContext(), progressBar, recyclerView.swapAdapter(new TopicAdapter(getApplicationContext(), progressBar,
postsList, new TopicTask()), false); postsList, new TopicTask()), false);

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

@ -42,14 +42,18 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; 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.CircleTransform;
import gr.thmmy.mthmmy.utils.FileManager.ThmmyFile; import gr.thmmy.mthmmy.utils.FileManager.ThmmyFile;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 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_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_THUMBNAIL_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_USERNAME; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_USERNAME;
@ -513,12 +517,11 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
@SuppressWarnings("SameReturnValue") @SuppressWarnings("SameReturnValue")
private boolean handleUri(final Uri uri) { private boolean handleUri(final Uri uri) {
final String host = uri.getHost();
final String uriString = uri.toString(); final String uriString = uri.toString();
//Checks if app can handle this url LinkTarget.Target target = LinkTarget.resolveLinkTarget(uri);
if (Objects.equals(host, "www.thmmy.gr")) { if (LinkTarget.targetEqual(target, LinkTarget.Target.TOPIC)) {
if (uriString.contains("topic=")) { //This url points to a topic //This url points to a topic
//Checks if this is the current topic //Checks if this is the current topic
if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), base_url)) { if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), base_url)) {
//Gets uri's targeted message's index number //Gets uri's targeted message's index number
@ -539,9 +542,25 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
} }
} }
topicTask.execute(uri.toString()); 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);
} }
return true;
}
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK); intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);

34
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.List;
import java.util.Objects; 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.FileManager.ThmmyFile;
import gr.thmmy.mthmmy.utils.ParseHelpers;
import mthmmy.utils.Report; import mthmmy.utils.Report;
/** /**
@ -193,36 +194,7 @@ class TopicParser {
p_subject = thisRow.select("div[id^=subject_]").first().select("a").first().text(); p_subject = thisRow.select("div[id^=subject_]").first().select("a").first().text();
//Finds post's text //Finds post's text
p_post = thisRow.select("div").select(".post").first().outerHtml(); p_post = ParseHelpers.youtubeEmbeddedFix(thisRow.select("div").select(".post").first());
{ //Fixes embedded videos
Elements noembedTag = thisRow.select("div").select(".post").first().select("noembed");
ArrayList<String> 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("<embed")) {
if (tmp_counter > embededVideosUrls.size())
break;
p_post = p_post.replace(
p_post.substring(p_post.indexOf("<embed"), p_post.indexOf("/noembed>") + 9)
, "<div class=\"yt\">"
+ "<a href=\"https://www.youtube.com/"
+ 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\""
+ "</a>"
+ "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter)
+ "/default.jpg\" alt=\"\" border=\"0\" width=\"40%\">"
+ "</div>");
}
}
//Add stuff to make it work in WebView //Add stuff to make it work in WebView
//style.css //style.css

2
app/src/main/java/gr/thmmy/mthmmy/data/Board.java → 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 { public class Board {
private final String url, title, mods, stats, lastPost, lastPostUrl; private final String url, title, mods, stats, lastPost, lastPostUrl;

2
app/src/main/java/gr/thmmy/mthmmy/data/Category.java → 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; import com.bignerdranch.expandablerecyclerview.model.Parent;

50
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;
}
}

2
app/src/main/java/gr/thmmy/mthmmy/data/Post.java → 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; import java.util.ArrayList;

2
app/src/main/java/gr/thmmy/mthmmy/data/PostSummary.java → 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 { public class PostSummary {
private final String topicUrl; private final String topicUrl;

2
app/src/main/java/gr/thmmy/mthmmy/data/Topic.java → 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 { public class Topic extends TopicSummary {
private final String lastPostUrl, stats; private final String lastPostUrl, stats;

2
app/src/main/java/gr/thmmy/mthmmy/data/TopicSummary.java → 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 { public class TopicSummary {
final String topicUrl; final String topicUrl;

42
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<String> 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("<embed")) {
if (tmp_counter > embededVideosUrls.size())
break;
fixed = fixed.replace(
fixed.substring(fixed.indexOf("<embed"), fixed.indexOf("/noembed>") + 9)
, "<div class=\"yt\">"
+ "<a href=\"https://www.youtube.com/"
+ 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\""
+ "</a>"
+ "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter)
+ "/default.jpg\" alt=\"\" border=\"0\" width=\"40%\">"
+ "</div>");
}
return fixed;
}
}
Loading…
Cancel
Save