package com.studio4plus.homerplayer;

import android.app.Application;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.provider.MediaStore;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
import com.studio4plus.homerplayer.analytics.AnalyticsTracker;
import com.studio4plus.homerplayer.ui.HomeActivity;
import com.studio4plus.homerplayer.util.MediaScannerUtil;

import java.io.File;
import java.io.IOException;

import javax.inject.Inject;

import io.fabric.sdk.android.Fabric;

public class HomerPlayerApplication extends Application {

    private static final String AUDIOBOOKS_DIRECTORY = "AudioBooks";
    private static final String DEMO_SAMPLES_URL =
            "http://msimonides.github.io/homerplayer/samples.zip";

    private ApplicationComponent component;
    private MediaStoreUpdateObserver mediaStoreUpdateObserver;

    @Inject public GlobalSettings globalSettings;
    @Inject public AnalyticsTracker analyticsTracker;  // Force creation of the tracker early.

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

        CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
        Fabric.with(this, new Crashlytics.Builder().core(core).build());

        component = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this, Uri.parse(DEMO_SAMPLES_URL)))
                .audioBookManagerModule(new AudioBookManagerModule(AUDIOBOOKS_DIRECTORY))
                .build();
        component.inject(this);

        mediaStoreUpdateObserver = new MediaStoreUpdateObserver(new Handler(getMainLooper()));
        getContentResolver().registerContentObserver(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreUpdateObserver);

        HomeActivity.setEnabled(this, globalSettings.isAnyKioskModeEnabled());

        createAudioBooksDirectory(component.getAudioBookManager().getDefaultAudioBooksDirectory());
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        getContentResolver().unregisterContentObserver(mediaStoreUpdateObserver);
        mediaStoreUpdateObserver = null;
    }

    public static ApplicationComponent getComponent(Context context) {
        return ((HomerPlayerApplication) context.getApplicationContext()).component;
    }

    private void createAudioBooksDirectory(File path) {
        if (!path.exists()) {
            if (path.mkdirs()) {
                // The MediaScanner doesn't work so well with directories (registers them as regular
                // files) so make it scan a dummy.
                final File dummyFile = new File(path, ".ignore");
                try {
                    if (dummyFile.createNewFile()) {
                        MediaScannerUtil.scanAndDeleteFile(this, dummyFile);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    // Just ignore.
                }
            }
        }
    }
}

@@ -770,43 +770,40 @@
 http
+s
 ://
-msimonides.github.io/
 homer
+-
 player
+.firebaseapp.com
 /sam

Move the samples file out of GitHub Pages.