Untitled
unknown
plain_text
2 years ago
40 kB
4
Indexable
package com.whatssdelete.reecover.WhatsappDemo02.adapter; import static com.whatssdelete.reecover.WhatsappDemo02.util_items.Utils.RootDirectoryWhatsappShow; import static com.whatssdelete.reecover.WhatsappDemo02.util_items.Utils.createFileFolder; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.media.MediaScannerConnection; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.databinding.DataBindingUtil; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.facebook.ads.Ad; import com.facebook.ads.CacheFlag; import com.facebook.ads.InterstitialAdListener; import com.facebook.ads.RewardData; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.FullScreenContentCallback; import com.google.android.gms.ads.LoadAdError; import com.google.android.gms.ads.interstitial.InterstitialAd; import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback; import com.whatssdelete.reecover.WhatsappDemo02.activity.ImagePreviewActivity; import com.whatssdelete.reecover.WhatsappDemo02.activity.VideoPlayerActivity; import com.whatssdelete.reecover.WhatsappDemo02.all_interfaces.FileListWhatsappClickInterface; import com.whatssdelete.reecover.WhatsappDemo02.util_items.Utils; import com.whatssdelete.reecover.WhatsappDemo02.wa_model.WhatsappStatusModel; import com.whatssdelete.reecover.messages.R; import com.whatssdelete.reecover.messages.adsnew.MyCustomAdDialog; import com.whatssdelete.reecover.messages.databinding.ItemsWhatsappViewBinding; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.EnumSet; import java.util.Objects; public class WhatsappStatusAdapter extends RecyclerView.Adapter<WhatsappStatusAdapter.ViewHolder> { private Context context; private ArrayList<WhatsappStatusModel> fileArrayList; private LayoutInflater layoutInflater; ProgressDialog dialogProgress; String fileName = ""; String gInterstitial; String fbInterstitial; InterstitialAd mInterstitialAd; AdRequest adRequest; public String saveFilePath = RootDirectoryWhatsappShow+ File.separator; private FileListWhatsappClickInterface fileListClickInterface; int fullScreenCount; SharedPreferences.Editor editor; SharedPreferences app_preferences; public static InterstitialAd InterstitialAdd; public static com.facebook.ads.InterstitialAd mInterstitialAdd; String ads_type; SharedPreferences mShare; MyCustomAdDialog adDialog; public WhatsappStatusAdapter(Context context, ArrayList<WhatsappStatusModel> files) { this.context = context; this.fileArrayList = files; initProgress(); } public WhatsappStatusAdapter(Context context, ArrayList<WhatsappStatusModel> files, FileListWhatsappClickInterface fileListClickInterface) { this.context = context; this.fileArrayList = files; this.fileListClickInterface=fileListClickInterface; initProgress(); } @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { if (layoutInflater == null) { layoutInflater = LayoutInflater.from(viewGroup.getContext()); } return new ViewHolder(DataBindingUtil.inflate(layoutInflater, R.layout.items_whatsapp_view, viewGroup, false)); } @Override public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { SharedPreferences preferences = context.getSharedPreferences("mPref", Context.MODE_PRIVATE); gInterstitial = preferences.getString("gInterstitial", ""); fbInterstitial = preferences.getString("fbInterstitial", ""); WhatsappStatusModel fileItem = fileArrayList.get(i); app_preferences = PreferenceManager.getDefaultSharedPreferences(context); fullScreenCount = Integer.parseInt(preferences.getString("fullscreencount", "")); ads_type = preferences.getString("adstype",""); editor = app_preferences.edit(); if (fileItem.getUri().toString().endsWith(".mp4")){ viewHolder.binding.ivPlay.setVisibility(View.VISIBLE); // viewHolder.binding.play.setVisibility(View.VISIBLE); }else { viewHolder.binding.ivPlay.setVisibility(View.GONE); // viewHolder.binding.play.setVisibility(View.GONE); } if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ Glide.with(context) .load(fileItem.getUri()) .into(viewHolder.binding.pcw); }else { Glide.with(context) .load(fileItem.getPath()) .into(viewHolder.binding.pcw); } viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (fileItem.getUri().toString().endsWith(".mp4")) { viewHolder.binding.ivPlay.setVisibility(View.VISIBLE); if (mInterstitialAd != null) { mInterstitialAd.show((Activity) v.getContext()); mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() { @Override public void onAdDismissedFullScreenContent() { // Called when fullscreen content is dismissed. Intent intent = new Intent(context, VideoPlayerActivity.class); intent.putExtra("PathVideo", fileItem.getUri().toString()); context.startActivity(intent); } @Override public void onAdFailedToShowFullScreenContent(AdError adError) { // Called when fullscreen content failed to show. Intent intent = new Intent(context, VideoPlayerActivity.class); intent.putExtra("PathVideo", fileItem.getUri().toString()); context.startActivity(intent); } @Override public void onAdShowedFullScreenContent() { // Called when fullscreen content is shown. // Make sure to set your reference to null so you don't // show it a second time. mInterstitialAd = null; } }); } else { Intent intent = new Intent(context, VideoPlayerActivity.class); intent.putExtra("PathVideo", fileItem.getUri().toString()); context.startActivity(intent); } } else { viewHolder.binding.ivPlay.setVisibility(View.GONE); Intent intent = new Intent(context, ImagePreviewActivity.class); intent.putExtra("imagepath", fileArrayList.get(i).getUri().toString()); Log.d("TAG", "onClick: "+fileArrayList.get(i).getUri().toString()); Log.d("TAG", "onClick11: "+fileItem.getUri().toString()); context.startActivity(intent); } } }); viewHolder.binding.tvDownload.setOnClickListener(view -> { createFileFolder(); if (ads_type.toString().equals("0")) { initInterstitialAd(fileItem); } else { loadFBInterstitialAd(fileItem); } }); // akki ads code 2 downside viewHolder.binding.ivPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, VideoPlayerActivity.class); intent.putExtra("PathVideo",fileItem.getUri().toString()); context.startActivity(intent); // if (ads_type.toString().equals("0")) { // // initInterstitialAd(fileItem); // // } else { // // loadFBInterstitialAd(fileItem); // } } }); } @Override public int getItemCount() { return fileArrayList == null ? 0 : fileArrayList.size(); } public class ViewHolder extends RecyclerView.ViewHolder { ItemsWhatsappViewBinding binding; public ViewHolder(ItemsWhatsappViewBinding mbinding) { super(mbinding.getRoot()); this.binding = mbinding; } } public void initProgress(){ dialogProgress = new ProgressDialog(context); dialogProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialogProgress.setTitle("Saving"); dialogProgress.setMessage("Saving. Please wait..."); dialogProgress.setIndeterminate(true); dialogProgress.setCanceledOnTouchOutside(false); } class DownloadFileTask extends AsyncTask<String, String, String> { @Override protected String doInBackground(String... furl) { try{ InputStream in = context.getContentResolver().openInputStream(Uri.parse(furl[0])); File f = null; f = new File(RootDirectoryWhatsappShow + File.separator + fileName); f.setWritable(true, false); OutputStream outputStream = new FileOutputStream(f); byte buffer[] = new byte[1024]; int length = 0; while((length=in.read(buffer)) > 0) { outputStream.write(buffer,0,length); } outputStream.close(); in.close(); } catch (IOException e) { System.out.println("error in creating a file"); e.printStackTrace(); } return null; } @Override protected void onProgressUpdate(String... progress) { } @Override protected void onPostExecute(String fileUrl) { Utils.setToast(context,context.getResources().getString(R.string.download_complete)); try { if (Build.VERSION.SDK_INT >= 19) { MediaScannerConnection.scanFile(context, new String[] {new File(RootDirectoryWhatsappShow+File.separator+fileName).getAbsolutePath()}, null, (path, uri) -> { //no action }); } else { context.sendBroadcast(new Intent("android.intent.action.MEDIA_MOUNTED", Uri.fromFile(new File(RootDirectoryWhatsappShow+File.separator+fileName)))); } }catch (Exception e){ e.printStackTrace(); } } @Override protected void onCancelled() { super.onCancelled(); } } private void initInterstitialAd(WhatsappStatusModel fileItem) { int adsCount = fullScreenCount; int count = app_preferences.getInt("count01", 0); if (count % adsCount != 0) { int increment1 = count + 1; editor.putInt("count01", increment1); editor.commit();// // Utils.arrayList.clear(); // Utils.arrayList.addAll(mItems); if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } } else { int increment1 = count + 1; editor.putInt("count01", increment1); editor.commit(); adDialog = new MyCustomAdDialog((Activity) context, "Loading ads"); adDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); adDialog.setCanceledOnTouchOutside(false); adDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); if (adDialog != null && !adDialog.isShowing()) { adDialog.show(); } AdRequest adRequest = new AdRequest.Builder().build(); com.google.android.gms.ads.interstitial.InterstitialAd.load(Objects.requireNonNull(context),gInterstitial, adRequest, new InterstitialAdLoadCallback() { @Override public void onAdLoaded(@NonNull com.google.android.gms.ads.interstitial.InterstitialAd interstitialAd) { adDialog.dismiss(); InterstitialAdd = interstitialAd; if (InterstitialAdd != null) { InterstitialAdd.show(Objects.requireNonNull((Activity) context)); InterstitialAdd.setFullScreenContentCallback(new FullScreenContentCallback() { @Override public void onAdDismissedFullScreenContent() { adDialog.dismiss(); if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } } @Override public void onAdFailedToShowFullScreenContent(@NonNull com.google.android.gms.ads.AdError adError) { // Utils.arrayList.clear(); // Utils.arrayList.addAll(mItems); adDialog.dismiss(); if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } } @Override public void onAdShowedFullScreenContent() { InterstitialAdd = null; adDialog.dismiss(); } }); } else { } } @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { InterstitialAdd = null; // Utils.arrayList.clear(); // Utils.arrayList.addAll(mItems); adDialog.dismiss(); if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } } }); } } public void loadFBInterstitialAd(WhatsappStatusModel fileItem) { int adsCount = fullScreenCount; int count = app_preferences.getInt("count01", 0); if (count % adsCount != 0) { int increment1 = count + 1; editor.putInt("count01", increment1); editor.commit();// if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } } else { int increment1 = count + 1; editor.putInt("count01", increment1); editor.commit();// adDialog = new MyCustomAdDialog((Activity) context, "Loading ads"); adDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); adDialog.setCanceledOnTouchOutside(false); adDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); if (adDialog != null && !adDialog.isShowing()) { adDialog.show(); } if (mInterstitialAdd != null) { mInterstitialAdd.destroy(); mInterstitialAdd = null; } mInterstitialAdd = new com.facebook.ads.InterstitialAd(context,fbInterstitial); // Load a new interstitial. com.facebook.ads.InterstitialAd.InterstitialLoadAdConfig loadAdConfig = mInterstitialAdd .buildLoadAdConfig() .withAdListener(new InterstitialAdListener() { @Override public void onInterstitialDisplayed(Ad ad) { adDialog.dismiss(); } @Override public void onInterstitialDismissed(Ad ad) { // AppUtils.arrayListWallpaper.clear(); // AppUtils.arrayListWallpaper.addAll(mItems); // Utils.arrayList.clear(); // Utils.arrayList.addAll(mItems); adDialog.dismiss(); if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } } @Override public void onError(Ad ad, com.facebook.ads.AdError adError) { // AppUtils.arrayListWallpaper.clear(); // AppUtils.arrayListWallpaper.addAll(mItems); // Utils.arrayList.clear(); // Utils.arrayList.addAll(mItems); adDialog.dismiss(); if (Build.VERSION.SDK_INT>Build.VERSION_CODES.Q){ try { if (fileItem.getUri().toString().endsWith(".mp4")) { fileName= "status_Saver_"+System.currentTimeMillis()+".mp4"; new DownloadFileTask().execute(fileItem.getUri().toString()); }else { fileName = "status_Saver_"+System.currentTimeMillis()+".png"; new DownloadFileTask().execute(fileItem.getUri().toString()); } } catch (Exception e) { e.printStackTrace(); } } else { final String path = fileItem.getPath(); String filename = path.substring(path.lastIndexOf("/") + 1); final File file = new File(path); File destFile = new File(saveFilePath); try { FileUtils.copyFileToDirectory(file, destFile); } catch (IOException e) { e.printStackTrace(); } String fileNameChange = filename.substring(12); File newFile = new File(saveFilePath + fileNameChange); String contentType = "image/*"; if (fileItem.getUri().toString().endsWith(".mp4")) { contentType = "video/*"; } else { contentType = "image/*"; } MediaScannerConnection.scanFile(context, new String[]{newFile.getAbsolutePath()}, new String[]{contentType}, new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { //NA } public void onScanCompleted(String path, Uri uri) { //NA } }); File from = new File(saveFilePath, filename); File to = new File(saveFilePath, fileNameChange); from.renameTo(to); Toast.makeText(context, context.getResources().getString(R.string.saved_to) + saveFilePath + fileNameChange, Toast.LENGTH_LONG).show(); } // downloadedFrame(); } @Override public void onAdLoaded(Ad ad) { if (adDialog != null && adDialog.isShowing()) { adDialog.dismiss(); } if (mInterstitialAdd == null || !mInterstitialAdd.isAdLoaded() || mInterstitialAdd.isAdInvalidated()) { // downloadedFrame(); } else { mInterstitialAdd.show(); } } @Override public void onAdClicked(Ad ad) { adDialog.dismiss(); } @Override public void onLoggingImpression(Ad ad) { adDialog.dismiss(); } }) .withCacheFlags(EnumSet.of(CacheFlag.VIDEO)) .withRewardData(new RewardData("YOUR_USER_ID", "YOUR_REWARD", 10)) .build(); mInterstitialAdd.loadAd(loadAdConfig); } } }
Editor is loading...