Skip to content

Commit

Permalink
update(Twitter - Custom Downloader): Save photos in Picture/Twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
crimera committed Jul 18, 2024
1 parent e420faf commit 2c8b1bb
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/src/main/java/app/revanced/integrations/twitter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ public static String[] addPref(String[] prefs, String pref) {
return bigger;
}

public static String getExtensionFromFilename(String filename) {
String extension = "";

int i = filename.lastIndexOf('.');
if (i > 0) {
extension = filename.substring(i+1);
}

return extension;
}

public static void downloadFile(String url, String filename) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading " + filename);
Expand All @@ -243,7 +254,13 @@ public static void downloadFile(String url, String filename) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Pref.getPublicFolder(), Pref.getVideoFolder(filename));

if (getExtensionFromFilename(filename).equals("jpg")) {
request.setDestinationInExternalPublicDir("Pictures", "Twitter/"+filename);
} else {
request.setDestinationInExternalPublicDir(Pref.getPublicFolder(), Pref.getVideoFolder(filename));
}

DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
long downloadId = manager.enqueue(request);
ctx.registerReceiver(new BroadcastReceiver() {
Expand Down

0 comments on commit 2c8b1bb

Please sign in to comment.