From 0d65df5271d8738e7a387fb4336af8b45abb0aee Mon Sep 17 00:00:00 2001 From: z583819556 Date: Mon, 4 Mar 2024 15:10:37 +0800 Subject: [PATCH] update --- app/build.gradle | 6 + app/src/main/AndroidManifest.xml | 24 +- app/src/main/java/com/yutou/nettools/Api.java | 24 ++ .../main/java/com/yutou/nettools/Bean.java | 34 +++ .../main/java/com/yutou/nettools/HttpApi.java | 24 ++ .../java/com/yutou/nettools/MainActivity.java | 48 ++++ .../java/com/yutou/nettools/Password.java | 101 +++++++++ app/src/main/res/layout/activity_main.xml | 18 ++ gradle.properties | 7 +- netlibs/.gitignore | 1 + netlibs/build.gradle | 42 ++++ netlibs/proguard-rules.pro | 21 ++ .../netlibs/ExampleInstrumentedTest.java | 26 +++ netlibs/src/main/AndroidManifest.xml | 12 + .../netlibs/converter/JsonCallAdapter.java | 19 ++ .../converter/JsonConverterFactory.java | 30 +++ .../converter/JsonRequestBodyConverter.java | 16 ++ .../converter/JsonResponseBodyConverter.java | 30 +++ .../main/java/com/yutou/netlibs/http/API.java | 56 +++++ .../java/com/yutou/netlibs/http/BaseAPI.java | 45 ++++ .../yutou/netlibs/http/GetRequestParams.java | 25 ++ .../java/com/yutou/netlibs/http/HttpBody.java | 40 ++++ .../netlibs/http/HttpLoggingInterceptor.java | 213 ++++++++++++++++++ .../com/yutou/netlibs/http/IRequestParam.java | 9 + .../com/yutou/netlibs/http/ParamsContext.java | 29 +++ .../yutou/netlibs/http/PostRequestParams.java | 65 ++++++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 +++ .../main/res/mipmap-anydpi/ic_launcher.xml | 6 + .../res/mipmap-anydpi/ic_launcher_round.xml | 6 + .../src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes .../src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes netlibs/src/main/res/values-night/themes.xml | 16 ++ netlibs/src/main/res/values/colors.xml | 10 + netlibs/src/main/res/values/strings.xml | 3 + netlibs/src/main/res/values/themes.xml | 16 ++ .../com/yutou/netlibs/ExampleUnitTest.java | 17 ++ settings.gradle | 1 + 46 files changed, 1237 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/yutou/nettools/Api.java create mode 100644 app/src/main/java/com/yutou/nettools/Bean.java create mode 100644 app/src/main/java/com/yutou/nettools/HttpApi.java create mode 100644 app/src/main/java/com/yutou/nettools/MainActivity.java create mode 100644 app/src/main/java/com/yutou/nettools/Password.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 netlibs/.gitignore create mode 100644 netlibs/build.gradle create mode 100644 netlibs/proguard-rules.pro create mode 100644 netlibs/src/androidTest/java/com/yutou/netlibs/ExampleInstrumentedTest.java create mode 100644 netlibs/src/main/AndroidManifest.xml create mode 100644 netlibs/src/main/java/com/yutou/netlibs/converter/JsonCallAdapter.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/converter/JsonConverterFactory.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/converter/JsonRequestBodyConverter.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/converter/JsonResponseBodyConverter.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/API.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/BaseAPI.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/GetRequestParams.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/HttpBody.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/HttpLoggingInterceptor.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/IRequestParam.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/ParamsContext.java create mode 100644 netlibs/src/main/java/com/yutou/netlibs/http/PostRequestParams.java create mode 100644 netlibs/src/main/res/drawable/ic_launcher_background.xml create mode 100644 netlibs/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 netlibs/src/main/res/mipmap-anydpi/ic_launcher.xml create mode 100644 netlibs/src/main/res/mipmap-anydpi/ic_launcher_round.xml create mode 100644 netlibs/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 netlibs/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 netlibs/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 netlibs/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 netlibs/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 netlibs/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 netlibs/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 netlibs/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 netlibs/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 netlibs/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 netlibs/src/main/res/values-night/themes.xml create mode 100644 netlibs/src/main/res/values/colors.xml create mode 100644 netlibs/src/main/res/values/strings.xml create mode 100644 netlibs/src/main/res/values/themes.xml create mode 100644 netlibs/src/test/java/com/yutou/netlibs/ExampleUnitTest.java 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 @@ + + + +