新增了分类
然后不知道改了啥
This commit is contained in:
@@ -17,15 +17,14 @@ android {
|
||||
keyPassword '34864394'
|
||||
}
|
||||
}
|
||||
compileSdkVersion 33
|
||||
buildToolsVersion "30.0.2"
|
||||
compileSdkVersion 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.yutou.passmanage"
|
||||
minSdkVersion 28
|
||||
targetSdkVersion 33
|
||||
targetSdkVersion 34
|
||||
versionCode 1
|
||||
versionName "1.2"
|
||||
versionName "1.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
signingConfig signingConfigs.yutou
|
||||
@@ -41,24 +40,35 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
namespace 'com.yutou.passmanage'
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||
implementation 'com.google.android.material:material:1.12.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.7.7'
|
||||
implementation 'androidx.navigation:navigation-ui:2.7.7'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.4'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
|
||||
implementation 'com.alibaba:fastjson:1.2.68'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.52'
|
||||
|
||||
def room_version = "2.2.6"
|
||||
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
annotationProcessor "androidx.room:room-compiler:$room_version"
|
||||
implementation "androidx.room:room-runtime:2.6.1"
|
||||
annotationProcessor "androidx.room:room-compiler:2.6.1"
|
||||
implementation "androidx.biometric:biometric:1.1.0"
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
|
||||
|
||||
api project(path:':TabLayout')
|
||||
api project(path:':ViewPager2Delegate')
|
||||
api project(path:':netlibs')
|
||||
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.yutou.passmanage">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:theme="@style/Theme.MyPassworldManage">
|
||||
<activity android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
android:theme="@style/Theme.MyPassworldManage"
|
||||
android:usesCleartextTraffic="true" >
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@@ -21,14 +21,17 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.netlibs.http.HttpCallback;
|
||||
import com.yutou.passmanage.Datas.ToolsPassword;
|
||||
import com.yutou.passmanage.Datas.ToolsPasswordDao;
|
||||
import com.yutou.passmanage.Interfaces.NetworkInterface;
|
||||
import com.yutou.passmanage.NetUtils.NetTools;
|
||||
import com.yutou.passmanage.R;
|
||||
import com.yutou.passmanage.Tools.NetworkTool;
|
||||
import com.yutou.passmanage.Tools.ResTools;
|
||||
import com.yutou.passmanage.Tools.RoomDatabaseManager;
|
||||
import com.yutou.passmanage.bean.BaseBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -58,8 +61,8 @@ public class PassWordListAdapter extends RecyclerView.Adapter<PassWordListAdapte
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
ToolsPassword data = list.get(holder.getAdapterPosition());
|
||||
String account=ResTools.getString(context,R.string.account)+":"+ data.getAccount();
|
||||
String password=ResTools.getString(context,R.string.password)+":"+data.getPassword();
|
||||
String account = ResTools.getString(context, R.string.account) + ":" + data.getAccount();
|
||||
String password = ResTools.getString(context, R.string.password) + ":" + data.getPassword();
|
||||
holder.name.setText(data.getTitle());
|
||||
holder.user.setText(account);
|
||||
holder.password.setText(password);
|
||||
@@ -69,13 +72,45 @@ public class PassWordListAdapter extends RecyclerView.Adapter<PassWordListAdapte
|
||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("", data.getPassword());
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(context, ResTools.getString(context,R.string.toast_copy_password), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context, ResTools.getString(context, R.string.toast_copy_password), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
holder.item_layout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog(data, holder.getAdapterPosition());
|
||||
NetTools.getApi().getPassword(data.getId()).enqueue(new HttpCallback<String>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, String response) {
|
||||
data.setPassword(response);
|
||||
showDialog(data, holder.getAdapterPosition());
|
||||
save(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
new Thread(() -> {
|
||||
ToolsPassword queried = dao.queryPassword(data.getId());
|
||||
if (queried != null) {
|
||||
new Handler(Looper.getMainLooper())
|
||||
.post(() -> showDialog(data, holder.getAdapterPosition()));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void save(ToolsPassword pwd) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ToolsPassword queried = dao.queryPassword(pwd.getId());
|
||||
if (queried == null) {
|
||||
dao.insert(pwd);
|
||||
} else {
|
||||
dao.update(pwd);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -86,11 +121,11 @@ public class PassWordListAdapter extends RecyclerView.Adapter<PassWordListAdapte
|
||||
private void showDialog(ToolsPassword data, int position) {
|
||||
View view = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.dialog_add_passworld, null);
|
||||
Button delete = view.findViewById(R.id.delete);
|
||||
EditText title, account, password,info;
|
||||
EditText title, account, password, info;
|
||||
title = view.findViewById(R.id.title);
|
||||
account = view.findViewById(R.id.account);
|
||||
password = view.findViewById(R.id.myPassword);
|
||||
info=view.findViewById(R.id.info);
|
||||
info = view.findViewById(R.id.info);
|
||||
title.setText(data.getTitle());
|
||||
account.setText(data.getAccount());
|
||||
password.setText(data.getPassword());
|
||||
@@ -105,40 +140,36 @@ public class PassWordListAdapter extends RecyclerView.Adapter<PassWordListAdapte
|
||||
.setPositiveButton("删除", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", data.getId());
|
||||
NetworkTool.httpPost(NetworkTool.NetworkAPI.PASSWORD_REMOVE, json, new NetworkInterface() {
|
||||
NetTools.getApi().removePassword(data.getId()).enqueue(new HttpCallback<BaseBean>() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
public void onResponse(int code, String status, BaseBean response) {
|
||||
remove(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
public void onFailure(Throwable throwable) {
|
||||
remove(true);
|
||||
}
|
||||
|
||||
void remove(boolean isError) {
|
||||
new Thread(() -> {
|
||||
if (isError) {
|
||||
if (data.isUpload()) {
|
||||
data.setRemove(true);
|
||||
dao.update(data);
|
||||
} else {
|
||||
dao.delete(data);
|
||||
}
|
||||
if (isError) {
|
||||
if (data.isUpload()) {
|
||||
data.setRemove(true);
|
||||
dao.update(data);
|
||||
} else {
|
||||
dao.delete(data);
|
||||
}
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(() -> {
|
||||
dialog.dismiss();
|
||||
removeDialog.dismiss();
|
||||
Toast.makeText(context, "删除成功", Toast.LENGTH_LONG).show();
|
||||
list.remove(position);
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
}).start();
|
||||
} else {
|
||||
dao.delete(data);
|
||||
}
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(() -> {
|
||||
dialog.dismiss();
|
||||
removeDialog.dismiss();
|
||||
Toast.makeText(context, "删除成功", Toast.LENGTH_LONG).show();
|
||||
list.remove(position);
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
@@ -153,12 +184,13 @@ public class PassWordListAdapter extends RecyclerView.Adapter<PassWordListAdapte
|
||||
.setTitle("查看信息")
|
||||
.setView(view)
|
||||
.setPositiveButton("更新", (dialog1, which) -> {
|
||||
addPassword(title.getText().toString(), account.getText().toString(), password.getText().toString(),info.getText().toString(), data.getId(), false, new NetworkInterface() {
|
||||
addPassword(title.getText().toString(), account.getText().toString(), password.getText().toString(), info.getText().toString(), data.getId(), false, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
addDatabase(title.getText().toString(),
|
||||
account.getText().toString(),
|
||||
password.getText().toString(),
|
||||
info.getText().toString(),
|
||||
true);
|
||||
}
|
||||
|
||||
@@ -167,20 +199,23 @@ public class PassWordListAdapter extends RecyclerView.Adapter<PassWordListAdapte
|
||||
addDatabase(title.getText().toString(),
|
||||
account.getText().toString(),
|
||||
password.getText().toString(),
|
||||
info.getText().toString(),
|
||||
false);
|
||||
}
|
||||
|
||||
void addDatabase(String title1, String account1, String password1, boolean upload) {
|
||||
void addDatabase(String title1, String account1, String password1, String info, boolean upload) {
|
||||
new Thread(() -> {
|
||||
data.setAccount(account1);
|
||||
data.setTitle(title1);
|
||||
data.setPassword(password1);
|
||||
data.setInfo(info);
|
||||
data.setUpload(upload);
|
||||
dao.update(data);
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(context, ResTools.getString(context,R.string.toast_update), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context, ResTools.getString(context, R.string.toast_update), Toast.LENGTH_LONG).show();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,9 +6,11 @@ import androidx.room.Entity;
|
||||
import androidx.room.Ignore;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* tools_password
|
||||
* @author
|
||||
* @author
|
||||
*/
|
||||
@Entity
|
||||
public class ToolsPassword{
|
||||
@@ -17,6 +19,7 @@ public class ToolsPassword{
|
||||
@ColumnInfo
|
||||
private String title;
|
||||
@ColumnInfo
|
||||
@JSONField(name = "username")
|
||||
private String account;
|
||||
@ColumnInfo
|
||||
private String password;
|
||||
@@ -112,4 +115,20 @@ public class ToolsPassword{
|
||||
public void setRemove(boolean remove) {
|
||||
this.remove = remove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ToolsPassword{" +
|
||||
"id=" + id +
|
||||
", title='" + title + '\'' +
|
||||
", account='" + account + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
", info='" + info + '\'' +
|
||||
", type=" + type +
|
||||
", uid=" + uid +
|
||||
", upload=" + upload +
|
||||
", remove=" + remove +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ public interface ToolsPasswordDao {
|
||||
List<ToolsPassword> getAll();
|
||||
@Query("select * from ToolsPassword where title=:title and account=:account and password=:password and info=:info")
|
||||
ToolsPassword isExist(String title,String account,String password,String info);
|
||||
@Query("select * from ToolsPassword where id=:id")
|
||||
ToolsPassword queryPassword(int id);
|
||||
@Query("select * from ToolsPassword where title like :title and remove=0")
|
||||
List<ToolsPassword> queryPassword(String title);
|
||||
@Insert
|
||||
|
||||
@@ -16,18 +16,22 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.angcyo.tablayout.DslTabLayout;
|
||||
import com.angcyo.tablayout.DslTabLayoutConfig;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.yutou.netlibs.http.HttpCallback;
|
||||
import com.yutou.passmanage.Adapters.PassWordListAdapter;
|
||||
import com.yutou.passmanage.Datas.AppData;
|
||||
import com.yutou.passmanage.Datas.ToolsPassword;
|
||||
import com.yutou.passmanage.Datas.ToolsPasswordDao;
|
||||
import com.yutou.passmanage.Interfaces.NetworkInterface;
|
||||
import com.yutou.passmanage.NetUtils.NetTools;
|
||||
import com.yutou.passmanage.Tools.NetworkTool;
|
||||
import com.yutou.passmanage.Tools.RoomDatabaseManager;
|
||||
import com.yutou.passmanage.Tools.Tools;
|
||||
import com.yutou.passmanage.bean.BaseBean;
|
||||
import com.yutou.passmanage.bean.PasswordBean;
|
||||
import com.yutou.passmanage.bean.PasswordTypeBean;
|
||||
|
||||
@@ -47,6 +51,10 @@ import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_WEAK;
|
||||
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||
import static com.yutou.passmanage.Tools.RoomDatabaseManager.addPassword;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.jvm.functions.Function4;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
EditText search;
|
||||
ImageView clearSearch;
|
||||
@@ -69,7 +77,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
BiometricPrompt prompt;
|
||||
|
||||
void auth() {
|
||||
if(true){
|
||||
if (BuildConfig.DEBUG) {
|
||||
init();
|
||||
authError.setVisibility(View.GONE);
|
||||
passList.setVisibility(View.VISIBLE);
|
||||
@@ -175,6 +183,32 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
});
|
||||
tabLayout.configTabLayoutConfig(new Function1<DslTabLayoutConfig, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DslTabLayoutConfig dslTabLayoutConfig) {
|
||||
dslTabLayoutConfig.setOnSelectItemView(new Function4<View, Integer, Boolean, Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(View view, Integer integer, Boolean aBoolean, Boolean aBoolean2) {
|
||||
if (aBoolean) {
|
||||
PasswordTypeBean typeBean = (PasswordTypeBean) view.getTag();
|
||||
NetTools.getApi().getTypePassword(typeBean.getId()).enqueue(new HttpCallback<List<ToolsPassword>>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, List<ToolsPassword> response) {
|
||||
setShow(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void showAddPasswordDialog() {
|
||||
@@ -254,137 +288,52 @@ public class MainActivity extends AppCompatActivity {
|
||||
ToolsPasswordDao dao;
|
||||
|
||||
void initData() {
|
||||
|
||||
NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_TYPE_ALL, new JSONObject(), new NetworkInterface<JSONObject>() {
|
||||
NetTools.getApi().getAllTypePassword().enqueue(new HttpCallback<List<PasswordTypeBean>>() {
|
||||
@Override
|
||||
public void httpGetData(JSONObject json, int state) {
|
||||
List<PasswordTypeBean> data = JSONArray.parseArray(json.getJSONArray("data").toJSONString(), PasswordTypeBean.class);
|
||||
for (PasswordTypeBean bean : data) {
|
||||
public void onResponse(int code, String status, List<PasswordTypeBean> response) {
|
||||
for (PasswordTypeBean bean : response) {
|
||||
Button tab = new Button(MainActivity.this);
|
||||
tab.setOnClickListener(view -> {
|
||||
|
||||
});
|
||||
tab.setText(bean.getTitle());
|
||||
tab.setTag(bean);
|
||||
tabLayout.addView(tab);
|
||||
}
|
||||
showLocalData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
e.printStackTrace();
|
||||
public void onFailure(Throwable throwable) {
|
||||
showLocalData();
|
||||
}
|
||||
});
|
||||
new Thread(() -> {
|
||||
|
||||
List<ToolsPassword> list = dao.getAllAndRemove();
|
||||
if (list.size() == 0) {
|
||||
new Thread(() -> {
|
||||
if (dao.getAll().isEmpty()) {
|
||||
authError.setText("列表为空,点击右下角+新增配置");
|
||||
authError.setVisibility(View.VISIBLE);
|
||||
passList.setVisibility(View.GONE);
|
||||
} else {
|
||||
for (ToolsPassword password : list) {
|
||||
if (!password.isUpload() && !password.isRemove()) {
|
||||
addPassword(password.getTitle(), password.getAccount(), password.getPassword(), password.getInfo(), -1, true, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
new Thread(() -> {
|
||||
password.setUpload(true);
|
||||
dao.update(password);
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
} else if (password.isRemove()) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", password.getId());
|
||||
NetworkTool.httpPost(NetworkTool.NetworkAPI.PASSWORD_REMOVE, json, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
remove(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
remove(true);
|
||||
}
|
||||
|
||||
void remove(boolean isError) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isError) {
|
||||
if (password.isUpload()) {
|
||||
password.setRemove(true);
|
||||
dao.update(password);
|
||||
} else {
|
||||
dao.delete(password);
|
||||
}
|
||||
} else {
|
||||
dao.delete(password);
|
||||
}
|
||||
showData();
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_ALL, new JSONObject(), new NetworkInterface<JSONObject>() {
|
||||
@Override
|
||||
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(() -> {
|
||||
try {
|
||||
for (ToolsPassword password : list) {
|
||||
if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword(), password.getInfo()) == null) {
|
||||
password.setUpload(true);
|
||||
dao.insert(password);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
dao.clear();
|
||||
for (ToolsPassword password : list) {
|
||||
if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword(), password.getInfo()) == null) {
|
||||
password.setUpload(true);
|
||||
dao.insert(password);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
showData();
|
||||
}
|
||||
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
new Thread(() -> showData()).start();
|
||||
}
|
||||
});
|
||||
private void showLocalData() {
|
||||
showData();
|
||||
}
|
||||
|
||||
private void setShow(List<ToolsPassword> data) {
|
||||
adapter.setList(data);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
void showData() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<ToolsPassword> list = dao.getAll();
|
||||
handler.post(() -> {
|
||||
adapter.setList(list);
|
||||
adapter.notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
void showData() {
|
||||
List<ToolsPassword> list = dao.getAll();
|
||||
handler.post(() -> {
|
||||
adapter.setList(list);
|
||||
adapter.notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
48
app/src/main/java/com/yutou/passmanage/NetUtils/NetApi.java
Normal file
48
app/src/main/java/com/yutou/passmanage/NetUtils/NetApi.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.yutou.passmanage.NetUtils;
|
||||
|
||||
import com.yutou.netlibs.http.HttpBody;
|
||||
import com.yutou.passmanage.Datas.ToolsPassword;
|
||||
import com.yutou.passmanage.bean.BaseBean;
|
||||
import com.yutou.passmanage.bean.PasswordTypeBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
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 NetApi {
|
||||
@GET("/tools/password/type/get/list.do")
|
||||
Call<HttpBody<List<PasswordTypeBean>>> getAllTypePassword();
|
||||
@GET("/tools/password/get/list.do")
|
||||
Call<HttpBody<List<ToolsPassword>>> getTypePassword(
|
||||
@Query("type") int type
|
||||
);
|
||||
|
||||
@GET("/tools/password/get/password.do")
|
||||
Call<HttpBody<String>> getPassword(
|
||||
@Query("id") int id
|
||||
);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/tools/password/set/add.do")
|
||||
Call<HttpBody<BaseBean>> addPassword(@Field("title") String title,
|
||||
@Field("account") String account,
|
||||
@Field("password") String password,
|
||||
@Field("info") String info);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/tools/password/set/update.do")
|
||||
Call<HttpBody<BaseBean>> updatePassword(@Field("id") int id,
|
||||
@Field("title") String title,
|
||||
@Field("account") String account,
|
||||
@Field("password") String password,
|
||||
@Field("info") String info);
|
||||
@FormUrlEncoded
|
||||
@POST("/tools/password/set/remove.do")
|
||||
Call<HttpBody<BaseBean>> removePassword(@Field("id") int id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yutou.passmanage.NetUtils;
|
||||
|
||||
import com.yutou.netlibs.http.API;
|
||||
import com.yutou.netlibs.http.BaseAPI;
|
||||
import com.yutou.passmanage.Datas.AppData;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class NetTools extends API<NetApi> {
|
||||
private NetTools(String url,HashMap<String,String> map) {
|
||||
super(url,map);
|
||||
}
|
||||
|
||||
public static NetApi getApi(){
|
||||
HashMap<String,String> map=new HashMap<>();
|
||||
map.put("token", AppData.key);
|
||||
return new NetTools("https://tools.yutou233.cn",map).createAPI(NetApi.class);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +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.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.passmanage.Datas.AppData;
|
||||
import com.yutou.passmanage.Interfaces.NetworkInterface;
|
||||
|
||||
@@ -29,162 +27,11 @@ public class NetworkTool {
|
||||
private final static String TAG = NetworkTool.class.getSimpleName();
|
||||
|
||||
public static class NetworkAPI {
|
||||
public static String HOME = "http://tools.yutou233.cn/tools/password/";
|
||||
public static String PASSWORD_ALL = HOME + "get/all.do";
|
||||
public static String PASSWORD_ADD = HOME + "set/add.do";
|
||||
public static String PASSWORD_UPDATE = HOME + "set/update.do";
|
||||
public static String PASSWORD_REMOVE = HOME + "set/remove.do";
|
||||
public static String PASSWORD_TYPE_ALL = HOME + "type/get/list.do";
|
||||
public static String PASSWORD_TYPE_ADD = HOME + "type/set/add.do";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static <T> void httpGet(String url, JSONObject body, NetworkInterface<T> networkInterface) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
System.out.println(url + "?" + toGetSplice(body));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url + "?" + toGetSplice(body)).openConnection();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
connection.connect();
|
||||
if (connection.getResponseCode() != 200) {
|
||||
networkInterface.httpError(new RuntimeException("http code to :" + connection.getResponseCode()));
|
||||
return;
|
||||
}
|
||||
String tmp;
|
||||
StringBuilder str = new StringBuilder();
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
reader.close();
|
||||
AppData.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (networkInterface != null) {
|
||||
try {
|
||||
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() + ")");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AppData.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (networkInterface != null)
|
||||
networkInterface.httpError(e);
|
||||
}
|
||||
});
|
||||
Log.e(TAG, url + " body =" + body.toJSONString());
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
private void ping(String url, NetworkInterface networkInterface) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setConnectTimeout(50);
|
||||
connection.setReadTimeout(50);
|
||||
connection.connect();
|
||||
InputStream inputStream = connection.getErrorStream();
|
||||
System.out.println(inputStream.read());
|
||||
inputStream.close();
|
||||
System.out.println(connection.getResponseCode());
|
||||
networkInterface.httpGetData(null, 0);
|
||||
connection.disconnect();
|
||||
} catch (Exception e) {
|
||||
networkInterface.httpError(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
public static void httpPost(final String url, final JSONObject body, final NetworkInterface networkInterface) {
|
||||
if (!url.startsWith("http:") && !Tools.isEmpty(NetworkAPI.HOME)) {
|
||||
httpPost(NetworkAPI.HOME + url, body, networkInterface);
|
||||
return;
|
||||
}
|
||||
body.put("token", AppData.key);
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String tmp;
|
||||
StringBuilder str = new StringBuilder();
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
//connection.addRequestProperty("Connection", "keep-alive");
|
||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||
// connection.addRequestProperty("content-type", "application/json");
|
||||
connection.addRequestProperty("charset", "UTF-8");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
|
||||
outputStream.write(toGetSplice(body).getBytes());
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
final String finalStr = str.toString();
|
||||
|
||||
Log.i(TAG + "[" + url + "?" + toGetSplice(body) + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
|
||||
AppData.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (networkInterface != null) {
|
||||
try {
|
||||
networkInterface.httpGetData(str.toString(), connection.getResponseCode());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
connection.disconnect();
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (networkInterface != null)
|
||||
networkInterface.httpError(e);
|
||||
} finally {
|
||||
Log.e(TAG, url + "\n传参:" + body.toString() + "\n接收:" + str);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
private String getExtUa() {
|
||||
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yutou.passmanage.Tools;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
@@ -12,10 +13,17 @@ import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteOpenHelper;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.netlibs.http.HttpBody;
|
||||
import com.yutou.passmanage.Datas.ToolsPassword;
|
||||
import com.yutou.passmanage.Datas.ToolsPasswordDao;
|
||||
import com.yutou.passmanage.Interfaces.NetworkInterface;
|
||||
import com.yutou.passmanage.NetUtils.NetTools;
|
||||
import com.yutou.passmanage.bean.BaseBean;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.HttpException;
|
||||
import retrofit2.Response;
|
||||
|
||||
@Database(entities = {ToolsPassword.class}, version = 2,exportSchema = false)
|
||||
public abstract class RoomDatabaseManager extends RoomDatabase {
|
||||
@@ -62,9 +70,29 @@ public abstract class RoomDatabaseManager extends RoomDatabase {
|
||||
json.put("id",id);
|
||||
}
|
||||
if(isAdd) {
|
||||
NetworkTool.httpPost(NetworkTool.NetworkAPI.PASSWORD_ADD, json, networkInterface);
|
||||
NetTools.getApi().addPassword(title,account,password,info).enqueue(new retrofit2.Callback<HttpBody<BaseBean>>() {
|
||||
@Override
|
||||
public void onResponse(Call<HttpBody<BaseBean>> call, Response<HttpBody<BaseBean>> response) {
|
||||
networkInterface.httpGetData(response.body().getData(), response.body().getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<HttpBody<BaseBean>> call, Throwable t) {
|
||||
networkInterface.httpError(new RuntimeException(t.getMessage()));
|
||||
}
|
||||
});
|
||||
}else{
|
||||
NetworkTool.httpPost(NetworkTool.NetworkAPI.PASSWORD_UPDATE, json, networkInterface);
|
||||
NetTools.getApi().updatePassword(id,title,account,password,info).enqueue(new retrofit2.Callback<HttpBody<BaseBean>>() {
|
||||
@Override
|
||||
public void onResponse(Call<HttpBody<BaseBean>> call, Response<HttpBody<BaseBean>> response) {
|
||||
networkInterface.httpGetData(response.body().getData(), response.body().getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<HttpBody<BaseBean>> call, Throwable t) {
|
||||
networkInterface.httpError(new RuntimeException(t.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public class Tools {
|
||||
public static boolean isEmpty(String str){
|
||||
if(str==null||str.trim().length()==0){
|
||||
if(str==null|| str.trim().isEmpty()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -71,4 +71,6 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:srcCompat="@android:drawable/ic_input_add" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -13,4 +13,9 @@
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
<!-- Base application theme. -->
|
||||
<style name="Base.Theme.MyPassworldManage" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<!-- Customize your dark theme here. -->
|
||||
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
|
||||
</style>
|
||||
</resources>
|
||||
@@ -7,4 +7,50 @@
|
||||
<string name="name">名字</string>
|
||||
<string name="toast_copy_password">已复制密码</string>
|
||||
<string name="toast_update">更新成功</string>
|
||||
<!-- Strings used for fragments for navigation -->
|
||||
<string name="first_fragment_label">First Fragment</string>
|
||||
<string name="second_fragment_label">Second Fragment</string>
|
||||
<string name="next">Next</string>
|
||||
<string name="previous">Previous</string>
|
||||
|
||||
<string name="lorem_ipsum">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris
|
||||
volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus
|
||||
dui nec risus. Maecenas non sodales nisi, vel dictum dolor. Class aptent taciti sociosqu ad
|
||||
litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse blandit eleifend
|
||||
diam, vel rutrum tellus vulputate quis. Aliquam eget libero aliquet, imperdiet nisl a,
|
||||
ornare ex. Sed rhoncus est ut libero porta lobortis. Fusce in dictum tellus.\n\n
|
||||
Suspendisse interdum ornare ante. Aliquam nec cursus lorem. Morbi id magna felis. Vivamus
|
||||
egestas, est a condimentum egestas, turpis nisl iaculis ipsum, in dictum tellus dolor sed
|
||||
neque. Morbi tellus erat, dapibus ut sem a, iaculis tincidunt dui. Interdum et malesuada
|
||||
fames ac ante ipsum primis in faucibus. Curabitur et eros porttitor, ultricies urna vitae,
|
||||
molestie nibh. Phasellus at commodo eros, non aliquet metus. Sed maximus nisl nec dolor
|
||||
bibendum, vel congue leo egestas.\n\n
|
||||
Sed interdum tortor nibh, in sagittis risus mollis quis. Curabitur mi odio, condimentum sit
|
||||
amet auctor at, mollis non turpis. Nullam pretium libero vestibulum, finibus orci vel,
|
||||
molestie quam. Fusce blandit tincidunt nulla, quis sollicitudin libero facilisis et. Integer
|
||||
interdum nunc ligula, et fermentum metus hendrerit id. Vestibulum lectus felis, dictum at
|
||||
lacinia sit amet, tristique id quam. Cras eu consequat dui. Suspendisse sodales nunc ligula,
|
||||
in lobortis sem porta sed. Integer id ultrices magna, in luctus elit. Sed a pellentesque
|
||||
est.\n\n
|
||||
Aenean nunc velit, lacinia sed dolor sed, ultrices viverra nulla. Etiam a venenatis nibh.
|
||||
Morbi laoreet, tortor sed facilisis varius, nibh orci rhoncus nulla, id elementum leo dui
|
||||
non lorem. Nam mollis ipsum quis auctor varius. Quisque elementum eu libero sed commodo. In
|
||||
eros nisl, imperdiet vel imperdiet et, scelerisque a mauris. Pellentesque varius ex nunc,
|
||||
quis imperdiet eros placerat ac. Duis finibus orci et est auctor tincidunt. Sed non viverra
|
||||
ipsum. Nunc quis augue egestas, cursus lorem at, molestie sem. Morbi a consectetur ipsum, a
|
||||
placerat diam. Etiam vulputate dignissim convallis. Integer faucibus mauris sit amet finibus
|
||||
convallis.\n\n
|
||||
Phasellus in aliquet mi. Pellentesque habitant morbi tristique senectus et netus et
|
||||
malesuada fames ac turpis egestas. In volutpat arcu ut felis sagittis, in finibus massa
|
||||
gravida. Pellentesque id tellus orci. Integer dictum, lorem sed efficitur ullamcorper,
|
||||
libero justo consectetur ipsum, in mollis nisl ex sed nisl. Donec maximus ullamcorper
|
||||
sodales. Praesent bibendum rhoncus tellus nec feugiat. In a ornare nulla. Donec rhoncus
|
||||
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
|
||||
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
|
||||
</string>
|
||||
<string name="title_activity_main2">MainActivity2</string>
|
||||
<string name="title_home">Home</string>
|
||||
<string name="title_dashboard">Dashboard</string>
|
||||
<string name="title_notifications">Notifications</string>
|
||||
</resources>
|
||||
@@ -13,4 +13,9 @@
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
<!-- Base application theme. -->
|
||||
<style name="Base.Theme.MyPassworldManage" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<!-- Customize your light theme here. -->
|
||||
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user