Browse Source

Fix some bugs

Infinite 3 years ago
parent
commit
9e6040fc03

+ 3 - 19
app/src/main/java/club/thepenguins/android/fragments/LinuxFragment.java

@@ -27,19 +27,13 @@ import retrofit2.Response;
 import retrofit2.Retrofit;
 import retrofit2.converter.gson.GsonConverterFactory;
 
-/**
- * A simple {@link Fragment} subclass.
- * Use the {@link LinuxFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
+
 public class LinuxFragment extends Fragment {
 
-    // TODO: Rename parameter arguments, choose names that match
-    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+
     private static final String ARG_PARAM1 = "param1";
     private static final String ARG_PARAM2 = "param2";
 
-    // TODO: Rename and change types of parameters
     private String mParam1;
     private String mParam2;
     private RecyclerView recyclerView;
@@ -53,15 +47,6 @@ public class LinuxFragment extends Fragment {
         // Required empty public constructor
     }
 
-    /**
-     * Use this factory method to create a new instance of
-     * this fragment using the provided parameters.
-     *
-     * @param param1 Parameter 1.
-     * @param param2 Parameter 2.
-     * @return A new instance of fragment LinuxFragment.
-     */
-    // TODO: Rename and change types and number of parameters
     public static LinuxFragment newInstance(String param1, String param2) {
         LinuxFragment fragment = new LinuxFragment();
         Bundle args = new Bundle();
@@ -148,8 +133,7 @@ public class LinuxFragment extends Fragment {
                 mListPost = response.body();
                 for (int i = 0; i < response.body().size(); i++) {
 
-                    list.add(new Model(response.body().get(i).getTitle().getRendered(), response.body().get(i).getContent().getRendered(), response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl(), response.body().get(i).getContent().getRendered(), response.body().get(i).getEmbedded().getAuthor().get(0).getName()));
-
+                    list.add(new Model(response.body().get(i).getTitle().getRendered().replace("&#8211;", "-"), response.body().get(i).getContent().getRendered(), response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl(), response.body().get(i).getLinks().getSelf().get(0).getHref(), response.body().get(i).getEmbedded().getAuthor().get(0).getName()));
                     //Log.d("Linux", "onResponse: " + response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl());
                 }
                 adapter.notifyDataSetChanged();

+ 23 - 23
app/src/main/java/club/thepenguins/android/fragments/NixFragment.java

@@ -83,49 +83,49 @@ public class NixFragment extends Fragment {
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
-            View rootView = inflater.inflate(R.layout.fragment_linux, container, false);
+        View rootView = inflater.inflate(R.layout.fragment_linux, container, false);
 
-            getActivity().setTitle("Choose Fragment");
+        getActivity().setTitle("Choose Fragment");
 
 
-            recyclerView = rootView.findViewById(R.id.recycler_view);
+        recyclerView = rootView.findViewById(R.id.recycler_view);
 
-            LayoutManager = new LinearLayoutManager(rootView.getContext(), LinearLayoutManager.VERTICAL, false);
-            recyclerView.setLayoutManager(LayoutManager);
+        LayoutManager = new LinearLayoutManager(rootView.getContext(), LinearLayoutManager.VERTICAL, false);
+        recyclerView.setLayoutManager(LayoutManager);
 
-            swipeContainer = rootView.findViewById(R.id.swiperefresh);
+        swipeContainer = rootView.findViewById(R.id.swiperefresh);
 
-            list = new ArrayList<>();
+        list = new ArrayList<>();
 
-            getRetrofit();
+        getRetrofit();
 
 
-            adapter = new PostRecyclerAdapter(list, rootView.getContext());
+        adapter = new PostRecyclerAdapter(list, rootView.getContext());
 
-            recyclerView.setAdapter(adapter);
+        recyclerView.setAdapter(adapter);
 
-            swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+        swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
 
-                @Override
+            @Override
 
-                public void onRefresh() {
+            public void onRefresh() {
 
-                    adapter.clear();
-                    getRetrofit();
-                }
+                adapter.clear();
+                getRetrofit();
+            }
 
-            });
+        });
 
 
-            swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
+        swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
 
-                    android.R.color.holo_green_light,
+                android.R.color.holo_green_light,
 
-                    android.R.color.holo_orange_light,
+                android.R.color.holo_orange_light,
 
-                    android.R.color.holo_red_light);
+                android.R.color.holo_red_light);
 
-            return rootView;
+        return rootView;
     }
 
     private void getRetrofit() {
@@ -148,7 +148,7 @@ public class NixFragment extends Fragment {
                 mListPost = response.body();
                 for (int i = 0; i < response.body().size(); i++) {
 
-                    list.add(new Model(response.body().get(i).getTitle().getRendered(), response.body().get(i).getContent().getRendered(), response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl(), response.body().get(i).getContent().getRendered(),response.body().get(i).getEmbedded().getAuthor().get(0).getName()));
+                    list.add(new Model(response.body().get(i).getTitle().getRendered().replace("&#8211;", "-"), response.body().get(i).getContent().getRendered(), response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl(), response.body().get(i).getLinks().getSelf().get(0).getHref(), response.body().get(i).getEmbedded().getAuthor().get(0).getName()));
 
                     //Log.d("Linux", "onResponse: " + response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl());
                 }

+ 25 - 19
app/src/main/java/club/thepenguins/android/fragments/PostFragment.java

@@ -2,9 +2,7 @@ package club.thepenguins.android.fragments;
 
 import android.os.Bundle;
 
-import androidx.appcompat.app.AppCompatActivity;
 import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
 
 import android.os.Handler;
 import android.util.Log;
@@ -15,6 +13,7 @@ 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;
@@ -96,7 +95,7 @@ public class PostFragment extends Fragment {
             public void onClick(View view) {
 
                 getActivity().getSupportFragmentManager().beginTransaction()
-                        .replace( ((ViewGroup)getView().getParent()).getId(), AuthorPostFragment.newInstance(mParam4, null), "findThisFragment")
+                        .replace(((ViewGroup) getView().getParent()).getId(), AuthorPostFragment.newInstance(mParam4, null), "findThisFragment")
                         .addToBackStack(null)
                         .commit();
             }
@@ -137,34 +136,41 @@ public class PostFragment extends Fragment {
             @Override
             public void run() {
 
-                Document doc = Jsoup.parse(postData.get(0).getContent());
+                try {
+                    Document doc = Jsoup.parse(postData.get(0).getContent());
 
-                Elements images = doc.select("img");
-                Elements iframes = doc.select("iframe");
+                    Elements images = doc.select("img");
+                    Elements iframes = doc.select("iframe");
 
-                for (Element image : images) {
+                    for (Element image : images) {
 
-                    image.attr("width", "100%");
-                    image.attr("height", "240px");
+                        image.attr("width", "100%");
+                        image.attr("height", "240px");
 
-                }
+                    }
+
+                    for (Element iframe : iframes) {
 
-                for (Element iframe : iframes) {
+                        if (iframe.attr("width").isEmpty()) {
+                            iframe.attr("width", "100%");
+                        }
 
-                    if (iframe.attr("width").isEmpty()) {
-                        iframe.attr("width", "100%");
                     }
 
-                }
+                    String htmlString = doc.html();
+
 
-                String htmlString = doc.html();
+                    WebView myWebView = rootView.findViewById(R.id.webview);
 
+                    myWebView.loadDataWithBaseURL(null, htmlString, "text/html", "UTF-8", null);
+                    myWebView.getSettings().getJavaScriptEnabled();
+                    progressBar.setVisibility(View.GONE);
+                } catch (Exception e) {
+                    Toast.makeText(rootView.getContext(), "Please retry", Toast.LENGTH_SHORT).show();
+                    Log.d("PostFragment", "run: " + e);
+                }
 
-                WebView myWebView = rootView.findViewById(R.id.webview);
 
-                myWebView.loadDataWithBaseURL(null, htmlString, "text/html", "UTF-8", null);
-                myWebView.getSettings().getJavaScriptEnabled();
-                progressBar.setVisibility(View.GONE);
             }
         }, 3000);