reverting the coroutines thing, it is too unstable

This commit is contained in:
tibbi 2021-03-09 09:11:55 +01:00
parent ab3e656a27
commit 350bf0a7f6
4 changed files with 17 additions and 28 deletions

View File

@ -96,14 +96,9 @@ dependencies {
kapt 'com.github.bumptech.glide:compiler:4.10.0' kapt 'com.github.bumptech.glide:compiler:4.10.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0' kapt 'androidx.room:room-compiler:2.2.6'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2" implementation 'androidx.room:room-runtime:2.2.6'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2" annotationProcessor 'androidx.room:room-compiler:2.2.6'
kapt "androidx.room:room-compiler:2.2.6"
implementation "androidx.room:room-ktx:2.2.6"
implementation "androidx.room:room-runtime:2.2.6"
annotationProcessor "androidx.room:room-compiler:2.2.6"
} }
// Apply the PESDKPlugin // Apply the PESDKPlugin

View File

@ -19,7 +19,6 @@ import android.util.DisplayMetrics
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.exifinterface.media.ExifInterface import androidx.exifinterface.media.ExifInterface
import androidx.lifecycle.lifecycleScope
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
@ -37,9 +36,6 @@ import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN
import com.simplemobiletools.gallery.pro.models.DateTaken import com.simplemobiletools.gallery.pro.models.DateTaken
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.InputStream import java.io.InputStream
@ -446,7 +442,7 @@ fun AppCompatActivity.fixDateTaken(
var didUpdateFile = false var didUpdateFile = false
val operations = ArrayList<ContentProviderOperation>() val operations = ArrayList<ContentProviderOperation>()
lifecycleScope.launch(Dispatchers.IO) { ensureBackgroundThread {
val dateTakens = ArrayList<DateTaken>() val dateTakens = ArrayList<DateTaken>()
for (path in paths) { for (path in paths) {
@ -490,8 +486,10 @@ fun AppCompatActivity.fixDateTaken(
toast(R.string.no_date_takens_found) toast(R.string.no_date_takens_found)
} }
withContext(Dispatchers.Main) { callback?.invoke() } runOnUiThread {
return@launch callback?.invoke()
}
return@ensureBackgroundThread
} }
val resultSize = contentResolver.applyBatch(MediaStore.AUTHORITY, operations).size val resultSize = contentResolver.applyBatch(MediaStore.AUTHORITY, operations).size
@ -504,7 +502,7 @@ fun AppCompatActivity.fixDateTaken(
dateTakensDB.insertAll(dateTakens) dateTakensDB.insertAll(dateTakens)
} }
withContext(Dispatchers.Main) { runOnUiThread {
if (showToasts) { if (showToasts) {
toast(if (didUpdateFile) R.string.dates_fixed_successfully else R.string.unknown_error_occurred) toast(if (didUpdateFile) R.string.dates_fixed_successfully else R.string.unknown_error_occurred)
} }

View File

@ -15,8 +15,6 @@ import com.simplemobiletools.gallery.pro.extensions.*
import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.Medium
import com.simplemobiletools.gallery.pro.models.ThumbnailItem import com.simplemobiletools.gallery.pro.models.ThumbnailItem
import com.simplemobiletools.gallery.pro.models.ThumbnailSection import com.simplemobiletools.gallery.pro.models.ThumbnailSection
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -460,13 +458,11 @@ class MediaFetcher(val context: Context) {
} }
val dateTakenValues = try { val dateTakenValues = try {
runBlocking {
if (folder == FAVORITES) { if (folder == FAVORITES) {
context.dateTakensDB.getAllDateTakens() context.dateTakensDB.getAllDateTakens()
} else { } else {
context.dateTakensDB.getDateTakensFromPath(folder) context.dateTakensDB.getDateTakensFromPath(folder)
} }
}
} catch (e: Exception) { } catch (e: Exception) {
return dateTakens return dateTakens
} }
@ -499,7 +495,7 @@ class MediaFetcher(val context: Context) {
} }
} }
val dateTakenValues = runBlocking(Dispatchers.IO) { context.dateTakensDB.getAllDateTakens() } val dateTakenValues = context.dateTakensDB.getAllDateTakens()
dateTakenValues.forEach { dateTakenValues.forEach {
dateTakens[it.fullPath] = it.taken dateTakens[it.fullPath] = it.taken

View File

@ -9,11 +9,11 @@ import com.simplemobiletools.gallery.pro.models.DateTaken
@Dao @Dao
interface DateTakensDao { interface DateTakensDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(dateTakens: List<DateTaken>) fun insertAll(dateTakens: List<DateTaken>)
@Query("SELECT full_path, filename, parent_path, date_taken, last_fixed, last_modified FROM date_takens WHERE parent_path = :path COLLATE NOCASE") @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed, last_modified FROM date_takens WHERE parent_path = :path COLLATE NOCASE")
suspend fun getDateTakensFromPath(path: String): List<DateTaken> fun getDateTakensFromPath(path: String): List<DateTaken>
@Query("SELECT full_path, filename, parent_path, date_taken, last_fixed, last_modified FROM date_takens") @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed, last_modified FROM date_takens")
suspend fun getAllDateTakens(): List<DateTaken> fun getAllDateTakens(): List<DateTaken>
} }