Browse Source

Dialogs and youtube embedded videos fixes.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
2bb62d31dc
  1. 3
      app/src/main/AndroidManifest.xml
  2. 43
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 24
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  4. 2
      app/src/main/res/layout/activity_about.xml
  5. 2
      app/src/main/res/layout/activity_main.xml
  6. 1
      app/src/main/res/values/colors.xml
  7. 15
      app/src/main/res/values/styles.xml

3
app/src/main/AndroidManifest.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gr.thmmy.mthmmy">
package="gr.thmmy.mthmmy">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
@ -8,6 +8,7 @@
<application
android:name=".utils.ImageController"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"

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

@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
@ -44,6 +45,7 @@ import javax.net.ssl.SSLHandshakeException;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity;
import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.data.Post;
import gr.thmmy.mthmmy.utils.CircularNetworkImageView;
import gr.thmmy.mthmmy.utils.ImageController;
@ -152,17 +154,31 @@ public class TopicActivity extends BaseActivity {
"Please sent below info to developers:\n"
+ getLocalClassName() + "." + "l"
+ Thread.currentThread().getStackTrace()[1].getLineNumber())
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Todo
//Maybe sent info back to developers?
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
} else if (tmp_curr_status != LOGGED_IN) {
new AlertDialog.Builder(TopicActivity.this, R.style.AppTheme_Dark_Dialog)
.setTitle(" ")
new AlertDialog.Builder(TopicActivity.this)
.setMessage("You need to be logged in to reply!")
.setIcon(android.R.drawable.ic_secure)
.setPositiveButton("Login", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(TopicActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.show();
} else {
//TODO
@ -450,7 +466,20 @@ public class TopicActivity extends BaseActivity {
//Post's WebView parameters set
post.setClickable(true);
post.setWebViewClient(new LinkLauncher());
//post.setWebViewClient(new LinkLauncher());
post.getSettings().setJavaScriptEnabled(true);
//TODO
post.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
post.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
//Avoiding errors about layout having 0 width/height
thumbnail.setMinimumWidth(1);

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

@ -92,6 +92,28 @@ class TopicParser {
//Find post's text
p_post = item.select("div").select(".post").first().html();
{
Elements noembedTag = item.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?") + 6
, _noembed.text().indexOf("target") - 6));
}
int tmp_counter = 0;
while (p_post.contains("<embed")) {
p_post = p_post.replace(
p_post.substring(p_post.indexOf("<embed"), p_post.indexOf("/noembed>") + 9)
, "<iframe width=\"200\" height=\"315\" src=\""
+ embededVideosUrls.get(tmp_counter)
+ "\" frameborder=\"0\" allowfullscreen></iframe>"
);
}
}
//Add stuff to make it work in WebView
p_post = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"
+ p_post); //style.css
@ -129,7 +151,7 @@ class TopicParser {
List<String> infoList = Arrays.asList(info.html().split("<br>"));
for (String line : infoList) {
Log.i(TAG, line);
//Log.i(TAG, line);
if (line.contains("Posts:")) {
postsLineIndex = infoList.indexOf(line);
//Remove any line breaks and spaces on the start and end

2
app/src/main/res/layout/activity_about.xml

@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/popupTheme">
app:popupTheme="@style/ToolbarTheme">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

2
app/src/main/res/layout/activity_main.xml

@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/popupTheme">
app:popupTheme="@style/ToolbarTheme">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout

1
app/src/main/res/values/colors.xml

@ -16,4 +16,5 @@
<color name="iron">#CCCCCC</color>
<color name="card_expand_text_color">#464646</color>
<color name="background">#D3D3D3</color>
<color name="dialog_bg_semi_transparent">#80212c6f</color>
</resources>

15
app/src/main/res/values/styles.xml

@ -17,6 +17,7 @@
<item name="android:textColorHint">@color/iron</item>
<item name="colorButtonNormal">@color/primary</item>
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
<style name="AppTheme.NoActionBar">
@ -24,13 +25,7 @@
<item name="windowNoTitle">true</item>
</style>
<!-- Toolbar style. -->
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- android:textColorPrimary is the color of the title text in the Toolbar -->
<item name="android:textColorPrimary">@android:color/white</item>
</style>
<style name="popupTheme" parent="ThemeOverlay.AppCompat.Light">
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:colorBackground">@color/colorPrimary</item>
</style>
@ -41,4 +36,10 @@
<item name="android:background">@color/primary</item>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:background">@color/dialog_bg_semi_transparent</item>
</style>
</resources>

Loading…
Cancel
Save