From cfbb969c5c08d61daf936b3885ffe08752013cad Mon Sep 17 00:00:00 2001 From: MrLetsplay Date: Tue, 4 Jul 2023 08:12:52 +0200 Subject: [PATCH] Add code import from URI handler --- .../urihandler/URIHandlerActivity.java | 23 +++++++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/urihandler/URIHandlerActivity.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/urihandler/URIHandlerActivity.java index 9e02249..6a4281b 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/urihandler/URIHandlerActivity.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/urihandler/URIHandlerActivity.java @@ -11,8 +11,11 @@ import androidx.appcompat.app.AppCompatActivity; import com.cringe_studios.cringe_authenticator.R; import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator.util.OTPParser; +import com.cringe_studios.cringe_authenticator.util.SettingsUtil; import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder; +import java.util.List; + public class URIHandlerActivity extends AppCompatActivity { @Override @@ -28,8 +31,24 @@ public class URIHandlerActivity extends AppCompatActivity { try { OTPData data = OTPParser.parse(intent.getData()); // TODO: choose group, add code - Toast.makeText(this, "Code received", Toast.LENGTH_LONG).show(); - finish(); + List groups = SettingsUtil.getGroups(this); + String[] groupNames = new String[groups.size()]; + for(int i = 0; i < groups.size(); i++) { + groupNames[i] = SettingsUtil.getGroupName(this, groups.get(i)); + } + + // TODO: add option to create new group? + AlertDialog dialog = new StyledDialogBuilder(this) + .setTitle(R.string.uri_handler_add_code_title) + .setItems(groupNames, (d, which) -> { + SettingsUtil.addOTP(this, groups.get(which), data); + Toast.makeText(this, R.string.uri_handler_code_added, Toast.LENGTH_SHORT).show(); + }) + .setPositiveButton(R.string.ok, (d, which) -> finish()) + .create(); + + dialog.setOnDismissListener(d -> finish()); + dialog.show(); }catch(IllegalArgumentException e) { AlertDialog dialog = new StyledDialogBuilder(this) .setTitle(R.string.uri_handler_failed_title) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 77b25c3..a7a12b9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,6 +76,8 @@ Edit Group Enable intro video Require biometric unlock + Code added + Add Code View Edit