Browse Source

Pagination and yt embedded videos fix

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
4a6eab0573
  1. 16
      app/src/main/assets/style.css
  2. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java
  3. 66
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  4. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java

16
app/src/main/assets/style.css

@ -505,9 +505,15 @@ img
height:auto !important; height:auto !important;
} }
.embedded-video-play{ .yt {
display: block; position: relative;
width: 5%; }
opacity: 0.7;
z-index: 2; .embedded-video-play {
position: absolute;
top: 22%;
left: 10%;
width: 20%;
opacity: 0.7;
z-index: 2;
} }

10
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java

@ -115,13 +115,15 @@ class ProfileParser {
break; break;
pHtml = pHtml.replace( pHtml = pHtml.replace(
pHtml.substring(pHtml.indexOf("<embed"), pHtml.indexOf("/noembed>") + 9) pHtml.substring(pHtml.indexOf("<embed"), pHtml.indexOf("/noembed>") + 9)
, "<div class=\"embedded-video\">" , "<div class=\"yt\">"
+ "<a href=\"https://www.youtube.com/" + "<a href=\"https://www.youtube.com/"
+ embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">" + embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">"
+ "<img src=\"https://img.youtube.com/vi/" + "<img class=\"embedded-video-play\" "
+ embededVideosUrls.get(tmp_counter) + "/default.jpg\" alt=\"\" border=\"0\">" + "src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\""
+ "</a>" + "</a>"
//+ "<img class=\"embedded-video-play\" src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\">" + "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter)
+ "/default.jpg\" alt=\"\" border=\"0\" width=\"40%\">"
+ "</div>"); + "</div>");
} }
} }

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

@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.topic;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -36,8 +35,6 @@ import mthmmy.utils.Report;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN;
/** /**
* 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>
* containing this topics's url using the key {@link #EXTRAS_TOPIC_URL} and a <b>String</b> containing * containing this topics's url using the key {@link #EXTRAS_TOPIC_URL} and a <b>String</b> containing
@ -200,7 +197,7 @@ public class TopicActivity extends BaseActivity {
topicTask.cancel(true); topicTask.cancel(true);
} }
//--------------------------------------BOTTOM NAV BAR METHODS-------------------------------------- //--------------------------------------BOTTOM NAV BAR METHODS--------------------------------------
private void initIncrementButton(ImageButton increment, final int step) { private void initIncrementButton(ImageButton increment, final int step) {
// Increment once for a click // Increment once for a click
increment.setOnClickListener(new View.OnClickListener() { increment.setOnClickListener(new View.OnClickListener() {
@ -333,7 +330,7 @@ public class TopicActivity extends BaseActivity {
base_url = strings[0].substring(0, strings[0].lastIndexOf(".")); //This topic's base url base_url = strings[0].substring(0, strings[0].lastIndexOf(".")); //This topic's base url
String newPageUrl = strings[0]; String newPageUrl = strings[0];
//Finds message focus if present //Finds the index of message focus if present
{ {
postFocus = NO_POST_FOCUS; postFocus = NO_POST_FOCUS;
if (newPageUrl.contains("msg")) { if (newPageUrl.contains("msg")) {
@ -345,33 +342,43 @@ public class TopicActivity extends BaseActivity {
} }
} }
if (!loadedPageUrl.contains(base_url)) { //Checks if the page to be loaded is the one already shown
loadedPageUrl = newPageUrl; if (!Objects.equals(loadedPageUrl, "") && !loadedPageUrl.contains(base_url)) {
Request request = new Request.Builder() if (newPageUrl.contains("topicseen#new"))
.url(newPageUrl) if (Integer.parseInt(loadedPageUrl.substring(base_url.length())) == numberOfPages)
.build(); return SAME_PAGE;
try { if (Objects.equals(loadedPageUrl.substring(base_url.length())
Response response = client.newCall(request).execute(); , newPageUrl.substring(base_url.length())))
document = Jsoup.parse(response.body().string()); return SAME_PAGE;
parse(document); }
for (int i = 0; i < postsList.size(); ++i) {
if (postsList.get(i).getPostIndex() == postFocus) { loadedPageUrl = newPageUrl;
postFocusPosition = i; Request request = new Request.Builder()
break; .url(newPageUrl)
} .build();
} try {
return SUCCESS; Response response = client.newCall(request).execute();
} catch (IOException e) { document = Jsoup.parse(response.body().string());
Report.i(TAG, "IO Exception", e); parse(document);
return NETWORK_ERROR; return SUCCESS;
} catch (Exception e) { } catch (IOException e) {
Report.e(TAG, "Exception", e); Report.i(TAG, "IO Exception", e);
return OTHER_ERROR; return NETWORK_ERROR;
} } catch (Exception e) {
} else return SAME_PAGE; Report.e(TAG, "Exception", e);
return OTHER_ERROR;
}
} }
protected void onPostExecute(Integer parseResult) { protected void onPostExecute(Integer parseResult) {
//Finds the position of the focused message if present
for (int i = 0; i < postsList.size(); ++i) {
if (postsList.get(i).getPostIndex() == postFocus) {
postFocusPosition = i;
break;
}
}
switch (parseResult) { switch (parseResult) {
case SUCCESS: case SUCCESS:
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
@ -397,6 +404,7 @@ public class TopicActivity extends BaseActivity {
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show(); Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show();
break; break;
case SAME_PAGE: case SAME_PAGE:
//TODO change focus
break; break;
default: default:
//Parse failed - should never happen //Parse failed - should never happen

20
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java

@ -211,13 +211,15 @@ class TopicParser {
break; break;
p_post = p_post.replace( p_post = p_post.replace(
p_post.substring(p_post.indexOf("<embed"), p_post.indexOf("/noembed>") + 9) p_post.substring(p_post.indexOf("<embed"), p_post.indexOf("/noembed>") + 9)
, "<div class=\"embedded-video\">" , "<div class=\"yt\">"
+ "<a href=\"https://www.youtube.com/" + "<a href=\"https://www.youtube.com/"
+ embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">" + embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">"
+ "<img src=\"https://img.youtube.com/vi/" + "<img class=\"embedded-video-play\" "
+ embededVideosUrls.get(tmp_counter) + "/default.jpg\" alt=\"\" border=\"0\">" + "src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\""
+ "</a>" + "</a>"
//+ "<img class=\"embedded-video-play\" src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\">" + "<img src=\"https://img.youtube.com/vi/"
+ embededVideosUrls.get(tmp_counter)
+ "/default.jpg\" alt=\"\" border=\"0\" width=\"40%\">"
+ "</div>"); + "</div>");
} }
} }
@ -284,7 +286,7 @@ class TopicParser {
try { try {
attachedUrl = new URL(tmpAttachedFileUrlAndName.attr("href")); attachedUrl = new URL(tmpAttachedFileUrlAndName.attr("href"));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Report.e(TAG,"Attached file malformed url", e); Report.e(TAG, "Attached file malformed url", e);
break; break;
} }
String attachedFileName = tmpAttachedFileUrlAndName.text().substring(1); String attachedFileName = tmpAttachedFileUrlAndName.text().substring(1);
@ -296,7 +298,7 @@ class TopicParser {
String attachedFileInfo = postAttachmentsTextSbstr.substring(attachedFileName String attachedFileInfo = postAttachmentsTextSbstr.substring(attachedFileName
.length(), postAttachmentsTextSbstr.indexOf("φορές.")) + "φορές.)"; .length(), postAttachmentsTextSbstr.indexOf("φορές.")) + "φορές.)";
p_attachedFiles.add(new ThmmyFile(attachedUrl,attachedFileName,attachedFileInfo)); p_attachedFiles.add(new ThmmyFile(attachedUrl, attachedFileName, attachedFileInfo));
} }
} }
} else { } else {
@ -344,7 +346,7 @@ class TopicParser {
try { try {
attachedUrl = new URL(tmpAttachedFileUrlAndName.attr("href")); attachedUrl = new URL(tmpAttachedFileUrlAndName.attr("href"));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Report.e(TAG,"Attached file malformed url", e); Report.e(TAG, "Attached file malformed url", e);
break; break;
} }
String attachedFileName = tmpAttachedFileUrlAndName.text().substring(1); String attachedFileName = tmpAttachedFileUrlAndName.text().substring(1);
@ -356,7 +358,7 @@ class TopicParser {
String attachedFileInfo = postAttachmentsTextSbstr.substring(attachedFileName String attachedFileInfo = postAttachmentsTextSbstr.substring(attachedFileName
.length(), postAttachmentsTextSbstr.indexOf("times.")) + "times.)"; .length(), postAttachmentsTextSbstr.indexOf("times.")) + "times.)";
p_attachedFiles.add(new ThmmyFile(attachedUrl,attachedFileName,attachedFileInfo)); p_attachedFiles.add(new ThmmyFile(attachedUrl, attachedFileName, attachedFileInfo));
} }
} }
} }
@ -453,6 +455,7 @@ class TopicParser {
* Returns one of the supported forum languages. * Returns one of the supported forum languages.
* <p>Forum supports: <ul><li>{@link #LANGUAGE_ENGLISH}</li> * <p>Forum supports: <ul><li>{@link #LANGUAGE_ENGLISH}</li>
* <li>{@link #LANGUAGE_GREEK}</li></ul></p> * <li>{@link #LANGUAGE_GREEK}</li></ul></p>
*
* @param topic {@link Document} object containing this topic's source code * @param topic {@link Document} object containing this topic's source code
* @return String containing the language of a topic * @return String containing the language of a topic
* @see org.jsoup.Jsoup Jsoup * @see org.jsoup.Jsoup Jsoup
@ -467,6 +470,7 @@ class TopicParser {
/** /**
* Returns the color of a user according to user's rank on forum. * Returns the color of a user according to user's rank on forum.
*
* @param starsUrl String containing the URL of a user's stars * @param starsUrl String containing the URL of a user's stars
* @return an int corresponding to the right color * @return an int corresponding to the right color
*/ */

Loading…
Cancel
Save