Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/src/main/java/app/revanced/integrations/twitter/Pref.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

@SuppressWarnings("unused")
public class Pref {
public static boolean ROUND_OFF_NUMBERS,ENABLE_FORCE_HD;
public static boolean ROUND_OFF_NUMBERS,ENABLE_FORCE_HD, HIDE_COMM_BADGE;
public static float POST_FONT_SIZE;
static{
ROUND_OFF_NUMBERS = isRoundOffNumbersEnabled();
ENABLE_FORCE_HD = enableForceHD();
POST_FONT_SIZE = setPostFontSize();
HIDE_COMM_BADGE = hideCommBadge();
}
public static float setPostFontSize() {
Float fontSize = 0.0f;
Expand All @@ -23,6 +24,16 @@ public static float setPostFontSize() {
}
return fontSize;
}
public static boolean serverResponseLogging() {
return Utils.getBooleanPerf(Settings.LOG_RES);
}
public static boolean serverResponseLoggingOverwriteFile() {
return Utils.getBooleanPerf(Settings.LOG_RES_OVRD);
}
public static boolean hideCommBadge() {
return Utils.getBooleanPerf(Settings.TIMELINE_HIDE_COMM_BADGE);
}

public static boolean showSensitiveMedia() {
return Utils.getBooleanPerf(Settings.TIMELINE_SHOW_SENSITIVE_MEDIA);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package app.revanced.integrations.twitter.patches.loggers;

import java.io.File;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import android.os.Environment;

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

public class ResponseLogger {
private static boolean LOG_RES;
static{
LOG_RES = Pref.serverResponseLogging();
if(Pref.serverResponseLoggingOverwriteFile()){
writeFile("".getBytes(),false);
// Utils.logger("Cleared response log file!!!");
}
}

public static InputStream saveInputStream(InputStream inputStream) throws Exception {
if(!LOG_RES) return inputStream;

StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
sb.append("\n");
inputStream.close();
byte[] contentBytes = sb.toString().getBytes();
if(!(sb.indexOf("session_token") == 2 || sb.indexOf("guest_token") == 2)){
writeFile(contentBytes,true);
}

return new ByteArrayInputStream(contentBytes);
}

private static boolean writeFile(byte[] data,boolean append){
try {
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File pikoDir = new File(downloadsDir, "Piko");

if (!pikoDir.exists()) {
pikoDir.mkdirs();
}

File outputFile = new File(pikoDir, "Server-Response-Log.txt");

FileOutputStream outputStream = new FileOutputStream(outputFile, append);
outputStream.write(data);
outputStream.close();
return true;
}catch (Exception e){
Utils.logger(e.toString());
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,43 @@ public void buildTimelineSection(boolean buildCategory){
)
);
}
if (SettingsStatus.hideCommBadge) {
addPreference(category,
helper.switchPreference(
strRes("piko_pref_hide_community_badge"),
"",
Settings.TIMELINE_HIDE_COMM_BADGE
)
);
}
}

public void buildLoggingSection(boolean buildCategory) {
LegacyTwitterPreferenceCategory category = null;
if (buildCategory)
category = preferenceCategory(strRes("piko_title_logging"));

if (SettingsStatus.serverResponseLogging) {
addPreference(category,
helper.switchPreference(
strRes("piko_pref_server_response_logging"),
strRes("piko_pref_server_response_logging_desc"),
Settings.LOG_RES
)
);
}

if (SettingsStatus.serverResponseLoggingOverwriteFile) {
addPreference(category,
helper.switchPreference(
strRes("piko_pref_server_response_logging_file_overwrite"),
strRes("piko_pref_server_response_logging_file_overwrite_desc"),
Settings.LOG_RES_OVRD
)
);
}

}
public void buildExportSection(boolean buildCategory){
LegacyTwitterPreferenceCategory category = null;
if(buildCategory)
Expand Down Expand Up @@ -924,6 +959,17 @@ public void buildSinglePageSettings(){
)
);
}

if (SettingsStatus.loggingSection()) {
addPreference(
helper.buttonPreference(
strRes("piko_title_logging"),
"",
Settings.LOGGING_SECTION,
"ic_vector_bug_stroke",null
)
);
}

addPreference(
helper.buttonPreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting TIMELINE_ENABLE_VID_FORCE_HD = new BooleanSetting("timeline_enable_vid_force_hd", true);
public static final BooleanSetting TIMELINE_HIDE_NUDGE_BUTTON = new BooleanSetting("timeline_hide_nudge_button", false);
public static final BooleanSetting TIMELINE_SHOW_SENSITIVE_MEDIA = new BooleanSetting("timeline_show_sensitive_media", true);
public static final BooleanSetting TIMELINE_HIDE_COMM_BADGE = new BooleanSetting("timeline_hide_community_badge", false);

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);
Expand All @@ -83,6 +84,9 @@ public class Settings extends BaseSettings {
public static final StringSetting CUSTOM_SEARCH_TYPE_AHEAD = new StringSetting("customisation_search_type_ahead", "");
public static final StringSetting CUSTOM_POST_FONT_SIZE = new StringSetting("customisation_post_font_size", String.valueOf(Utils.getResourceDimension("font_size_normal")));

public static final BooleanSetting LOG_RES = new BooleanSetting("logging_response", false);
public static final BooleanSetting LOG_RES_OVRD = new BooleanSetting("logging_response_overwrite_file", false);

public static final BooleanSetting EXPORT_PREF = new BooleanSetting("export_pref", true);
public static final BooleanSetting EXPORT_FLAGS = new BooleanSetting("export_flags", true);
public static final BooleanSetting IMPORT_PREF = new BooleanSetting("import_pref", true);
Expand All @@ -99,6 +103,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting MISC_SECTION = new BooleanSetting("misc_section", true);
public static final BooleanSetting CUSTOMISE_SECTION = new BooleanSetting("custommise_section", true);
public static final BooleanSetting TIMELINE_SECTION = new BooleanSetting("timeline_section", true);
public static final BooleanSetting LOGGING_SECTION = new BooleanSetting("logging_section", true);
public static final BooleanSetting BACKUP_SECTION = new BooleanSetting("backup_section", true);
public static final BooleanSetting NATIVE_SECTION = new BooleanSetting("native_section", true);
public static final BooleanSetting SINGLE_PAGE_SETTINGS = new BooleanSetting("single_page_settings", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,19 @@ public class SettingsStatus {
public static boolean hideNudgeButton = false;
public static boolean hideSocialProof = false;
public static boolean customPostFontSize = false;
public static boolean hideCommBadge = false;
public static boolean serverResponseLogging = false;
public static boolean serverResponseLoggingOverwriteFile = false;

public static void serverResponseLogging() {
serverResponseLogging = true;
}
public static void serverResponseLoggingOverwriteFile() {
serverResponseLoggingOverwriteFile = true;
}
public static void hideCommBadge() {
hideCommBadge = true;
}
public static void customPostFontSize() {
customPostFontSize = true;
}
Expand Down Expand Up @@ -322,7 +334,7 @@ public static void typeaheadCustomisation() {
}

public static boolean enableTimelineSection() {
return ( showSensitiveMedia || hideNudgeButton || disableAutoTimelineScroll || forceTranslate || hidePromoteButton || hideCommunityNote || hideLiveThreads || hideBanner || hideInlineBmk || showPollResultsEnabled || hideImmersivePlayer || enableVidAutoAdvance || enableForceHD);
return ( hideCommBadge || showSensitiveMedia || hideNudgeButton || disableAutoTimelineScroll || forceTranslate || hidePromoteButton || hideCommunityNote || hideLiveThreads || hideBanner || hideInlineBmk || showPollResultsEnabled || hideImmersivePlayer || enableVidAutoAdvance || enableForceHD);
}

public static boolean enableMiscSection() {
Expand All @@ -348,6 +360,9 @@ public static boolean enablePremiumSection() {
public static boolean enableCustomisationSection() {
return (searchTabCustomisation || typeaheadCustomisation || exploreTabCustomisation || customPostFontSize || inlineBarCustomisation || navBarCustomisation || sideBarCustomisation || profileTabCustomisation || timelineTabCustomisation || defaultReplySortFilter);
}
public static boolean loggingSection() {
return (serverResponseLogging || serverResponseLoggingOverwriteFile);
}

public static void load() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}else if (bundle.getBoolean(Settings.NATIVE_SECTION.key, false)) {
screenBuilder.buildNativeSection(false);
toolbarText = "piko_title_native";
}else if (bundle.getBoolean(Settings.LOGGING_SECTION.key, false)) {
screenBuilder.buildLoggingSection(false);
toolbarText = "piko_title_logging";
}

ActivityHook.toolbar.setTitle(StringRef.str(toolbarText));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ public void onCreate(@org.jetbrains.annotations.Nullable Bundle savedInstanceSta
flags.put(strEnableRes("piko_pref_force_hd"),SettingsStatus.enableForceHD);
flags.put(strRes("piko_pref_hide_nudge_button"),SettingsStatus.hideNudgeButton);
flags.put(strRes("piko_pref_hide_social_proof"),SettingsStatus.hideSocialProof);
flags.put(strRes("piko_pref_hide_community_badge"),SettingsStatus.hideCommBadge);
flags.put(strRes("piko_title_native_translator"),SettingsStatus.nativeTranslator);
flags.put(strRes("piko_pref_customisation_post_font_size"),SettingsStatus.customPostFontSize);
flags.put(strRemoveRes("piko_pref_top_people_search"),SettingsStatus.hideTopPeopleSearch);
flags.put(strRes("piko_pref_customisation_searchtabs"),SettingsStatus.searchTabCustomisation);
flags.put(strRemoveRes("piko_pref_hide_todays_news"),SettingsStatus.hideTodaysNews);
flags.put(strRemoveRes("piko_pref_server_response_logging"),SettingsStatus.serverResponseLogging);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
screenBuilder.buildMiscSection(buildCategory);
screenBuilder.buildCustomiseSection(buildCategory);
screenBuilder.buildTimelineSection(buildCategory);
screenBuilder.buildLoggingSection(buildCategory);
screenBuilder.buildExportSection(buildCategory);
screenBuilder.buildPikoSection(buildCategory);

Expand Down
Loading