Add dialog style to all dialogs, Implement OTP delete
This commit is contained in:
parent
29fef9a266
commit
7a82b98169
17
.idea/deploymentTargetDropDown.xml
Normal file
17
.idea/deploymentTargetDropDown.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="R38N50464FV" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-07-03T11:36:15.677414106Z" />
|
||||
</component>
|
||||
</project>
|
@ -34,6 +34,7 @@ import com.cringe_studios.cringe_authenticator.scanner.QRScannerContract;
|
||||
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||
|
||||
import java.util.Locale;
|
||||
@ -194,13 +195,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
options[0] = OTPType.TOTP.getFriendlyName() + " (TOTP)";
|
||||
options[1] = OTPType.HOTP.getFriendlyName() + " (HOTP)";
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
AlertDialog dialog = new StyledDialogBuilder(this)
|
||||
.setTitle(R.string.create_totp_title)
|
||||
.setView(binding.getRoot())
|
||||
.setNegativeButton(R.string.cancel, (view, which) -> {})
|
||||
.create();
|
||||
|
||||
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed); // TODO: dialog style
|
||||
binding.codeTypes.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, options));
|
||||
binding.codeTypes.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
|
||||
switch(position) {
|
||||
@ -238,7 +238,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public void addGroup(MenuItem item) {
|
||||
EditText t = new EditText(this);
|
||||
new AlertDialog.Builder(this)
|
||||
new StyledDialogBuilder(this)
|
||||
.setTitle(R.string.action_new_group)
|
||||
.setView(t)
|
||||
.setPositiveButton(R.string.add, (view, which) -> {
|
||||
|
@ -9,7 +9,6 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
@ -19,6 +18,7 @@ import com.cringe_studios.cringe_authenticator.otplist.OTPListItem;
|
||||
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPException;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||
|
||||
@ -75,15 +75,12 @@ public class GroupFragment extends NamedFragment {
|
||||
}
|
||||
|
||||
private void showOTPDialog(OTPData data) {
|
||||
new AlertDialog.Builder(requireContext())
|
||||
new StyledDialogBuilder(requireContext())
|
||||
.setTitle(R.string.edit_otp_title)
|
||||
.setItems(R.array.view_edit_delete, (dialog, which) -> {
|
||||
switch(which) {
|
||||
case 0:
|
||||
DialogUtil.showViewCodeDialog(getLayoutInflater(), data, newData -> {
|
||||
otpListAdapter.replace(data, newData);
|
||||
saveOTPs();
|
||||
}, () -> showOTPDialog(data));
|
||||
DialogUtil.showViewCodeDialog(getLayoutInflater(), data, () -> showOTPDialog(data));
|
||||
break;
|
||||
case 1:
|
||||
DialogUtil.showEditCodeDialog(getLayoutInflater(), data, newData -> {
|
||||
@ -91,7 +88,17 @@ public class GroupFragment extends NamedFragment {
|
||||
saveOTPs();
|
||||
}, () -> showOTPDialog(data));
|
||||
break;
|
||||
case 2: break;
|
||||
case 2:
|
||||
new StyledDialogBuilder(requireContext())
|
||||
.setTitle("Delete?")
|
||||
.setMessage("Delete this?")
|
||||
.setPositiveButton(R.string.yes, (d, w) -> {
|
||||
otpListAdapter.remove(data);
|
||||
saveOTPs();
|
||||
})
|
||||
.setNegativeButton(R.string.no, (d, w) -> {})
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialog, which) -> {})
|
||||
|
@ -7,12 +7,12 @@ import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
||||
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -55,7 +55,7 @@ public class GroupListAdapter extends RecyclerView.Adapter<GroupListItem> {
|
||||
|
||||
holder.getBinding().button.setOnClickListener(view -> navigateToGroup.accept(group));
|
||||
holder.getBinding().button.setOnLongClickListener(view -> {
|
||||
new AlertDialog.Builder(context)
|
||||
new StyledDialogBuilder(context)
|
||||
.setTitle(R.string.group_delete_title)
|
||||
.setMessage(R.string.group_delete_message)
|
||||
.setPositiveButton(R.string.yes, (dialog, which) -> removeGroup.accept(group))
|
||||
|
@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
import com.cringe_studios.cringe_authenticator.util.OTPParser;
|
||||
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||
|
||||
public class URIHandlerActivity extends AppCompatActivity {
|
||||
|
||||
@ -30,7 +31,7 @@ public class URIHandlerActivity extends AppCompatActivity {
|
||||
Toast.makeText(this, "Code received", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}catch(IllegalArgumentException e) {
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
AlertDialog dialog = new StyledDialogBuilder(this)
|
||||
.setTitle(R.string.uri_handler_failed_title)
|
||||
.setMessage(e.getMessage())
|
||||
.setPositiveButton(R.string.ok, (d, which) -> finish())
|
||||
|
@ -24,7 +24,7 @@ public class DialogUtil {
|
||||
private static final Integer[] DIGITS = new Integer[]{6, 7, 8, 9, 10, 11, 12};
|
||||
|
||||
private static void showCodeDialog(Context context, View view, DialogCallback ok, Runnable back) {
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
AlertDialog dialog = new StyledDialogBuilder(context)
|
||||
.setTitle(R.string.code_input_title)
|
||||
.setView(view)
|
||||
.setPositiveButton(R.string.ok, (btnView, which) -> {})
|
||||
@ -32,8 +32,6 @@ public class DialogUtil {
|
||||
.setNegativeButton(R.string.cancel, (btnView, which) -> {})
|
||||
.create();
|
||||
|
||||
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed); // TODO: dialog style
|
||||
|
||||
dialog.setOnShowListener(d -> {
|
||||
Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
okButton.setOnClickListener(v -> {
|
||||
@ -45,13 +43,11 @@ public class DialogUtil {
|
||||
}
|
||||
|
||||
public static void showErrorDialog(Context context, String errorMessage) {
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
new StyledDialogBuilder(context)
|
||||
.setTitle(R.string.failed_title)
|
||||
.setMessage(errorMessage)
|
||||
.setPositiveButton(R.string.ok, (d, which) -> {})
|
||||
.create();
|
||||
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed); // TODO: dialog style
|
||||
dialog.show();
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showTOTPDialog(LayoutInflater inflater, OTPData initialData, Consumer<OTPData> callback, Runnable back, boolean view) {
|
||||
@ -160,10 +156,10 @@ public class DialogUtil {
|
||||
}, back);
|
||||
}
|
||||
|
||||
public static void showViewCodeDialog(LayoutInflater inflater, @NonNull OTPData initialData, Consumer<OTPData> callback, Runnable back) {
|
||||
public static void showViewCodeDialog(LayoutInflater inflater, @NonNull OTPData initialData, Runnable back) {
|
||||
switch(initialData.getType()) {
|
||||
case HOTP: showHOTPDialog(inflater, initialData, callback, back, true); break;
|
||||
case TOTP: showTOTPDialog(inflater, initialData, callback, back, true); break;
|
||||
case HOTP: showHOTPDialog(inflater, initialData, d -> {}, back, true); break;
|
||||
case TOTP: showTOTPDialog(inflater, initialData, d -> {}, back, true); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.cringe_studios.cringe_authenticator.util;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
|
||||
public class StyledDialogBuilder extends AlertDialog.Builder {
|
||||
|
||||
public StyledDialogBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public StyledDialogBuilder(Context context, int themeResId) {
|
||||
super(context, themeResId);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AlertDialog create() {
|
||||
AlertDialog dialog = super.create();
|
||||
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user