From d305c7809c8c45ea82b12d6770876b72d1b80af4 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 16 Aug 2021 09:38:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E7=89=881.2=E7=89=88=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=86=E5=89=B2=E7=BA=BF=20=E4=BC=98=E5=8C=96=EF=BC=9A?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=B8=85=E7=A9=BA=E6=8C=89=E9=92=AE=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=8C=87=E7=BA=B9?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../Adapters/PassWordListAdapter.java | 18 ++- .../com/yutou/passmanage/MainActivity.java | 139 ++++++++++-------- .../com/yutou/passmanage/Tools/ResTools.java | 9 ++ app/src/main/res/drawable/ic_close.png | Bin 0 -> 683 bytes app/src/main/res/layout/activity_main.xml | 24 ++- .../main/res/layout/dialog_add_passworld.xml | 28 ++-- app/src/main/res/layout/recycler_list.xml | 95 ++++++------ app/src/main/res/values/strings.xml | 6 + app/src/main/res/values/values.xml | 4 + build.gradle | 2 +- 11 files changed, 199 insertions(+), 128 deletions(-) create mode 100644 app/src/main/java/com/yutou/passmanage/Tools/ResTools.java create mode 100644 app/src/main/res/drawable/ic_close.png create mode 100644 app/src/main/res/values/values.xml diff --git a/app/build.gradle b/app/build.gradle index 56ed923..0eb555c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,7 +25,7 @@ android { minSdkVersion 23 targetSdkVersion 30 versionCode 1 - versionName "1.1" + versionName "1.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" signingConfig signingConfigs.yutou diff --git a/app/src/main/java/com/yutou/passmanage/Adapters/PassWordListAdapter.java b/app/src/main/java/com/yutou/passmanage/Adapters/PassWordListAdapter.java index c03e356..c12ab0d 100644 --- a/app/src/main/java/com/yutou/passmanage/Adapters/PassWordListAdapter.java +++ b/app/src/main/java/com/yutou/passmanage/Adapters/PassWordListAdapter.java @@ -27,6 +27,7 @@ import com.yutou.passmanage.Datas.ToolsPasswordDao; import com.yutou.passmanage.Interfaces.NetworkInterface; import com.yutou.passmanage.R; import com.yutou.passmanage.Tools.NetworkTool; +import com.yutou.passmanage.Tools.ResTools; import com.yutou.passmanage.Tools.RoomDatabaseManager; import java.util.List; @@ -54,26 +55,27 @@ public class PassWordListAdapter extends RecyclerView.Adapter= android.os.Build.VERSION_CODES.M) { - /* Intent enrollIntent = new Intent(Settings.ACTION_BIOMETRIC_ENROLL); - enrollIntent.putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, - BIOMETRIC_STRONG | DEVICE_CREDENTIAL); - startActivityForResult(enrollIntent, 233);*/ - } - prompt=new BiometricPrompt(this, ContextCompat.getMainExecutor(this), new BiometricPrompt.AuthenticationCallback() { + prompt = new BiometricPrompt(this, ContextCompat.getMainExecutor(this), new BiometricPrompt.AuthenticationCallback() { @Override public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); Toast.makeText(MainActivity.this, "验证成功", Toast.LENGTH_LONG).show(); - initView(); init(); + authError.setVisibility(View.GONE); + passList.setVisibility(View.VISIBLE); } @Override @@ -87,9 +87,11 @@ public class MainActivity extends AppCompatActivity { public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { super.onAuthenticationError(errorCode, errString); System.out.println("errorCode = " + errorCode + ", errString = " + errString); - if(errorCode==10){ - auth(); - }else if(errorCode==13){ + if (errorCode == 10) { + authError.setText("未授权,点击授权"); + authError.setVisibility(View.VISIBLE); + passList.setVisibility(View.GONE); + } else if (errorCode == 13) { } } @@ -106,7 +108,8 @@ public class MainActivity extends AppCompatActivity { Toast.makeText(this, "必须在支持指纹的设备上使用", Toast.LENGTH_LONG).show(); } } - void exit(){ + + void exit() { MainActivity.this.finish(); System.exit(0); } @@ -115,6 +118,7 @@ public class MainActivity extends AppCompatActivity { dao = RoomDatabaseManager.build(this).passwordDao(); adapter = new PassWordListAdapter(this, new ArrayList<>()); search = findViewById(R.id.search); + authError = findViewById(R.id.goneText); clearSearch = findViewById(R.id.clearSearch); passList = findViewById(R.id.passList); floatButton = findViewById(R.id.floatButton); @@ -125,7 +129,12 @@ public class MainActivity extends AppCompatActivity { search.setText(""); new Thread(this::showData).start(); }); - + authError.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + auth(); + } + }); search.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -157,16 +166,16 @@ public class MainActivity extends AppCompatActivity { void showAddPasswordDialog() { View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_add_passworld, null); - 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); AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) .setTitle("添加账号") .setView(view) .setPositiveButton("保存", (dialog1, which) -> { - addPassword(title.getText().toString(), account.getText().toString(), password.getText().toString(), info.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,71 +243,77 @@ public class MainActivity extends AppCompatActivity { void initData() { new Thread(() -> { List list = dao.getAllAndRemove(); - 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(); + if (list.size() == 0) { + 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) { + @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); - } + } + }); + } 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); - } + @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); + 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); } - } else { - dao.delete(password); + showData(); } - showData(); - } - }).start(); + }).start(); - } - }); + } + }); + } } } NetworkTool.httpGet(NetworkTool.NetworkAPI.PASSWORD_ALL, new JSONObject(), new NetworkInterface() { @Override public void httpGetData(Object data, int state) { - data=((String)data).replace("desc","info"); + 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(),password.getInfo()) == null) { + if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword(), password.getInfo()) == null) { password.setUpload(true); dao.insert(password); } @@ -307,7 +322,7 @@ public class MainActivity extends AppCompatActivity { e.printStackTrace(); dao.clear(); for (ToolsPassword password : list) { - if (dao.isExist(password.getTitle(), password.getAccount(), password.getPassword(),password.getInfo()) == 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/ResTools.java b/app/src/main/java/com/yutou/passmanage/Tools/ResTools.java new file mode 100644 index 0000000..ddb9b69 --- /dev/null +++ b/app/src/main/java/com/yutou/passmanage/Tools/ResTools.java @@ -0,0 +1,9 @@ +package com.yutou.passmanage.Tools; + +import android.content.Context; + +public class ResTools { + public static String getString(Context context,int id){ + return context.getResources().getString(id); + } +} diff --git a/app/src/main/res/drawable/ic_close.png b/app/src/main/res/drawable/ic_close.png new file mode 100644 index 0000000000000000000000000000000000000000..82777ce2c44fe53dbbaabbf4d23269ff63852adf GIT binary patch literal 683 zcmV;c0#yBpP)Px%Wl2OqR9HvNmpzCRQ4q)f^CH-IMK;3qChLKgcPK^_6g(RRZEUSP&C^0bJHZp| z6twU*dRDeJ3fg#rf?`CuD^EB#u|F`I;%o%-Mqc8E-OYZy#FNdoZ+7N4A8+=*gq$DB zIX*@LC_3Md5Ot4(F;BoW1JgPI0yY`g1Yw1_@U|oOd@xPS2%zXR7XV%$VAjMj18V>+ zcVuNb%RUvLXI>nfn`XJue^F0Og9{2o^}F1&T{lG=M1_Syd9wm{Lk!t=x7xN0M?Q_55nuT>{J)Wb`)q!fu91{AF*8* zp!2`GJS7Tvms%ypN$;|~@^^{#O)cl!U4X8qy(mC)KV)UidgShd!m|LxIt0#nm+Y^* zo#w0puco(&?|E|XjR=7I5kNJgzk@&l2>8Kcz>?fGJZT>e0hAoK$w1j)z`_s!bmk)j z*WZp-TiTUq1-1a}G62vf1BhPxhFg;5=BFp^smTJEgcjsGgjU_X1;%1(^AxJy75h`# zHMAbOhak{M^+Q|Vks$nnz>~N|1ceKVu`_ECF$zb0)igP)SZAL5 z$EXjH~T zE75wgoRo~}z+kM&{xOMGrLUU!1VGi;Uo&t6OmBR(V=|~l6) - @@ -36,9 +38,20 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/search" > - + + diff --git a/app/src/main/res/layout/dialog_add_passworld.xml b/app/src/main/res/layout/dialog_add_passworld.xml index 223d3dc..a7b0563 100644 --- a/app/src/main/res/layout/dialog_add_passworld.xml +++ b/app/src/main/res/layout/dialog_add_passworld.xml @@ -1,8 +1,10 @@ + android:text="@string/account" /> + android:hint="@string/account" /> @@ -40,16 +42,17 @@ android:layout_gravity="center" android:layout_marginStart="20dp" android:layout_weight="1" - android:text="账号" /> + android:text="@string/account" /> + android:hint="@string/account" + android:autofillHints="name" /> + android:text="@string/password" /> + android:hint="@string/password" + android:autofillHints="name" + android:inputType="textPersonName" + /> + android:text="@string/info" /> - - + android:orientation="vertical"> + android:orientation="horizontal"> - + - + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_marginStart="10dp" + android:layout_marginEnd="10dp" + android:layout_weight="2" + android:orientation="vertical"> - + + + + + + + +