// Path: app/src/main/java/com/miz/utils/FileUtils.java
// public class FileUtils {
// 
// 	private FileUtils() {} // No instantiation!
// 	
// 	public static File getDatabaseFile(Context context) {
// 		return context.getDatabasePath(DatabaseHelper.DATABASE_NAME);
// 	}
// 	
// 	public static void copyFile(File src, File dst) throws IOException {
// 		InputStream in = new FileInputStream(src);
// 		OutputStream out = new FileOutputStream(dst);
// 
// 		// Transfer bytes from in to out
// 		byte[] buf = new byte[1024];
// 		int len;
// 		while ((len = in.read(buf)) > 0) {
// 			out.write(buf, 0, len);
// 		}
// 		in.close();
// 		out.close();
// 	}
// 
// 	public static void deleteRecursive(File fileOrDirectory, boolean deleteTopFolder) {
// 		if (fileOrDirectory.isDirectory()) {
// 			File[] listFiles = fileOrDirectory.listFiles();
// 			if (listFiles != null) {
// 				int count = listFiles.length;
// 				for (int i = 0; i < count; i++)
// 					deleteRecursive(listFiles[i], true);
// 			}
// 		}
// 
// 		if (deleteTopFolder)
// 			fileOrDirectory.delete();
// 	}
// 
// 	public static File getMovieThumb(Context c, String movieId) {
// 		return new File(MizuuApplication.getMovieThumbFolder(c), movieId + ".jpg");
// 	}
// 
// 	public static File getMovieBackdrop(Context c, String movieId) {
// 		return new File(MizuuApplication.getMovieBackdropFolder(c), movieId + "_bg.jpg");
// 	}
// 
// 	public static File getTvShowThumb(Context c, String showId) {
// 		return new File(MizuuApplication.getTvShowThumbFolder(c), showId + ".jpg");
// 	}
// 
// 	public static File getTvShowBackdrop(Context c, String showId) {
// 		return new File(MizuuApplication.getTvShowBackdropFolder(c), showId + "_tvbg.jpg");
// 	}
// 
// 	public static File getTvShowEpisode(Context c, String showId, String season, String episode) {
// 		return new File(MizuuApplication.getTvShowEpisodeFolder(c), showId + "_S" + MizLib.addIndexZero(season) + "E" + MizLib.addIndexZero(episode) + ".jpg");
// 	}
// 
// 	public static File getTvShowEpisode(Context c, String showId, int season, int episode) {
// 		return getTvShowEpisode(c, showId, String.valueOf(season), String.valueOf(episode));
// 	}
// 
// 	public static File getTvShowSeason(Context c, String showId, String season) {
// 		return new File(MizuuApplication.getTvShowSeasonFolder(c), showId + "_S" + MizLib.addIndexZero(season) + ".jpg");
// 	}
// 
// 	public static File getTvShowSeason(Context c, String showId, int season) {
// 		return getTvShowSeason(c, showId, String.valueOf(season));
// 	}
// 
// 	public static File getOfflineFile(Context c, String filepath) {
// 		return new File(MizuuApplication.getAvailableOfflineFolder(c), MizLib.md5(filepath) + "." + StringUtils.getExtension(filepath));
// 	}
// 
//     public static boolean hasOfflineCopy(Context c, Filepath path) {
//         return getOfflineCopyFile(c, path).exists();
//     }
// 
//     private static File getOfflineCopyFile(Context c, Filepath path) {
//         return getOfflineFile(c, path.getFilepath());
//     }
// 
//     public static String copyDatabase(Context context) {
//         try {
//             File newPath = new File(MizuuApplication.getAppFolder(context), "database.db");
//             newPath.createNewFile();
//             newPath.setReadable(true);
//             FileUtils.copyFile(FileUtils.getDatabaseFile(context), newPath);
// 
//             return newPath.exists() ? newPath.getAbsolutePath() : null;
//         } catch (IOException e) {
//             return null;
//         }
//     }
// }
// 
// Path: app/src/main/java/com/miz/functions/PreferenceKeys.java
// public static final String LANGUAGE_PREFERENCE = "prefsLanguagePreference";


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;
import static com.miz.functions.PreferenceKeys.LANGUAGE_PREFERENCE;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.widget.Toast;
import com.miz.mizuu.R;
import com.miz.utils.FileUtils;
/*
 * Copyright (C) 2014 Michell Bak
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.miz.mizuu.fragments;





public class Prefs extends PreferenceFragment {

	private Preference mLanguagePref, mCopyDatabase;
	private Locale[] mSystemLocales;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		int res=getActivity().getResources().getIdentifier(getArguments().getString("resource"), "xml", getActivity().getPackageName());
		addPreferencesFromResource(res);

        mCopyDatabase = getPreferenceScreen().findPreference("prefsCopyDatabase");
        if (mCopyDatabase != null)
            mCopyDatabase.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
// Path: app/src/main/java/com/miz/utils/FileUtils.java
// public class FileUtils {
// 
// 	private FileUtils() {} // No instantiation!
// 	
// 	public static File getDatabaseFile(Context context) {
// 		return context.getDatabasePath(DatabaseHelper.DATABASE_NAME);
// 	}
// 	
// 	public static void copyFile(File src, File dst) throws IOException {
// 		InputStream in = new FileInputStream(src);
// 		OutputStream out = new FileOutputStream(dst);
// 
// 		// Transfer bytes from in to out
// 		byte[] buf = new byte[1024];
// 		int len;
// 		while ((len = in.read(buf)) > 0) {
// 			out.write(buf, 0, len);
// 		}
// 		in.close();
// 		out.close();
// 	}
// 
// 	public static void deleteRecursive(File fileOrDirectory, boolean deleteTopFolder) {
// 		if (fileOrDirectory.isDirectory()) {
// 			File[] listFiles = fileOrDirectory.listFiles();
// 			if (listFiles != null) {
// 				int count = listFiles.length;
// 				for (int i = 0; i < count; i++)
// 					deleteRecursive(listFiles[i], true);
// 			}
// 		}
// 
// 		if (deleteTopFolder)
// 			fileOrDirectory.delete();
// 	}
// 
// 	public static File getMovieThumb(Context c, String movieId) {
// 		return new File(MizuuApplication.getMovieThumbFolder(c), movieId + ".jpg");
// 	}
// 
// 	public static File getMovieBackdrop(Context c, String movieId) {
// 		return new File(MizuuApplication.getMovieBackdropFolder(c), movieId + "_bg.jpg");
// 	}
// 
// 	public static File getTvShowThumb(Context c, String showId) {
// 		return new File(MizuuApplication.getTvShowThumbFolder(c), showId + ".jpg");
// 	}
// 
// 	public static File getTvShowBackdrop(Context c, String showId) {
// 		return new File(MizuuApplication.getTvShowBackdropFolder(c), showId + "_tvbg.jpg");
// 	}
// 
// 	public static File getTvShowEpisode(Context c, String showId, String season, String episode) {
// 		return new File(MizuuApplication.getTvShowEpisodeFolder(c), showId + "_S" + MizLib.addIndexZero(season) + "E" + MizLib.addIndexZero(episode) + ".jpg");
// 	}
// 
// 	public static File getTvShowEpisode(Context c, String showId, int season, int episode) {
// 		return getTvShowEpisode(c, showId, String.valueOf(season), String.valueOf(episode));
// 	}
// 
// 	public static File getTvShowSeason(Context c, String showId, String season) {
// 		return new File(MizuuApplication.getTvShowSeasonFolder(c), showId + "_S" + MizLib.addIndexZero(season) + ".jpg");
// 	}
// 
// 	public static File getTvShowSeason(Context c, String showId, int season) {
// 		return getTvShowSeason(c, showId, String.valueOf(season));
// 	}
// 
// 	public static File getOfflineFile(Context c, String filepath) {
// 		return new File(MizuuApplication.getAvailableOfflineFolder(c), MizLib.md5(filepath) + "." + StringUtils.getExtension(filepath));
// 	}
// 
//     public static boolean hasOfflineCopy(Context c, Filepath path) {
//         return getOfflineCopyFile(c, path).exists();
//     }
// 
//     private static File getOfflineCopyFile(Context c, Filepath path) {
//         return getOfflineFile(c, path.getFilepath());
//     }
// 
//     public static String copyDatabase(Context context) {
//         try {
//             File newPath = new File(MizuuApplication.getAppFolder(context), "database.db");
//             newPath.createNewFile();
//             newPath.setReadable(true);
//             FileUtils.copyFile(FileUtils.getDatabaseFile(context), newPath);
// 
//             return newPath.exists() ? newPath.getAbsolutePath() : null;
//         } catch (IOException e) {
//             return null;
//         }
//     }
// }
// 
// Path: app/src/main/java/com/miz/functions/PreferenceKeys.java
// public static final String LANGUAGE_PREFERENCE = "prefsLanguagePreference";


// Path: app/src/main/java/com/miz/mizuu/fragments/Prefs.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;
import static com.miz.functions.PreferenceKeys.LANGUAGE_PREFERENCE;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.widget.Toast;
import com.miz.mizuu.R;
import com.miz.utils.FileUtils;

/*
 * Copyright (C) 2014 Michell Bak
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.miz.mizuu.fragments;





public class Prefs extends PreferenceFragment {

	private Preference mLanguagePref, mCopyDatabase;
	private Locale[] mSystemLocales;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		int res=getActivity().getResources().getIdentifier(getArguments().getString("resource"), "xml", getActivity().getPackageName());
		addPreferencesFromResource(res);

        mCopyDatabase = getPreferenceScreen().findPreference("prefsCopyDatabase");
        if (mCopyDatabase != null)
            mCopyDatabase.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String path = FileUtils.copyDatabase(getActivity());