Commit 38a4fb19 authored by Administrator's avatar Administrator

update

parent 9f80a6ed
......@@ -52,7 +52,8 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
//引入netty之后,class直接就爆炸了。考虑实现API精简
implementation 'com.android.support:multidex:1.0.3'
......
......@@ -16,7 +16,7 @@ public class APIServices {
private static Retrofit retrofit = new Retrofit.Builder()
.baseUrl(EchoConfig.getApiURL())
.callFactory(createInterceptedOkHttp())
.addConverterFactory(GsonConverterFactory.create())
// .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
......
package com.virjar.echo.adr.repo;
import com.google.gson.JsonObject;
import retrofit2.Call;
import retrofit2.http.GET;
public interface UserApi {
@GET("api/user/userInfo")
Call<?> loginWithToken();
Call<JsonObject> loginWithToken();
}
......@@ -2,6 +2,7 @@ package com.virjar.echo.adr.ui;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
......@@ -11,7 +12,14 @@ import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.JsonObject;
import com.virjar.echo.adr.R;
import com.virjar.echo.adr.repo.APIServices;
import com.virjar.echo.adr.repo.EchoConfig;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class LoginActivity extends AppCompatActivity {
......@@ -42,18 +50,26 @@ public class LoginActivity extends AppCompatActivity {
}
private void autoLoginWithToken() {
// String token = EchoConfig.getToken();
// if (TextUtils.isEmpty(token)) {
// autoLoginWithUserName();
// return;
// }
// return new Request.Builder()
// .get()
// .url(url)
// .addHeader("Connection","close")
// .build();
//
// HttpClient.getClient().newCall()
String token = EchoConfig.getToken();
if (TextUtils.isEmpty(token)) {
autoLoginWithUserName();
return;
}
Call<JsonObject> loginResponse = APIServices.userApi.loginWithToken();
loginResponse.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
JsonObject body = response.body();
if (!body.get("ok").getAsBoolean()) {
autoLoginWithUserName();
}
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
autoLoginWithUserName();
}
});
}
private void autoLoginWithUserName() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment