diff --git a/app/build.gradle b/app/build.gradle index fc06fc0..56ed923 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,6 +3,20 @@ plugins { } android { + signingConfigs { + debug { + storeFile file('D:\\AndroidKeys\\yutou.jks') + storePassword '34864394' + keyAlias 'yutou' + keyPassword '34864394' + } + yutou { + storeFile file('D:\\AndroidKeys\\yutou.jks') + storePassword '34864394' + keyAlias 'yutou' + keyPassword '34864394' + } + } compileSdkVersion 30 buildToolsVersion "30.0.2" @@ -11,9 +25,10 @@ android { minSdkVersion 23 targetSdkVersion 30 versionCode 1 - versionName "1.0" + versionName "1.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + signingConfig signingConfigs.yutou } buildTypes { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5ab2851..7cad1d6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + { - addPassword(title.getText().toString(), account.getText().toString(), password.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(), diff --git a/app/src/main/java/com/yutou/passmanage/Datas/ToolsPassword.java b/app/src/main/java/com/yutou/passmanage/Datas/ToolsPassword.java index 6ac4261..a210ecf 100644 --- a/app/src/main/java/com/yutou/passmanage/Datas/ToolsPassword.java +++ b/app/src/main/java/com/yutou/passmanage/Datas/ToolsPassword.java @@ -22,7 +22,7 @@ public class ToolsPassword{ private String password; @Ignore private String url; - @Ignore + @ColumnInfo private String info; @ColumnInfo private Integer type; diff --git a/app/src/main/java/com/yutou/passmanage/Datas/ToolsPasswordDao.java b/app/src/main/java/com/yutou/passmanage/Datas/ToolsPasswordDao.java index 2db493e..89ff266 100644 --- a/app/src/main/java/com/yutou/passmanage/Datas/ToolsPasswordDao.java +++ b/app/src/main/java/com/yutou/passmanage/Datas/ToolsPasswordDao.java @@ -14,8 +14,8 @@ public interface ToolsPasswordDao { List getAllAndRemove(); @Query("select * from ToolsPassword where remove=0") List getAll(); - @Query("select * from ToolsPassword where title=:title and account=:account and password=:password") - ToolsPassword isExist(String title,String account,String password); + @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 title like :title and remove=0") List queryPassword(String title); @Insert diff --git a/app/src/main/java/com/yutou/passmanage/MainActivity.java b/app/src/main/java/com/yutou/passmanage/MainActivity.java index ac990c9..093bb1b 100644 --- a/app/src/main/java/com/yutou/passmanage/MainActivity.java +++ b/app/src/main/java/com/yutou/passmanage/MainActivity.java @@ -157,15 +157,16 @@ public class MainActivity extends AppCompatActivity { void showAddPasswordDialog() { View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_add_passworld, null); - EditText title, account, password; + 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); AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) .setTitle("添加账号") .setView(view) .setPositiveButton("保存", (dialog1, which) -> { - addPassword(title.getText().toString(), account.getText().toString(), password.getText().toString(), -1, true, new NetworkInterface() { + addPassword(title.getText().toString(), account.getText().toString(), password.getText().toString(), info.getText().toString(),-1, true, new NetworkInterface() { @Override public void httpGetData(Object data, int state) { addDatabase(title.getText().toString(), @@ -234,9 +235,8 @@ public class MainActivity extends AppCompatActivity { new Thread(() -> { List list = dao.getAllAndRemove(); for (ToolsPassword password : list) { - System.out.println(JSONObject.toJSONString(password)); if (!password.isUpload() && !password.isRemove()) { - addPassword(password.getTitle(), password.getAccount(), password.getPassword(), -1, true, new NetworkInterface() { + addPassword(password.getTitle(), password.getAccount(), password.getPassword(),password.getInfo(), -1, true, new NetworkInterface() { @Override public void httpGetData(Object data, int state) { new Thread(() -> { @@ -291,13 +291,14 @@ public class MainActivity extends AppCompatActivity { NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_ALL, new JSONObject(), new NetworkInterface() { @Override public void httpGetData(Object data, int state) { + data=((String)data).replace("desc","info"); JSONObject json = JSONObject.parseObject((String) data); if (json.getInteger("code") == 0) { List 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()) == null) { + if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword(),password.getInfo()) == null) { password.setUpload(true); dao.insert(password); } @@ -306,7 +307,7 @@ public class MainActivity extends AppCompatActivity { e.printStackTrace(); dao.clear(); for (ToolsPassword password : list) { - if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword()) == null) { + if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword(),password.getInfo()) == null) { password.setUpload(true); dao.insert(password); } diff --git a/app/src/main/java/com/yutou/passmanage/Tools/RoomDatabaseManager.java b/app/src/main/java/com/yutou/passmanage/Tools/RoomDatabaseManager.java index 74ed111..798a1a0 100644 --- a/app/src/main/java/com/yutou/passmanage/Tools/RoomDatabaseManager.java +++ b/app/src/main/java/com/yutou/passmanage/Tools/RoomDatabaseManager.java @@ -8,6 +8,8 @@ import androidx.room.DatabaseConfiguration; import androidx.room.InvalidationTracker; import androidx.room.Room; import androidx.room.RoomDatabase; +import androidx.room.migration.Migration; +import androidx.sqlite.db.SupportSQLiteDatabase; import androidx.sqlite.db.SupportSQLiteOpenHelper; import com.alibaba.fastjson.JSONObject; @@ -15,7 +17,7 @@ import com.yutou.passmanage.Datas.ToolsPassword; import com.yutou.passmanage.Datas.ToolsPasswordDao; import com.yutou.passmanage.Interfaces.NetworkInterface; -@Database(entities = {ToolsPassword.class}, version = 1,exportSchema = false) +@Database(entities = {ToolsPassword.class}, version = 2,exportSchema = false) public abstract class RoomDatabaseManager extends RoomDatabase { public abstract ToolsPasswordDao passwordDao(); @@ -35,17 +37,26 @@ public abstract class RoomDatabaseManager extends RoomDatabase { public void clearAllTables() { } + private static final Migration update1to2=new Migration(1,2) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE ToolsPassword ADD COLUMN `info` ` TEXT` "); + + } + }; public static RoomDatabaseManager build(Context context) { - return Room.databaseBuilder(context.getApplicationContext(), RoomDatabaseManager.class, "password.db").build(); + return Room.databaseBuilder(context.getApplicationContext(), RoomDatabaseManager.class, "password.db") + .addMigrations(update1to2) + .build(); } - public static void addPassword(String title, String account, String password,int id,boolean isAdd, NetworkInterface networkInterface) { + public static void addPassword(String title, String account, String password,String info,int id,boolean isAdd, NetworkInterface networkInterface) { JSONObject json = new JSONObject(); json.put("title", title); json.put("username", account); json.put("password", password); json.put("url", ""); - json.put("info", ""); + json.put("info", info); json.put("type", "-1"); if(id!=-1){ json.put("id",id); diff --git a/app/src/main/res/layout/dialog_add_passworld.xml b/app/src/main/res/layout/dialog_add_passworld.xml index 5fcd6c2..223d3dc 100644 --- a/app/src/main/res/layout/dialog_add_passworld.xml +++ b/app/src/main/res/layout/dialog_add_passworld.xml @@ -71,6 +71,32 @@ android:layout_weight="1" android:ems="10" android:hint="密码" /> + + + + + + + + +