// Path: app/src/main/java/de/stephanlindauer/criticalmaps/App.java
// public class App extends Application {
// 
//     private static AppComponent appComponent;
// 
//     public static AppComponent components() {
//         return appComponent;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         if (BuildConfig.DEBUG) {
//             Timber.plant(new Timber.DebugTree());
//         } else {
//             Timber.plant(new NoOpTree());
//         }
// 
//         appComponent = DaggerAppComponent.builder().app(this).build();
//     }
// 
//     private static class NoOpTree extends Timber.Tree {
//         @Override
//         protected void log(int priority, String tag, @NotNull String message, Throwable t) {
//         }
//     }
// }
// 
// Path: app/src/main/java/de/stephanlindauer/criticalmaps/prefs/SharedPrefsKeys.java
// public interface SharedPrefsKeys {
//     String PRIVACY_POLICY_ACCEPTED =
//             BuildConfig.APPLICATION_ID + ".PRIVACY_POLICY_ACCEPTED";
//     String OSMDROID_BASE_PATH =
//             BuildConfig.APPLICATION_ID + ".OSMDROID_BASE_PATH";
//     String OBSERVER_MODE_ACTIVE =
//             BuildConfig.APPLICATION_ID + ".OBSERVER_MODE_ACTIVE";
//     String SHOW_ON_LOCKSCREEN =
//             BuildConfig.APPLICATION_ID + ".SHOW_ON_LOCKSCREEN";
//     String KEEP_SCREEN_ON =
//             BuildConfig.APPLICATION_ID + ".KEEP_SCREEN_ON";
//     String DISABLE_MAP_ROTATION =
//             BuildConfig.APPLICATION_ID + ".DISABLE_MAP_ROTATION";
//     String USE_HIGH_RES_MAP_TILES =
//             BuildConfig.APPLICATION_ID + ".USE_HIGH_RES_MAP_TILES";
//     String SHOW_GPX =
//             BuildConfig.APPLICATION_ID + ".SHOW_GPX";
//     String GPX_FILE =
//             BuildConfig.APPLICATION_ID + ".GPX_FILE";
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.os.EnvironmentCompat;
import org.osmdroid.tileprovider.modules.SqlTileWriter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.inject.Inject;
import javax.inject.Singleton;
import de.stephanlindauer.criticalmaps.App;
import de.stephanlindauer.criticalmaps.R;
import de.stephanlindauer.criticalmaps.prefs.SharedPrefsKeys;
import info.metadude.android.typedpreferences.StringPreference;
import timber.log.Timber;
        boolean pathAvailable = false;
        if (path.exists()) {
            if (!isPathInInternalFilesDir(context, path)) {
                String state = EnvironmentCompat.getStorageState(path);
                pathAvailable = Environment.MEDIA_MOUNTED.equals(state);
            } else {
                // result of getFilesDir() is guaranteed to be writable
                pathAvailable = true;
            }
        }
        return pathAvailable;
    }

    public static class StorageLocation {
        public String displayName;
        public File storagePath;
        public File osmdroidBasePath;
        public File osmdroidTilePath;
        public long totalSize;
        public long freeSpace;
        public long usedSpace;

        private File dbFile;

        public StorageLocation(Context context, File path) {
            if (!path.exists() || !isPathAvailableForWrite(context, path)) {
                throw new IllegalArgumentException("Path does not exist or is read only: " + path);
            }

            this.storagePath = path;
// Path: app/src/main/java/de/stephanlindauer/criticalmaps/App.java
// public class App extends Application {
// 
//     private static AppComponent appComponent;
// 
//     public static AppComponent components() {
//         return appComponent;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         if (BuildConfig.DEBUG) {
//             Timber.plant(new Timber.DebugTree());
//         } else {
//             Timber.plant(new NoOpTree());
//         }
// 
//         appComponent = DaggerAppComponent.builder().app(this).build();
//     }
// 
//     private static class NoOpTree extends Timber.Tree {
//         @Override
//         protected void log(int priority, String tag, @NotNull String message, Throwable t) {
//         }
//     }
// }
// 
// Path: app/src/main/java/de/stephanlindauer/criticalmaps/prefs/SharedPrefsKeys.java
// public interface SharedPrefsKeys {
//     String PRIVACY_POLICY_ACCEPTED =
//             BuildConfig.APPLICATION_ID + ".PRIVACY_POLICY_ACCEPTED";
//     String OSMDROID_BASE_PATH =
//             BuildConfig.APPLICATION_ID + ".OSMDROID_BASE_PATH";
//     String OBSERVER_MODE_ACTIVE =
//             BuildConfig.APPLICATION_ID + ".OBSERVER_MODE_ACTIVE";
//     String SHOW_ON_LOCKSCREEN =
//             BuildConfig.APPLICATION_ID + ".SHOW_ON_LOCKSCREEN";
//     String KEEP_SCREEN_ON =
//             BuildConfig.APPLICATION_ID + ".KEEP_SCREEN_ON";
//     String DISABLE_MAP_ROTATION =
//             BuildConfig.APPLICATION_ID + ".DISABLE_MAP_ROTATION";
//     String USE_HIGH_RES_MAP_TILES =
//             BuildConfig.APPLICATION_ID + ".USE_HIGH_RES_MAP_TILES";
//     String SHOW_GPX =
//             BuildConfig.APPLICATION_ID + ".SHOW_GPX";
//     String GPX_FILE =
//             BuildConfig.APPLICATION_ID + ".GPX_FILE";
// }


// Path: app/src/main/java/de/stephanlindauer/criticalmaps/provider/StorageLocationProvider.java
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.os.EnvironmentCompat;
import org.osmdroid.tileprovider.modules.SqlTileWriter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.inject.Inject;
import javax.inject.Singleton;
import de.stephanlindauer.criticalmaps.App;
import de.stephanlindauer.criticalmaps.R;
import de.stephanlindauer.criticalmaps.prefs.SharedPrefsKeys;
import info.metadude.android.typedpreferences.StringPreference;
import timber.log.Timber;

        boolean pathAvailable = false;
        if (path.exists()) {
            if (!isPathInInternalFilesDir(context, path)) {
                String state = EnvironmentCompat.getStorageState(path);
                pathAvailable = Environment.MEDIA_MOUNTED.equals(state);
            } else {
                // result of getFilesDir() is guaranteed to be writable
                pathAvailable = true;
            }
        }
        return pathAvailable;
    }

    public static class StorageLocation {
        public String displayName;
        public File storagePath;
        public File osmdroidBasePath;
        public File osmdroidTilePath;
        public long totalSize;
        public long freeSpace;
        public long usedSpace;

        private File dbFile;

        public StorageLocation(Context context, File path) {
            if (!path.exists() || !isPathAvailableForWrite(context, path)) {
                throw new IllegalArgumentException("Path does not exist or is read only: " + path);
            }

            this.storagePath = path;
            this.osmdroidBasePath = new File(storagePath, "osmdroid");