From a05ecbe8610185e16fe9cf1aa9878bf086398f5f Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 25 Apr 2017 23:23:36 +0200 Subject: [PATCH] try prefetching directories after install, before first app launch --- app/src/main/AndroidManifest.xml | 8 ++++++++ .../asynctasks/GetDirectoriesAsynctask.kt | 3 +++ .../gallery/receivers/InstallReceiver.kt | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d7cf72c79..f3cf094b3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -174,5 +174,13 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> + + + + + + diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 818a47cb0..29d39b91a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -20,6 +20,9 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va var shouldStop = false override fun doInBackground(vararg params: Void): ArrayList { + if (!context.hasWriteStoragePermission()) + return ArrayList() + val media = ArrayList() val showMedia = config.showMedia val fileSorting = config.fileSorting diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt new file mode 100644 index 000000000..fc3566bc0 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/receivers/InstallReceiver.kt @@ -0,0 +1,16 @@ +package com.simplemobiletools.gallery.receivers + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.google.gson.Gson +import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask +import com.simplemobiletools.gallery.extensions.config + +class InstallReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + GetDirectoriesAsynctask(context, false, false) { + context.config.directories = Gson().toJson(it) + }.execute() + } +}