restore proper file paths

This commit is contained in:
tibbi 2019-01-12 15:44:04 +01:00
parent dc7de93cf7
commit 84ebb59482
2 changed files with 49 additions and 49 deletions

View file

@ -307,10 +307,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
}
private fun fixDateTaken() {
Thread {
activity.fixDateTaken(getSelectedPaths()) {
listener?.refreshItems()
finishActMode()
}
}.start()
}
private fun checkDeleteConfirmation() {

View file

@ -6,7 +6,6 @@ import android.content.Intent
import android.media.ExifInterface
import android.provider.MediaStore
import android.util.DisplayMetrics
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.simplemobiletools.commons.activities.BaseSimpleActivity
@ -237,6 +236,7 @@ fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit)
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: () -> Unit) {
Thread {
val newPaths = ArrayList<String>()
paths.forEach {
val source = it
val destination = it.removePrefix(recycleBinPath)
@ -250,6 +250,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
if (File(source).length() == File(destination).length()) {
mediumDao.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN$destination")
}
newPaths.add(destination)
} catch (e: Exception) {
showErrorToast(e)
} finally {
@ -262,7 +263,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
callback()
}
fixDateTaken(paths)
fixDateTaken(newPaths)
}.start()
}
@ -315,7 +316,6 @@ fun Activity.hasNavBar(): Boolean {
fun Activity.fixDateTaken(paths: ArrayList<String>, callback: (() -> Unit)? = null) {
val BATCH_SIZE = 50
toast(R.string.fixing)
Thread {
try {
var didUpdateFile = false
val operations = ArrayList<ContentProviderOperation>()
@ -346,7 +346,6 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, callback: (() -> Unit)? = nu
operations.clear()
}
Log.e("DEBUG", "restoring $path")
mediumDao.updateFavoriteDateTaken(path, timestamp)
didUpdateFile = true
}
@ -364,5 +363,4 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, callback: (() -> Unit)? = nu
} catch (e: Exception) {
showErrorToast(e)
}
}.start()
}