Browse Source

Fix for embedded videos and reversed order in user stats.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
d74331b05d
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java
  4. 1
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  5. 25
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  7. 7
      app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java

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

@ -201,7 +201,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
.url(boardUrl[0])
.build();
try {
Response response = BaseActivity.getClient().newCall(request).execute();
Response response = client.newCall(request).execute();
parseBoard(Jsoup.parse(response.body().string()));
} catch (SSLHandshakeException e) {
Report.w(TAG, "Certificate problem (please switch to unsafe connection).");

2
app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java

@ -192,7 +192,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
.url(downloadsUrl[0])
.build();
try {
Response response = BaseActivity.getClient().newCall(request).execute();
Response response = client.newCall(request).execute();
parseDownloads(Jsoup.parse(response.body().string()));
} catch (SSLHandshakeException e) {
Report.w(TAG, "Certificate problem (please switch to unsafe connection).");

3
app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java

@ -33,6 +33,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.net.ssl.SSLHandshakeException;
@ -206,6 +207,7 @@ public class StatsFragment extends Fragment {
Integer.parseInt(dataCols.last().text())));
mostPopularBoardsByPostsLabels.add(dataCols.first().text());
}
Collections.reverse(mostPopularBoardsByPostsLabels);
}
{
Elements mostPopularBoardsByActivityRows = statsRows.last().select(">td").last()
@ -218,6 +220,7 @@ public class StatsFragment extends Fragment {
Float.parseFloat(tmp.substring(0, tmp.indexOf("%")))));
mostPopularBoardsByActivityLabels.add(dataCols.first().text());
}
Collections.reverse(mostPopularBoardsByActivityLabels);
}
}
return true;

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

@ -79,6 +79,7 @@ public abstract class BaseActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
if (client == null)
client = BaseApplication.getInstance().getClient(); //must check every time - e.g.
// they become null when app restarts after crash
if (sessionManager == null)
sessionManager = BaseApplication.getInstance().getSessionManager();

25
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -19,11 +19,17 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.session.SessionManager;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class BaseApplication extends Application {
@ -40,7 +46,7 @@ public class BaseApplication extends Application {
//Display Metrics
private static float dpHeight, dpWidth;
public static BaseApplication getInstance(){
public static BaseApplication getInstance() {
return baseApplication;
}
@ -54,6 +60,22 @@ public class BaseApplication extends Application {
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor);
client = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
HttpUrl oldUrl = chain.request().url();
if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) {
if (!oldUrl.toString().contains("theme=4")) {
//Probably works but needs more testing:
HttpUrl newUrl = oldUrl.newBuilder().addQueryParameter("theme", "4").build();
request = request.newBuilder().url(newUrl).build();
}
}
return chain.proceed(request);
}
})
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
@ -71,6 +93,7 @@ public class BaseApplication extends Application {
public void set(ImageView imageView, Uri uri, Drawable placeholder) {
Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
}
@Override
public void cancel(ImageView imageView) {
Picasso.with(imageView.getContext()).cancelRequest(imageView);

2
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -332,7 +332,7 @@ public class SessionManager {
if (!avatar.isEmpty())
return avatar.first().attr("src");
Report.e(TAG, "Extracting avatar's link failed!");
Report.i(TAG, "Extracting avatar's link failed!");
return null;
}

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

@ -1,5 +1,7 @@
package gr.thmmy.mthmmy.utils;
import android.util.Log;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
@ -153,15 +155,16 @@ public class ParseHelpers {
fixed = fixed.replace(
fixed.substring(fixed.indexOf("<embed"), fixed.indexOf("/noembed>") + 9)
, "<div class=\"yt\">"
+ "<a href=\"https://www.youtube.com/"
+ "<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=\"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>");
++tmp_counter;
}
return fixed;
}

Loading…
Cancel
Save