Fetch Data from server :
Data come in the form of 2 Table ,in One Table data come(SectionID,SectionName):
and another Table all data come ,we fetch Data According to Section Id :
And show that data on Recycler View ,we store data on ArrayList :
loadingDialog = new Dialog(currentActivity);
loadingDialog.setContentView(R.layout.loading_progress_dialog);
loadingDialog.setCancelable(false);
loadingDialog.getWindow().setBackgroundDrawable(getDrawable(R.drawable.slider_background));
loadingDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
loadingDialog.show();
if (Validator.getInstance().isNetworkAvailable(currentActivity)) {
Call<BlogHomeResponseModel> call = RetrofitClient.getInstance().getApi().getPostsForHome();
call.enqueue(new Callback<BlogHomeResponseModel>() {
@Override
public void onResponse(Call<BlogHomeResponseModel> call, Response<BlogHomeResponseModel> response) {
if (response.isSuccessful()) {
BlogHomeResponseModel blogHomeResponseModel = response.body();
String status = blogHomeResponseModel.getStatus();
if (status.equals("1")) {
loadingDialog.dismiss();
layout.setVisibility(View.VISIBLE); //Here Two List is globally we Define for store both table Id :
blogSectionNameTypeList = new ArrayList<>();
blogPostList = new ArrayList<>();
blogSectionNameTypeList = blogHomeResponseModel.getData().getTable();
blogPostList = blogHomeResponseModel.getData().getTable1();
featuredPostList = new ArrayList<>();
latestPostList = new ArrayList<>();
stickyPostList = new ArrayList<>();
trendingPostList = new ArrayList<>();
topStoriesPostList = new ArrayList<>();
videoPostPostList = new ArrayList<>();
for (int i = 0; i < blogSectionNameTypeList.size(); i++) {
String id = blogSectionNameTypeList.get(i).getBlogSectionID();
for (int j = 0; j < blogPostList.size(); j++) {
String idd = blogPostList.get(j).getBlogSection();
if (id.equals(idd)) {
if (idd.equals("FT")) {
featuredPostList.add(blogPostList.get(j));
} else if (idd.equals("LT")) {
latestPostList.add(blogPostList.get(j));
} else if (idd.equals("ST")) {
stickyPostList.add(blogPostList.get(j));
} else if (idd.equals("TD")) {
trendingPostList.add(blogPostList.get(j));
} else if (idd.equals("TS")) {
topStoriesPostList.add(blogPostList.get(j));
} else if (idd.equals("VP")) {
videoPostPostList.add(blogPostList.get(j));
}
}
}
}
trendingBlogAdapter = new TrendingBlogAdapter(trendingPostList, currentActivity);
trendingRecyclerView.setAdapter(trendingBlogAdapter);
latestBlogAdapter = new LatestBlogAdapter(latestPostList, currentActivity);
LatestRecyclerView.setAdapter(latestBlogAdapter);
featuredBlogAdapter = new FeaturedBlogAdapter(featuredPostList, currentActivity);
featuredRecyclerView.setAdapter(featuredBlogAdapter);
topStoriesBlogAdapter = new TopStoriesBlogAdapter(topStoriesPostList, currentActivity);
topStoriesRecyclerView.setAdapter(topStoriesBlogAdapter);
setBannerSliderViewPager(stickyPostList);
mainlinearLayout.setVisibility(View.VISIBLE);
} else if (status.equals("-1")) {
loadingDialog.dismiss();
Toast.makeText(currentActivity, "Empty", Toast.LENGTH_SHORT).show();
}
} else if (response.code() == 400) {
loadingDialog.dismiss();
} else if (response.code() == 500) {
loadingDialog.dismiss();
Toast.makeText(currentActivity, "500", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<BlogHomeResponseModel> call, Throwable t) {
loadingDialog.dismiss();
Toast.makeText(currentActivity, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Set Image come from Server :
String profileImage = getBlogByCategoryResponseModel.getAuthorImage();
if(Strings.isNullOrEmpty(profileImage)){
}else {
Glide.with(context)
.load("https://pass Domain Name/ClientContent/Images/Large/" + profileImage)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(profile_image);
}/////Make Model Class Where Data come in the form of Table And String
public class GetBlogViewDetailsResponseModel {
@SerializedName("Status")
private String status;
@SerializedName("TagList")
private List<TagListPostModel> tagList;
@SerializedName("ProductList")
private List<BuyerGetProdTypeProductsTable1Item> productList;
@SerializedName("BlogByCategory")
private List<BlogListPostModel> blogByCategory;
@SerializedName("BlogByAuthor")
private List<BlogListPostModel> blogByAuthor;
@SerializedName("TrendingPost")
private List<BlogTraindingListPostModel> trendingPost;
@SerializedName("CommentList")
private List<CommentModel> commentList;
@SerializedName("BlogID")
private String blogID;
@SerializedName("BlogTitle")
private String blogTitle;
@SerializedName("SlugURL")
private String slugURL;
@SerializedName("ProductSlugURL")
private String productSlugURL;
@SerializedName("ViewCount")
private String viewCount;
@SerializedName("CommentCount")
private String commentCount;
@SerializedName("BlogAuthor")
private String blogAuthor;
@SerializedName("VideoURL")
private String videoURL;
@SerializedName("BlogShortDescription")
private String blogShortDescription;
@SerializedName("BlogImage")
private String blogImage;
@SerializedName("BlogDate")
private String blogDate;
@SerializedName("ProductName")
private String productName;
@SerializedName("BlogDescription")
private String blogDescription;
@SerializedName("AuthorImage")
private String authorImage;
@SerializedName("AuthorURL")
private String authorURL;
public String getViewCount() {
return viewCount;
}
public void setViewCount(String viewCount) {
this.viewCount = viewCount;
}
public String getCommentCount() {
return commentCount;
}
public void setCommentCount(String commentCount) {
this.commentCount = commentCount;
}
public String getBlogDescription() {
return blogDescription;
}
public void setBlogDescription(String blogDescription) {
this.blogDescription = blogDescription;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public List<TagListPostModel> getTagList() {
return tagList;
}
public void setTagList(List<TagListPostModel> tagList) {
this.tagList = tagList;
}
public List<BuyerGetProdTypeProductsTable1Item> getProductList() {
return productList;
}
public void setProductList(List<BuyerGetProdTypeProductsTable1Item> productList) {
this.productList = productList;
}
public List<BlogListPostModel> getBlogByCategory() {
return blogByCategory;
}
public void setBlogByCategory(List<BlogListPostModel> blogByCategory) {
this.blogByCategory = blogByCategory;
}
public List<BlogListPostModel> getBlogByAuthor() {
return blogByAuthor;
}
public void setBlogByAuthor(List<BlogListPostModel> blogByAuthor) {
this.blogByAuthor = blogByAuthor;
}
public List<BlogTraindingListPostModel> getTrendingPost() {
return trendingPost;
}
public void setTrendingPost(List<BlogTraindingListPostModel> trendingPost) {
this.trendingPost = trendingPost;
}
public List<CommentModel> getCommentList() {
return commentList;
}
public void setCommentList(List<CommentModel> commentList) {
this.commentList = commentList;
}
public String getBlogID() {
return blogID;
}
public void setBlogID(String blogID) {
this.blogID = blogID;
}
public String getBlogTitle() {
return blogTitle;
}
public void setBlogTitle(String blogTitle) {
this.blogTitle = blogTitle;
}
public String getSlugURL() {
return slugURL;
}
public void setSlugURL(String slugURL) {
this.slugURL = slugURL;
}
public String getProductSlugURL() {
return productSlugURL;
}
public void setProductSlugURL(String productSlugURL) {
this.productSlugURL = productSlugURL;
}
public String getBlogAuthor() {
return blogAuthor;
}
public void setBlogAuthor(String blogAuthor) {
this.blogAuthor = blogAuthor;
}
public String getVideoURL() {
return videoURL;
}
public void setVideoURL(String videoURL) {
this.videoURL = videoURL;
}
public String getBlogShortDescription() {
return blogShortDescription;
}
public void setBlogShortDescription(String blogShortDescription) {
this.blogShortDescription = blogShortDescription;
}
public String getBlogImage() {
return blogImage;
}
public void setBlogImage(String blogImage) {
this.blogImage = blogImage;
}
public String getBlogDate() {
return blogDate;
}
public void setBlogDate(String blogDate) {
this.blogDate = blogDate;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getAuthorImage() {
return authorImage;
}
public void setAuthorImage(String authorImage) {
this.authorImage = authorImage;
}
public String getAuthorURL() {
return authorURL;
}
public void setAuthorURL(String authorURL) {
this.authorURL = authorURL;
}
}//Fetch Data from shared preferences on Activity :String userid = SharedPreferenceUtils.getInstance(context).getString(ENDUSERID);