Search in sources :

Example 1 with LegacyUtils

use of com.simplecity.amp_library.utils.LegacyUtils in project Shuttle by timusus.

the class ShuttleApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    if (LeakCanary.isInAnalyzerProcess(this)) {
        // You should not init your app in this process.
        return;
    }
    instance = this;
    if (BuildConfig.DEBUG) {
    // Traceur.enableLogging();
    // enableStrictMode();
    }
    appComponent = initDagger(this);
    refWatcher = LeakCanary.install(this);
    // workaround to fix InputMethodManager leak as suggested by LeakCanary lib
    InputMethodManagerLeaks.fixFocusedViewLeak(this);
    // Crashlytics
    CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
    Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).answers(new Answers()).build());
    // Firebase
    FirebaseApp.initializeApp(this);
    FirebaseAnalytics.getInstance(this);
    VideoCastManager.initialize(this, new CastConfiguration.Builder(Config.CHROMECAST_APP_ID).enableLockScreen().enableNotification().build());
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // files with readAgain flag set to false, so always check KEY_HAS_SET_DEFAULT_VALUES
    if (!prefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
        PreferenceManager.setDefaultValues(this, R.xml.settings_headers, true);
        PreferenceManager.setDefaultValues(this, R.xml.settings_artwork, true);
        PreferenceManager.setDefaultValues(this, R.xml.settings_blacklist, true);
        PreferenceManager.setDefaultValues(this, R.xml.settings_display, true);
        PreferenceManager.setDefaultValues(this, R.xml.settings_headset, true);
        PreferenceManager.setDefaultValues(this, R.xml.settings_scrobbling, true);
        PreferenceManager.setDefaultValues(this, R.xml.settings_themes, true);
    }
    // Turn off logging for jaudiotagger.
    jaudioTaggerLogger1.setLevel(Level.OFF);
    jaudioTaggerLogger2.setLevel(Level.OFF);
    TagOptionSingleton.getInstance().setPadNumbers(true);
    SettingsManager.getInstance().incrementLaunchCount();
    Completable.fromAction(() -> {
        Query query = new Query.Builder().uri(CustomArtworkTable.URI).projection(new String[] { CustomArtworkTable.COLUMN_ID, CustomArtworkTable.COLUMN_KEY, CustomArtworkTable.COLUMN_TYPE, CustomArtworkTable.COLUMN_PATH }).build();
        SqlUtils.createActionableQuery(ShuttleApplication.this, cursor -> userSelectedArtwork.put(cursor.getString(cursor.getColumnIndexOrThrow(CustomArtworkTable.COLUMN_KEY)), new UserSelectedArtwork(cursor.getInt(cursor.getColumnIndexOrThrow(CustomArtworkTable.COLUMN_TYPE)), cursor.getString(cursor.getColumnIndexOrThrow(CustomArtworkTable.COLUMN_PATH)))), query);
    }).subscribeOn(Schedulers.io()).subscribe();
    Completable.timer(5, TimeUnit.SECONDS).andThen(Completable.defer(this::repairMediaStoreYearFromTags)).doOnError(throwable -> LogUtils.logException(TAG, "Failed to update year from tags", throwable)).onErrorComplete().subscribeOn(Schedulers.io()).subscribe();
    Completable.timer(10, TimeUnit.SECONDS).andThen(Completable.defer(this::cleanGenres)).doOnError(throwable -> LogUtils.logException(TAG, "Failed to clean genres", throwable)).onErrorComplete().subscribeOn(Schedulers.io()).subscribe();
    Completable.timer(15, TimeUnit.SECONDS).andThen(Completable.defer(this::cleanMostPlayedPlaylist)).doOnError(throwable -> LogUtils.logException(TAG, "Failed to clean most played", throwable)).onErrorComplete().subscribeOn(Schedulers.io()).subscribe();
    Completable.timer(20, TimeUnit.SECONDS).andThen(Completable.defer(LegacyUtils::deleteOldResources)).doOnError(throwable -> LogUtils.logException(TAG, "Failed to delete old resources", throwable)).onErrorComplete().subscribeOn(Schedulers.io()).subscribe();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) Genre(com.simplecity.amp_library.model.Genre) PackageManager(android.content.pm.PackageManager) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) Completable(io.reactivex.Completable) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) CastConfiguration(com.google.android.libraries.cast.companionlibrary.cast.CastConfiguration) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) UserSelectedArtwork(com.simplecity.amp_library.model.UserSelectedArtwork) Manifest(android.Manifest) DaggerAppComponent(com.simplecity.amp_library.dagger.component.DaggerAppComponent) AudioFile(org.jaudiotagger.audio.AudioFile) MediaStore(android.provider.MediaStore) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) FirebaseAnalytics(com.google.firebase.analytics.FirebaseAnalytics) FieldKey(org.jaudiotagger.tag.FieldKey) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextCompat(android.support.v4.content.ContextCompat) VideoCastManager(com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager) Logger(java.util.logging.Logger) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) PreferenceManager(android.support.v7.preference.PreferenceManager) Query(com.simplecity.amp_library.model.Query) List(java.util.List) Config(com.simplecity.amp_library.constants.Config) Application(android.app.Application) TagException(org.jaudiotagger.tag.TagException) AudioFileIO(org.jaudiotagger.audio.AudioFileIO) Fabric(io.fabric.sdk.android.Fabric) CompletableTransformer(io.reactivex.CompletableTransformer) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) ContentValues(android.content.ContentValues) Answers(com.crashlytics.android.answers.Answers) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) AppModule(com.simplecity.amp_library.dagger.module.AppModule) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) TagOptionSingleton(org.jaudiotagger.tag.TagOptionSingleton) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) RefWatcher(com.squareup.leakcanary.RefWatcher) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) StringUtils(com.simplecity.amp_library.utils.StringUtils) InputMethodManagerLeaks(com.simplecity.amp_library.utils.InputMethodManagerLeaks) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Observable(io.reactivex.Observable) AppComponent(com.simplecity.amp_library.dagger.component.AppComponent) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) TextUtils(android.text.TextUtils) IOException(java.io.IOException) Tag(org.jaudiotagger.tag.Tag) CustomArtworkTable(com.simplecity.amp_library.sql.databases.CustomArtworkTable) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) StrictMode(android.os.StrictMode) Crashlytics(com.crashlytics.android.Crashlytics) DataManager(com.simplecity.amp_library.utils.DataManager) LeakCanary(com.squareup.leakcanary.LeakCanary) LegacyUtils(com.simplecity.amp_library.utils.LegacyUtils) Collections(java.util.Collections) ContentUris(android.content.ContentUris) FirebaseApp(com.google.firebase.FirebaseApp) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) Answers(com.crashlytics.android.answers.Answers) Query(com.simplecity.amp_library.model.Query) SharedPreferences(android.content.SharedPreferences) UserSelectedArtwork(com.simplecity.amp_library.model.UserSelectedArtwork)

Aggregations

Manifest (android.Manifest)1 Application (android.app.Application)1 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentUris (android.content.ContentUris)1 ContentValues (android.content.ContentValues)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Environment (android.os.Environment)1 StrictMode (android.os.StrictMode)1 MediaStore (android.provider.MediaStore)1 NonNull (android.support.annotation.NonNull)1 ContextCompat (android.support.v4.content.ContextCompat)1 PreferenceManager (android.support.v7.preference.PreferenceManager)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 Glide (com.bumptech.glide.Glide)1 Crashlytics (com.crashlytics.android.Crashlytics)1 Answers (com.crashlytics.android.answers.Answers)1