Revert "added multithread download for some large methods"
This reverts commit 34a0615003.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package ru.vtosters.lite.downloaders.messages;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vtosters.lite.R;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -17,7 +18,6 @@ import ru.vtosters.lite.downloaders.messages.items.MiniUser;
|
||||
import ru.vtosters.lite.proxy.ProxyUtils;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -108,36 +108,38 @@ public class MessagesDownloader {
|
||||
var req = new Request.a()
|
||||
.b(url)
|
||||
.a();
|
||||
|
||||
try (Response response = VtOkHttpClient.getInstance().a(req).execute()) {
|
||||
File file = new File(AndroidUtils.getGlobalContext().getCacheDir(), "response" + "_user_list" + ".json");
|
||||
|
||||
try (BufferedSink sink = Okio.a(Okio.b(file))) {
|
||||
sink.a(response.a().f());
|
||||
VtOkHttpClient.getInstance().a(req).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("MessagesDownloader", String.valueOf(e));
|
||||
}
|
||||
|
||||
JSONObject obj = new JSONObject(IOUtils.readAllLines(file)).getJSONObject("response");
|
||||
@Override
|
||||
public void a(Call call, Response response)
|
||||
throws IOException {
|
||||
try {
|
||||
JSONObject obj = new JSONObject(response.a().g()).getJSONObject("response");
|
||||
|
||||
SparseArray<MiniUser> users = new SparseArray<>();
|
||||
parseUsers(users, obj.optJSONArray("profiles"), false);
|
||||
parseUsers(users, obj.optJSONArray("groups"), true);
|
||||
SparseArray<MiniUser> users = new SparseArray<>();
|
||||
parseUsers(users, obj.optJSONArray("profiles"), false);
|
||||
parseUsers(users, obj.optJSONArray("groups"), true);
|
||||
|
||||
List<MiniMsg> msgs = parseMessages(obj.getJSONArray("items"));
|
||||
List<MiniMsg> msgs = parseMessages(obj.getJSONArray("items"));
|
||||
|
||||
usersArray = users;
|
||||
usersArray = users;
|
||||
|
||||
fos.write(format.provideHeader("TODO", formatTime(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8));
|
||||
for (MiniMsg msg : msgs) {
|
||||
fos.write(format.provideMessage(msg, users.get(msg.fromId)).getBytes(StandardCharsets.UTF_8));
|
||||
fos.write(format.provideHeader("TODO", formatTime(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8));
|
||||
for (MiniMsg msg : msgs) {
|
||||
fos.write(format.provideMessage(msg, users.get(msg.fromId)).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
fos.write(format.provideDocumentEnd().getBytes(StandardCharsets.UTF_8));
|
||||
fos.close();
|
||||
ToastUtils.a(AndroidUtils.getString(R.string.saved_as) + " " + out.getAbsolutePath());
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
fos.write(format.provideDocumentEnd().getBytes(StandardCharsets.UTF_8));
|
||||
fos.close();
|
||||
ToastUtils.a(AndroidUtils.getString(R.string.saved_as) + " " + out.getAbsolutePath());
|
||||
|
||||
file.delete();
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<MiniMsg> parseMessages(JSONArray jsonArray) throws JSONException {
|
||||
|
||||
@@ -5,9 +5,6 @@ import com.vk.dto.music.MusicTrack;
|
||||
import java8.util.concurrent.CompletableFuture;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.music.converter.ts.FFMpeg;
|
||||
@@ -56,19 +53,13 @@ public class M3UDownloader implements ITrackDownloader {
|
||||
return;
|
||||
}
|
||||
|
||||
Request request = new Request.a().b(track.D).a();
|
||||
|
||||
try (Response response = client.a(request).execute()) {
|
||||
File file = new File(AndroidUtils.getGlobalContext().getCacheDir(), track.y1());
|
||||
|
||||
try (BufferedSink sink = Okio.a(Okio.b(file))) {
|
||||
sink.a(response.a().f());
|
||||
}
|
||||
|
||||
parse(IOUtils.readAllLines(file), outDir, callback, track, cache);
|
||||
file.delete();
|
||||
try {
|
||||
Request request = new Request.a().b(track.D).a();
|
||||
String response = client.a(request).execute().a().g();
|
||||
parse(response, outDir, callback, track, cache);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
callback.onFailure();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import android.util.Log;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
import ru.vtosters.lite.utils.NetworkUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -37,18 +35,21 @@ public class UsersList {
|
||||
.b(Utils.getDomain() + "/api/getUsersWithServiceDescriptionsAndBanners")
|
||||
.a();
|
||||
|
||||
try (Response response = VtOkHttpClient.getInstance().a(request).execute()) {
|
||||
File file = new File(AndroidUtils.getGlobalContext().getCacheDir(), "response" + "_user_list" + ".json");
|
||||
|
||||
try (BufferedSink sink = Okio.a(Okio.b(file))) {
|
||||
sink.a(response.a().f());
|
||||
VtOkHttpClient.getInstance().a(request).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
parseJson(new JSONObject(IOUtils.readAllLines(file)).getJSONObject("response"));
|
||||
file.delete();
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Override
|
||||
public void a(Call call, Response response) {
|
||||
try {
|
||||
parseJson(new JSONObject(response.a().g()).getJSONObject("response"));
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasDescription(int id) {
|
||||
|
||||
@@ -52,7 +52,6 @@ public class VTVerifications {
|
||||
prefs.edit()
|
||||
.putString("ids", r)
|
||||
.apply();
|
||||
file.delete();
|
||||
} catch (IOException e) {
|
||||
if (prefs.contains("ids")) parseJson(prefs.getString("ids", "[]"));
|
||||
Log.d("VTVerifications", e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user