Skip to content

Commit

Permalink
Merge pull request #69 from crimera/dev
Browse files Browse the repository at this point in the history
chore: Merge branch `dev` to `main`
  • Loading branch information
crimera authored Jul 24, 2024
2 parents 2de3a53 + 7f29c80 commit 25d7f72
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
## [1.21.1-dev.3](https://github.com/crimera/revanced-integrations/compare/v1.21.1-dev.2...v1.21.1-dev.3) (2024-07-21)


### Bug Fixes

* Setting backup preference title ([ca2c5de](https://github.com/crimera/revanced-integrations/commit/ca2c5de5e0317a5aae063da01a73c509eb5e3449))

## [1.21.1-dev.2](https://github.com/crimera/revanced-integrations/compare/v1.21.1-dev.1...v1.21.1-dev.2) (2024-07-18)


### Updates

* **Twitter - Custom Downloader:** Save photos in `Picture/Twitter` ([2c8b1bb](https://github.com/crimera/revanced-integrations/commit/2c8b1bb6358d9871710a8b5e275d1f9117177128))
* **Twitter - Custom Downloader:** The numbers from filename now follows media index from the post. ([b3ab727](https://github.com/crimera/revanced-integrations/commit/b3ab7271df108e542aa80226cb25c0b03fcf38f1))

## [1.21.1-dev.1](https://github.com/crimera/revanced-integrations/compare/v1.21.0...v1.21.1-dev.1) (2024-07-18)


### Updates

* **Twitter - Custom Downloader:** Auto start download when only 1 media is present in a post ([b44f715](https://github.com/crimera/revanced-integrations/commit/b44f7150d1009792f3a409128ddb584da517862c))
* **Twitter - Native Downloader:** Now saves photos on `/sdcard/Pictures/Twitter`, filenames now follow its index. ([e5b7919](https://github.com/crimera/revanced-integrations/commit/e5b7919705d548a13e681f5b3d61b1b1b9a896b9))

## [1.21.0](https://github.com/crimera/revanced-integrations/compare/v1.20.1...v1.21.0) (2024-07-17)


Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package app.revanced.integrations.twitter.patches;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.widget.LinearLayout;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.*;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import app.revanced.integrations.twitter.Utils;
import app.revanced.integrations.twitter.Pref;

public class NativeDownloader {

Expand Down Expand Up @@ -244,10 +238,17 @@ public static void downloader(Context ctx,Object t57){
}


if(mediaData.size()==0){
assert mediaData != null;
if(mediaData.isEmpty()){
Utils.toast(strRes("piko_pref_native_downloader_no_media"));
return;
}

if (mediaData.size()==1) {
downloadMedia(fileName, mediaData);
return;
}

alertbox(ctx,fileName,mediaData);
}catch (Exception ex){
logger(ex.toString());
Expand Down Expand Up @@ -276,14 +277,23 @@ public void onClick(DialogInterface dialogInterface, int which) {
ArrayList<HashMap> mData = new ArrayList<HashMap>();
HashMap<String,String> media = mediaData.get(which);
mData.add(media);
downloadMedia(filename,mData);
downloadMedia(filename+"_"+(which+1),mData);
dialogInterface.dismiss();
}
});
builder.setNegativeButton(strRes("piko_pref_native_downloader_download_all"),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int index) {
downloadMedia(filename,mediaData);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
int i = 0;
for (HashMap ignored : mediaData) {
ArrayList<HashMap> mData = new ArrayList<>();
HashMap media = mediaData.get(i);
mData.add(media);
downloadMedia(filename+"_"+(++i),mData);
}

}
dialogInterface.dismiss();
}
});
Expand All @@ -302,7 +312,7 @@ private static void downloadMedia(String filename,ArrayList<HashMap> mediaData){
String mediaUrl = (String)media.get("url");
String ext = (String)media.get("ext");

String updFileName = filename+"_"+String.valueOf(i+1)+"."+ext;
String updFileName = filename+"."+ext;

Utils.downloadFile(mediaUrl,updFileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
LegacyTwitterPreferenceCategory backupPref = preferenceCategory(strRes("piko_title_backup"), screen);
backupPref.addPreference(
buttonPreference(
StringRef.str("piko_pref_export",strRes("notification_settings_preferences_category")),
StringRef.str("piko_pref_export",strRes("settings_notification_pref_item_title")),
"",
Settings.EXPORT_PREF.key
)
Expand All @@ -500,7 +500,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
);
backupPref.addPreference(
buttonPreference(
StringRef.str("piko_pref_import",strRes("notification_settings_preferences_category")),
StringRef.str("piko_pref_import",strRes("settings_notification_pref_item_title")),
strRes("piko_pref_app_restart_rec"),
Settings.IMPORT_PREF.key
)
Expand All @@ -515,7 +515,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

backupPref.addPreference(
buttonPreference(
strRes("delete")+": "+strRes("notification_settings_preferences_category"),
strRes("delete")+": "+strRes("settings_notification_pref_item_title"),
"",
Settings.RESET_PREF.key
)
Expand Down Expand Up @@ -730,4 +730,4 @@ private static void setSetPref(String key, Set<String> val) {
}

//end
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.parallel = true
org.gradle.caching = true
android.useAndroidX = true
version = 1.21.0
version = 1.21.1-dev.3

0 comments on commit 25d7f72

Please sign in to comment.