Skip to content

Commit

Permalink
Merge pull request #70 from swakwork/dev
Browse files Browse the repository at this point in the history
Some more features
  • Loading branch information
crimera authored Jul 30, 2024
2 parents 2839191 + 427b386 commit 3f17e81
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 47 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/app/revanced/integrations/twitter/Pref.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ public static boolean hideImmersivePlayer() {
return !Utils.getBooleanPerf(Settings.TIMELINE_HIDE_IMMERSIVE_PLAYER);
}

public static int enableVidAutoAdvance() {
if(Utils.getBooleanPerf(Settings.TIMELINE_ENABLE_VID_AUTO_ADVANCE)){
return 1;
}
return -1;
}

public static boolean hideHiddenReplies(boolean bool){
if(Utils.getBooleanPerf(Settings.TIMELINE_HIDE_HIDDEN_REPLIES)){
return false;
Expand Down Expand Up @@ -205,6 +212,11 @@ public static boolean hideCTJ() {
public static boolean hideRBMK() {
return Utils.getBooleanPerf(Settings.ADS_HIDE_REVISIT_BMK);
}
public static String removePremiumUpsell(String def) {
if(Utils.getBooleanPerf(Settings.ADS_REMOVE_PREMIUM_UPSELL)) return "";
return def;

}

public static boolean hideRPinnedPosts() {
return Utils.getBooleanPerf(Settings.ADS_HIDE_REVISIT_PINNED_POSTS);
Expand All @@ -226,6 +238,10 @@ public static boolean enableUndoPosts() {
return Utils.getBooleanPerf(Settings.PREMIUM_UNDO_POSTS);
}

public static boolean enableForcePip() {
return Utils.getBooleanPerf(Settings.PREMIUM_ENABLE_FORCE_PIP);
}

public static boolean enableDebugMenu() {
return Utils.getBooleanPerf(Settings.MISC_DEBUG_MENU);
}
Expand Down
15 changes: 3 additions & 12 deletions app/src/main/java/app/revanced/integrations/twitter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,9 @@ public static String[] addPref(String[] prefs, String pref) {
return bigger;
}

public static String getExtensionFromFilename(String filename) {
String extension = "";
public static void downloadFile(String url,String mediaName,String ext) {
String filename = mediaName+"."+ext;

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);
request.setTitle(filename);
Expand All @@ -255,7 +246,7 @@ public static void downloadFile(String url, String filename) {
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}

if (getExtensionFromFilename(filename).equals("jpg")) {
if (ext.equals("jpg")) {
request.setDestinationInExternalPublicDir("Pictures", "Twitter/"+filename);
} else {
request.setDestinationInExternalPublicDir(Pref.getPublicFolder(), Pref.getVideoFolder(filename));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static void downloader(Context ctx,Object t57){
}

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

Expand Down Expand Up @@ -277,23 +277,14 @@ 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+"_"+(which+1),mData);
downloadMedia(filename,mData,which+1);
dialogInterface.dismiss();
}
});
builder.setNegativeButton(strRes("piko_pref_native_downloader_download_all"),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int index) {
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);
}

}
downloadMedia(filename,mediaData,0);
dialogInterface.dismiss();
}
});
Expand All @@ -303,19 +294,21 @@ public void onClick(DialogInterface dialogInterface, int index) {
//endfunc
}

private static void downloadMedia(String filename,ArrayList<HashMap> mediaData){
private static void downloadMedia(String filename,ArrayList<HashMap> mediaData,int pos){
try{
Utils.toast(strRes("download_started"));
int n = mediaData.size();
for(int i=0;i<n;i++){
HashMap<String, String> media = mediaData.get(i);
String mediaUrl = (String)media.get("url");
String ext = (String)media.get("ext");

String updFileName = filename+"."+ext;

Utils.downloadFile(mediaUrl,updFileName);
}
if(pos == 0){ //download all
filename+="_"+(++i);
}else if(pos > 0){ //download specific media
filename+="_"+pos;
}//else for < 0 only filename
Utils.downloadFile(mediaUrl,filename,ext);
}

} catch (Exception e){
Utils.logger(e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting ADS_HIDE_DETAILED_POSTS = new BooleanSetting("ads_hide_detailed_posts", true);
public static final BooleanSetting ADS_HIDE_PREMIUM_PROMPT = new BooleanSetting("ads_hide_premium_prompt", true);
public static final BooleanSetting ADS_DEL_FROM_DB = new BooleanSetting("ads_del_from_db", false);
public static final BooleanSetting ADS_REMOVE_PREMIUM_UPSELL = new BooleanSetting("ads_remove_premium_upsell", true);

public static final BooleanSetting TIMELINE_DISABLE_AUTO_SCROLL = new BooleanSetting("timeline_disable_auto_scroll", true);
public static final BooleanSetting TIMELINE_HIDE_LIVETHREADS = new BooleanSetting("timeline_hide_livethreads", false);
Expand All @@ -44,10 +45,12 @@ public class Settings extends BaseSettings {
public static final BooleanSetting TIMELINE_HIDE_PROMOTE_BUTTON = new BooleanSetting("timeline_hide_promote_button", false);
public static final BooleanSetting TIMELINE_HIDE_FORCE_TRANSLATE = new BooleanSetting("timeline_force_translate", false);
public static final BooleanSetting TIMELINE_HIDE_HIDDEN_REPLIES = new BooleanSetting("timeline_hide_hidden_replies", false);
public static final BooleanSetting TIMELINE_ENABLE_VID_AUTO_ADVANCE = new BooleanSetting("timeline_enable_vid_auto_advance", true);

public static final BooleanSetting PREMIUM_READER_MODE = new BooleanSetting("premium_reader_mode", false);
public static final BooleanSetting PREMIUM_UNDO_POSTS = new BooleanSetting("premium_undo_posts", false);
public static final StringSetting PREMIUM_ICONS = new StringSetting("premium_app_icon", "");
public static final BooleanSetting PREMIUM_ENABLE_FORCE_PIP = new BooleanSetting("premium_enable_force_pip", false);

public static final StringSetting CUSTOM_PROFILE_TABS = new StringSetting("customisation_profile_tabs", "");
public static final StringSetting CUSTOM_TIMELINE_TABS = new StringSetting("customisation_timeline_tabs", "show_both");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public void onCreate(@org.jetbrains.annotations.Nullable Bundle savedInstanceSta
);

TreeMap<String,Boolean> flags = new TreeMap();
flags.put(strRes("piko_pref_video_download"),SettingsStatus.enableVidDownload);
flags.put(strRes("piko_pref_reader_mode"),SettingsStatus.enableReaderMode);
flags.put(strEnableRes("piko_pref_video_download"),SettingsStatus.enableVidDownload);
flags.put(strEnableRes("piko_pref_reader_mode"),SettingsStatus.enableReaderMode);
flags.put(strEnableRes("piko_pref_undo_posts"),SettingsStatus.enableUndoPosts);
flags.put(strRes("app_icon"),SettingsStatus.customAppIcon);
flags.put(strRes("custom_navigation"),SettingsStatus.navBarCustomisation);
flags.put(strRes("piko_pref_download"),SettingsStatus.changeDownloadEnabled);
Expand All @@ -70,7 +71,7 @@ public void onCreate(@org.jetbrains.annotations.Nullable Bundle savedInstanceSta
flags.put(strRemoveRes("piko_pref_pinned_posts_section"),SettingsStatus.hideRPinnedPosts);
flags.put(strRemoveRes("piko_pref_hide_detailed_posts"),SettingsStatus.hideDetailedPosts);
flags.put(strRemoveRes("piko_pref_hide_trends"),SettingsStatus.hidePromotedTrend);
flags.put(strRes("piko_pref_chirp_font"),SettingsStatus.enableFontMod);
flags.put(strEnableRes("piko_pref_chirp_font"),SettingsStatus.enableFontMod);
flags.put(strRemoveRes("piko_pref_hide_fab"),SettingsStatus.hideFAB);
flags.put(strRemoveRes("piko_pref_hide_fab_menu"),SettingsStatus.hideFABBtns);
flags.put(strRes("piko_pref_show_sensitive_media"),SettingsStatus.showSensitiveMedia);
Expand All @@ -97,12 +98,15 @@ public void onCreate(@org.jetbrains.annotations.Nullable Bundle savedInstanceSta
flags.put(strRes("piko_pref_force_translate"),SettingsStatus.forceTranslate);
flags.put(strRes("piko_pref_round_off_numbers"),SettingsStatus.roundOffNumbers);
flags.put(strRes("piko_pref_customisation_inlinetabs"),SettingsStatus.inlineBarCustomisation);
flags.put(strRes("piko_pref_debug_menu"),SettingsStatus.enableDebugMenu);
flags.put(strEnableRes("piko_pref_debug_menu"),SettingsStatus.enableDebugMenu);
flags.put(strRemoveRes("piko_pref_hide_premium_prompt"),SettingsStatus.hidePremiumPrompt);
flags.put(strRemoveRes("piko_pref_hide_hidden_replies"),SettingsStatus.hideHiddenReplies);
flags.put(strRes("piko_pref_del_from_db"),SettingsStatus.deleteFromDb);
flags.put(strRes("piko_pref_video_download"),SettingsStatus.enableVidDownload);
flags.put(strRes("piko_title_native_downloader"),SettingsStatus.nativeDownloader);
flags.put(strEnableRes("piko_pref_enable_vid_auto_advance"),SettingsStatus.enableVidAutoAdvance);
flags.put(strEnableRes("piko_pref_enable_force_pip"),SettingsStatus.enableForcePip);
flags.put(strRemoveRes("piko_pref_hide_premium_upsell"),SettingsStatus.removePremiumUpsell);

LegacyTwitterPreferenceCategory patPref = preferenceCategory(strRes("piko_pref_patches"), screen);

Expand Down Expand Up @@ -170,4 +174,7 @@ private static String strRes(String tag) {
private static String strRemoveRes(String tag) {
return StringRef.str("piko_pref_remove",strRes(tag));
}
private static String strEnableRes(String tag) {
return StringRef.str("piko_pref_enable",strRes(tag));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (SettingsStatus.enableReaderMode) {
premiumPrefs.addPreference(
switchPreference(
strRes("piko_pref_reader_mode"),
strEnableRes("piko_pref_reader_mode"),
strRes("piko_pref_reader_mode_desc"),
Settings.PREMIUM_READER_MODE
)
Expand All @@ -48,7 +48,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (SettingsStatus.enableUndoPosts) {
premiumPrefs.addPreference(
switchPreference(
strRes("piko_pref_undo_posts"),
strEnableRes("piko_pref_undo_posts"),
strRes("piko_pref_undo_posts_desc"),
Settings.PREMIUM_UNDO_POSTS
)
Expand All @@ -71,6 +71,15 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
)
);
}
if (SettingsStatus.enableForcePip) {
premiumPrefs.addPreference(
switchPreference(
strEnableRes("piko_pref_enable_force_pip"),
strRes("piko_pref_enable_force_pip_desc"),
Settings.PREMIUM_ENABLE_FORCE_PIP
)
);
}
}

//download section
Expand Down Expand Up @@ -201,6 +210,16 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
);
}

if (SettingsStatus.removePremiumUpsell) {
adsPrefs.addPreference(
switchPreference(
strRemoveRes("piko_pref_hide_premium_upsell"),
strRes("piko_pref_hide_premium_upsell_desc"),
Settings.ADS_REMOVE_PREMIUM_UPSELL
)
);
}

if (SettingsStatus.deleteFromDb) {
adsPrefs.addPreference(
buttonPreference(
Expand All @@ -220,7 +239,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (SettingsStatus.enableFontMod) {
miscPrefs.addPreference(
switchPreference(
strRes("piko_pref_chirp_font"),
strEnableRes("piko_pref_chirp_font"),
"",
Settings.MISC_FONT
)
Expand Down Expand Up @@ -298,7 +317,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (SettingsStatus.enableDebugMenu) {
miscPrefs.addPreference(
switchPreference(
strRes("piko_pref_debug_menu"),
strEnableRes("piko_pref_debug_menu"),
"",
Settings.MISC_DEBUG_MENU
)
Expand Down Expand Up @@ -467,7 +486,15 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
)
);
}

if (SettingsStatus.enableVidAutoAdvance) {
timelinePrefs.addPreference(
switchPreference(
strEnableRes("piko_pref_enable_vid_auto_advance"),
strRes("piko_pref_enable_vid_auto_advance_desc"),
Settings.TIMELINE_ENABLE_VID_AUTO_ADVANCE
)
);
}
if (SettingsStatus.hideHiddenReplies) {
timelinePrefs.addPreference(
switchPreference(
Expand All @@ -486,7 +513,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
LegacyTwitterPreferenceCategory backupPref = preferenceCategory(strRes("piko_title_backup"), screen);
backupPref.addPreference(
buttonPreference(
StringRef.str("piko_pref_export",strRes("settings_notification_pref_item_title")),
StringRef.str("piko_pref_export",strRes("piko_name"))+" "+strRes("settings_notification_pref_item_title"),
"",
Settings.EXPORT_PREF.key
)
Expand All @@ -498,9 +525,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
Settings.EXPORT_FLAGS.key
)
);

backupPref.addPreference(
buttonPreference(
StringRef.str("piko_pref_import",strRes("settings_notification_pref_item_title")),
StringRef.str("piko_pref_import",strRes("piko_name"))+" "+strRes("settings_notification_pref_item_title"),
strRes("piko_pref_app_restart_rec"),
Settings.IMPORT_PREF.key
)
Expand All @@ -515,7 +543,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

backupPref.addPreference(
buttonPreference(
strRes("delete")+": "+strRes("settings_notification_pref_item_title"),
strRes("delete")+": "+strRes("piko_name")+" "+strRes("settings_notification_pref_item_title"),
"",
Settings.RESET_PREF.key
)
Expand Down Expand Up @@ -646,10 +674,10 @@ public boolean onPreferenceClick(Preference preference) {
app.revanced.integrations.twitter.Utils.startAppIconNNavIconActivity();
} else if (key.equals(Settings.MISC_FEATURE_FLAGS.key)) {
startFragment(new FeatureFlagsFragment());
} else if (key.equals(Settings.EXPORT_PREF.key)) {
startBackupFragment(new BackupPrefFragment(), false);
} else if (key.equals(Settings.EXPORT_FLAGS.key)) {
startBackupFragment(new BackupPrefFragment(), true);
} else if (key.equals(Settings.EXPORT_PREF.key)) {
startBackupFragment(new BackupPrefFragment(), false);
} else if (key.equals(Settings.IMPORT_PREF.key)) {
startBackupFragment(new RestorePrefFragment(), false);
} else if (key.equals(Settings.IMPORT_FLAGS.key)) {
Expand Down Expand Up @@ -714,6 +742,10 @@ private static String strRemoveRes(String tag) {
return StringRef.str("piko_pref_remove",strRes(tag));
}

private static String strEnableRes(String tag) {
return StringRef.str("piko_pref_enable",strRes(tag));
}

private static void setBooleanPerf(String key, Boolean val) {
app.revanced.integrations.twitter.Utils.setBooleanPerf(key, val);
}
Expand Down
Loading

0 comments on commit 3f17e81

Please sign in to comment.