diff --git a/app/build.gradle b/app/build.gradle index 0d4f278..645acaf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,13 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.11.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + implementation project(path:":netlibs") + + api 'com.squareup.okhttp3:okhttp:3.14.9' + api 'com.squareup.retrofit2:retrofit:2.3.0' + api 'com.alibaba.fastjson2:fastjson2:2.0.47' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5be129f..ed400c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - + + tools:targetApi="31"> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/yutou/nettools/Api.java b/app/src/main/java/com/yutou/nettools/Api.java new file mode 100644 index 0000000..8d1624c --- /dev/null +++ b/app/src/main/java/com/yutou/nettools/Api.java @@ -0,0 +1,24 @@ +package com.yutou.nettools; + + +import com.yutou.netlibs.http.API; + +import java.util.HashMap; + +public class Api extends API { + + public Api(String url) { + super(url); + } + + public Api(String url, HashMap params) { + super(url, params); + + } + public static HttpApi getInstance(HashMap params){ + return new Api("http://tools.yutou233.cn",params).createAPI(HttpApi.class); + } + public static HttpApi getInstance(){ + return new Api("http://tools.yutou233.cn").createAPI(HttpApi.class); + } +} diff --git a/app/src/main/java/com/yutou/nettools/Bean.java b/app/src/main/java/com/yutou/nettools/Bean.java new file mode 100644 index 0000000..8e776bb --- /dev/null +++ b/app/src/main/java/com/yutou/nettools/Bean.java @@ -0,0 +1,34 @@ +package com.yutou.nettools; + + +public class Bean { + String url; + String version; + + public Bean() { + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String toString() { + return "Bean{" + + "url='" + url + '\'' + + ", version='" + version + '\'' + + '}'; + } +} diff --git a/app/src/main/java/com/yutou/nettools/HttpApi.java b/app/src/main/java/com/yutou/nettools/HttpApi.java new file mode 100644 index 0000000..84a8fa0 --- /dev/null +++ b/app/src/main/java/com/yutou/nettools/HttpApi.java @@ -0,0 +1,24 @@ +package com.yutou.nettools; + + +import com.yutou.netlibs.http.HttpBody; + +import java.util.List; + +import retrofit2.Call; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.POST; +import retrofit2.http.Query; + +public interface HttpApi { + @GET("/public/request.do") + Call> getVersion(); + @GET("tools/password/type/get/list.do") + Call>> getList(@Query("token")String token); + @FormUrlEncoded + @POST("/public/request.do") + Call> postVersion(@Field("test")String data); + +} diff --git a/app/src/main/java/com/yutou/nettools/MainActivity.java b/app/src/main/java/com/yutou/nettools/MainActivity.java new file mode 100644 index 0000000..3811900 --- /dev/null +++ b/app/src/main/java/com/yutou/nettools/MainActivity.java @@ -0,0 +1,48 @@ +package com.yutou.nettools; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +import com.yutou.netlibs.http.HttpBody; + +import java.util.List; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + findViewById(R.id.button) + .setOnClickListener(v -> { + Api.getInstance().getList("") + .enqueue(new Callback>>() { + @Override + public void onResponse(Call>> call, Response>> response) { + System.out.println("response = " + response.body().getData()); + } + + @Override + public void onFailure(Call>> call, Throwable t) { + + } + }); + Api.getInstance().getVersion().enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + System.out.println("response = " + response.body().getData()); + } + + @Override + public void onFailure(Call> call, Throwable t) { + + } + }); + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yutou/nettools/Password.java b/app/src/main/java/com/yutou/nettools/Password.java new file mode 100644 index 0000000..0bd19d3 --- /dev/null +++ b/app/src/main/java/com/yutou/nettools/Password.java @@ -0,0 +1,101 @@ +package com.yutou.nettools; + + +public class Password { + private int id; + private String info; + private String password; // 实际应用中,密码不应该以明文形式存储或传输 + private String title; + private String titlePinyin; + private int type; + private int uid; + private String url; + private String username; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitlePinyin() { + return titlePinyin; + } + + public void setTitlePinyin(String titlePinyin) { + this.titlePinyin = titlePinyin; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getUid() { + return uid; + } + + public void setUid(int uid) { + this.uid = uid; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Override + public String toString() { + return "Password{" + + "id=" + id + + ", info='" + info + '\'' + + ", password='" + password + '\'' + + ", title='" + title + '\'' + + ", titlePinyin='" + titlePinyin + '\'' + + ", type=" + type + + ", uid=" + uid + + ", url='" + url + '\'' + + ", username='" + username + '\'' + + '}'; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..ddad10b --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + +