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 0000000..82777ce Binary files /dev/null and b/app/src/main/res/drawable/ic_close.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 683f279..bdcf5ca 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,12 +18,14 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - @@ -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"> - + + + + + + + +