// Path: demo/src/main/java/com/moagrius/helpers/FileCopier.java
// public class FileCopier {
// 
//   private File mDirectory;
//   private String mPreferencesKey;
//   private Listener mListener;
// 
//   public FileCopier(File directory, String preferencesKey, Listener listener) {
//     mDirectory = directory;
//     mPreferencesKey = preferencesKey;
//     mListener = listener;
//   }
// 
//   public void copyFiles(Activity activity) throws Exception {
//     Log.d("TV", "about to copy asset tiles to " + mDirectory);
//     Helpers.saveBooleanPreference(activity, mPreferencesKey, false);
//     AssetManager assetManager = activity.getAssets();
//     String[] assetPaths = assetManager.list("tiles");
//     for (String assetPath : assetPaths) {
//       InputStream assetStream = assetManager.open("tiles/" + assetPath);
//       File dest = new File(mDirectory, assetPath);
//       FileOutputStream outputStream = new FileOutputStream(dest);
//       Helpers.copyStreams(assetStream, outputStream);
//       Log.d("TV", assetPath + " copied to " + dest);
//       activity.runOnUiThread(() -> mListener.onProgress(dest));
//     }
//     activity.runOnUiThread(() -> mListener.onComplete(mDirectory));
//     Helpers.saveBooleanPreference(activity, mPreferencesKey, true);
//     Log.d("TV", "done copying files");
//   }
// 
//   public void copyFilesAsync(Activity activity) {
//     new Thread(() -> {
//       try {
//         copyFiles(activity);
//       } catch (Exception e) {
//         mListener.onError(e);
//       }
//     }).start();
//   }
// 
//   public interface Listener {
//     void onProgress(File file);
//     void onComplete(File directory);
//     void onError(Throwable throwable);
//   }
// 
// }
// 
// Path: demo/src/main/java/com/moagrius/helpers/Helpers.java
// public class Helpers {
// 
//   public static final String EXTERNAL_STORAGE_KEY = "external";
//   public static final String INTERNAL_STORAGE_KEY = "internal";
// 
//   private static final String PREFS_FILE_NAME = "preferences";
// 
//   public static void copyStreams(InputStream inputStream, OutputStream outputStream) throws IOException {
//     try {
//       int data = inputStream.read();
//       while (data != -1) {
//         outputStream.write(data);
//         data = inputStream.read();
//       }
//     } finally {
//       inputStream.close();
//       outputStream.close();
//     }
//   }
// 
//   public static void saveBooleanPreference(Context context, String key, boolean value) {
//     SharedPreferences preferences = context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE);
//     SharedPreferences.Editor editor = preferences.edit();
//     editor.putBoolean(key, value);
//     editor.apply();
//   }
// 
//   public static boolean getBooleanPreference(Context context, String key) {
//     return context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE).getBoolean(key, false);
//   }
// 
// }


import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;
import com.moagrius.helpers.FileCopier;
import com.moagrius.helpers.Helpers;
import java.io.File;
    }
  }

  private void copyAssetTilesToDirectory(String preference, File directory) {
    if (Helpers.getBooleanPreference(this, preference)) {
      showWarning(preference, directory);
      return;
    }
    new FileCopier(directory, preference, this).copyFilesAsync(this);
  }

  private void showToast(String message) {
    runOnUiThread(() -> Toast.makeText(this, message, Toast.LENGTH_LONG).show());
  }

  private void showWarning(String preference, File directory) {
    new AlertDialog.Builder(this)
        .setTitle("Warning")
        .setMessage("It looks like you've already copied this files.  Click IGNORE to proceed anyway")
        .setPositiveButton(R.string.label_ignore, (d, i) -> copyAssetTilesToDirectory(preference, directory))
        .setNegativeButton(R.string.label_cancel, null)
        .create()
        .show();
  }

  @Override
  public void onProgress(File file) {
    showToast("Copied " + file);
  }

// Path: demo/src/main/java/com/moagrius/helpers/FileCopier.java
// public class FileCopier {
// 
//   private File mDirectory;
//   private String mPreferencesKey;
//   private Listener mListener;
// 
//   public FileCopier(File directory, String preferencesKey, Listener listener) {
//     mDirectory = directory;
//     mPreferencesKey = preferencesKey;
//     mListener = listener;
//   }
// 
//   public void copyFiles(Activity activity) throws Exception {
//     Log.d("TV", "about to copy asset tiles to " + mDirectory);
//     Helpers.saveBooleanPreference(activity, mPreferencesKey, false);
//     AssetManager assetManager = activity.getAssets();
//     String[] assetPaths = assetManager.list("tiles");
//     for (String assetPath : assetPaths) {
//       InputStream assetStream = assetManager.open("tiles/" + assetPath);
//       File dest = new File(mDirectory, assetPath);
//       FileOutputStream outputStream = new FileOutputStream(dest);
//       Helpers.copyStreams(assetStream, outputStream);
//       Log.d("TV", assetPath + " copied to " + dest);
//       activity.runOnUiThread(() -> mListener.onProgress(dest));
//     }
//     activity.runOnUiThread(() -> mListener.onComplete(mDirectory));
//     Helpers.saveBooleanPreference(activity, mPreferencesKey, true);
//     Log.d("TV", "done copying files");
//   }
// 
//   public void copyFilesAsync(Activity activity) {
//     new Thread(() -> {
//       try {
//         copyFiles(activity);
//       } catch (Exception e) {
//         mListener.onError(e);
//       }
//     }).start();
//   }
// 
//   public interface Listener {
//     void onProgress(File file);
//     void onComplete(File directory);
//     void onError(Throwable throwable);
//   }
// 
// }
// 
// Path: demo/src/main/java/com/moagrius/helpers/Helpers.java
// public class Helpers {
// 
//   public static final String EXTERNAL_STORAGE_KEY = "external";
//   public static final String INTERNAL_STORAGE_KEY = "internal";
// 
//   private static final String PREFS_FILE_NAME = "preferences";
// 
//   public static void copyStreams(InputStream inputStream, OutputStream outputStream) throws IOException {
//     try {
//       int data = inputStream.read();
//       while (data != -1) {
//         outputStream.write(data);
//         data = inputStream.read();
//       }
//     } finally {
//       inputStream.close();
//       outputStream.close();
//     }
//   }
// 
//   public static void saveBooleanPreference(Context context, String key, boolean value) {
//     SharedPreferences preferences = context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE);
//     SharedPreferences.Editor editor = preferences.edit();
//     editor.putBoolean(key, value);
//     editor.apply();
//   }
// 
//   public static boolean getBooleanPreference(Context context, String key) {
//     return context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE).getBoolean(key, false);
//   }
// 
// }


// Path: demo/src/main/java/com/moagrius/MainActivity.java
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;
import com.moagrius.helpers.FileCopier;
import com.moagrius.helpers.Helpers;
import java.io.File;

    }
  }

  private void copyAssetTilesToDirectory(String preference, File directory) {
    if (Helpers.getBooleanPreference(this, preference)) {
      showWarning(preference, directory);
      return;
    }
    new FileCopier(directory, preference, this).copyFilesAsync(this);
  }

  private void showToast(String message) {
    runOnUiThread(() -> Toast.makeText(this, message, Toast.LENGTH_LONG).show());
  }

  private void showWarning(String preference, File directory) {
    new AlertDialog.Builder(this)
        .setTitle("Warning")
        .setMessage("It looks like you've already copied this files.  Click IGNORE to proceed anyway")
        .setPositiveButton(R.string.label_ignore, (d, i) -> copyAssetTilesToDirectory(preference, directory))
        .setNegativeButton(R.string.label_cancel, null)
        .create()
        .show();
  }

  @Override
  public void onProgress(File file) {
    showToast("Copied " + file);
  }

  @Override