Browse Source

Add categories

Infinite 3 years ago
parent
commit
c69917f1c9

+ 11 - 4
app/src/main/java/club/thepenguins/android/activities/MainActivity.java

@@ -20,6 +20,8 @@ import club.thepenguins.android.R;
 
 import club.thepenguins.android.fragments.AboutFragment;
 import club.thepenguins.android.fragments.HomeFragment;
+import club.thepenguins.android.fragments.LinuxFragment;
+import club.thepenguins.android.fragments.NixFragment;
 
 public class MainActivity extends AppCompatActivity {
 
@@ -154,15 +156,20 @@ public class MainActivity extends AppCompatActivity {
 
                 break;
 
-            //case R.id.nav_third_fragment:
+            case R.id.linuxfrag:
 
-            // fragmentClass = ThirdFragment.class;
+                fragmentClass = LinuxFragment.class;
 
-            // break;
+                break;
+            case R.id.nixfrag:
+
+                fragmentClass = NixFragment.class;
+
+                break;
 
             default:
 
-                // fragmentClass = FirstFragment.class;
+                 fragmentClass = HomeFragment.class;
 
         }
 

+ 4 - 0
app/src/main/java/club/thepenguins/android/api/APIService.java

@@ -6,6 +6,7 @@ import club.thepenguins.android.data.Image;
 import club.thepenguins.android.data.Posts;
 import retrofit2.Call;
 import retrofit2.http.GET;
+import retrofit2.http.Query;
 
 public interface APIService {
 
@@ -15,4 +16,7 @@ public interface APIService {
     @GET(".")
     Call<Image> getFeaturedImageLink();
 
+    @GET("wp-json/wp/v2/posts?_embed")
+    Call<List<Posts>> getCategoryPosts(@Query("categories") String id);
+
 }

+ 66 - 0
app/src/main/java/club/thepenguins/android/fragments/HardwareFragment.java

@@ -0,0 +1,66 @@
+package club.thepenguins.android.fragments;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import club.thepenguins.android.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Use the {@link HardwareFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class HardwareFragment 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;
+
+    public HardwareFragment() {
+        // 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 HardwareFragment.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static HardwareFragment newInstance(String param1, String param2) {
+        HardwareFragment fragment = new HardwareFragment();
+        Bundle args = new Bundle();
+        args.putString(ARG_PARAM1, param1);
+        args.putString(ARG_PARAM2, param2);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            mParam1 = getArguments().getString(ARG_PARAM1);
+            mParam2 = getArguments().getString(ARG_PARAM2);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        // Inflate the layout for this fragment
+        return inflater.inflate(R.layout.fragment_hardware, container, false);
+    }
+}

+ 167 - 0
app/src/main/java/club/thepenguins/android/fragments/LinuxFragment.java

@@ -0,0 +1,167 @@
+package club.thepenguins.android.fragments;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import club.thepenguins.android.R;
+import club.thepenguins.android.adapters.PostRecyclerAdapter;
+import club.thepenguins.android.api.APIService;
+import club.thepenguins.android.data.Model;
+import club.thepenguins.android.data.Posts;
+import club.thepenguins.android.utils.Constants;
+import retrofit2.Call;
+import retrofit2.Callback;
+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;
+    private LinearLayoutManager LayoutManager;
+    private ArrayList<Model> list;
+    private PostRecyclerAdapter adapter;
+    public static List<Posts> mListPost;
+    private SwipeRefreshLayout swipeContainer;
+
+    public LinuxFragment() {
+        // 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();
+        args.putString(ARG_PARAM1, param1);
+        args.putString(ARG_PARAM2, param2);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            mParam1 = getArguments().getString(ARG_PARAM1);
+            mParam2 = getArguments().getString(ARG_PARAM2);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        View rootView = inflater.inflate(R.layout.fragment_linux, container, false);
+
+        getActivity().setTitle("Choose Fragment");
+
+
+        recyclerView = rootView.findViewById(R.id.recycler_view);
+
+        LayoutManager = new LinearLayoutManager(rootView.getContext(), LinearLayoutManager.VERTICAL, false);
+        recyclerView.setLayoutManager(LayoutManager);
+
+        swipeContainer = rootView.findViewById(R.id.swiperefresh);
+
+        list = new ArrayList<>();
+
+        getRetrofit();
+
+
+        adapter = new PostRecyclerAdapter(list, rootView.getContext());
+
+        recyclerView.setAdapter(adapter);
+
+        swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+
+            @Override
+
+            public void onRefresh() {
+
+                adapter.clear();
+                getRetrofit();
+            }
+
+        });
+
+
+        swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
+
+                android.R.color.holo_green_light,
+
+                android.R.color.holo_orange_light,
+
+                android.R.color.holo_red_light);
+
+        return rootView;
+    }
+
+    private void getRetrofit() {
+
+        swipeContainer.setRefreshing(true);
+
+        Retrofit retrofit = new Retrofit.Builder()
+                .baseUrl(Constants.BaseUrl)
+                .addConverterFactory(GsonConverterFactory.create())
+                .build();
+
+        APIService service = retrofit.create(APIService.class);
+        Call<List<Posts>> call = service.getCategoryPosts("4");
+
+
+        call.enqueue(new Callback<List<Posts>>() {
+            @Override
+            public void onResponse(Call<List<Posts>> call, Response<List<Posts>> response) {
+
+                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()));
+
+                    //Log.d("Linux", "onResponse: " + response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl());
+                }
+                adapter.notifyDataSetChanged();
+                swipeContainer.setRefreshing(false);
+
+            }
+
+            @Override
+            public void onFailure(Call<List<Posts>> call, Throwable t) {
+
+                Log.d("Linux", "onFailure: ", t);
+            }
+        });
+    }
+}

+ 66 - 0
app/src/main/java/club/thepenguins/android/fragments/NewsFragment.java

@@ -0,0 +1,66 @@
+package club.thepenguins.android.fragments;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import club.thepenguins.android.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Use the {@link NewsFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class NewsFragment 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;
+
+    public NewsFragment() {
+        // 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 NewsFragment.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static NewsFragment newInstance(String param1, String param2) {
+        NewsFragment fragment = new NewsFragment();
+        Bundle args = new Bundle();
+        args.putString(ARG_PARAM1, param1);
+        args.putString(ARG_PARAM2, param2);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            mParam1 = getArguments().getString(ARG_PARAM1);
+            mParam2 = getArguments().getString(ARG_PARAM2);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        // Inflate the layout for this fragment
+        return inflater.inflate(R.layout.fragment_news, container, false);
+    }
+}

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

@@ -0,0 +1,167 @@
+package club.thepenguins.android.fragments;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import club.thepenguins.android.R;
+import club.thepenguins.android.adapters.PostRecyclerAdapter;
+import club.thepenguins.android.api.APIService;
+import club.thepenguins.android.data.Model;
+import club.thepenguins.android.data.Posts;
+import club.thepenguins.android.utils.Constants;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+import retrofit2.converter.gson.GsonConverterFactory;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Use the {@link NixFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class NixFragment 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;
+    private LinearLayoutManager LayoutManager;
+    private ArrayList<Model> list;
+    private PostRecyclerAdapter adapter;
+    public static List<Posts> mListPost;
+    private SwipeRefreshLayout swipeContainer;
+
+    public NixFragment() {
+        // 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 NixFragment.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static NixFragment newInstance(String param1, String param2) {
+        NixFragment fragment = new NixFragment();
+        Bundle args = new Bundle();
+        args.putString(ARG_PARAM1, param1);
+        args.putString(ARG_PARAM2, param2);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            mParam1 = getArguments().getString(ARG_PARAM1);
+            mParam2 = getArguments().getString(ARG_PARAM2);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+            View rootView = inflater.inflate(R.layout.fragment_linux, container, false);
+
+            getActivity().setTitle("Choose Fragment");
+
+
+            recyclerView = rootView.findViewById(R.id.recycler_view);
+
+            LayoutManager = new LinearLayoutManager(rootView.getContext(), LinearLayoutManager.VERTICAL, false);
+            recyclerView.setLayoutManager(LayoutManager);
+
+            swipeContainer = rootView.findViewById(R.id.swiperefresh);
+
+            list = new ArrayList<>();
+
+            getRetrofit();
+
+
+            adapter = new PostRecyclerAdapter(list, rootView.getContext());
+
+            recyclerView.setAdapter(adapter);
+
+            swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+
+                @Override
+
+                public void onRefresh() {
+
+                    adapter.clear();
+                    getRetrofit();
+                }
+
+            });
+
+
+            swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
+
+                    android.R.color.holo_green_light,
+
+                    android.R.color.holo_orange_light,
+
+                    android.R.color.holo_red_light);
+
+            return rootView;
+    }
+
+    private void getRetrofit() {
+
+        swipeContainer.setRefreshing(true);
+
+        Retrofit retrofit = new Retrofit.Builder()
+                .baseUrl(Constants.BaseUrl)
+                .addConverterFactory(GsonConverterFactory.create())
+                .build();
+
+        APIService service = retrofit.create(APIService.class);
+        Call<List<Posts>> call = service.getCategoryPosts("12");
+
+
+        call.enqueue(new Callback<List<Posts>>() {
+            @Override
+            public void onResponse(Call<List<Posts>> call, Response<List<Posts>> response) {
+
+                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()));
+
+                    //Log.d("Linux", "onResponse: " + response.body().get(i).getEmbedded().getWpFeaturedmedia().get(0).getSourceUrl());
+                }
+                adapter.notifyDataSetChanged();
+                swipeContainer.setRefreshing(false);
+
+            }
+
+            @Override
+            public void onFailure(Call<List<Posts>> call, Throwable t) {
+
+                Log.d("Linux", "onFailure: ", t);
+            }
+        });
+    }
+}

+ 66 - 0
app/src/main/java/club/thepenguins/android/fragments/TechFragment.java

@@ -0,0 +1,66 @@
+package club.thepenguins.android.fragments;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import club.thepenguins.android.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Use the {@link TechFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class TechFragment 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;
+
+    public TechFragment() {
+        // 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 TechFragment.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static TechFragment newInstance(String param1, String param2) {
+        TechFragment fragment = new TechFragment();
+        Bundle args = new Bundle();
+        args.putString(ARG_PARAM1, param1);
+        args.putString(ARG_PARAM2, param2);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            mParam1 = getArguments().getString(ARG_PARAM1);
+            mParam2 = getArguments().getString(ARG_PARAM2);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        // Inflate the layout for this fragment
+        return inflater.inflate(R.layout.fragment_tech, container, false);
+    }
+}

+ 14 - 0
app/src/main/res/layout/fragment_hardware.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".fragments.HardwareFragment">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:text="@string/hello_blank_fragment" />
+
+</FrameLayout>

+ 29 - 0
app/src/main/res/layout/fragment_linux.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".fragments.LinuxFragment">
+
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+            android:id="@+id/swiperefresh"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/recycler_view"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent">
+
+            </androidx.recyclerview.widget.RecyclerView>
+        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
+
+    </RelativeLayout>
+
+</FrameLayout>

+ 14 - 0
app/src/main/res/layout/fragment_news.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".fragments.NewsFragment">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:text="@string/hello_blank_fragment" />
+
+</FrameLayout>

+ 28 - 0
app/src/main/res/layout/fragment_nix.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".fragments.NixFragment">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+            android:id="@+id/swiperefresh"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/recycler_view"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent">
+
+            </androidx.recyclerview.widget.RecyclerView>
+        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
+
+    </RelativeLayout>
+
+</FrameLayout>

+ 14 - 0
app/src/main/res/layout/fragment_tech.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".fragments.TechFragment">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:text="@string/hello_blank_fragment" />
+
+</FrameLayout>

+ 4 - 2
app/src/main/res/menu/drawer_view.xml

@@ -8,9 +8,11 @@
         <menu>
             <group>
                 <item
-
+                    android:id="@+id/linuxfrag"
                     android:title="Linux" />
-                <item android:title="Nix" />
+                <item
+                    android:id="@+id/nixfrag"
+                    android:title="Nix" />
                 <item android:title="News" />
                 <item android:title="Hardware" />
                 <item android:title="Technology" />

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

@@ -2,4 +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>
 </resources>