SHARE
TWEET

Untitled

a guest May 25th, 2019 172 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.ova.studio.anime.wallpaper.adapter;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.graphics.Color;
  6. import android.os.Build;
  7. import android.os.Handler;
  8. import android.support.v4.app.FragmentActivity;
  9. import android.support.v7.widget.LinearLayoutManager;
  10. import android.support.v7.widget.RecyclerView;
  11. import android.util.Log;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.Button;
  16. import android.widget.ImageView;
  17. import android.widget.LinearLayout;
  18. import android.widget.RelativeLayout;
  19. import android.widget.TextView;
  20. import android.widget.Toast;
  21. import com.facebook.ads.Ad;
  22. import com.facebook.ads.AdChoicesView;
  23. import com.facebook.ads.AdError;
  24. import com.facebook.ads.AdIconView;
  25. import com.facebook.ads.AdSettings;
  26. import com.facebook.ads.AudienceNetworkAds;
  27. import com.facebook.ads.MediaView;
  28. import com.facebook.ads.NativeAd;
  29. import com.facebook.ads.NativeAdListener;
  30. import com.github.vivchar.viewpagerindicator.ViewPagerIndicator;
  31. import com.ova.studio.anime.wallpaper.R;
  32. import com.ova.studio.anime.wallpaper.config.AdConfig;
  33. import com.ova.studio.anime.wallpaper.config.Config;
  34. import com.ova.studio.anime.wallpaper.entity.Category;
  35. import com.ova.studio.anime.wallpaper.entity.Slide;
  36. import com.ova.studio.anime.wallpaper.entity.User;
  37. import com.ova.studio.anime.wallpaper.entity.Wallpaper;
  38. import com.ova.studio.anime.wallpaper.manager.FavoritesStorage;
  39. import com.ova.studio.anime.wallpaper.manager.PrefManager;
  40. import com.ova.studio.anime.wallpaper.ui.WallpaperActivity;
  41. import com.ova.studio.anime.wallpaper.ui.view.ClickableViewPager;
  42. import com.squareup.picasso.Picasso;
  43.  
  44. import java.text.ParseException;
  45. import java.text.SimpleDateFormat;
  46. import java.util.ArrayList;
  47. import java.util.Calendar;
  48. import java.util.Date;
  49. import java.util.List;
  50. import java.util.Random;
  51.  
  52.  
  53. import com.google.android.gms.ads.InterstitialAd;
  54.  
  55. import static com.facebook.FacebookSdk.getApplicationContext;
  56.  
  57. /**
  58.  * Created by hsn on 27/11/2017.
  59.  */
  60.  
  61. public class WallpaperAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
  62.  
  63.  
  64.     private boolean favorites = false;
  65.     private List<Wallpaper> wallpaperList = new ArrayList<>();
  66.     private List<Category> categoryList = new ArrayList<>();
  67.     private List<User> userList;
  68.     public Activity activity;
  69.     private List<Slide> slideList = new ArrayList<>();
  70.     private SlideAdapter slide_adapter;
  71.     private LinearLayoutManager linearLayoutManager;
  72.     private FollowAdapter followAdapter;
  73.     private LinearLayoutManager linearLayoutManagerCategories;
  74.     private CategoryAdapter categoryAdapter;
  75.     private InterstitialAd mInterstitialAdDownload;
  76.     private boolean premium;
  77.  
  78.     int random;
  79.  
  80.     public WallpaperAdapter(List<Wallpaper> wallpaperList, List<Slide> slideList, Activity activity) {
  81.         this.wallpaperList = wallpaperList;
  82.         this.slideList = slideList;
  83.         this.activity = activity;
  84.  
  85.     }
  86.  
  87.     public WallpaperAdapter(List<Wallpaper> wallpaperList, List<Slide> slideList, FragmentActivity activity, boolean favorites) {
  88.         this(wallpaperList, slideList, activity);
  89.         this.favorites = favorites;
  90.     }
  91.  
  92.     public WallpaperAdapter(List<Wallpaper> wallpaperList, List<Slide> slideList, FragmentActivity activity, List<User> userList) {
  93.         this(wallpaperList, slideList, activity);
  94.         this.userList = userList;
  95.         this.categoryList = categoryList;
  96.  
  97.     }
  98.  
  99.     public WallpaperAdapter(List<Wallpaper> wallpaperList, List<Slide> slideList, FragmentActivity activity, List<User> userList, List<Category> categoryList) {
  100.         this(wallpaperList, slideList, activity);
  101.         this.userList = userList;
  102.         this.categoryList = categoryList;
  103.  
  104.     }
  105.  
  106.     @Override
  107.     public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  108.         RecyclerView.ViewHolder viewHolder = null;
  109.         LayoutInflater inflater = LayoutInflater.from(parent.getContext());
  110.         switch (viewType) {
  111.             case 1: {
  112.                 View v1 = inflater.inflate(R.layout.item_wallpaper, parent, false);
  113.                 viewHolder = new WallpaperHolder(v1);
  114.                 break;
  115.             }
  116.             case 2: {
  117.                 View v2 = inflater.inflate(R.layout.item_slide, parent, false);
  118.                 viewHolder = new SlideHolder(v2);
  119.                 break;
  120.             }
  121.             case 3: {
  122.                 View v3 = inflater.inflate(R.layout.item_followings, parent, false);
  123.                 viewHolder = new FollowHolder(v3);
  124.                 break;
  125.             }
  126.             case 4: {
  127.                 View v4 = inflater.inflate(R.layout.item_categories, parent, false);
  128.                 viewHolder = new CategoriesHolder(v4);
  129.                 break;
  130.             }
  131.             case 5: {
  132.                 View v5 = inflater.inflate(R.layout.item_facebook_ads, parent, false);
  133.                 viewHolder = new FacebookNativeHolder(v5);
  134.                 break;
  135.             }
  136.         }
  137.         return viewHolder;
  138.     }
  139.  
  140.     @Override
  141.     public int getItemViewType(int position) {
  142.         if (wallpaperList.get(position) == null) {
  143.             return 1;
  144.         } else {
  145.             return wallpaperList.get(position).getViewType();
  146.         }
  147.     }
  148.  
  149.     @Override
  150.     public void onBindViewHolder(RecyclerView.ViewHolder holder_parent, final int position) {
  151.         switch (getItemViewType(position)) {
  152.             case 1: {
  153.                 final WallpaperHolder holder = (WallpaperHolder) holder_parent;
  154.                 holder.relative_layout_wallpaper_item.setBackgroundColor(Color.parseColor(wallpaperList.get(position).getColor()));
  155.                 holder.linear_layout_wallpaper_item.setBackgroundColor(Color.parseColor(wallpaperList.get(position).getColor()));
  156.                 holder.text_view_wallpaper_item_title.setText(wallpaperList.get(position).getTitle());
  157.                 holder.text_view_wallpaper_item_user.setText(wallpaperList.get(position).getUser());
  158.                 Picasso.with(activity.getApplicationContext()).load(wallpaperList.get(position).getThumbnail()).placeholder(R.drawable.placeholder).into(holder.image_view_wallpaper_item);
  159.                 if (wallpaperList.get(position).getReview() != null) {
  160.                     if (wallpaperList.get(position).getReview()) {
  161.                         holder.text_view_review_wallpaper_item.setVisibility(View.VISIBLE);
  162.                     } else {
  163.                         holder.text_view_review_wallpaper_item.setVisibility(View.GONE);
  164.                     }
  165.                 }
  166.                 if (wallpaperList.get(position).getPremium() != null) {
  167.                     if (wallpaperList.get(position).getPremium()) {
  168.                         holder.image_view_item_wallpaper_premium.setVisibility(View.VISIBLE);
  169.                     } else {
  170.                         holder.image_view_item_wallpaper_premium.setVisibility(View.GONE);
  171.                     }
  172.                 }
  173.                 holder.linear_layout_wallpaper_item_global.setOnClickListener(new View.OnClickListener() {
  174.                     @Override
  175.                     public void onClick(View v) {
  176.  
  177.  
  178.                         if (!premium) {
  179.  
  180.  
  181.                             if (Config.Counter == 1){
  182.                                 Config.Counter = 0;
  183.                                 new AdConfig(activity);
  184.                             }
  185.  
  186.                             else{
  187.                                 Config.Counter ++;
  188.                             }
  189.  
  190.                         }
  191.  
  192.  
  193.                         Intent intent = new Intent(activity, WallpaperActivity.class);
  194.                         intent.putExtra("id", wallpaperList.get(position).getId());
  195.                         intent.putExtra("title", wallpaperList.get(position).getTitle());
  196.                         intent.putExtra("comment", wallpaperList.get(position).getComment());
  197.                         intent.putExtra("thumbnail", wallpaperList.get(position).getThumbnail());
  198.                         intent.putExtra("image", wallpaperList.get(position).getImage());
  199.                         intent.putExtra("userid", wallpaperList.get(position).getUserid());
  200.                         intent.putExtra("wallpaper", wallpaperList.get(position).getWallpaper());
  201.                         intent.putExtra("color", wallpaperList.get(position).getColor());
  202.                         intent.putExtra("resolution", wallpaperList.get(position).getResolution());
  203.                         intent.putExtra("size", wallpaperList.get(position).getSize());
  204.                         intent.putExtra("user", wallpaperList.get(position).getUser());
  205.                         intent.putExtra("userimage", wallpaperList.get(position).getUserimage());
  206.                         intent.putExtra("comments", wallpaperList.get(position).getComments());
  207.                         intent.putExtra("type", wallpaperList.get(position).getType());
  208.                         intent.putExtra("extension", wallpaperList.get(position).getExtension());
  209.                         intent.putExtra("downloads", wallpaperList.get(position).getDownloads());
  210.                         intent.putExtra("premium", wallpaperList.get(position).getPremium());
  211.                         intent.putExtra("trusted", wallpaperList.get(position).getTrusted());
  212.  
  213.                         activity.startActivity(intent);
  214.                         activity.overridePendingTransition(R.anim.enter, R.anim.exit);
  215.                     }
  216.                 });
  217.                 final FavoritesStorage storageFavorites = new FavoritesStorage(activity.getApplicationContext());
  218.                 List<Wallpaper> wallpapers = storageFavorites.loadFavorites();
  219.                 Boolean exist = false;
  220.                 if (wallpapers == null) {
  221.                     wallpapers = new ArrayList<>();
  222.                 }
  223.                 for (int i = 0; i < wallpapers.size(); i++) {
  224.                     if (wallpapers.get(i).getId().equals(wallpaperList.get(position).getId())) {
  225.                         exist = true;
  226.                     }
  227.                 }
  228.                 if (exist == false) {
  229.                     holder.image_view_fav_wallpaper_item.setImageResource(R.drawable.ic_fav);
  230.                 } else {
  231.                     holder.image_view_fav_wallpaper_item.setImageResource(R.drawable.ic_fav_done);
  232.                 }
  233.                 holder.image_view_fav_wallpaper_item.setOnClickListener(new View.OnClickListener() {
  234.                     @Override
  235.                     public void onClick(View v) {
  236.                         List<Wallpaper> favorites_list = storageFavorites.loadFavorites();
  237.                         Boolean exist = false;
  238.                         if (favorites_list == null) {
  239.                             favorites_list = new ArrayList<>();
  240.                         }
  241.                         for (int i = 0; i < favorites_list.size(); i++) {
  242.                             if (favorites_list.get(i).getId().equals(wallpaperList.get(position).getId())) {
  243.                                 exist = true;
  244.                             }
  245.                         }
  246.                         if (exist == false) {
  247.                             ArrayList<Wallpaper> audios = new ArrayList<Wallpaper>();
  248.                             for (int i = 0; i < favorites_list.size(); i++) {
  249.                                 audios.add(favorites_list.get(i));
  250.                             }
  251.                             audios.add(wallpaperList.get(position));
  252.                             storageFavorites.storeAudio(audios);
  253.                             holder.image_view_fav_wallpaper_item.setImageResource(R.drawable.ic_fav_done);
  254.  
  255.                         } else {
  256.                             ArrayList<Wallpaper> new_favorites = new ArrayList<Wallpaper>();
  257.                             for (int i = 0; i < favorites_list.size(); i++) {
  258.                                 if (!favorites_list.get(i).getId().equals(wallpaperList.get(position).getId())) {
  259.                                     new_favorites.add(favorites_list.get(i));
  260.  
  261.                                 }
  262.                             }
  263.                             if (favorites) {
  264.                                 wallpaperList.remove(position);
  265.                                 notifyDataSetChanged();
  266.                             }
  267.                             storageFavorites.storeAudio(new_favorites);
  268.                             holder.image_view_fav_wallpaper_item.setImageResource(R.drawable.ic_fav);
  269.                         }
  270.                     }
  271.                 });
  272.  
  273.                 break;
  274.             }
  275.             case 2: {
  276.                 final SlideHolder holder = (SlideHolder) holder_parent;
  277.  
  278.                 slide_adapter = new SlideAdapter(activity, slideList);
  279.                 holder.view_pager_slide.setAdapter(this.slide_adapter);
  280.                 holder.view_pager_slide.setOffscreenPageLimit(1);
  281.  
  282.                 holder.view_pager_slide.setClipToPadding(false);
  283.                 holder.view_pager_slide.setPageMargin(0);
  284.                 holder.view_pager_indicator.setupWithViewPager(holder.view_pager_slide);
  285.  
  286.                 holder.view_pager_slide.setCurrentItem(slideList.size() / 2);
  287.                 break;
  288.             }
  289.             case 3: {
  290.  
  291.                 final WallpaperAdapter.FollowHolder holder = (WallpaperAdapter.FollowHolder) holder_parent;
  292.                 this.linearLayoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
  293.                 this.followAdapter = new FollowAdapter(userList, activity);
  294.                 holder.recycle_view_follow_items.setHasFixedSize(true);
  295.                 holder.recycle_view_follow_items.setAdapter(followAdapter);
  296.                 holder.recycle_view_follow_items.setLayoutManager(linearLayoutManager);
  297.                 followAdapter.notifyDataSetChanged();
  298.                 break;
  299.             }
  300.             case 4: {
  301.                 final WallpaperAdapter.CategoriesHolder holder = (WallpaperAdapter.CategoriesHolder) holder_parent;
  302.                 this.linearLayoutManagerCategories = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
  303.                 this.categoryAdapter = new CategoryAdapter(categoryList, activity);
  304.                 holder.recycle_view_categories_items.setHasFixedSize(true);
  305.                 holder.recycle_view_categories_items.setAdapter(categoryAdapter);
  306.                 holder.recycle_view_categories_items.setLayoutManager(linearLayoutManagerCategories);
  307.                 categoryAdapter.notifyDataSetChanged();
  308.                 break;
  309.             }
  310.             case 5: {
  311.  
  312.                 break;
  313.             }
  314.         }
  315.     }
  316.  
  317.     private class SlideHolder extends RecyclerView.ViewHolder {
  318.         private final ViewPagerIndicator view_pager_indicator;
  319.         private final ClickableViewPager view_pager_slide;
  320.  
  321.         public SlideHolder(View itemView) {
  322.             super(itemView);
  323.             this.view_pager_indicator = (ViewPagerIndicator) itemView.findViewById(R.id.view_pager_indicator);
  324.             this.view_pager_slide = (ClickableViewPager) itemView.findViewById(R.id.view_pager_slide);
  325.         }
  326.  
  327.     }
  328.  
  329.     public static class FollowHolder extends RecyclerView.ViewHolder {
  330.         private final RecyclerView recycle_view_follow_items;
  331.  
  332.         public FollowHolder(View view) {
  333.             super(view);
  334.             recycle_view_follow_items = (RecyclerView) itemView.findViewById(R.id.recycle_view_follow_items);
  335.         }
  336.     }
  337.  
  338.     public static class CategoriesHolder extends RecyclerView.ViewHolder {
  339.         private final RecyclerView recycle_view_categories_items;
  340.  
  341.         public CategoriesHolder(View view) {
  342.             super(view);
  343.             recycle_view_categories_items = (RecyclerView) itemView.findViewById(R.id.recycle_view_categories_items);
  344.         }
  345.     }
  346.  
  347.     public class FacebookNativeHolder extends RecyclerView.ViewHolder {
  348.         private final String TAG = "WALLPAPERADAPTER";
  349.         private LinearLayout nativeAdContainer;
  350.         private LinearLayout adView;
  351.         private NativeAd nativeAd;
  352.  
  353.         public FacebookNativeHolder(View view) {
  354.             super(view);
  355.             loadNativeAd(view);
  356.         }
  357.  
  358.         private void loadNativeAd(final View view) {
  359.  
  360.             AudienceNetworkAds.initialize(activity);
  361.             AudienceNetworkAds.isInAdsProcess(activity);
  362.  
  363.             // Instantiate a NativeAd object.
  364.             // NOTE: the placement ID will eventually identify this as your App, you can ignore it for
  365.             // now, while you are testing and replace it later when you have signed up.
  366.             // While you are using this temporary code you will only get test ads and if you release
  367.             // your code like this to the Google Play your users will not receive ads (you will get a no fill error).
  368.             nativeAd = new NativeAd(activity, activity.getString(R.string.FACEBOOK_ADS_NATIVE_PLACEMENT_ID));
  369.             /*AdSettings.addTestDevice("a7c48fb1-dc6f-4f33-90e5-652ca11e1dbe");
  370.             AdSettings.addTestDevice("f8a80ada-1d17-4071-a74c-d1418e055ba9");
  371.             AdSettings.addTestDevice("a6cea904-fae8-4158-816c-4feafc6ed410");*/
  372.  
  373.             nativeAd.setAdListener(new NativeAdListener() {
  374.                 @Override
  375.                 public void onMediaDownloaded(Ad ad) {
  376.                     // Native ad finished downloading all assets
  377.                     Log.e(TAG, "Native ad finished downloading all assets.");
  378.                 }
  379.  
  380.                 @Override
  381.                 public void onError(Ad ad, AdError adError) {
  382.                     // Native ad failed to load
  383.                     Log.e(TAG, "Native ad failed to load: " + adError.getErrorMessage());
  384.                     Toast.makeText(getApplicationContext(), "Native ad failed to load: " + adError.getErrorMessage(),Toast.LENGTH_SHORT).show();
  385.  
  386.                 }
  387.  
  388.                 @Override
  389.                 public void onAdLoaded(Ad ad) {
  390.                     // Native ad is loaded and ready to be displayed
  391.                     Log.d(TAG, "Native ad is loaded and ready to be displayed!");
  392.                     //Toast.makeText(getApplicationContext(), "Native ad is loaded and ready to be displayed!", Toast.LENGTH_SHORT).show();
  393.                     // Race condition, load() called again before last ad was displayed
  394.                     if (nativeAd == null || nativeAd != ad) {
  395.                         return;
  396.                     }
  397.                    /* NativeAdViewAttributes viewAttributes = new NativeAdViewAttributes()
  398.                             .setBackgroundColor(activity.getResources().getColor(R.color.colorPrimaryDark))
  399.                             .setTitleTextColor(Color.WHITE)
  400.                             .setDescriptionTextColor(Color.WHITE)
  401.                             .setButtonColor(Color.WHITE);
  402.  
  403.                     View adView = NativeAdView.render(activity, nativeAd, NativeAdView.Type.HEIGHT_300, viewAttributes);
  404.  
  405.                     LinearLayout nativeAdContainer = (LinearLayout) view.findViewById(R.id.native_ad_container);
  406.                     nativeAdContainer.addView(adView);*/
  407.                     // Inflate Native Ad into Container
  408.                     inflateAd(nativeAd, view);
  409.                 }
  410.  
  411.                 @Override
  412.                 public void onAdClicked(Ad ad) {
  413.                     // Native ad clicked
  414.                     Log.d(TAG, "Native ad clicked!");
  415.                 }
  416.  
  417.                 @Override
  418.                 public void onLoggingImpression(Ad ad) {
  419.                     // Native ad impression
  420.                     Log.d(TAG, "Native ad impression logged!");
  421.                 }
  422.             });
  423.  
  424.             // Request an ad
  425.             nativeAd.loadAd();
  426.         }
  427.  
  428.         private void inflateAd(NativeAd nativeAd, View view) {
  429.  
  430.             nativeAd.unregisterView();
  431.  
  432.             // Add the Ad view into the ad container.
  433.             nativeAdContainer = view.findViewById(R.id.native_ad_container);
  434.             LayoutInflater inflater = LayoutInflater.from(activity);
  435.             // Inflate the Ad view.  The layout referenced should be the one you created in the last step.
  436.             adView = (LinearLayout) inflater.inflate(R.layout.native_ad_layout_1, nativeAdContainer, false);
  437.             nativeAdContainer.addView(adView);
  438.  
  439.             // Add the AdChoices icon
  440.             LinearLayout adChoicesContainer = view.findViewById(R.id.ad_choices_container);
  441.             AdChoicesView adChoicesView = new AdChoicesView(activity, nativeAd, true);
  442.             adChoicesContainer.addView(adChoicesView, 0);
  443.  
  444.             // Create native UI using the ad metadata.
  445.             AdIconView nativeAdIcon = adView.findViewById(R.id.native_ad_icon);
  446.             TextView nativeAdTitle = adView.findViewById(R.id.native_ad_title);
  447.             MediaView nativeAdMedia = adView.findViewById(R.id.native_ad_media);
  448.             TextView nativeAdSocialContext = adView.findViewById(R.id.native_ad_social_context);
  449.             TextView nativeAdBody = adView.findViewById(R.id.native_ad_body);
  450.             TextView sponsoredLabel = adView.findViewById(R.id.native_ad_sponsored_label);
  451.             Button nativeAdCallToAction = adView.findViewById(R.id.native_ad_call_to_action);
  452.  
  453.             // Set the Text.
  454.             nativeAdTitle.setText(nativeAd.getAdvertiserName());
  455.             nativeAdBody.setText(nativeAd.getAdBodyText());
  456.             nativeAdSocialContext.setText(nativeAd.getAdSocialContext());
  457.             nativeAdCallToAction.setVisibility(nativeAd.hasCallToAction() ? View.VISIBLE : View.INVISIBLE);
  458.             nativeAdCallToAction.setText(nativeAd.getAdCallToAction());
  459.             sponsoredLabel.setText(nativeAd.getSponsoredTranslation());
  460.  
  461.             // Create a list of clickable views
  462.             List<View> clickableViews = new ArrayList<>();
  463.             clickableViews.add(nativeAdTitle);
  464.             clickableViews.add(nativeAdCallToAction);
  465.  
  466.             // Register the Title and CTA button to listen for clicks.
  467.             nativeAd.registerViewForInteraction(
  468.                     adView,
  469.                     nativeAdMedia,
  470.                     nativeAdIcon,
  471.                     clickableViews);
  472.         }
  473.  
  474.     }
  475.  
  476.     public static class WallpaperHolder extends RecyclerView.ViewHolder {
  477.         private LinearLayout linear_layout_wallpaper_item_global;
  478.         private ImageView image_view_wallpaper_item;
  479.         private RelativeLayout relative_layout_wallpaper_item;
  480.         private TextView text_view_wallpaper_item_title;
  481.         private TextView text_view_wallpaper_item_user;
  482.         private LinearLayout linear_layout_wallpaper_item;
  483.         private TextView text_view_review_wallpaper_item;
  484.         //   private LikeButton like_button_fav_video_item;
  485.         private ImageView image_view_fav_wallpaper_item;
  486.         private ImageView image_view_item_wallpaper_premium;
  487.  
  488.         public WallpaperHolder(View itemView) {
  489.             super(itemView);
  490.             //  this.like_button_fav_video_item=(LikeButton) itemView.findViewById(R.id.like_button_fav_video_item);
  491.             this.image_view_fav_wallpaper_item = (ImageView) itemView.findViewById(R.id.image_view_fav_wallpaper_item);
  492.             this.image_view_item_wallpaper_premium = (ImageView) itemView.findViewById(R.id.image_view_item_wallpaper_premium);
  493.  
  494.             this.text_view_review_wallpaper_item = (TextView) itemView.findViewById(R.id.text_view_review_wallpaper_item);
  495.             this.linear_layout_wallpaper_item_global = (LinearLayout) itemView.findViewById(R.id.linear_layout_wallpaper_item_global);
  496.             this.linear_layout_wallpaper_item = (LinearLayout) itemView.findViewById(R.id.linear_layout_wallpaper_item);
  497.             this.text_view_wallpaper_item_user = (TextView) itemView.findViewById(R.id.text_view_wallpaper_item_user);
  498.             this.text_view_wallpaper_item_title = (TextView) itemView.findViewById(R.id.text_view_wallpaper_item_title);
  499.             this.image_view_wallpaper_item = (ImageView) itemView.findViewById(R.id.image_view_wallpaper_item);
  500.             this.relative_layout_wallpaper_item = (RelativeLayout) itemView.findViewById(R.id.relative_layout_wallpaper_item);
  501.         }
  502.  
  503.  
  504.     }
  505.  
  506.     @Override
  507.     public int getItemCount() {
  508.         return wallpaperList.size();
  509.     }
  510.  
  511.  
  512.     public boolean checkSUBSCRIBED() {
  513.         PrefManager prefManager = new PrefManager(getApplicationContext());
  514.         if (prefManager.getString("SUBSCRIBED").equals("FALSE")) {
  515.             return false;
  516.         }
  517.         return true;
  518.     }
  519.  
  520.  
  521.     public boolean check() {
  522.         PrefManager prf = new PrefManager(getApplicationContext());
  523.         if (getApplicationContext().getString(R.string.AD_MOB_ENABLED_INTERSTITAL).equals("false")) {
  524.             return false;
  525.         }
  526.         if (!prf.getString("SUBSCRIBED").equals("FALSE")) {
  527.             return false;
  528.         }
  529.         Calendar c = Calendar.getInstance();
  530.         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  531.         String strDate = sdf.format(c.getTime());
  532.  
  533.         if (prf.getString("LAST_DATE_ADS").equals("")) {
  534.             prf.setString("LAST_DATE_ADS", strDate);
  535.         } else {
  536.             String toyBornTime = prf.getString("LAST_DATE_ADS");
  537.             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  538.  
  539.             try {
  540.                 Date oldDate = dateFormat.parse(toyBornTime);
  541.                 System.out.println(oldDate);
  542.  
  543.                 Date currentDate = new Date();
  544.  
  545.                 long diff = currentDate.getTime() - oldDate.getTime();
  546.                 long seconds = diff / 1000;
  547.  
  548.                 if (seconds > Integer.parseInt(activity.getResources().getString(R.string.AD_MOB_TIME))) {
  549.                     prf.setString("LAST_DATE_ADS", strDate);
  550.                     return true;
  551.                 }
  552.             } catch (ParseException e) {
  553.                 e.printStackTrace();
  554.             }
  555.         }
  556.         return false;
  557.     }
  558.  
  559.  
  560.  
  561. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top