Merge pull request #1939 from Isira-Seneviratne/Use_suspend_functions_in_DateTakensDao
Use suspend functions in DateTakensDao.
This commit is contained in:
commit
e0a78cc057
|
@ -96,9 +96,14 @@ dependencies {
|
||||||
|
|
||||||
kapt 'com.github.bumptech.glide:compiler:4.10.0'
|
kapt 'com.github.bumptech.glide:compiler:4.10.0'
|
||||||
|
|
||||||
kapt 'androidx.room:room-compiler:2.2.6'
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
|
||||||
implementation 'androidx.room:room-runtime:2.2.6'
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
|
||||||
annotationProcessor 'androidx.room:room-compiler:2.2.6'
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -18,6 +18,7 @@ import android.provider.MediaStore.Images
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.DecodeFormat
|
import com.bumptech.glide.load.DecodeFormat
|
||||||
|
@ -36,7 +37,13 @@ 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 java.io.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -423,7 +430,12 @@ fun Activity.hasNavBar(): Boolean {
|
||||||
return (realDisplayMetrics.widthPixels - displayMetrics.widthPixels > 0) || (realDisplayMetrics.heightPixels - displayMetrics.heightPixels > 0)
|
return (realDisplayMetrics.widthPixels - displayMetrics.widthPixels > 0) || (realDisplayMetrics.heightPixels - displayMetrics.heightPixels > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.fixDateTaken(paths: ArrayList<String>, showToasts: Boolean, hasRescanned: Boolean = false, callback: (() -> Unit)? = null) {
|
fun AppCompatActivity.fixDateTaken(
|
||||||
|
paths: ArrayList<String>,
|
||||||
|
showToasts: Boolean,
|
||||||
|
hasRescanned: Boolean = false,
|
||||||
|
callback: (() -> Unit)? = null
|
||||||
|
) {
|
||||||
val BATCH_SIZE = 50
|
val BATCH_SIZE = 50
|
||||||
if (showToasts) {
|
if (showToasts) {
|
||||||
toast(R.string.fixing)
|
toast(R.string.fixing)
|
||||||
|
@ -434,7 +446,7 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, showToasts: Boolean, hasResc
|
||||||
var didUpdateFile = false
|
var didUpdateFile = false
|
||||||
val operations = ArrayList<ContentProviderOperation>()
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
|
|
||||||
ensureBackgroundThread {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val dateTakens = ArrayList<DateTaken>()
|
val dateTakens = ArrayList<DateTaken>()
|
||||||
|
|
||||||
for (path in paths) {
|
for (path in paths) {
|
||||||
|
@ -478,10 +490,8 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, showToasts: Boolean, hasResc
|
||||||
toast(R.string.no_date_takens_found)
|
toast(R.string.no_date_takens_found)
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
withContext(Dispatchers.Main) { callback?.invoke() }
|
||||||
callback?.invoke()
|
return@launch
|
||||||
}
|
|
||||||
return@ensureBackgroundThread
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val resultSize = contentResolver.applyBatch(MediaStore.AUTHORITY, operations).size
|
val resultSize = contentResolver.applyBatch(MediaStore.AUTHORITY, operations).size
|
||||||
|
@ -494,7 +504,7 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, showToasts: Boolean, hasResc
|
||||||
dateTakensDB.insertAll(dateTakens)
|
dateTakensDB.insertAll(dateTakens)
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
withContext(Dispatchers.Main) {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ 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.*
|
||||||
|
|
||||||
|
@ -458,11 +460,13 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -495,7 +499,7 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val dateTakenValues = context.dateTakensDB.getAllDateTakens()
|
val dateTakenValues = runBlocking(Dispatchers.IO) { context.dateTakensDB.getAllDateTakens() }
|
||||||
|
|
||||||
dateTakenValues.forEach {
|
dateTakenValues.forEach {
|
||||||
dateTakens[it.fullPath] = it.taken
|
dateTakens[it.fullPath] = it.taken
|
||||||
|
|
|
@ -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)
|
||||||
fun insertAll(dateTakens: List<DateTaken>)
|
suspend 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")
|
||||||
fun getDateTakensFromPath(path: String): List<DateTaken>
|
suspend 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")
|
||||||
fun getAllDateTakens(): List<DateTaken>
|
suspend fun getAllDateTakens(): List<DateTaken>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue