// Path: modules/android/src/main/java/de/tobifleig/lxc/plaf/android/activity/SettingsActivity.java
// public class SettingsActivity extends KeepServiceRunningActivity implements CancelablePermissionPromptActivity {
// 
//     private DownloadPathPreference permissionDownloadPathPref;
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         // load layout
//         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//         // display the fragment as the main content.
//         getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
//     }
// 
//     @Override
//     public void cancelPermissionPromptAction() {
//         permissionDownloadPathPref = null;
//         Snackbar.make(findViewById(android.R.id.content), R.string.snackbar_action_cancelled_permission_storage_missing, Snackbar.LENGTH_LONG).show();
//     }
// 
//     @Override
//     public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//         if (requestCode == MainActivity.RETURNCODE_PERMISSION_PROMPT_STORAGE) {
//             if (grantResults.length == 0) {
//                 // cancelled, try again
//                 PermissionTools.verifyStoragePermission(this, this);
//                 return;
//             }
//             if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//                 // continue what the user tried to do when the permission dialog fired
//                 Thread t = new Thread(new Runnable() {
//                     @Override
//                     public void run() {
//                         if (permissionDownloadPathPref != null) {
//                             permissionDownloadPathPref.prompt();
//                             permissionDownloadPathPref = null;
//                         }
//                     }
//                 });
//                 t.setName("lxc_helper_useraction");
//                 t.setDaemon(true);
//                 t.start();
//             } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
//                 cancelPermissionPromptAction();
//             }
//         }
//     }
// 
//     public boolean verifyStoragePermission(DownloadPathPreference pref) {
//         permissionDownloadPathPref = pref;
//         boolean result = PermissionTools.verifyStoragePermission(this, this);
//         if (result) {
//             // delete action cache on success
//             permissionDownloadPathPref = null;
//         }
//         return result;
//     }
// }


import android.content.Context;
import android.content.res.TypedArray;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import de.tobifleig.lxc.plaf.android.activity.SettingsActivity;
import net.rdrei.android.dirchooser.DirectoryChooserConfig;
import net.rdrei.android.dirchooser.DirectoryChooserFragment;
/*
 * Copyright 2017 Tobias Fleig (tobifleig gmail com)
 * All rights reserved.
 *
 * Usage of this source code is governed by the GNU GENERAL PUBLIC LICENSE version 3 or (at your option) any later version.
 * For the full license text see the file COPYING or https://github.com/tfg13/LanXchange/blob/master/COPYING
 */
package de.tobifleig.lxc.plaf.android.ui;


/**
 * Custom preference to select the download target directory.
 * Currently, this only supports the internal storage (no external sd cards).
 */
public class DownloadPathPreference extends Preference {

    private DirectoryChooserFragment dialog;

    private String downloadPath;

    public DownloadPathPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void prompt() {
        // super ugly cast
// Path: modules/android/src/main/java/de/tobifleig/lxc/plaf/android/activity/SettingsActivity.java
// public class SettingsActivity extends KeepServiceRunningActivity implements CancelablePermissionPromptActivity {
// 
//     private DownloadPathPreference permissionDownloadPathPref;
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         // load layout
//         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//         // display the fragment as the main content.
//         getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
//     }
// 
//     @Override
//     public void cancelPermissionPromptAction() {
//         permissionDownloadPathPref = null;
//         Snackbar.make(findViewById(android.R.id.content), R.string.snackbar_action_cancelled_permission_storage_missing, Snackbar.LENGTH_LONG).show();
//     }
// 
//     @Override
//     public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//         if (requestCode == MainActivity.RETURNCODE_PERMISSION_PROMPT_STORAGE) {
//             if (grantResults.length == 0) {
//                 // cancelled, try again
//                 PermissionTools.verifyStoragePermission(this, this);
//                 return;
//             }
//             if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//                 // continue what the user tried to do when the permission dialog fired
//                 Thread t = new Thread(new Runnable() {
//                     @Override
//                     public void run() {
//                         if (permissionDownloadPathPref != null) {
//                             permissionDownloadPathPref.prompt();
//                             permissionDownloadPathPref = null;
//                         }
//                     }
//                 });
//                 t.setName("lxc_helper_useraction");
//                 t.setDaemon(true);
//                 t.start();
//             } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
//                 cancelPermissionPromptAction();
//             }
//         }
//     }
// 
//     public boolean verifyStoragePermission(DownloadPathPreference pref) {
//         permissionDownloadPathPref = pref;
//         boolean result = PermissionTools.verifyStoragePermission(this, this);
//         if (result) {
//             // delete action cache on success
//             permissionDownloadPathPref = null;
//         }
//         return result;
//     }
// }


// Path: modules/android/src/main/java/de/tobifleig/lxc/plaf/android/ui/DownloadPathPreference.java
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import de.tobifleig.lxc.plaf.android.activity.SettingsActivity;
import net.rdrei.android.dirchooser.DirectoryChooserConfig;
import net.rdrei.android.dirchooser.DirectoryChooserFragment;

/*
 * Copyright 2017 Tobias Fleig (tobifleig gmail com)
 * All rights reserved.
 *
 * Usage of this source code is governed by the GNU GENERAL PUBLIC LICENSE version 3 or (at your option) any later version.
 * For the full license text see the file COPYING or https://github.com/tfg13/LanXchange/blob/master/COPYING
 */
package de.tobifleig.lxc.plaf.android.ui;


/**
 * Custom preference to select the download target directory.
 * Currently, this only supports the internal storage (no external sd cards).
 */
public class DownloadPathPreference extends Preference {

    private DirectoryChooserFragment dialog;

    private String downloadPath;

    public DownloadPathPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void prompt() {
        // super ugly cast
        SettingsActivity myActivity = (SettingsActivity) getContext();