diff --git a/app/src/main/java/app/revanced/integrations/twitter/Pref.java b/app/src/main/java/app/revanced/integrations/twitter/Pref.java index d4bbddb91c..3d81842531 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/Pref.java +++ b/app/src/main/java/app/revanced/integrations/twitter/Pref.java @@ -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; @@ -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); @@ -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); } diff --git a/app/src/main/java/app/revanced/integrations/twitter/Utils.java b/app/src/main/java/app/revanced/integrations/twitter/Utils.java index 72c79580cd..0603fa1402 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/Utils.java +++ b/app/src/main/java/app/revanced/integrations/twitter/Utils.java @@ -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); @@ -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)); diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/NativeDownloader.java b/app/src/main/java/app/revanced/integrations/twitter/patches/NativeDownloader.java index f13c89bd43..b76644c10e 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/NativeDownloader.java +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/NativeDownloader.java @@ -245,7 +245,7 @@ public static void downloader(Context ctx,Object t57){ } if (mediaData.size()==1) { - downloadMedia(fileName, mediaData); + downloadMedia(fileName, mediaData,-1); return; } @@ -277,23 +277,14 @@ public void onClick(DialogInterface dialogInterface, int which) { ArrayList mData = new ArrayList(); HashMap 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 mData = new ArrayList<>(); - HashMap media = mediaData.get(i); - mData.add(media); - downloadMedia(filename+"_"+(++i),mData); - } - - } + downloadMedia(filename,mediaData,0); dialogInterface.dismiss(); } }); @@ -303,7 +294,7 @@ public void onClick(DialogInterface dialogInterface, int index) { //endfunc } - private static void downloadMedia(String filename,ArrayList mediaData){ + private static void downloadMedia(String filename,ArrayList mediaData,int pos){ try{ Utils.toast(strRes("download_started")); int n = mediaData.size(); @@ -311,11 +302,13 @@ private static void downloadMedia(String filename,ArrayList mediaData){ HashMap 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()); diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java b/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java index 70dfe03676..99537456b1 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java @@ -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); @@ -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"); diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsAboutFragment.java b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsAboutFragment.java index 3737b957cd..0496aedeb2 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsAboutFragment.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsAboutFragment.java @@ -55,8 +55,9 @@ public void onCreate(@org.jetbrains.annotations.Nullable Bundle savedInstanceSta ); TreeMap 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); @@ -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); @@ -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); @@ -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)); + } } \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsFragment.java b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsFragment.java index 1d277dfb1c..989365e189 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsFragment.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsFragment.java @@ -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 ) @@ -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 ) @@ -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 @@ -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( @@ -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 ) @@ -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 ) @@ -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( @@ -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 ) @@ -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 ) @@ -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 ) @@ -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)) { @@ -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); } diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java index 13a091e8a0..3b3ecc68cb 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java @@ -32,12 +32,15 @@ public class SettingsStatus { public static boolean hideRPinnedPosts = false; public static boolean hidePremiumPrompt = false; public static boolean hideHiddenReplies = false; + public static boolean removePremiumUpsell = false; public static boolean enableReaderMode = false; public static boolean enableUndoPosts = false; public static boolean customAppIcon = false; + public static boolean enableForcePip = false; public static boolean hideImmersivePlayer = false; + public static boolean enableVidAutoAdvance = false; public static boolean profileTabCustomisation = false; public static boolean timelineTabCustomisation = false; @@ -54,6 +57,8 @@ public class SettingsStatus { public static boolean deleteFromDb = false; public static boolean nativeDownloader = false; + public static void removePremiumUpsell() { removePremiumUpsell = true; } + public static void enableVidAutoAdvance() { enableVidAutoAdvance = true; } public static void nativeDownloader() { nativeDownloader = true; } public static void deleteFromDb() { deleteFromDb = true; } public static void cleartrackingparams() { cleartrackingparams = true; } @@ -100,6 +105,7 @@ public class SettingsStatus { public static void enableReaderMode() { enableReaderMode = true; } public static void enableUndoPosts() { enableUndoPosts = true; } public static void customAppIcon() { customAppIcon = true; } + public static void enableForcePip() { enableForcePip = true; } public static void hideImmersivePlayer() { hideImmersivePlayer = true; } public static void profileTabCustomisation() { profileTabCustomisation = true; } @@ -108,12 +114,12 @@ public class SettingsStatus { public static void navBarCustomisation() { navBarCustomisation = true; } public static void inlineBarCustomisation() { inlineBarCustomisation = true; } - public static boolean enableTimelineSection(){ return (inlineBarCustomisation || navBarCustomisation || disableAutoTimelineScroll || forceTranslate || hidePromoteButton || hideCommunityNote|| hideLiveThreads || hideBanner || hideInlineBmk || showPollResultsEnabled || hideImmersivePlayer); } + public static boolean enableTimelineSection(){ return (inlineBarCustomisation || navBarCustomisation || disableAutoTimelineScroll || forceTranslate || hidePromoteButton || hideCommunityNote|| hideLiveThreads || hideBanner || hideInlineBmk || showPollResultsEnabled || hideImmersivePlayer || enableVidAutoAdvance); } public static boolean enableMiscSection() { return (roundOffNumbers || enableFontMod || hideRecommendedUsers || hideFAB || hideViewCount || customSharingDomainEnabled || hideFABBtns); } - public static boolean enableAdsSection() {return (hideAds|| hideGAds || hideWTF || hideCTS || hideCTJ || hideDetailedPosts || hideRBMK ||hidePromotedTrend); } + public static boolean enableAdsSection() {return (hideAds|| hideGAds || hideWTF || hideCTS || hideCTJ || hideDetailedPosts || hideRBMK ||hidePromotedTrend || removePremiumUpsell); } public static boolean enableDownloadSection() {return (nativeDownloader || changeDownloadEnabled || mediaLinkHandle); } - public static boolean enablePremiumSection() {return (enableReaderMode || enableUndoPosts || customAppIcon); } + public static boolean enablePremiumSection() {return (enableReaderMode || enableUndoPosts || customAppIcon || enableForcePip); } public static boolean enableCustomisationSection() {return (navBarCustomisation || sideBarCustomisation || profileTabCustomisation || timelineTabCustomisation); } public static void load() {}