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.DialogUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
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 com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -194,13 +195,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
options[0] = OTPType.TOTP.getFriendlyName() + " (TOTP)";
|
options[0] = OTPType.TOTP.getFriendlyName() + " (TOTP)";
|
||||||
options[1] = OTPType.HOTP.getFriendlyName() + " (HOTP)";
|
options[1] = OTPType.HOTP.getFriendlyName() + " (HOTP)";
|
||||||
|
|
||||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
AlertDialog dialog = new StyledDialogBuilder(this)
|
||||||
.setTitle(R.string.create_totp_title)
|
.setTitle(R.string.create_totp_title)
|
||||||
.setView(binding.getRoot())
|
.setView(binding.getRoot())
|
||||||
.setNegativeButton(R.string.cancel, (view, which) -> {})
|
.setNegativeButton(R.string.cancel, (view, which) -> {})
|
||||||
.create();
|
.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.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, options));
|
||||||
binding.codeTypes.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
|
binding.codeTypes.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
|
||||||
switch(position) {
|
switch(position) {
|
||||||
@ -238,7 +238,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public void addGroup(MenuItem item) {
|
public void addGroup(MenuItem item) {
|
||||||
EditText t = new EditText(this);
|
EditText t = new EditText(this);
|
||||||
new AlertDialog.Builder(this)
|
new StyledDialogBuilder(this)
|
||||||
.setTitle(R.string.action_new_group)
|
.setTitle(R.string.action_new_group)
|
||||||
.setView(t)
|
.setView(t)
|
||||||
.setPositiveButton(R.string.add, (view, which) -> {
|
.setPositiveButton(R.string.add, (view, which) -> {
|
||||||
|
@ -9,7 +9,6 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
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.DialogUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
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.OTPException;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||||
|
|
||||||
@ -75,23 +75,30 @@ public class GroupFragment extends NamedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showOTPDialog(OTPData data) {
|
private void showOTPDialog(OTPData data) {
|
||||||
new AlertDialog.Builder(requireContext())
|
new StyledDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.edit_otp_title)
|
.setTitle(R.string.edit_otp_title)
|
||||||
.setItems(R.array.view_edit_delete, (dialog, which) -> {
|
.setItems(R.array.view_edit_delete, (dialog, which) -> {
|
||||||
switch(which) {
|
switch(which) {
|
||||||
case 0:
|
case 0:
|
||||||
DialogUtil.showViewCodeDialog(getLayoutInflater(), data, newData -> {
|
DialogUtil.showViewCodeDialog(getLayoutInflater(), data, () -> showOTPDialog(data));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
DialogUtil.showEditCodeDialog(getLayoutInflater(), data, newData -> {
|
||||||
otpListAdapter.replace(data, newData);
|
otpListAdapter.replace(data, newData);
|
||||||
saveOTPs();
|
saveOTPs();
|
||||||
}, () -> showOTPDialog(data));
|
}, () -> showOTPDialog(data));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 2:
|
||||||
DialogUtil.showEditCodeDialog(getLayoutInflater(), data, newData -> {
|
new StyledDialogBuilder(requireContext())
|
||||||
otpListAdapter.replace(data, newData);
|
.setTitle("Delete?")
|
||||||
saveOTPs();
|
.setMessage("Delete this?")
|
||||||
}, () -> showOTPDialog(data));
|
.setPositiveButton(R.string.yes, (d, w) -> {
|
||||||
|
otpListAdapter.remove(data);
|
||||||
|
saveOTPs();
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.no, (d, w) -> {})
|
||||||
|
.show();
|
||||||
break;
|
break;
|
||||||
case 2: break;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialog, which) -> {})
|
.setNegativeButton(R.string.cancel, (dialog, which) -> {})
|
||||||
|
@ -7,12 +7,12 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.core.util.Consumer;
|
import androidx.core.util.Consumer;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.setOnClickListener(view -> navigateToGroup.accept(group));
|
||||||
holder.getBinding().button.setOnLongClickListener(view -> {
|
holder.getBinding().button.setOnLongClickListener(view -> {
|
||||||
new AlertDialog.Builder(context)
|
new StyledDialogBuilder(context)
|
||||||
.setTitle(R.string.group_delete_title)
|
.setTitle(R.string.group_delete_title)
|
||||||
.setMessage(R.string.group_delete_message)
|
.setMessage(R.string.group_delete_message)
|
||||||
.setPositiveButton(R.string.yes, (dialog, which) -> removeGroup.accept(group))
|
.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.OTPData;
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
import com.cringe_studios.cringe_authenticator.util.OTPParser;
|
import com.cringe_studios.cringe_authenticator.util.OTPParser;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||||
|
|
||||||
public class URIHandlerActivity extends AppCompatActivity {
|
public class URIHandlerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class URIHandlerActivity extends AppCompatActivity {
|
|||||||
Toast.makeText(this, "Code received", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "Code received", Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
}catch(IllegalArgumentException e) {
|
}catch(IllegalArgumentException e) {
|
||||||
AlertDialog dialog = new AlertDialog.Builder(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) -> finish())
|
||||||
|
@ -24,7 +24,7 @@ public class DialogUtil {
|
|||||||
private static final Integer[] DIGITS = new Integer[]{6, 7, 8, 9, 10, 11, 12};
|
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) {
|
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)
|
.setTitle(R.string.code_input_title)
|
||||||
.setView(view)
|
.setView(view)
|
||||||
.setPositiveButton(R.string.ok, (btnView, which) -> {})
|
.setPositiveButton(R.string.ok, (btnView, which) -> {})
|
||||||
@ -32,8 +32,6 @@ public class DialogUtil {
|
|||||||
.setNegativeButton(R.string.cancel, (btnView, which) -> {})
|
.setNegativeButton(R.string.cancel, (btnView, which) -> {})
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed); // TODO: dialog style
|
|
||||||
|
|
||||||
dialog.setOnShowListener(d -> {
|
dialog.setOnShowListener(d -> {
|
||||||
Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
okButton.setOnClickListener(v -> {
|
okButton.setOnClickListener(v -> {
|
||||||
@ -45,13 +43,11 @@ public class DialogUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showErrorDialog(Context context, String errorMessage) {
|
public static void showErrorDialog(Context context, String errorMessage) {
|
||||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
new StyledDialogBuilder(context)
|
||||||
.setTitle(R.string.failed_title)
|
.setTitle(R.string.failed_title)
|
||||||
.setMessage(errorMessage)
|
.setMessage(errorMessage)
|
||||||
.setPositiveButton(R.string.ok, (d, which) -> {})
|
.setPositiveButton(R.string.ok, (d, which) -> {})
|
||||||
.create();
|
.show();
|
||||||
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed); // TODO: dialog style
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showTOTPDialog(LayoutInflater inflater, OTPData initialData, Consumer<OTPData> callback, Runnable back, boolean view) {
|
public static void showTOTPDialog(LayoutInflater inflater, OTPData initialData, Consumer<OTPData> callback, Runnable back, boolean view) {
|
||||||
@ -160,10 +156,10 @@ public class DialogUtil {
|
|||||||
}, back);
|
}, 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()) {
|
switch(initialData.getType()) {
|
||||||
case HOTP: showHOTPDialog(inflater, initialData, callback, back, true); break;
|
case HOTP: showHOTPDialog(inflater, initialData, d -> {}, back, true); break;
|
||||||
case TOTP: showTOTPDialog(inflater, initialData, callback, 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