added offline and news injector

This commit is contained in:
gdlbo
2022-06-22 16:41:41 +03:00
parent 8694d39dcb
commit d14f9a7a4d
25 changed files with 200 additions and 101 deletions
@@ -18,6 +18,7 @@ import static ru.vtosters.lite.utils.Preferences.hasSpecialVerif;
import static ru.vtosters.lite.utils.Preferences.isValidSignature;
import static ru.vtosters.lite.utils.Preferences.navbar;
import static ru.vtosters.lite.utils.Preferences.offline;
import static ru.vtosters.lite.utils.Preferences.preferences;
import static ru.vtosters.lite.utils.Preferences.shortinfo;
import static ru.vtosters.lite.utils.Preferences.vkme;
import static ru.vtosters.lite.utils.Themes.applyTheme;
@@ -66,11 +67,6 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
String keyVKAccount = getCurrentAccount().getString("key_vk_account", "");
String avatarUrl = withRegex(keyVKAccount, ".*\"photo\":\\{.*?:\"(.*?)\"\\}.*", "https://vk.com/images/camera_200.png").replace("\\/", "/");
String name = withRegex(keyVKAccount, ".*\"name\":\\{.*?:\"(.*?)\"\\}.*", "");
String id = "@id" + getUserId();
String feedsumm = getValAsString("vtlfeedsumm", ads());
String docksumm = getDocksumm();
String musicsumm = getValAsString("vtlmusicsumm", isIntegrationEnabled());
@@ -87,26 +83,11 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
int vtosterXml = getIdentifier("empty", "xml");
this.addPreferencesFromResource(vtosterXml);
if (vkme()) {
PreferencesUtil.addPreferenceDrawable(this, "", name, id, drawableFromUrl(avatarUrl), preference -> {
Context context = getContext();
Intent a2 = new Navigator(SettingsAccountFragment.class).b(context);
context.startActivity(a2);
return false;
});
} else {
PreferencesUtil.addPreferenceCategory(this, Globals.getString("vtsettdarktheme"));
}
PreferencesUtil.addPreferenceCategory(this, Globals.getString("vtsettdarktheme"));
PreferencesUtil.addMaterialSwitchPreference(this, "isdark", Globals.getString("vtsettdarktheme"), "", "ic_palette_24", false, (preference, o) -> {
boolean value = (boolean) o;
if(value){
applyTheme(getLightTheme());
} else {
applyTheme(getDarkTheme());
}
edit().putBoolean("isdark", value).commit();
setTheme(this.getActivity());
@@ -356,6 +337,11 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
}
}
@Override
public void onResume() {
super.onResume();
}
public static String getValAsString(String stringid, Boolean value) {
if(disableSettingsSumms()) return "";
@@ -4,7 +4,7 @@ import static java.lang.Long.MAX_VALUE;
import static ru.vtosters.lite.ui.fragments.dockbar.DockBarManager.getInstance;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Preferences.CommentsSort;
import static ru.vtosters.lite.utils.Globals.sendToast;
import static ru.vtosters.lite.utils.Preferences.adsgroup;
import static ru.vtosters.lite.utils.Preferences.adsstories;
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
@@ -38,6 +38,7 @@ import com.vtosters.lite.fragments.y2.VideosFragment;
import com.vtosters.lite.general.fragments.GamesFragment;
import com.vtosters.lite.general.fragments.PhotosFragment;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -51,15 +52,15 @@ import java.util.List;
public class Newsfeed {
public static List<String> mFilters;
public static boolean isBlockedByFilter(String str) {
public static boolean isBlockedByFilter(String str){
for (String str2 : mFilters) {
if (str.toLowerCase().contains(str2.toLowerCase())) return true;
if(str.toLowerCase().contains(str2.toLowerCase())) return true;
}
return false;
}
public static void setupFilters() {
mFilters = new ArrayList();
public static void setupFilters(){
mFilters=new ArrayList();
getFilter("refsfilter", "Referals.txt");
getFilter("shortlinkfilter", "LinkShorter.txt");
@@ -68,19 +69,19 @@ public class Newsfeed {
String customfilters = getPrefsValue("spamfilters");
if (!customfilters.isEmpty()) {
if(!customfilters.isEmpty()){
mFilters.addAll(Arrays.asList(customfilters.split(", ")));
}
}
public static void getFilter(String boolname, String filename) {
if (getBoolValue(boolname, true)) {
public static void getFilter(String boolname, String filename){
if(getBoolValue(boolname, true)){
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getContext().getAssets().open(filename)));
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(getContext().getAssets().open(filename)));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
String readLine=bufferedReader.readLine();
if(readLine != null){
mFilters.add(readLine);
} else {
bufferedReader.close();
@@ -93,90 +94,115 @@ public class Newsfeed {
}
} // Get needed filter list from assets
public static boolean injectFilters(JSONObject jSONObject) {
String optString = jSONObject.optString(NavigatorKeys.e, "");
if (!ads(optString) && !checkCopyright(optString) && !authors_rec(optString) && !recomm(optString) && !friendrecomm(optString)) {
String optString2 = jSONObject.optString("post_type", "");
if (!ads(optString2) && !authors_rec(optString2) && !recomm(optString2) && !friendrecomm(optString2)) {
String optString3 = jSONObject.optString("filters", "");
if (ads(optString3) || authors_rec(optString3) || recomm(optString3) || friendrecomm(optString3) || isBlockedByFilter(jSONObject.optString(NavigatorKeys.h0, "")) || captions(jSONObject)) {
return false;
}
return !AD(jSONObject);
public static boolean injectFilters(JSONObject obj) throws JSONException{
String optString = obj.optString("type", "");
if(isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString) || isRecomsGroup(optString) || isMusicBlock(optString) || isNewsBlock(optString)){
return false;
}
optString = obj.optString("post_type", "");
if(isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString) || isMusicBlock(optString) || isNewsBlock(optString)){
return false;
}
optString = obj.optString("filters", "");
if(isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString)) {
return false;
}
checkCopyright(obj);
optString = obj.optString("text", "");
if(isBadNew(optString)) return false;
if(checkCaption(obj)) return false;
return !isGroupAds(obj);
}
private static boolean checkCopyright(JSONObject json) throws JSONException{
if(json.opt("copyright") != null) {
JSONObject copyright = json.getJSONObject("copyright");
String copyrightlink = copyright.getString("link");
return !copyrightlink.contains("vk.com") || !copyright_post(); // fuck you, it doesn't work to detect link value
}
return true;
}
private static boolean isRecomsGroup(String src){
return src.equals("recommended_groups") && authorsrecomm();
}
private static boolean isMusicBlock(String src){
return (src.equals("recommended_audios") || src.equals("recommended_artists") || src.equals("recommended_playlists")) && authorsrecomm();
}
private static boolean isNewsBlock(String src){
return (src.equals("tags_suggestions")) && Preferences.ads();
}
public static String getAllFilters(){
return getPrefsValue("spamfilters");
}
public static boolean isBadNew(String text){
for (String filter : mFilters) {
if(text.toLowerCase().contains(filter.toLowerCase())){
return true;
}
}
return false;
} // json newsfeed/posts injector to detect and delete posts
public static boolean authors_rec(String str) {
return str.equals("authors_rec") && authorsrecomm();
}
public static boolean captions(JSONObject jSONObject) {
public static boolean checkCaption(JSONObject postJson){
try {
JSONObject jSONObject2 = jSONObject.getJSONObject("caption");
if (Preferences.captions()) {
JSONObject captionJson = postJson.getJSONObject("caption");
if(Preferences.captions())
return true;
}
return (jSONObject2.getString(NavigatorKeys.e).equals("explorebait") && postsrecomm()) || ((jSONObject2.getString(NavigatorKeys.e).equals("shared") && postsrecomm()) || ((jSONObject.getString(NavigatorKeys.e).equals("digest") && postsrecomm()) || ((jSONObject2.getString(NavigatorKeys.e).equals("commented") && postsrecomm()) || (jSONObject2.getString(NavigatorKeys.e).equals("voted") && postsrecomm()))));
} catch (JSONException unused) {
boolean postAds = postsrecomm();
return (captionJson.getString("type").equals("explorebait") && postAds) || // Может быть интересно
(captionJson.getString("type").equals("shared") && postAds) || // Поделился записью
(postJson.getString("type").equals("digest") && postAds) || // Рекомедации
(captionJson.getString("type").equals("commented") && postAds) || // Комментирует
(captionJson.getString("type").equals("voted") && postAds); // Проголосовал в опросе
} catch (JSONException e) {
return false;
}
}
public static boolean ads(String str) {
if ((str.equals("ads_easy_promote") || str.equals("promo_button") || str.equals("app_widget") || str.equals("ads")) && Preferences.ads()) {
return true;
}
return false;
public static boolean isAds(String optString){
return (optString.equals("ads_easy_promote") ||
optString.equals("promo_button") ||
optString.equals("app_widget") ||
optString.equals("ads")) && Preferences.ads();
}
public static boolean recomm(String str) {
return (str.equals("user_rec") || str.equals("live_recommended") || str.equals("inline_user_rec")) && postsrecomm();
public static boolean isAuthorRecommendations(String optString){
return optString.equals("authors_rec") && authorsrecomm();
}
public static boolean friendrecomm(String str) {
return str.equals("friends_recommendations") && friendsrecomm();
public static boolean isPostRecommendations(String optString){
return (optString.equals("live_recommended") ||
optString.equals("inline_user_rec")) && postsrecomm();
}
public static boolean AD(JSONObject jSONObject) {
return jSONObject.optInt("marked_as_ads", 0) == 1 && adsgroup();
public static boolean isFriendsRecommendations(String optString){
return (optString.equals("user_rec") ||
optString.equals("friends_recommendations") ||
optString.equals("friends_recomm")) && friendsrecomm();
}
public static boolean checkCopyright(String str) {
return str.equals("copyright") && copyright_post();
public static boolean isGroupAds(JSONObject obj){
return (obj.optInt("marked_as_ads", 0) == 1) && adsgroup();
}
public static String friendsads() {
return postsrecomm() ? "null" : "user_rec";
}
public static String getFriendRecomm() {
return friendsrecomm() ? "null" : "friends_recommendations";
}
public static String authorsads() {
return authorsrecomm() ? "null" : "authors_rec";
}
public static String widgetads() {
return Preferences.ads() ? "null" : "app_widget";
}
public static String promoads() {
return Preferences.ads() ? "null" : "promo_button";
}
public static String storyads() {
public static String storyads(){
return adsstories() ? "null" : "ads";
}
public static String getCommentsSort(int value) {
return !CommentsSort() && value == 2 || value == 1 ? "desc" : "asc";
}
public static long getUpdateNewsfeed(boolean refresh_timeout) {
if (vkme()) {
public static long getUpdateNewsfeed(boolean refresh_timeout){
if(vkme()){
return MAX_VALUE;
}
switch (getPrefsValue("newsupdate")) {
@@ -189,8 +215,8 @@ public class Newsfeed {
}
}
public static Class getStartFragment() {
if (vkme()) {
public static Class getStartFragment(){
if(vkme()){
return DialogsFragment.class;
}
switch (getPrefsValue("start_values")) {
+4 -4
View File
@@ -1,12 +1,12 @@
VERSION_BUILD=fb8252e
VERSION_BUILD=68c3619
VERSION_BRANCH=vtl-remaster
VERSION_BASE=
VERSION_BRANCHID=vtl-remaster
VERSION_BRANCHTYPE=vtl-remaster
VERSION_COMMIT=fb8252eebe32850caeac8a25e2273ce785c37f31
VERSION_COMMIT=68c3619f7f4404af65f67e02dae2c13a21c48736
VERSION_GRADLE=
VERSION_DISPLAY=vtl-remaster-fb8252e-dirty
VERSION_FULL=vtl-remaster-fb8252e-dirty
VERSION_DISPLAY=vtl-remaster-68c3619-dirty
VERSION_FULL=vtl-remaster-68c3619-dirty
VERSION_SCM=git
VERSION_TAG=
VERSION_LAST_TAG=v0.2.9-beta2
@@ -100,6 +100,8 @@
invoke-virtual {v0, p1}, Lcom/vk/api/voip/VoipGetLongPollServer$a;->b(Ljava/lang/String;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object v0
.end method
@@ -78,6 +78,8 @@
check-cast p1, Ljava/lang/Integer;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -97,6 +97,8 @@
check-cast p1, Lcom/vk/im/engine/models/chats/ChatPreview;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -178,6 +178,8 @@
.line 13
invoke-virtual {p1, p2}, Lcom/vk/api/sdk/VKApiManager;->a(Lcom/vk/api/sdk/VKMethodCall;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
.end method
@@ -90,6 +90,8 @@
move-result-object p1
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -151,6 +151,8 @@
goto :goto_0
:cond_1
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object v0
.end method
@@ -178,6 +178,8 @@
goto :goto_0
:cond_1
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object v0
.end method
@@ -305,6 +305,8 @@
check-cast p1, Lcom/vk/im/engine/internal/api_commands/messages/MessagesGetConversationsApiCmd$b;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -122,6 +122,8 @@
check-cast p1, Lcom/vk/im/engine/internal/api_commands/messages/MessagesGetConversationsByIdApiCmd$b;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -354,6 +354,8 @@
.line 20
invoke-direct/range {v4 .. v9}, Lcom/vk/im/engine/internal/api_commands/messages/MessagesGetHistoryApiCmd$e;-><init>(Lcom/vk/im/engine/models/dialogs/DialogApiModel;Ljava/util/List;ZZLcom/vk/im/engine/models/ProfilesSimpleInfo;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object v0
.end method
@@ -496,6 +498,8 @@
.line 18
invoke-direct/range {v0 .. v5}, Lcom/vk/im/engine/internal/api_commands/messages/MessagesGetHistoryApiCmd$e;-><init>(Lcom/vk/im/engine/models/dialogs/DialogApiModel;Ljava/util/List;ZZLcom/vk/im/engine/models/ProfilesSimpleInfo;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object v6
.end method
@@ -659,6 +663,8 @@
.line 19
invoke-direct/range {v4 .. v9}, Lcom/vk/im/engine/internal/api_commands/messages/MessagesGetHistoryApiCmd$e;-><init>(Lcom/vk/im/engine/models/dialogs/DialogApiModel;Ljava/util/List;ZZLcom/vk/im/engine/models/ProfilesSimpleInfo;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object v0
.end method
@@ -94,6 +94,8 @@
move-result-object p1
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -827,6 +827,8 @@
check-cast p1, Ljava/lang/Integer;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -106,5 +106,7 @@
check-cast p1, Ljava/lang/String;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -112,6 +112,8 @@
move-result-object p1
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-object p1
.end method
@@ -292,6 +292,8 @@
invoke-virtual {p1, p2}, Lcom/vk/api/sdk/VKApiManager;->a(Lcom/vk/api/sdk/VKMethodCall;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
.end method
@@ -170,6 +170,8 @@
invoke-virtual {p1, p2}, Lcom/vk/api/sdk/VKApiManager;->a(Lcom/vk/api/sdk/VKMethodCall;)V
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
.end method
@@ -2657,6 +2657,8 @@
invoke-virtual {p0, p1}, Lcom/vk/newsfeed/EntriesListFragment;->a(Lio/reactivex/disposables/Disposable;)V
:cond_0
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
.end method
@@ -147,6 +147,8 @@
invoke-virtual {p0, p2, p1}, Lcom/vk/api/base/ApiRequest;->c(Ljava/lang/String;Ljava/lang/String;)Lcom/vk/api/base/ApiRequest;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
.end method
@@ -588,6 +588,8 @@
invoke-virtual {p0, v2, v1}, Lcom/vk/api/base/ApiRequest;->a(Ljava/lang/String;Z)Lcom/vk/api/base/ApiRequest;
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
.end method
@@ -635,7 +637,7 @@
.end method
.method private b(Lorg/json/JSONObject;)Lcom/vtosters/lite/api/newsfeed/NewsfeedGet$Response;
.locals 10
.locals 11
.annotation build Landroidx/annotation/Nullable;
.end annotation
@@ -764,10 +766,22 @@
invoke-virtual {v1, v5}, Lorg/json/JSONArray;->getJSONObject(I)Lorg/json/JSONObject;
move-result-object v2
invoke-static {v2}, Lru/vtosters/lite/utils/Newsfeed;->injectFilters(Lorg/json/JSONObject;)Z
move-result v10
if-nez v10, :cond_70
add-int/lit8 v5, v5, 0x1
goto :goto_2
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1
.line 39
:cond_70
:try_start_1
iget-object v3, p0, Lcom/vtosters/lite/api/newsfeed/NewsfeedGet;->H:Ljava/lang/String;
@@ -351,7 +351,7 @@
# virtual methods
.method public a(Lorg/json/JSONObject;)Lcom/vtosters/lite/api/wall/WallGet$Result;
.locals 10
.locals 11
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
@@ -534,10 +534,22 @@
invoke-virtual {p1, v4}, Lorg/json/JSONArray;->getJSONObject(I)Lorg/json/JSONObject;
move-result-object v8
invoke-static {v8}, Lru/vtosters/lite/utils/Newsfeed;->injectFilters(Lorg/json/JSONObject;)Z
move-result v10
if-nez v10, :cond_70
add-int/lit8 v4, v4, 0x1
goto :goto_2
:try_end_1
.catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_2
.line 21
:cond_70
:try_start_2
iget-object v9, p0, Lcom/vtosters/lite/api/wall/WallGet;->F:Ljava/lang/String;
@@ -51,7 +51,17 @@
.method public a(Lcom/vk/api/sdk/exceptions/VKApiExecutionException;)V
.locals 5
.line 4
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->offline()Z
move-result v2
if-nez v2, :cond_a
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
:cond_a
invoke-virtual {p1}, Lcom/vk/api/sdk/exceptions/VKApiExecutionException;->d()I
move-result v0
@@ -109,6 +109,17 @@
.line 2
:cond_0
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->offline()Z
move-result v2
if-nez v2, :cond_a
invoke-static {}, Lru/vtosters/lite/utils/Preferences;->forceOffline()V
return-void
:cond_a
invoke-static {}, Lcom/vk/core/preference/Preference;->b()Landroid/content/SharedPreferences;
move-result-object v0