Add code import from URI handler

This commit is contained in:
MrLetsplay 2023-07-04 08:12:52 +02:00
parent 0af97052e2
commit cfbb969c5c
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
2 changed files with 23 additions and 2 deletions

View File

@ -11,8 +11,11 @@ import androidx.appcompat.app.AppCompatActivity;
import com.cringe_studios.cringe_authenticator.R; import com.cringe_studios.cringe_authenticator.R;
import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator.model.OTPData;
import com.cringe_studios.cringe_authenticator.util.OTPParser; 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 com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
import java.util.List;
public class URIHandlerActivity extends AppCompatActivity { public class URIHandlerActivity extends AppCompatActivity {
@Override @Override
@ -28,8 +31,24 @@ public class URIHandlerActivity extends AppCompatActivity {
try { try {
OTPData data = OTPParser.parse(intent.getData()); OTPData data = OTPParser.parse(intent.getData());
// TODO: choose group, add code // TODO: choose group, add code
Toast.makeText(this, "Code received", Toast.LENGTH_LONG).show(); List<String> groups = SettingsUtil.getGroups(this);
finish(); 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) { }catch(IllegalArgumentException e) {
AlertDialog dialog = new StyledDialogBuilder(this) AlertDialog dialog = new StyledDialogBuilder(this)
.setTitle(R.string.uri_handler_failed_title) .setTitle(R.string.uri_handler_failed_title)

View File

@ -76,6 +76,8 @@
<string name="edit_group_title">Edit Group</string> <string name="edit_group_title">Edit Group</string>
<string name="settings_enable_intro_video">Enable intro video</string> <string name="settings_enable_intro_video">Enable intro video</string>
<string name="settings_biometric_lock">Require biometric unlock</string> <string name="settings_biometric_lock">Require biometric unlock</string>
<string name="uri_handler_code_added">Code added</string>
<string name="uri_handler_add_code_title">Add Code</string>
<string-array name="view_edit_delete"> <string-array name="view_edit_delete">
<item>View</item> <item>View</item>
<item>Edit</item> <item>Edit</item>