فهرست منبع

Fix webview scrolling issue

Infinite 3 سال پیش
والد
کامیت
e51cbe2fbf
2فایلهای تغییر یافته به همراه18 افزوده شده و 117 حذف شده
  1. 14 49
      app/src/main/java/club/thepenguins/android/fragments/PostFragment.java
  2. 4 68
      app/src/main/res/layout/fragment_post.xml

+ 14 - 49
app/src/main/java/club/thepenguins/android/fragments/PostFragment.java

@@ -10,19 +10,13 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.webkit.WebView;
-import android.widget.ImageView;
 import android.widget.ProgressBar;
-import android.widget.TextView;
 import android.widget.Toast;
 
-import com.squareup.picasso.Callback;
-import com.squareup.picasso.NetworkPolicy;
-import com.squareup.picasso.Picasso;
 
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
-import org.jsoup.parser.Parser;
 import org.jsoup.select.Elements;
 
 import java.util.ArrayList;
@@ -84,48 +78,8 @@ public class PostFragment extends Fragment {
         View rootView = inflater.inflate(R.layout.fragment_post, container, false);
 
 
-        ImageView imageView = rootView.findViewById(R.id.postImg);
-        TextView textView = rootView.findViewById(R.id.author);
-        TextView textView2 = rootView.findViewById(R.id.postTitle);
-        textView2.setText(Parser.unescapeEntities(mParam3, false));
-        textView.setText(mParam4);
         progressBar = rootView.findViewById(R.id.progress);
 
-        textView.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-
-                getActivity().getSupportFragmentManager().beginTransaction()
-                        .replace(((ViewGroup) getView().getParent()).getId(), AuthorPostFragment.newInstance(mParam4, null), "findThisFragment")
-                        .addToBackStack(null)
-                        .commit();
-            }
-        });
-
-
-        Picasso.get()
-                .load(mParam2)
-                .placeholder(R.color.preloadColor)
-                .fit()
-                .centerCrop()
-                .networkPolicy(NetworkPolicy.OFFLINE)
-                .into(imageView, new Callback() {
-                    @Override
-                    public void onSuccess() {
-
-                    }
-
-                    @Override
-                    public void onError(Exception e) {
-                        Picasso.get()
-                                .load(mParam2)
-                                .placeholder(R.color.preloadColor)
-                                .fit()
-                                .centerCrop()
-                                .into(imageView);
-                    }
-                });
-
         postData = new ArrayList<>();
         postData.clear();
 
@@ -138,7 +92,8 @@ public class PostFragment extends Fragment {
             public void run() {
 
                 try {
-                    Document doc = Jsoup.parse(postData.get(0).getContent());
+                    Document doc = Jsoup.parseBodyFragment(postData.get(0).getContent());
+                    doc.outputSettings().prettyPrint(false);
 
                     Elements images = doc.select("img");
                     Elements iframes = doc.select("iframe");
@@ -158,12 +113,22 @@ public class PostFragment extends Fragment {
 
                     }
 
-                    String htmlString = doc.html();
+                    String htmlString = doc.select("body").html();
+
+                    char quotes = '"';
+
+                    String postTitle = "<h2>" + mParam3 + "</h2>" + "\n";
+
+                    String postAuthor = "<p>" + "Author: " + mParam4 + "</p>" + "\n";
+
+                    String postImage = "<img src= " + quotes + mParam2 + quotes + " width =" + quotes + "100%" + quotes + "/>" + "\n";
+
+                    String newHtmlString = postImage + postTitle + postAuthor + htmlString;
 
 
                     WebView myWebView = rootView.findViewById(R.id.webview);
 
-                    myWebView.loadDataWithBaseURL(null, htmlString, "text/html", "UTF-8", null);
+                    myWebView.loadDataWithBaseURL(null, newHtmlString, "text/html", "UTF-8", null);
                     myWebView.getSettings().setJavaScriptEnabled(true);
                     progressBar.setVisibility(View.GONE);
                 } catch (Exception e) {

+ 4 - 68
app/src/main/res/layout/fragment_post.xml

@@ -9,79 +9,15 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
-        <RelativeLayout
-            android:id="@+id/linear1"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:orientation="vertical">
-
-            <RelativeLayout
-                android:id="@+id/relative1"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content">
-
-                <ImageView
-                    android:id="@+id/postImg"
-                    android:layout_width="match_parent"
-                    android:layout_height="480px"
-                    android:padding="5dp"
-                    android:src="@drawable/ic_launcher_background" />
-
-                <LinearLayout
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:layout_below="@+id/postImg">
-
-                    <RelativeLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content">
-
-                        <TextView
-                            android:id="@+id/postTitle"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginStart="10dp"
-                            android:text="Post title"
-                            android:textSize="20sp"
-                            android:textStyle="bold" />
-
-                        <LinearLayout
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_below="@+id/postTitle"
-                            android:orientation="horizontal">
-
-                            <TextView
-                                android:layout_width="wrap_content"
-                                android:layout_height="wrap_content"
-                                android:layout_marginStart="10dp"
-                                android:gravity="left"
-                                android:text="Author:"
-                                android:textSize="16sp"
-                                android:textStyle="bold" />
-
-                            <TextView
-                                android:id="@+id/author"
-                                android:layout_width="wrap_content"
-                                android:layout_height="wrap_content"
-                                android:gravity="right"
-                                android:padding="5dp"
-                                android:text="Name"
-                                android:textSize="15sp" />
-
-                        </LinearLayout>
-
-                    </RelativeLayout>
-
-                </LinearLayout>
-
-            </RelativeLayout>
+       <RelativeLayout
+           android:layout_width="match_parent"
+           android:layout_height="match_parent"
+           >
 
             <ProgressBar
                 android:id="@+id/progress"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:layout_below="@+id/relative1"
                 android:visibility="gone" />