Clean up code, Close app properly on URI import
This commit is contained in:
parent
a3ed96c6b0
commit
378e6ad76b
@ -3,6 +3,7 @@ package com.cringe_studios.cringe_authenticator.urihandler;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@ -26,49 +27,28 @@ public class URIHandlerActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if(intent == null) {
|
if(intent == null) {
|
||||||
finish();
|
finishAndRemoveTask();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri uri = intent.getData();
|
|
||||||
switch(uri.getScheme().toLowerCase()) {
|
|
||||||
case "otpauth":
|
|
||||||
importCode(uri);
|
|
||||||
break;
|
|
||||||
case "otpauth-migration":
|
|
||||||
importMigration(uri);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void importCode(Uri uri) {
|
|
||||||
try {
|
try {
|
||||||
OTPData data = OTPParser.parse(uri);
|
Uri uri = intent.getData();
|
||||||
importCodes(data);
|
switch(uri.getScheme().toLowerCase()) {
|
||||||
|
case "otpauth":
|
||||||
|
importCodes(OTPParser.parse(uri));
|
||||||
|
break;
|
||||||
|
case "otpauth-migration":
|
||||||
|
importCodes(OTPParser.parseMigration(uri));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}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)
|
||||||
.setMessage(e.getMessage())
|
.setMessage(e.getMessage())
|
||||||
.setPositiveButton(R.string.ok, (d, which) -> finish())
|
.setPositiveButton(R.string.ok, (d, which) -> finishAndRemoveTask())
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
dialog.setOnDismissListener(d -> finish());
|
dialog.setOnDismissListener(d -> finishAndRemoveTask());
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void importMigration(Uri uri) {
|
|
||||||
try {
|
|
||||||
OTPData[] data = OTPParser.parseMigration(uri);
|
|
||||||
importCodes(data);
|
|
||||||
}catch(IllegalArgumentException e) {
|
|
||||||
AlertDialog dialog = new StyledDialogBuilder(this)
|
|
||||||
.setTitle(R.string.uri_handler_failed_title)
|
|
||||||
.setMessage(e.getMessage())
|
|
||||||
.setPositiveButton(R.string.ok, (d, which) -> finish())
|
|
||||||
.create();
|
|
||||||
|
|
||||||
dialog.setOnDismissListener(d -> finish());
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +56,8 @@ public class URIHandlerActivity extends AppCompatActivity {
|
|||||||
private void importCodes(OTPData... data) {
|
private void importCodes(OTPData... data) {
|
||||||
DialogUtil.showImportCodeDialog(this, group -> {
|
DialogUtil.showImportCodeDialog(this, group -> {
|
||||||
for(OTPData d : data) SettingsUtil.addOTP(this, group, d);
|
for(OTPData d : data) SettingsUtil.addOTP(this, group, d);
|
||||||
}, this::finish);
|
Toast.makeText(this, R.string.uri_handler_code_added, Toast.LENGTH_SHORT).show();
|
||||||
|
}, this::finishAndRemoveTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@ -247,7 +246,6 @@ public class DialogUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callback.accept(groups.get(which - 1));
|
callback.accept(groups.get(which - 1));
|
||||||
Toast.makeText(context, R.string.uri_handler_code_added, Toast.LENGTH_SHORT).show();
|
|
||||||
if(onDismiss != null) onDismiss.run();
|
if(onDismiss != null) onDismiss.run();
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (d, which) -> { if(onDismiss != null) onDismiss.run(); })
|
.setNegativeButton(R.string.cancel, (d, which) -> { if(onDismiss != null) onDismiss.run(); })
|
||||||
|
Loading…
Reference in New Issue
Block a user