mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-06-03 00:58:06 -04:00
优化连接
This commit is contained in:
parent
299595bcad
commit
95afd4f57a
@ -32,7 +32,7 @@ public class HomeActivity extends BaseActivity{
|
|||||||
|
|
||||||
tvContiner = findViewById(R.id.tvItems);
|
tvContiner = findViewById(R.id.tvItems);
|
||||||
|
|
||||||
JfClient.init(this);
|
JfClient.init(getApplication());
|
||||||
|
|
||||||
Log.d(TAG, "onCreate: " + JfClient.config.getJellyfinUrl());
|
Log.d(TAG, "onCreate: " + JfClient.config.getJellyfinUrl());
|
||||||
if(JfClient.AccessToken.equals("") ||JfClient.UserId.equals("")){
|
if(JfClient.AccessToken.equals("") ||JfClient.UserId.equals("")){
|
||||||
|
@ -18,6 +18,7 @@ import com.lzy.okgo.model.HttpHeaders;
|
|||||||
import com.lzy.okgo.model.Response;
|
import com.lzy.okgo.model.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Timer;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
@ -40,9 +41,16 @@ public class JfClient {
|
|||||||
* 初始化配置
|
* 初始化配置
|
||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
public static void init(Context context) {
|
public static void init(Application application) {
|
||||||
config = new Config(context);
|
config = new Config(application);
|
||||||
SetHeaders();
|
SetHeaders();
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
builder.connectTimeout(5,TimeUnit.SECONDS);
|
||||||
|
builder.readTimeout(3, TimeUnit.SECONDS);
|
||||||
|
builder.writeTimeout(5,TimeUnit.SECONDS);
|
||||||
|
OkGo.getInstance().init(application)
|
||||||
|
.setOkHttpClient(builder.build())
|
||||||
|
.setRetryCount(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -333,6 +341,7 @@ public class JfClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(String str) {
|
public void onSuccess(String str) {
|
||||||
JsonObject serverInfo = strToGson(str, JsonObject.class);
|
JsonObject serverInfo = strToGson(str, JsonObject.class);
|
||||||
|
Log.d(TAG, "onSuccess: " + str);
|
||||||
String ServerId = jeFromGson(serverInfo, "Id") == null ? null : jeFromGson(serverInfo, "Id").getAsString();
|
String ServerId = jeFromGson(serverInfo, "Id") == null ? null : jeFromGson(serverInfo, "Id").getAsString();
|
||||||
if (ServerId == null || ServerId.length() == 0) {
|
if (ServerId == null || ServerId.length() == 0) {
|
||||||
cb.onSuccess(false);
|
cb.onSuccess(false);
|
||||||
@ -451,7 +460,7 @@ public class JfClient {
|
|||||||
public static JsonElement jeFromGson(JsonObject obj, String key) {
|
public static JsonElement jeFromGson(JsonObject obj, String key) {
|
||||||
JsonElement jo = null;
|
JsonElement jo = null;
|
||||||
if (obj != null && obj.has(key)) {
|
if (obj != null && obj.has(key)) {
|
||||||
jo = obj.get(key).getAsJsonObject();
|
jo = obj.get(key);
|
||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user