Prechádzať zdrojové kódy

Post loading is superb fast now

Infinite 3 rokov pred
rodič
commit
79abcd5a51

+ 1 - 2
app/src/main/AndroidManifest.xml

@@ -11,6 +11,7 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/Theme.PenguinsRead">
+        <activity android:name=".activities.PostActivity" />
         <activity android:name=".activities.SplashActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -22,7 +23,6 @@
             android:name=".activities.MainActivity"
             android:configChanges="uiMode" />
 
-
         <service
             android:name=".services.NotificationService"
             android:exported="true">
@@ -30,7 +30,6 @@
                 <action android:name="com.google.firebase.MESSAGING_EVENT" />
             </intent-filter>
         </service>
-
     </application>
 
 </manifest>

+ 35 - 63
app/src/main/java/club/thepenguins/android/fragments/PostFragment.java → app/src/main/java/club/thepenguins/android/activities/PostActivity.java

@@ -1,26 +1,22 @@
-package club.thepenguins.android.fragments;
+package club.thepenguins.android.activities;
 
-import android.content.Context;
-import android.content.res.Configuration;
-import android.os.Bundle;
-
-import androidx.fragment.app.Fragment;
+import androidx.appcompat.app.AppCompatActivity;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.webkit.WebSettingsCompat;
 import androidx.webkit.WebViewFeature;
 
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Bundle;
 import android.os.Handler;
 import android.util.Log;
-import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup;
-import android.webkit.WebSettings;
 import android.webkit.WebView;
+import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
 
-
 import com.facebook.shimmer.ShimmerFrameLayout;
 
 import org.jsoup.Jsoup;
@@ -47,17 +43,8 @@ import retrofit2.converter.gson.GsonConverterFactory;
 
 import static club.thepenguins.android.utils.Constants.noInternet;
 
+public class PostActivity extends AppCompatActivity {
 
-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;
     private ArrayList<PostContent> postData;
     private ArrayList<CommentModel> comments;
     private RecyclerView recyclerView;
@@ -65,51 +52,38 @@ public class PostFragment extends Fragment {
     private LinearLayoutManager layoutManager;
     private TextView textView;
     private ShimmerFrameLayout loader;
+    private ImageView imageView;
 
 
-    public PostFragment() {
-        // Required empty public constructor
-    }
-
-
-    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;
-    }
-
     @Override
-    public void onCreate(Bundle savedInstanceState) {
+    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        if (getArguments() != null) {
-            mParam1 = getArguments().getString(ARG_PARAM1);
-            mParam2 = getArguments().getString(ARG_PARAM2);
-            mParam3 = getArguments().getString(ARG_PARAM3);
-            mParam4 = getArguments().getString(ARG_PARAM4);
-        }
-    }
+        setContentView(R.layout.activity_post);
 
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                             Bundle savedInstanceState) {
+        imageView = findViewById(R.id.back);
 
-        View rootView = inflater.inflate(R.layout.fragment_post, container, false);
+        imageView.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
 
-        loader = (ShimmerFrameLayout) rootView.findViewById(R.id.shimmer_view_container);
+                PostActivity.super.onBackPressed();
+            }
+        });
+
+        String content = getIntent().getStringExtra("content");
+        String title = getIntent().getStringExtra("title");
+        String author = getIntent().getStringExtra("author");
+        String image = getIntent().getStringExtra("image");
+
+        loader = (ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);
 
         postData = new ArrayList<>();
         comments = new ArrayList<>();
 
         postData.clear();
 
-        getRetrofit(mParam1, rootView.getContext());
+        getRetrofit(content, PostActivity.this);
 
-        Log.d("TAG", "onCreateView: " + mParam1);
 
         final Handler handler = new Handler();
         handler.postDelayed(new Runnable() {
@@ -142,16 +116,16 @@ public class PostFragment extends Fragment {
 
                     char quotes = '"';
 
-                    String postTitle = "<h2>" + mParam3 + "</h2>" + "\n";
+                    String postTitle = "<h2>" + title + "</h2>" + "\n";
 
-                    String postAuthor = "<p>" + "Author: " + mParam4 + "</p>" + "\n";
+                    String postAuthor = "<p>" + "Author: " + author + "</p>" + "\n";
 
-                    String postImage = "<img src= " + quotes + mParam2 + quotes + " width =" + quotes + "100%" + quotes + "/>" + "\n";
+                    String postImage = "<img src= " + quotes + image + quotes + " width =" + quotes + "100%" + quotes + "/>" + "\n";
 
                     String newHtmlString = postImage + postTitle + postAuthor + htmlString;
 
 
-                    WebView myWebView = rootView.findViewById(R.id.webview);
+                    WebView myWebView = findViewById(R.id.webview);
 
                     myWebView.loadDataWithBaseURL(null, newHtmlString, "text/html", "UTF-8", null);
                     myWebView.getSettings().setJavaScriptEnabled(true);
@@ -168,7 +142,7 @@ public class PostFragment extends Fragment {
                     recyclerView.setVisibility(View.VISIBLE);
 
                 } catch (Exception e) {
-                    Toasty.error(rootView.getContext(), noInternet, Toast.LENGTH_LONG, true).show();
+                    Toasty.error(PostActivity.this, noInternet, Toast.LENGTH_LONG, true).show();
                     Log.d("PostFragment", "run: " + e);
                 }
 
@@ -176,27 +150,26 @@ public class PostFragment extends Fragment {
             }
         }, 3000);
 
-        textView = rootView.findViewById(R.id.txtview);
+        textView = findViewById(R.id.txtview);
 
-        recyclerView = rootView.findViewById(R.id.recyclerComment);
+        recyclerView = findViewById(R.id.recyclerComment);
 
-        layoutManager = new LinearLayoutManager(rootView.getContext(), LinearLayoutManager.VERTICAL, false);
+        layoutManager = new LinearLayoutManager(PostActivity.this, LinearLayoutManager.VERTICAL, false);
         recyclerView.setLayoutManager(layoutManager);
 
 
         handler.postDelayed(new Runnable() {
             @Override
             public void run() {
-                commentAdapter = new CommentAdapter(comments, rootView.getContext());
+                commentAdapter = new CommentAdapter(comments, PostActivity.this);
                 recyclerView.setAdapter(commentAdapter);
-                String intValue = mParam1.replaceAll("[^0-9]", "").substring(1);
+                String intValue = content.replaceAll("[^0-9]", "").substring(1);
 
                 getComments(intValue);
             }
         }, 5000);
 
 
-        return rootView;
     }
 
     private void getRetrofit(String postUrl, Context context) {
@@ -277,5 +250,4 @@ public class PostFragment extends Fragment {
 
     }
 
-
 }

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

@@ -1,6 +1,7 @@
 package club.thepenguins.android.adapters;
 
 import android.content.Context;
+import android.content.Intent;
 import android.text.Html;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -9,9 +10,7 @@ import android.widget.ImageView;
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
 import androidx.cardview.widget.CardView;
-import androidx.fragment.app.FragmentManager;
 import androidx.recyclerview.widget.RecyclerView;
 
 import com.squareup.picasso.Callback;
@@ -21,8 +20,8 @@ import com.squareup.picasso.Picasso;
 import java.util.ArrayList;
 
 import club.thepenguins.android.R;
+import club.thepenguins.android.activities.PostActivity;
 import club.thepenguins.android.data.Model;
-import club.thepenguins.android.fragments.PostFragment;
 
 public class PostRecyclerAdapter extends RecyclerView.Adapter<PostRecyclerAdapter.ViewHolder> {
 
@@ -91,10 +90,21 @@ public class PostRecyclerAdapter extends RecyclerView.Adapter<PostRecyclerAdapte
             @Override
             public void onClick(View v) {
 
+                Intent intent = new Intent(ctx, PostActivity.class);
+                intent.putExtra("content", object.Content);
+                intent.putExtra("author", object.author);
+                intent.putExtra("image", object.Image);
+                intent.putExtra("title", object.title);
+                ctx.startActivity(intent);
+
+                /*
+
                 FragmentManager fragmentManager = ((AppCompatActivity) ctx).getSupportFragmentManager();
 
                 fragmentManager.beginTransaction().replace(R.id.flContent, PostFragment.newInstance(object.Content, object.Image, object.title, object.author)).addToBackStack(null).commit();
 
+
+                 */
             }
         });
 

+ 9 - 0
app/src/main/res/drawable/back_black.xml

@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24.0"
+    android:viewportHeight="24.0">
+    <path
+        android:fillColor="@color/textColor"
+        android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
+</vector>

+ 117 - 0
app/src/main/res/layout/activity_post.xml

@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/birthday_constraint"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".activities.PostActivity">
+
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+
+        <androidx.cardview.widget.CardView
+            android:layout_width="match_parent"
+            android:layout_height="?actionBarSize"
+            tools:ignore="MissingConstraints">
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="@color/backgroundColor"
+                android:orientation="horizontal">
+
+                <ImageView
+                    android:id="@+id/back"
+                    android:layout_width="0dp"
+                    android:layout_height="match_parent"
+                    android:layout_marginTop="15dp"
+                    android:layout_marginBottom="15dp"
+                    android:layout_weight="1"
+                    android:src="@drawable/back_black" />
+
+                <TextView
+                    android:layout_width="0dp"
+                    android:layout_height="match_parent"
+                    android:layout_gravity="center"
+                    android:layout_weight="4"
+                    android:fontFamily="@font/unifrakturcook"
+                    android:gravity="center"
+                    android:text="@string/name"
+                    android:textAlignment="center"
+                    android:textColor="@color/textColor"
+                    android:textSize="25sp" />
+
+                <ImageView
+                    android:layout_width="0dp"
+                    android:layout_height="match_parent"
+                    android:layout_marginTop="20dp"
+                    android:layout_marginBottom="20dp"
+                    android:layout_weight="1"
+                    android:alpha="0.6"
+                    android:src="#00FFFFFF" />
+            </LinearLayout>
+
+        </androidx.cardview.widget.CardView>
+
+        <androidx.core.widget.NestedScrollView
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <RelativeLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent">
+
+                <com.facebook.shimmer.ShimmerFrameLayout
+                    android:id="@+id/shimmer_view_container"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    app:shimmer_auto_start="false">
+
+                    <LinearLayout
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:orientation="vertical">
+
+                        <include layout="@layout/shimmer_post_detail" />
+
+                    </LinearLayout>
+
+
+                </com.facebook.shimmer.ShimmerFrameLayout>
+
+
+                <WebView
+                    android:id="@+id/webview"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@+id/shimmer_view_container"
+                    android:nestedScrollingEnabled="true" />
+
+                <TextView
+                    android:id="@+id/txtview"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@+id/webview"
+                    android:layout_margin="10dp"
+                    android:textColor="@color/textColor"
+                    android:textSize="25sp"
+                    android:visibility="gone" />
+
+                <androidx.recyclerview.widget.RecyclerView
+                    android:id="@+id/recyclerComment"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/txtview"
+                    android:visibility="gone" />
+
+            </RelativeLayout>
+
+
+        </androidx.core.widget.NestedScrollView>
+    </LinearLayout>
+
+</LinearLayout>

+ 0 - 66
app/src/main/res/layout/fragment_post.xml

@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context=".fragments.PostFragment">
-
-    <androidx.core.widget.NestedScrollView
-        android:layout_width="match_parent"
-        android:layout_height="match_parent">
-
-        <RelativeLayout
-            android:layout_width="match_parent"
-            android:layout_height="match_parent">
-
-            <com.facebook.shimmer.ShimmerFrameLayout
-                android:id="@+id/shimmer_view_container"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                app:shimmer_auto_start="false">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical">
-
-                    <include layout="@layout/shimmer_post_detail" />
-
-                </LinearLayout>
-
-
-            </com.facebook.shimmer.ShimmerFrameLayout>
-
-
-            <WebView
-                android:id="@+id/webview"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_below="@+id/shimmer_view_container"
-                android:nestedScrollingEnabled="true" />
-
-            <TextView
-                android:id="@+id/txtview"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_below="@+id/webview"
-                android:layout_margin="10dp"
-                android:textColor="@color/textColor"
-                android:textSize="25sp"
-                android:visibility="gone" />
-
-            <androidx.recyclerview.widget.RecyclerView
-                android:id="@+id/recyclerComment"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_below="@id/txtview"
-                android:visibility="gone" />
-
-        </RelativeLayout>
-
-
-    </androidx.core.widget.NestedScrollView>
-
-
-</FrameLayout>

+ 1 - 1
app/src/main/res/layout/toolbar.xml

@@ -26,7 +26,7 @@
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:fontFamily="@font/unifrakturcook"
-        android:text="The Penguins Club"
+        android:text="@string/name"
         android:textColor="@color/textColor"
         android:textSize="25sp" />
 

+ 2 - 2
app/src/main/res/values/strings.xml

@@ -2,6 +2,6 @@
     <string name="app_name">Penguins Read</string>
     <string name="drawer_open">Open navigation drawer</string>
     <string name="drawer_close">Close navigation drawer</string>
-    <!-- TODO: Remove or change this placeholder text -->
-    <string name="hello_blank_fragment">Hello blank fragment</string>
+    <string name="name">The Penguins Club</string>
+    <string name="hello_blank_fragment">Hello</string>
 </resources>