Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
gzip decompressing
test list getter
  • Loading branch information
gdlbo committed Jan 31, 2024
1 parent 3b834c2 commit 7728ea9
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/ru/vtosters/hooks/AdBlockHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.utils.NewsFeedFiltersUtils;
import ru.vtosters.lite.utils.newsfeed.NewsFeedFiltersUtils;

public class AdBlockHook {
public static JSONObject discoverInject(JSONObject json) throws JSONException {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ru/vtosters/hooks/JsonInjectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.utils.FriendsCatalogUtils;
import ru.vtosters.lite.utils.NewsFeedFiltersUtils;
import ru.vtosters.lite.utils.newsfeed.NewsFeedFiltersUtils;
import ru.vtosters.lite.utils.OnlineBypass;
import ru.vtosters.lite.utils.SuperAppUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import static ru.vtosters.hooks.other.Preferences.checkupdates;
import static ru.vtosters.lite.utils.CacheUtils.getInstance;
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
import static ru.vtosters.lite.utils.newsfeed.NewsFeedFiltersUtils.setupFilters;

public class MainActivityInjector {
public static void inject(Activity activity) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ru/vtosters/hooks/other/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ru.vtosters.lite.proxy.ProxyUtils;
import ru.vtosters.lite.ui.fragments.VTSettings;
import ru.vtosters.lite.utils.*;
import ru.vtosters.lite.utils.newsfeed.NewsFeedFiltersUtils;

import java.security.NoSuchAlgorithmException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import com.vtosters.lite.ui.SummaryListPreference;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.ui.components.NewsfeedListManager;
import ru.vtosters.lite.utils.newsfeed.Filters;
import ru.vtosters.lite.utils.NavigatorUtils;
import ru.vtosters.lite.utils.NewsFeedFiltersUtils;
import ru.vtosters.lite.utils.newsfeed.NewsFeedFiltersUtils;
import ru.vtosters.lite.utils.newsfeed.UpdatableFilters;

import java.util.ArrayList;
import java.util.Objects;

import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
Expand Down Expand Up @@ -75,6 +78,19 @@ private void prefs() {
return true;
});

findPreference("getlists").setOnPreferenceClickListener(preference -> {
ArrayList<Filters> lists = UpdatableFilters.getLists();

StringBuilder str = new StringBuilder().append("Filters ids: ");

for (var filter : lists) {
str.append(filter.getId()).append(", ");
}

sendToast(str.toString());
return true;
});

findPreference("whitelisted_filters_groups").setOnPreferenceClickListener(preference -> {
remdialog("whitelisted_filters_groups", getContext());
return true;
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/ru/vtosters/lite/utils/GzipDecompressor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.vtosters.lite.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

public class GzipDecompressor {
public static String decompress(byte[] compressedData) throws IOException {
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(compressedData);
GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {

byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = gzipInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}

return outputStream.toString();
}
}
}
57 changes: 57 additions & 0 deletions app/src/main/java/ru/vtosters/lite/utils/newsfeed/Filters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ru.vtosters.lite.utils.newsfeed;

public class Filters {
int id;
String title;
String summary;
String version;
String link;

public Filters(int id, String title, String summary, String version, String link) {
this.id = id;
this.title = title;
this.summary = summary;
this.version = version;
this.link = link;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getSummary() {
return summary;
}

public void setSummary(String summary) {
this.summary = summary;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getLink() {
return link;
}

public void setLink(String link) {
this.link = link;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ru.vtosters.lite.utils;
package ru.vtosters.lite.utils.newsfeed;

import android.text.TextUtils;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.utils.AccountManagerUtils;

import java.io.IOException;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ru.vtosters.lite.utils.newsfeed;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.utils.GzipDecompressor;

import java.io.IOException;
import java.util.ArrayList;

public class UpdatableFilters {
private static final String URL = "https://adlist.vtosters.app/v1/";
private static final OkHttpClient client = VtOkHttpClient.getInstance();

public static ArrayList<Filters> getLists() {
Request request = new Request.a()
.b(URL + "lists/get")
.a("Content-Type", "application/json")
.a("Accept-Encoding", "gzip")
.a();

ArrayList<Filters> filters = new ArrayList<>();

try (Response resp = client.a(request).execute()) {
JSONArray jsonArray = new JSONArray(GzipDecompressor.decompress(resp.a().b()));

for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);

int id = jsonObject.getInt("id");
String title = jsonObject.getString("title");
String summary = jsonObject.getString("summary");
String version = jsonObject.getString("version");
String link = jsonObject.getString("link");

Filters filter = new Filters(id, title, summary, version, link);

filters.add(filter);
}
} catch (JSONException | IOException e) {
e.printStackTrace();
}

return filters;
}
}
3 changes: 3 additions & 0 deletions smali/res/xml/preferences_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<Preference
android:key="whitelisted_ad_groups"
android:title="@string/whitelisted_ad_groups_title"/>
<Preference
android:key="getlists"
android:title="Получить рекламные фильтры (тест)"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/stories">
<com.vtosters.lite.ui.MaterialSwitchPreference
Expand Down

0 comments on commit 7728ea9

Please sign in to comment.