fixed DownloadUtils + added custom folders reset

This commit is contained in:
gdlbo
2022-08-12 01:07:54 +03:00
parent f3cda292e0
commit 820ca12c3e
3 changed files with 19 additions and 4 deletions
@@ -61,11 +61,11 @@ public class DownloadUtils {
File b2;
boolean c2 = MediaUtils.c(MediaUtils.b(str2));
if (str.endsWith("png") || str.endsWith("jpg") || str.endsWith("jpeg")) {
if (file.endsWith(".jpg") || file.endsWith(".png") || file.endsWith(".jpeg")) {
b2 = new File(getPhotosDir(), file);
} else if (str.endsWith("mp3") || str.endsWith("wav") || str.endsWith("ogg") || str.endsWith("aac") || str.endsWith("flac") || str.endsWith("m4a")) {
} else if (file.endsWith(".mp3") || file.endsWith(".wav") || file.endsWith(".ogg") || file.endsWith(".aac") || file.endsWith(".flac") || file.endsWith(".m4a")) {
b2 = new File(getMusicDir(), file);
} else if (str.endsWith("mp4") || str.endsWith("mkv") || str.endsWith("avi") || str.endsWith("flv") || str.endsWith("wmv") || str.endsWith("mov") || str.endsWith("3gp")) {
} else if (file.endsWith(".mp4") || file.endsWith(".mkv") || file.endsWith(".avi") || file.endsWith(".flv") || file.endsWith(".wmv") || file.endsWith(".mov") || file.endsWith(".3gp")) {
b2 = new File(getVideosDir(), file);
} else {
b2 = new File(getDownloadsDir(), file);
@@ -76,7 +76,11 @@ public class DownloadUtils {
final InputStream h = c3 == null ? null : c3.h();
if (h != null) {
try {
if (b2.exists() || FileUtils.b(b2)) {
if (b2.getParentFile() != null) {
b2.createNewFile();
}
if (b2.exists()) {
VkExecutors.x.a().execute(() -> ToastUtils.a(context.getString(R.string.file_saved, b2.getAbsoluteFile())));
}
} catch (Exception e2) {
@@ -86,6 +90,7 @@ public class DownloadUtils {
return;
}
}
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(str2));
request.setDestinationUri(Uri.fromFile(b2));
request.setMimeType(FileUtils.f(new File(str)));
@@ -9,6 +9,7 @@ import static ru.vtosters.lite.ui.components.BackupManager.deletePrefs;
import static ru.vtosters.lite.ui.components.BackupManager.restoreBackup;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
import static ru.vtosters.lite.utils.AndroidUtils.edit;
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
import static ru.vtosters.lite.utils.CacheUtils.deleteCache;
@@ -95,6 +96,12 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
return true;
});
findPreference("resetfolders").setOnPreferenceClickListener(preference -> {
edit().remove("photos_directory").remove("videos_directory").remove("audios_directory").remove("downloads_directory").apply();
Toast.makeText(getContext(), "Папки успешно сброшены", LENGTH_SHORT).show();
return true;
});
var pref = getDefaultPrefs().getString("autoclearcache", "Default");
switch (pref) {
case "Default":
+3
View File
@@ -19,6 +19,9 @@
<Preference
android:key="applicationstop"
android:title="@string/killappbtn" />
<Preference
android:key="resetfolders"
android:title="Сбросить пути папок" />
<Preference
android:key="tokencopy"
android:title="@string/copytokenbtn" />