This commit is contained in:
2024-08-02 10:34:16 +08:00
parent d305c7809c
commit 9e889a2f14
42 changed files with 6797 additions and 27 deletions

View File

@@ -5,25 +5,25 @@ plugins {
android {
signingConfigs {
debug {
storeFile file('D:\\AndroidKeys\\yutou.jks')
storeFile file('C:\\Users\\58381\\Documents\\AndroidSign\\yutou.jks')
storePassword '34864394'
keyAlias 'yutou'
keyPassword '34864394'
}
yutou {
storeFile file('D:\\AndroidKeys\\yutou.jks')
storeFile file('C:\\Users\\58381\\Documents\\AndroidSign\\yutou.jks')
storePassword '34864394'
keyAlias 'yutou'
keyPassword '34864394'
}
}
compileSdkVersion 30
compileSdkVersion 33
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.yutou.passmanage"
minSdkVersion 23
targetSdkVersion 30
minSdkVersion 28
targetSdkVersion 33
versionCode 1
versionName "1.2"
@@ -59,5 +59,6 @@ dependencies {
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.biometric:biometric:1.1.0"
api project(path:':TabLayout')
api project(path:':ViewPager2Delegate')
}

View File

@@ -11,7 +11,8 @@
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.MyPassworldManage">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -1,16 +1,16 @@
package com.yutou.passmanage.Interfaces;
public interface NetworkInterface {
public abstract class NetworkInterface<T> {
/**
* 请求成功
* @param data 请求参数
* @param state http状态
*/
void httpGetData(Object data, int state);
public void httpGetData(T data, int state){}
/**
* 请求异常
* @param e 异常
*/
void httpError(Exception e);
public void httpError(Exception e){}
}

View File

@@ -5,9 +5,11 @@ import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -16,6 +18,7 @@ import android.widget.Toast;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.angcyo.tablayout.DslTabLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.yutou.passmanage.Adapters.PassWordListAdapter;
import com.yutou.passmanage.Datas.AppData;
@@ -25,6 +28,8 @@ import com.yutou.passmanage.Interfaces.NetworkInterface;
import com.yutou.passmanage.Tools.NetworkTool;
import com.yutou.passmanage.Tools.RoomDatabaseManager;
import com.yutou.passmanage.Tools.Tools;
import com.yutou.passmanage.bean.PasswordBean;
import com.yutou.passmanage.bean.PasswordTypeBean;
import java.util.ArrayList;
import java.util.List;
@@ -49,6 +54,7 @@ public class MainActivity extends AppCompatActivity {
FloatingActionButton floatButton;
PassWordListAdapter adapter;
TextView authError;
DslTabLayout tabLayout;
Handler handler = new Handler(Looper.getMainLooper());
@Override
@@ -63,6 +69,12 @@ public class MainActivity extends AppCompatActivity {
BiometricPrompt prompt;
void auth() {
if(true){
init();
authError.setVisibility(View.GONE);
passList.setVisibility(View.VISIBLE);
return;
}
BiometricManager manager = BiometricManager.from(this);
if (manager.canAuthenticate(BIOMETRIC_WEAK | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) {
@@ -122,6 +134,7 @@ public class MainActivity extends AppCompatActivity {
clearSearch = findViewById(R.id.clearSearch);
passList = findViewById(R.id.passList);
floatButton = findViewById(R.id.floatButton);
tabLayout = findViewById(R.id.tabLayout);
floatButton.setOnClickListener(v -> showAddPasswordDialog());
passList.setLayoutManager(new LinearLayoutManager(this));
passList.setAdapter(adapter);
@@ -241,7 +254,29 @@ public class MainActivity extends AppCompatActivity {
ToolsPasswordDao dao;
void initData() {
NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_TYPE_ALL, new JSONObject(), new NetworkInterface<JSONObject>() {
@Override
public void httpGetData(JSONObject json, int state) {
List<PasswordTypeBean> data = JSONArray.parseArray(json.getJSONArray("data").toJSONString(), PasswordTypeBean.class);
for (PasswordTypeBean bean : data) {
Button tab = new Button(MainActivity.this);
tab.setOnClickListener(view -> {
});
tab.setText(bean.getTitle());
tab.setTag(bean);
tabLayout.addView(tab);
}
}
@Override
public void httpError(Exception e) {
e.printStackTrace();
}
});
new Thread(() -> {
List<ToolsPassword> list = dao.getAllAndRemove();
if (list.size() == 0) {
authError.setText("列表为空,点击右下角+新增配置");
@@ -303,11 +338,11 @@ public class MainActivity extends AppCompatActivity {
}
}
NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_ALL, new JSONObject(), new NetworkInterface() {
NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_ALL, new JSONObject(), new NetworkInterface<JSONObject>() {
@Override
public void httpGetData(Object data, int state) {
data = ((String) data).replace("desc", "info");
JSONObject json = JSONObject.parseObject((String) data);
public void httpGetData(JSONObject json, int state) {
// data = ((String) data).replace("desc", "info");
// JSONObject json = JSONObject.parseObject((String) data);
if (json.getInteger("code") == 0) {
List<ToolsPassword> list = JSONArray.parseArray(json.getJSONArray("data").toJSONString(), ToolsPassword.class);
new Thread(() -> {

View File

@@ -3,6 +3,8 @@ package com.yutou.passmanage.Tools;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.yutou.passmanage.Datas.AppData;
@@ -13,9 +15,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;
import java.util.Set;
@@ -36,7 +41,7 @@ public class NetworkTool {
}
public static void httpGet(String url, JSONObject body, NetworkInterface networkInterface) {
public static <T> void httpGet(String url, JSONObject body, NetworkInterface<T> networkInterface) {
new Thread(new Runnable() {
@Override
public void run() {
@@ -60,15 +65,26 @@ public class NetworkTool {
public void run() {
if (networkInterface != null) {
try {
networkInterface.httpGetData(str.toString(), connection.getResponseCode());
} catch (IOException e) {
JSONObject json=JSONObject.parseObject(str.toString());
Type[] types = ((ParameterizedType) networkInterface.getClass().getGenericSuperclass()).getActualTypeArguments();
if(types.length==0){
networkInterface.httpGetData((T) JSONObject.parseObject(str.toString()),connection.getResponseCode());
}else {
Type type=types[0];
if (type.getTypeName().contains("JSON")) {
networkInterface.httpGetData((T) JSONObject.parseObject(str.toString()), connection.getResponseCode());
}else {
networkInterface.httpGetData(JSONObject.parseObject(json.getJSONObject("data").toJSONString(), type), connection.getResponseCode());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
//Log.i(TAG + "[" + url + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
Log.i(TAG + "[" + url + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
} catch (Exception e) {
e.printStackTrace();
AppData.handler.post(new Runnable() {
@@ -129,7 +145,7 @@ public class NetworkTool {
connection.setReadTimeout(10 * 1000);
//connection.addRequestProperty("Connection", "keep-alive");
//connection.addRequestProperty("User-Agent", getExtUa());
// connection.addRequestProperty("content-type", "application/json");
// connection.addRequestProperty("content-type", "application/json");
connection.addRequestProperty("charset", "UTF-8");
OutputStream outputStream = connection.getOutputStream();
@@ -142,7 +158,7 @@ public class NetworkTool {
}
final String finalStr = str.toString();
// Log.i(TAG + "[" + url + "?" + toGetSplice(body) + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
Log.i(TAG + "[" + url + "?" + toGetSplice(body) + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
AppData.handler.post(new Runnable() {
@Override
public void run() {

View File

@@ -0,0 +1,6 @@
package com.yutou.passmanage.bean;
import java.io.Serializable;
public class BaseBean implements Serializable {
}

View File

@@ -0,0 +1,88 @@
package com.yutou.passmanage.bean;
public class PasswordBean extends BaseBean{
private int id;
private String title;
private String titlePinyin;
private String username;
private String password;
private String url;
private String info;
private int type;
private int uid;
public PasswordBean() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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 String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
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;
}
}

View File

@@ -0,0 +1,43 @@
package com.yutou.passmanage.bean;
public class PasswordTypeBean extends BaseBean{
private int id;
private String title;
private int uid;
public PasswordTypeBean() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
@Override
public String toString() {
return "PasswordTypeBean{" +
"id=" + id +
", title='" + title + '\'' +
", uid=" + uid +
'}';
}
}

View File

@@ -29,16 +29,24 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.angcyo.tablayout.DslTabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
</com.angcyo.tablayout.DslTabLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/passList"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search" >
</androidx.recyclerview.widget.RecyclerView>
app:layout_constraintTop_toBottomOf="@+id/search"/>
<TextView
android:id="@+id/goneText"

View File

@@ -18,7 +18,7 @@
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_weight="1"
android:text="@string/account" />
android:text="@string/title" />
<EditText
android:id="@+id/title"
@@ -27,7 +27,7 @@
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="@string/account" />
android:hint="@string/title" />
</LinearLayout>

View File

@@ -2,6 +2,7 @@
<string name="app_name">密码管理器</string>
<string name="password">密码</string>
<string name="account">账号</string>
<string name="title">标题</string>
<string name="info">备注</string>
<string name="name">名字</string>
<string name="toast_copy_password">已复制密码</string>