restore from recycle bin SDK 30+

- when file is on the root of Internal Storage or SD Card, change the destination to the /Pictures folder, we cannot write to the root of any volume on SDK 30+
- call handleSAFDialogSdk30, so users are prompted to allow SAF when restoring, if not previously allowed
- if there are conflicts, handle it as though it's a CONFLICT_KEEP_BOTH by appending some characters to the destination name
- add new string restore_to_path shown when restoring to /Pictures folder on SDK 30+ instead of the root folder
This commit is contained in:
darthpaul 2022-04-11 16:23:14 +01:00
parent 04d135019c
commit b2d08c401e
44 changed files with 86 additions and 25 deletions

View file

@ -341,8 +341,23 @@ fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit)
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, callback: () -> Unit) {
ensureBackgroundThread {
val newPaths = ArrayList<String>()
var shownRestoringToPictures = false
for (source in paths) {
val destination = source.removePrefix(recycleBinPath)
var destination = source.removePrefix(recycleBinPath)
val destinationParent = destination.getParentPath()
val isAStorageRootFolder = isAStorageRootFolder(destinationParent)
if (isRPlus() && isAStorageRootFolder) {
// if the file is on the root of Internal Storage or SD Card, change it to Pictures
// we cannot write there on 30+
val picturesDirectory = getPicturesDirectoryPath(destination)
destination = File(picturesDirectory, destination.getFilenameFromPath()).path
if (!shownRestoringToPictures) {
toast(getString(R.string.restore_to_path, humanizePath(picturesDirectory)))
shownRestoringToPictures = true
}
}
val lastModified = File(source).lastModified()
val isShowingSAF = handleSAFDialog(destination) {}
@ -350,6 +365,16 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, callback
return@ensureBackgroundThread
}
val isShowingSAFSdk30 = handleSAFDialogSdk30(destination) {}
if (isShowingSAFSdk30) {
return@ensureBackgroundThread
}
if (getDoesFilePathExist(destination)) {
val newFile = getAlternativeFile(File(destination))
destination = newFile.path
}
var inputStream: InputStream? = null
var out: OutputStream? = null
try {
@ -368,7 +393,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, callback
out?.flush()
if (File(source).length() == copiedSize) {
mediaDB.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN$destination")
mediaDB.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN${source.removePrefix(recycleBinPath)}")
}
newPaths.add(destination)

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">تعيين كمجلد افتراضي</string>
<string name="unset_as_default_folder">إلغاء التعيين كمجلد افتراضي</string>
<string name="reorder_by_dragging">إعادة ترتيب المجلدات عن طريق السحب</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">فلترة الوسائط</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">ডিফল্ট ফোল্ডার হিশেবে সেট করুন</string>
<string name="unset_as_default_folder">ডিফল্ট ফোল্ডার হিশেবে আর রাখবেন না</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">মিডিয়া ফিল্টার করুন</string>

View file

@ -39,7 +39,7 @@
<string name="set_as_default_folder">Estableix com a carpeta predeterminada</string>
<string name="unset_as_default_folder">Desactiva com a carpeta predeterminada</string>
<string name="reorder_by_dragging">Reordeneu les carpetes arrossegant-les</string>
<string name="copy_to_restricted_folder_message">El sistema no permet copiar a aquesta carpeta.</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtre multimèdia</string>
<string name="images">Imatges</string>
@ -373,4 +373,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtr médií</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Vælg som standardmappe</string>
<string name="unset_as_default_folder">Fravælg som standardmappe</string>
<string name="reorder_by_dragging">Omorganiser mapper ved at trække</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrer medier</string>

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">Als Standardordner festlegen</string>
<string name="unset_as_default_folder">Nicht mehr als Standardordner festlegen</string>
<string name="reorder_by_dragging">Neuordnung von Ordnern durch Ziehen</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Medien filtern</string>
<string name="images">Bilder</string>
@ -370,4 +371,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,7 +33,7 @@
<string name="set_as_default_folder">Ορισμός ως προεπιλεγμένου φακέλου</string>
<string name="unset_as_default_folder">Κατάργηση ως προεπιλεγμένου φακέλου</string>
<string name="reorder_by_dragging">Αναδιάταξη φακέλων με μεταφορά</string>
<string name="copy_to_restricted_folder_message">Το σύστημα δεν επιτρέπει την αντιγραφή σε αυτόν τον φάκελο.</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Φιλτράρισμα πολυμέσων</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>
<string name="images">Bildoj</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Poner como carpeta predeterminada</string>
<string name="unset_as_default_folder">Quitar como carpeta predeterminada</string>
<string name="reorder_by_dragging">Reordenar carpetas arrastrándolas</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtro de medios</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Ezarri lehenetsitako karpeta gisa</string>
<string name="unset_as_default_folder">Kendu karpeta lehenetsitako karpeta gisa</string>
<string name="reorder_by_dragging">Berrordenatu karpetak arrastatuz</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Iragazi multimedia</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">تنظیم به عنوان شاخهٔ پیش‌گزیده</string>
<string name="unset_as_default_folder">برداشتن تنظیم به عنوان شاخهٔ پیش‌گزیده</string>
<string name="reorder_by_dragging">مرتب‌سازی مجدد شاخه‌ها با کشیدن</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">پالایش رسانه</string>

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">Aseta oletushakemistoksi</string>
<string name="unset_as_default_folder">Älä käytä oletushakemistona</string>
<string name="reorder_by_dragging">Järjestä kansiot uudelleen vetämällä</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Suodata media</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Dossier par défaut</string>
<string name="unset_as_default_folder">Oublier le dossier</string>
<string name="reorder_by_dragging">Réordonner par glisser</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrer les médias</string>
<string name="images">Images</string>
@ -362,4 +363,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrar medios</string>
<string name="images">Imaxes</string>
@ -419,4 +420,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtriranje medija</string>
<string name="images">Slike</string>

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">Beállítás alapértelmezett mappaként</string>
<string name="unset_as_default_folder">Eltávolítás mint alapértelmezett mappa</string>
<string name="reorder_by_dragging">Mappák átrendezése húzással</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Médiafájlok szűrése</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Imposta come cartella predefinita</string>
<string name="unset_as_default_folder">Non impostare come cartella predefinita</string>
<string name="reorder_by_dragging">Riordina cartelle trascinandole</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtra i file</string>
<string name="images">Immagini</string>
@ -419,4 +420,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">デフォルトのフォルダとして設定</string>
<string name="unset_as_default_folder">デフォルトのフォルダから外す</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">表示する形式</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">필터 설정</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtruoti mediją</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Sett som standardmappe</string>
<string name="unset_as_default_folder">Ikke lenger sett som standardmappe</string>
<string name="reorder_by_dragging">Endre mapperekkefølge ved å dra</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrer media</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -35,7 +35,8 @@
<string name="set_as_default_folder">Als standaardmap instellen</string>
<string name="unset_as_default_folder">Standaardmap herstellen</string>
<string name="reorder_by_dragging">Volgorde mappen bepalen met sleepgebaren</string>
<string name="copy_to_restricted_folder_message">Het systeem staat het kopiëren naar deze map niet toe.</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Media filteren</string>
<string name="images">Afbeeldingen</string>
@ -425,4 +426,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -39,7 +39,8 @@
<string name="set_as_default_folder">Ustaw jako folder domyślny</string>
<string name="unset_as_default_folder">Anuluj ustawienie folderu domyślnego</string>
<string name="reorder_by_dragging">Przeorganizuj foldery przeciągając</string>
<string name="copy_to_restricted_folder_message">System nie pozwala na kopiowanie do tego folderu</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtruj multimedia</string>
<string name="images">Obrazy</string>
@ -424,4 +425,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">Definir como pasta padrão</string>
<string name="unset_as_default_folder">Indefinir como pasta padrão</string>
<string name="reorder_by_dragging">Reordenar as pastas ao arrastar</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrar mídia</string>

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">Utilizar como pasta padrão</string>
<string name="unset_as_default_folder">Deixar de utilizar como pasta padrão</string>
<string name="reorder_by_dragging">Organizar pasta por arrasto</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrar multimédia</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Setază ca dosar implicit</string>
<string name="unset_as_default_folder">Dezactivează ca dosar implicit</string>
<string name="reorder_by_dragging">Reordonează dosarele prin tragere</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrează elementele media</string>
<string name="images">Imagini</string>
@ -419,4 +420,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,7 +33,7 @@
<string name="set_as_default_folder">Установить как папку по умолчанию</string>
<string name="unset_as_default_folder">Отключить как папку по умолчанию</string>
<string name="reorder_by_dragging">Менять порядок папок перетаскиванием</string>
<string name="copy_to_restricted_folder_message">Система не разрешает копирование в эту папку.</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Фильтр медиа</string>
<string name="images">Изображения</string>
@ -422,4 +422,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,7 +33,7 @@
<string name="set_as_default_folder">Nastaviť ako predvolený priečinok</string>
<string name="unset_as_default_folder">Odobrať predvolený priečinok</string>
<string name="reorder_by_dragging">Zmeniť poradie priečinkov presunutím</string>
<string name="copy_to_restricted_folder_message">Systém nepovoľuje kopírovanie do tohto priečinka.</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter médií</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtriranje datotek</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Филтрирај медију</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filtrera media</string>
<string name="images">Bilder</string>
@ -419,4 +420,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -39,6 +39,7 @@
<string name="set_as_default_folder">இயல்புநிலை அடைவாக அமை</string>
<string name="unset_as_default_folder">இயல்புநிலை அடைவாக அமைக்காதே</string>
<string name="reorder_by_dragging">பிடித்திழுத்து அடைவுகளை மறுசீரமை</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">ஊடகத்தை வடிகட்டு</string>
<string name="images">படங்கள்</string>
@ -427,4 +428,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -39,7 +39,7 @@
<string name="set_as_default_folder">Öntanımlı klasör olarak ayarla</string>
<string name="unset_as_default_folder">Öntanımlı klasör ayarını kaldır</string>
<string name="reorder_by_dragging">Sürükleyerek klasörleri yeniden sırala</string>
<string name="copy_to_restricted_folder_message">Sistem bu klasöre kopyalamaya izin vermiyor.</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Medyayı filtrele</string>
<string name="images">Resimler</string>
@ -372,4 +372,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Встановити теку за замовчуванням</string>
<string name="unset_as_default_folder">Відмінити встановлення теки за замовчуванням</string>
<string name="reorder_by_dragging">Сортувати папки шляхом переміщення</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Фільтр мультимедійних файлів</string>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Lọc</string>

View file

@ -39,7 +39,7 @@
<string name="set_as_default_folder">设置为默认文件夹</string>
<string name="unset_as_default_folder">取消设置为默认文件夹</string>
<string name="reorder_by_dragging">通过拖动重新排序文件夹</string>
<string name="copy_to_restricted_folder_message">此系统不允许复制到这个文件夹。</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">筛选媒体文件</string>
<string name="images">图片</string>
@ -428,4 +428,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">篩選媒體檔案</string>

View file

@ -33,7 +33,7 @@
<string name="set_as_default_folder">設為預設資料夾</string>
<string name="unset_as_default_folder">取消設為預設資料夾</string>
<string name="reorder_by_dragging">透過拖曳來重新排序資料夾</string>
<string name="copy_to_restricted_folder_message">系統不允許複製至此資料夾。</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">篩選媒體檔案</string>
<string name="images">圖片</string>
@ -421,4 +421,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -33,6 +33,7 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>