|
@@ -3,6 +3,8 @@ package club.thepenguins.android.fragments;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
@@ -11,20 +13,28 @@ import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.ProgressBar;
|
|
|
|
+import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.facebook.shimmer.ShimmerFrameLayout;
|
|
|
|
+
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.select.Elements;
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
import club.thepenguins.android.R;
|
|
import club.thepenguins.android.R;
|
|
|
|
+import club.thepenguins.android.adapters.CommentAdapter;
|
|
import club.thepenguins.android.api.APIService;
|
|
import club.thepenguins.android.api.APIService;
|
|
|
|
+import club.thepenguins.android.data.CommentModel;
|
|
|
|
+import club.thepenguins.android.data.Comments;
|
|
import club.thepenguins.android.data.IndividualPost;
|
|
import club.thepenguins.android.data.IndividualPost;
|
|
import club.thepenguins.android.data.PostContent;
|
|
import club.thepenguins.android.data.PostContent;
|
|
|
|
+import club.thepenguins.android.utils.Constants;
|
|
import retrofit2.Call;
|
|
import retrofit2.Call;
|
|
import retrofit2.Response;
|
|
import retrofit2.Response;
|
|
import retrofit2.Retrofit;
|
|
import retrofit2.Retrofit;
|
|
@@ -42,7 +52,13 @@ public class PostFragment extends Fragment {
|
|
private String mParam3;
|
|
private String mParam3;
|
|
private String mParam4;
|
|
private String mParam4;
|
|
private ArrayList<PostContent> postData;
|
|
private ArrayList<PostContent> postData;
|
|
- private ProgressBar progressBar;
|
|
|
|
|
|
+ private ArrayList<CommentModel> comments;
|
|
|
|
+ private RecyclerView recyclerView;
|
|
|
|
+ private CommentAdapter commentAdapter;
|
|
|
|
+ private LinearLayoutManager layoutManager;
|
|
|
|
+ private TextView textView;
|
|
|
|
+ private ShimmerFrameLayout loader;
|
|
|
|
+
|
|
|
|
|
|
public PostFragment() {
|
|
public PostFragment() {
|
|
// Required empty public constructor
|
|
// Required empty public constructor
|
|
@@ -77,13 +93,15 @@ public class PostFragment extends Fragment {
|
|
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_post, container, false);
|
|
View rootView = inflater.inflate(R.layout.fragment_post, container, false);
|
|
|
|
|
|
-
|
|
|
|
- progressBar = rootView.findViewById(R.id.progress);
|
|
|
|
|
|
+ loader = (ShimmerFrameLayout) rootView.findViewById(R.id.shimmer_view_container);
|
|
|
|
|
|
postData = new ArrayList<>();
|
|
postData = new ArrayList<>();
|
|
|
|
+ comments = new ArrayList<>();
|
|
|
|
+
|
|
postData.clear();
|
|
postData.clear();
|
|
|
|
|
|
getRetrofit(mParam1);
|
|
getRetrofit(mParam1);
|
|
|
|
+
|
|
Log.d("TAG", "onCreateView: " + mParam1);
|
|
Log.d("TAG", "onCreateView: " + mParam1);
|
|
|
|
|
|
final Handler handler = new Handler();
|
|
final Handler handler = new Handler();
|
|
@@ -130,7 +148,10 @@ public class PostFragment extends Fragment {
|
|
|
|
|
|
myWebView.loadDataWithBaseURL(null, newHtmlString, "text/html", "UTF-8", null);
|
|
myWebView.loadDataWithBaseURL(null, newHtmlString, "text/html", "UTF-8", null);
|
|
myWebView.getSettings().setJavaScriptEnabled(true);
|
|
myWebView.getSettings().setJavaScriptEnabled(true);
|
|
- progressBar.setVisibility(View.GONE);
|
|
|
|
|
|
+ loader.setVisibility(View.GONE);
|
|
|
|
+ textView.setVisibility(View.VISIBLE);
|
|
|
|
+ recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
+
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
Toast.makeText(rootView.getContext(), "Please retry", Toast.LENGTH_SHORT).show();
|
|
Toast.makeText(rootView.getContext(), "Please retry", Toast.LENGTH_SHORT).show();
|
|
Log.d("PostFragment", "run: " + e);
|
|
Log.d("PostFragment", "run: " + e);
|
|
@@ -140,13 +161,32 @@ public class PostFragment extends Fragment {
|
|
}
|
|
}
|
|
}, 3000);
|
|
}, 3000);
|
|
|
|
|
|
|
|
+ textView = rootView.findViewById(R.id.txtview);
|
|
|
|
+
|
|
|
|
+ recyclerView = rootView.findViewById(R.id.recyclerComment);
|
|
|
|
+
|
|
|
|
+ layoutManager = new LinearLayoutManager(rootView.getContext(), LinearLayoutManager.VERTICAL, false);
|
|
|
|
+ recyclerView.setLayoutManager(layoutManager);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ handler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ commentAdapter = new CommentAdapter(comments, rootView.getContext());
|
|
|
|
+ recyclerView.setAdapter(commentAdapter);
|
|
|
|
+ String intValue = mParam1.replaceAll("[^0-9]", "").substring(1);
|
|
|
|
+
|
|
|
|
+ getComments(intValue);
|
|
|
|
+ }
|
|
|
|
+ }, 5000);
|
|
|
|
+
|
|
|
|
|
|
return rootView;
|
|
return rootView;
|
|
}
|
|
}
|
|
|
|
|
|
private void getRetrofit(String postUrl) {
|
|
private void getRetrofit(String postUrl) {
|
|
|
|
|
|
- progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
+ loader.startShimmer();
|
|
|
|
|
|
|
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
@@ -181,5 +221,46 @@ public class PostFragment extends Fragment {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void getComments(String id) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Retrofit retrofit = new Retrofit.Builder()
|
|
|
|
+ .baseUrl(Constants.BaseUrl)
|
|
|
|
+ .addConverterFactory(GsonConverterFactory.create())
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ APIService service = retrofit.create(APIService.class);
|
|
|
|
+ Call<List<Comments>> call = service.getPostComments(id);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ call.enqueue(new retrofit2.Callback<List<Comments>>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onResponse(Call<List<Comments>> call, Response<List<Comments>> response) {
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < response.body().size(); i++) {
|
|
|
|
+
|
|
|
|
+ comments.add(new CommentModel(response.body().get(i).getAuthorAvatarUrls().get96(), response.body().get(i).getAuthorName(), response.body().get(i).getDate(), response.body().get(i).getContent().getRendered()));
|
|
|
|
+
|
|
|
|
+ System.out.println(response.body().get(i).getContent());
|
|
|
|
+ }
|
|
|
|
+ commentAdapter.notifyDataSetChanged();
|
|
|
|
+ if (comments.size() != 0) {
|
|
|
|
+ textView.setText("Comments:");
|
|
|
|
+ } else {
|
|
|
|
+ textView.setText("No Comments");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFailure(Call<List<Comments>> call, Throwable t) {
|
|
|
|
+
|
|
|
|
+ Log.d("PostRecyclerAdapter", "onFailure: ", t);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|