Bläddra i källkod

Fix post layout

Infinite 3 år sedan
förälder
incheckning
8ca50317d5

+ 1 - 1
app/src/main/java/club/thepenguins/android/adapters/PostRecyclerAdapter.java

@@ -93,7 +93,7 @@ public class PostRecyclerAdapter extends RecyclerView.Adapter<PostRecyclerAdapte
 
                 FragmentManager fragmentManager = ((AppCompatActivity) ctx).getSupportFragmentManager();
 
-                fragmentManager.beginTransaction().replace(R.id.flContent, PostFragment.newInstance(object.Content, object.Image)).addToBackStack("DetailedPizza").commit();
+                fragmentManager.beginTransaction().replace(R.id.flContent, PostFragment.newInstance(object.Content, object.Image, object.title, object.author)).addToBackStack("DetailedPizza").commit();
 
             }
         });

+ 22 - 4
app/src/main/java/club/thepenguins/android/fragments/PostFragment.java

@@ -8,6 +8,12 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.webkit.WebView;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.squareup.picasso.Callback;
+import com.squareup.picasso.NetworkPolicy;
+import com.squareup.picasso.Picasso;
 
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
@@ -16,23 +22,30 @@ import org.jsoup.select.Elements;
 
 import club.thepenguins.android.R;
 
+
 public class PostFragment extends Fragment {
 
     private static final String ARG_PARAM1 = "param1";
     private static final String ARG_PARAM2 = "param2";
+    private static final String ARG_PARAM3 = "param3";
+    private static final String ARG_PARAM4 = "param4";
     private String mParam1;
     private String mParam2;
+    private String mParam3;
+    private String mParam4;
 
     public PostFragment() {
         // Required empty public constructor
     }
 
 
-    public static PostFragment newInstance(String param1, String param2) {
+    public static PostFragment newInstance(String param1, String param2, String param3, String param4) {
         PostFragment fragment = new PostFragment();
         Bundle args = new Bundle();
         args.putString(ARG_PARAM1, param1);
         args.putString(ARG_PARAM2, param2);
+        args.putString(ARG_PARAM3, param3);
+        args.putString(ARG_PARAM4, param4);
         fragment.setArguments(args);
         return fragment;
     }
@@ -43,6 +56,8 @@ public class PostFragment extends Fragment {
         if (getArguments() != null) {
             mParam1 = getArguments().getString(ARG_PARAM1);
             mParam2 = getArguments().getString(ARG_PARAM2);
+            mParam3 = getArguments().getString(ARG_PARAM3);
+            mParam4 = getArguments().getString(ARG_PARAM4);
         }
     }
 
@@ -53,8 +68,12 @@ public class PostFragment extends Fragment {
         View rootView = inflater.inflate(R.layout.fragment_post, container, false);
 
 
-        /*
-        ImageView imageView = rootView.findViewById(R.id.postImage);
+        ImageView imageView = rootView.findViewById(R.id.postImg);
+        TextView textView = rootView.findViewById(R.id.author);
+        TextView textView2 = rootView.findViewById(R.id.postTitle);
+        textView2.setText(mParam3);
+        textView.setText(mParam4);
+
 
         Picasso.get()
                 .load(mParam2)
@@ -79,7 +98,6 @@ public class PostFragment extends Fragment {
                     }
                 });
 
-         */
 
         Document doc = Jsoup.parse(mParam1);
 

+ 61 - 0
app/src/main/java/club/thepenguins/android/utils/TouchyWebView.java

@@ -0,0 +1,61 @@
+package club.thepenguins.android.utils;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.ViewParent;
+import android.webkit.WebView;
+
+import androidx.annotation.Nullable;
+
+public class TouchyWebView extends WebView {
+    ViewParent mViewParent;
+
+    public TouchyWebView(Context context) {
+        super(context);
+    }
+
+    public TouchyWebView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public TouchyWebView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    public void setViewParent(@Nullable final ViewParent viewParent) { //any ViewGroup
+        mViewParent = viewParent;
+    }
+
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+
+        switch (event.getAction()) {
+            case MotionEvent.ACTION_DOWN:
+                if (null == mViewParent) {
+                    getParent().requestDisallowInterceptTouchEvent(true);
+                } else {
+                    mViewParent.requestDisallowInterceptTouchEvent(true);
+                }
+                break;
+            case MotionEvent.ACTION_UP:
+                if (null == mViewParent) {
+                    getParent().requestDisallowInterceptTouchEvent(false);
+                } else {
+                    mViewParent.requestDisallowInterceptTouchEvent(false);
+                }
+                break;
+            default:
+                break;
+        }
+        return super.onTouchEvent(event);
+    }
+
+    @Override
+    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
+        super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
+        requestDisallowInterceptTouchEvent(true);
+
+
+    }}

+ 77 - 10
app/src/main/res/layout/fragment_post.xml

@@ -5,23 +5,90 @@
     android:layout_height="match_parent"
     tools:context=".fragments.PostFragment">
 
-    <LinearLayout
+    <androidx.core.widget.NestedScrollView
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical">
+        android:layout_height="match_parent">
 
-
-        <ScrollView
+        <RelativeLayout
+            android:id="@+id/linear1"
             android:layout_width="match_parent"
-            android:layout_height="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>
+
 
             <WebView
                 android:id="@+id/webview"
                 android:layout_width="match_parent"
-                android:layout_height="wrap_content">
+                android:layout_height="wrap_content"
+                android:layout_below="@+id/relative1"
+                android:nestedScrollingEnabled="true" />
+
+        </RelativeLayout>
+
+
+    </androidx.core.widget.NestedScrollView>
 
-            </WebView>
-        </ScrollView>
-    </LinearLayout>
 
 </FrameLayout>

+ 29 - 31
app/src/main/res/layout/post_item.xml

@@ -1,79 +1,78 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:orientation="horizontal"
+    android:id="@+id/card"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_margin="5dp"
-    android:id="@+id/card"
+    android:orientation="horizontal"
     app:cardElevation="5dp">
 
 
     <RelativeLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        >
+        android:layout_height="wrap_content">
+
         <ImageView
+            android:id="@+id/Icon"
             android:layout_width="match_parent"
             android:layout_height="200dp"
-            android:src="@drawable/ic_launcher_background"
-            android:id="@+id/Icon"
             android:layout_margin="5dp"
-            />
+            android:src="@drawable/ic_launcher_background" />
 
 
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:orientation="vertical"
+            android:layout_below="@+id/Icon"
             android:gravity="center_vertical"
-            android:paddingTop="10dp"
-            android:layout_below="@+id/Icon">
+            android:orientation="vertical"
+            android:paddingTop="10dp">
 
             <TextView
+                android:id="@+id/title"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:textStyle="bold"
+                android:layout_marginBottom="5dp"
                 android:gravity="left"
-                android:id="@+id/title"
                 android:padding="5dp"
                 android:textSize="20sp"
-                android:layout_marginBottom="5dp"/>
+                android:textStyle="bold" />
 
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
+                android:orientation="horizontal">
 
-            <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textSize="16sp"
-                android:textStyle="bold"
-                android:padding="5dp"
-                android:gravity="left"
-                android:text="Author:"/>
                 <TextView
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:textSize="15sp"
-                    android:padding="5dp"
+                    android:layout_marginStart="5dp"
+                    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:id="@+id/author"/>
+                    android:textSize="15sp" />
 
             </LinearLayout>
 
             <TextView
+                android:id="@+id/subtitle"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:gravity="left"
-                android:id="@+id/subtitle"
-                android:padding="5dp"
                 android:layout_marginBottom="5dp"
+                android:gravity="left"
+                android:lineSpacingExtra="2dp"
                 android:maxLines="5"
-                android:lineSpacingExtra="2dp"/>
+                android:padding="5dp" />
 
         </LinearLayout>
 
@@ -81,5 +80,4 @@
     </RelativeLayout>
 
 
-
 </androidx.cardview.widget.CardView>