catch exceptions thrown at fixing date taken values
This commit is contained in:
parent
429925ba18
commit
21305a6d6d
1 changed files with 45 additions and 30 deletions
|
@ -102,7 +102,8 @@ fun SimpleActivity.launchAbout() {
|
||||||
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons),
|
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons),
|
||||||
FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons),
|
FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons),
|
||||||
FAQItem(R.string.faq_9_title_commons, R.string.faq_9_text_commons),
|
FAQItem(R.string.faq_9_title_commons, R.string.faq_9_text_commons),
|
||||||
FAQItem(R.string.faq_10_title_commons, R.string.faq_10_text_commons))
|
FAQItem(R.string.faq_10_title_commons, R.string.faq_10_text_commons)
|
||||||
|
)
|
||||||
|
|
||||||
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
|
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
|
||||||
}
|
}
|
||||||
|
@ -240,8 +241,10 @@ fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList<FileDirItem>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean,
|
fun BaseSimpleActivity.tryDeleteFileDirItem(
|
||||||
callback: ((wasSuccess: Boolean) -> Unit)? = null) {
|
fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean,
|
||||||
|
callback: ((wasSuccess: Boolean) -> Unit)? = null
|
||||||
|
) {
|
||||||
deleteFile(fileDirItem, allowDeleteFolder) {
|
deleteFile(fileDirItem, allowDeleteFolder) {
|
||||||
if (deleteFromDatabase) {
|
if (deleteFromDatabase) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
|
@ -445,38 +448,50 @@ fun AppCompatActivity.fixDateTaken(
|
||||||
val dateTakens = ArrayList<DateTaken>()
|
val dateTakens = ArrayList<DateTaken>()
|
||||||
|
|
||||||
for (path in paths) {
|
for (path in paths) {
|
||||||
val dateTime = ExifInterface(path).getAttribute(ExifInterface.TAG_DATETIME_ORIGINAL)
|
try {
|
||||||
?: ExifInterface(path).getAttribute(ExifInterface.TAG_DATETIME) ?: continue
|
val dateTime: String = ExifInterface(path).getAttribute(ExifInterface.TAG_DATETIME_ORIGINAL)
|
||||||
|
?: ExifInterface(path).getAttribute(ExifInterface.TAG_DATETIME) ?: continue
|
||||||
|
|
||||||
// some formats contain a "T" in the middle, some don't
|
// some formats contain a "T" in the middle, some don't
|
||||||
// sample dates: 2015-07-26T14:55:23, 2018:09:05 15:09:05
|
// sample dates: 2015-07-26T14:55:23, 2018:09:05 15:09:05
|
||||||
val t = if (dateTime.substring(10, 11) == "T") "\'T\'" else " "
|
val t = if (dateTime.substring(10, 11) == "T") "\'T\'" else " "
|
||||||
val separator = dateTime.substring(4, 5)
|
val separator = dateTime.substring(4, 5)
|
||||||
val format = "yyyy${separator}MM${separator}dd${t}kk:mm:ss"
|
val format = "yyyy${separator}MM${separator}dd${t}kk:mm:ss"
|
||||||
val formatter = SimpleDateFormat(format, Locale.getDefault())
|
val formatter = SimpleDateFormat(format, Locale.getDefault())
|
||||||
val timestamp = formatter.parse(dateTime).time
|
val timestamp = formatter.parse(dateTime).time
|
||||||
|
|
||||||
val uri = getFileUri(path)
|
val uri = getFileUri(path)
|
||||||
ContentProviderOperation.newUpdate(uri).apply {
|
ContentProviderOperation.newUpdate(uri).apply {
|
||||||
val selection = "${Images.Media.DATA} = ?"
|
val selection = "${Images.Media.DATA} = ?"
|
||||||
val selectionArgs = arrayOf(path)
|
val selectionArgs = arrayOf(path)
|
||||||
withSelection(selection, selectionArgs)
|
withSelection(selection, selectionArgs)
|
||||||
withValue(Images.Media.DATE_TAKEN, timestamp)
|
withValue(Images.Media.DATE_TAKEN, timestamp)
|
||||||
operations.add(build())
|
operations.add(build())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operations.size % BATCH_SIZE == 0) {
|
if (operations.size % BATCH_SIZE == 0) {
|
||||||
contentResolver.applyBatch(MediaStore.AUTHORITY, operations)
|
contentResolver.applyBatch(MediaStore.AUTHORITY, operations)
|
||||||
operations.clear()
|
operations.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaDB.updateFavoriteDateTaken(path, timestamp)
|
mediaDB.updateFavoriteDateTaken(path, timestamp)
|
||||||
didUpdateFile = true
|
didUpdateFile = true
|
||||||
|
|
||||||
val dateTaken = DateTaken(null, path, path.getFilenameFromPath(), path.getParentPath(), timestamp, (System.currentTimeMillis() / 1000).toInt(), File(path).lastModified())
|
val dateTaken = DateTaken(
|
||||||
dateTakens.add(dateTaken)
|
null,
|
||||||
if (!hasRescanned && getFileDateTaken(path) == 0L) {
|
path,
|
||||||
pathsToRescan.add(path)
|
path.getFilenameFromPath(),
|
||||||
|
path.getParentPath(),
|
||||||
|
timestamp,
|
||||||
|
(System.currentTimeMillis() / 1000).toInt(),
|
||||||
|
File(path).lastModified()
|
||||||
|
)
|
||||||
|
dateTakens.add(dateTaken)
|
||||||
|
if (!hasRescanned && getFileDateTaken(path) == 0L) {
|
||||||
|
pathsToRescan.add(path)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue