-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gzip decompressing test list getter
- Loading branch information
Showing
10 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/ru/vtosters/lite/utils/GzipDecompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
app/src/main/java/ru/vtosters/lite/utils/newsfeed/Filters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...ters/lite/utils/NewsFeedFiltersUtils.java → .../utils/newsfeed/NewsFeedFiltersUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/java/ru/vtosters/lite/utils/newsfeed/UpdatableFilters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters