style: 使用kotlin代替java
更改网络请求相关类为kotlin代码(补充)
This commit is contained in:
parent
316169ef8f
commit
53cd25e650
@ -1,69 +0,0 @@
|
||||
package com.kaixed.kchat.entity.login;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* @Author: kaixed
|
||||
* @Date: 2024/5/19 23:59
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class Login {
|
||||
private String code;
|
||||
private String msg;
|
||||
private Data data;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
private String username;
|
||||
private String nickname;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Login{" +
|
||||
"username='" + username + '\'' +
|
||||
", nickname='" + nickname + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.kaixed.kchat.event;
|
||||
|
||||
import com.kaixed.kchat.database.entity.Messages;
|
||||
|
||||
/**
|
||||
* @Author: kaixed
|
||||
* @Date: 2024/5/26 10:02
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class MessagesEvent {
|
||||
|
||||
public final Messages messages;
|
||||
|
||||
public MessagesEvent(Messages messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.kaixed.kchat.network;
|
||||
|
||||
/**
|
||||
* @Author: kaixed
|
||||
* @Date: 2024/5/20 22:25
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class NetworkInterface {
|
||||
|
||||
public static final String URL = "app.kaixed.com/kchat";
|
||||
public static final String SERVER_URL = "https://" + URL;
|
||||
public static final String WEBSOCKET_SERVER_URL = "wss://" + URL;
|
||||
public static final String WEBSOCKET = "/websocket/single/";
|
||||
public static final String USER_INFO = "/users/info/";
|
||||
public static final String USER_LOGIN = "/users/login";
|
||||
public static final String USER_MESSAGES_COUNT = "/users/%s/%s/msgCounts";
|
||||
public static final String USER_MESSAGES = "/users/%s/%s/messages";
|
||||
public static final String MESSAGE_WITHDRAW = "/messages/";
|
||||
|
||||
public static final String USER_LIST = "/users/lists/";
|
||||
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.kaixed.kchat.network;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* @author hui
|
||||
*/
|
||||
public class NetworkRequest {
|
||||
|
||||
private final OkHttpClient client;
|
||||
|
||||
|
||||
public NetworkRequest() {
|
||||
this.client = OkhttpHelper.getInstance();
|
||||
}
|
||||
|
||||
|
||||
public void postAsync(String url, RequestBody formBody, final Callback callback) {
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(formBody)
|
||||
.build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
public void postAsync(String url, String json, final Callback callback) {
|
||||
|
||||
MediaType mediaType = MediaType.get("application/json; charset=utf-8");
|
||||
RequestBody body = RequestBody.create(json, mediaType);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
public void getAsync(String url, final Callback callback) {
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
call.enqueue(callback);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.kaixed.kchat.network;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/**
|
||||
* @Author: kaixed
|
||||
* @Date: 2024/5/27 8:58
|
||||
* @Description: 使用单例模式的okhttp实例类
|
||||
*/
|
||||
public class OkhttpHelper {
|
||||
private static OkHttpClient client;
|
||||
|
||||
private OkhttpHelper() {
|
||||
}
|
||||
|
||||
public static OkHttpClient getInstance() {
|
||||
if (client == null) {
|
||||
client = new OkHttpClient();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user