diff --git a/app/build.gradle b/app/build.gradle index 440428d..35efdbf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.9' - def camerax_version = "1.2.2" + def camerax_version = "1.2.3" implementation "androidx.camera:camera-core:${camerax_version}" implementation "androidx.camera:camera-camera2:${camerax_version}" implementation "androidx.camera:camera-lifecycle:${camerax_version}" diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java index 652dafc..8f484ee 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java @@ -10,7 +10,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.EditText; import android.widget.Toast; import androidx.activity.result.ActivityResultLauncher; @@ -237,23 +236,12 @@ public class MainActivity extends AppCompatActivity { } public void addGroup(MenuItem item) { - EditText t = new EditText(this); - new StyledDialogBuilder(this) - .setTitle(R.string.action_new_group) - .setView(t) - .setPositiveButton(R.string.add, (view, which) -> { - if(t.getText().length() == 0) { - DialogUtil.showErrorDialog(this, getString(R.string.new_group_missing_title)); - return; - } - - Fragment frag = NavigationUtil.getCurrentFragment(this); - if(frag instanceof MenuFragment) { - ((MenuFragment) frag).addGroup(t.getText().toString()); - } - }) - .setNegativeButton(R.string.cancel, (view, which) -> {}) - .show(); + DialogUtil.showCreateGroupDialog(getLayoutInflater(), null, group -> { + Fragment frag = NavigationUtil.getCurrentFragment(this); + if(frag instanceof MenuFragment) { + ((MenuFragment) frag).addGroup(group); + } + }); } @Override diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/GroupFragment.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/GroupFragment.java index 61dfa37..268998a 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/GroupFragment.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/GroupFragment.java @@ -10,9 +10,9 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.cringe_studios.cringe_authenticator.OTPData; import com.cringe_studios.cringe_authenticator.R; import com.cringe_studios.cringe_authenticator.databinding.FragmentGroupBinding; +import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator.otplist.OTPListAdapter; import com.cringe_studios.cringe_authenticator.otplist.OTPListItem; import com.cringe_studios.cringe_authenticator.util.DialogUtil; @@ -28,7 +28,7 @@ public class GroupFragment extends NamedFragment { public static final String BUNDLE_GROUP = "group"; - private String groupName; + private String groupID; private FragmentGroupBinding binding; @@ -40,7 +40,7 @@ public class GroupFragment extends NamedFragment { @Override public String getName() { - return groupName; + return SettingsUtil.getGroupName(requireContext(), groupID); } @Override @@ -53,7 +53,7 @@ public class GroupFragment extends NamedFragment { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = FragmentGroupBinding.inflate(inflater, container, false); - groupName = requireArguments().getString(GroupFragment.BUNDLE_GROUP); + groupID = requireArguments().getString(GroupFragment.BUNDLE_GROUP); FabUtil.showFabs(requireActivity()); @@ -90,8 +90,8 @@ public class GroupFragment extends NamedFragment { break; case 2: new StyledDialogBuilder(requireContext()) - .setTitle("Delete?") - .setMessage("Delete this?") + .setTitle(R.string.otp_delete_title) + .setMessage(R.string.otp_delete_message) .setPositiveButton(R.string.yes, (d, w) -> { otpListAdapter.remove(data); saveOTPs(); @@ -103,30 +103,15 @@ public class GroupFragment extends NamedFragment { }) .setNegativeButton(R.string.cancel, (dialog, which) -> {}) .show(); - - /*switch(data.getType()) { - case HOTP: - DialogUtil.showHOTPDialog(getLayoutInflater(), data, newData -> { - otpListAdapter.replace(data, newData); - saveOTPs(); - }); - break; - case TOTP: - DialogUtil.showTOTPDialog(getLayoutInflater(), data, newData -> { - otpListAdapter.replace(data, newData); - saveOTPs(); - }); - break; - }*/ } private void saveOTPs() { - SettingsUtil.updateOTPs(requireContext(), groupName, otpListAdapter.getItems()); + SettingsUtil.updateOTPs(requireContext(), groupID, otpListAdapter.getItems()); refreshCodes(); } private void loadOTPs() { - List data = SettingsUtil.getOTPs(requireContext(), groupName); + List data = SettingsUtil.getOTPs(requireContext(), groupID); for(OTPData otp : data) { otpListAdapter.add(otp); @@ -134,7 +119,7 @@ public class GroupFragment extends NamedFragment { } public void addOTP(OTPData data) { - SettingsUtil.addOTP(requireContext(), groupName, data); + SettingsUtil.addOTP(requireContext(), groupID, data); otpListAdapter.add(data); } diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java index d09903c..0051ec1 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/MenuFragment.java @@ -8,13 +8,17 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.cringe_studios.cringe_authenticator.R; import com.cringe_studios.cringe_authenticator.databinding.FragmentMenuBinding; import com.cringe_studios.cringe_authenticator.grouplist.GroupListAdapter; +import com.cringe_studios.cringe_authenticator.util.DialogUtil; import com.cringe_studios.cringe_authenticator.util.FabUtil; 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 java.util.List; +import java.util.UUID; public class MenuFragment extends NamedFragment { @@ -36,21 +40,42 @@ public class MenuFragment extends NamedFragment { Bundle bundle = new Bundle(); bundle.putString(GroupFragment.BUNDLE_GROUP, group); NavigationUtil.navigate(this, GroupFragment.class, bundle); - }, this::removeGroup); + }, this::showGroupDialog); binding.menuItems.setAdapter(groupListAdapter); loadGroups(); - /*binding.editSwitch.setOnCheckedChangeListener((view, checked) -> { - // TODO: edit mode - });*/ - FabUtil.hideFabs(requireActivity()); return binding.getRoot(); } + private void showGroupDialog(String group) { + new StyledDialogBuilder(requireContext()) + .setTitle(R.string.edit_group_title) + .setItems(R.array.rename_delete, (dialog, which) -> { + switch(which) { + case 0: + DialogUtil.showCreateGroupDialog(getLayoutInflater(), SettingsUtil.getGroupName(requireContext(), group), newName -> { + renameGroup(group, newName); + }); + + break; + case 1: + new StyledDialogBuilder(requireContext()) + .setTitle(R.string.group_delete_title) + .setMessage(R.string.group_delete_message) + .setPositiveButton(R.string.yes, (d, w) -> removeGroup(group)) + .setNegativeButton(R.string.no, (d, w) -> {}) + .show(); + break; + } + }) + .setNegativeButton(R.string.cancel, (dialog, which) -> {}) + .show(); + } + private void loadGroups() { List items = SettingsUtil.getGroups(requireContext()); @@ -59,9 +84,10 @@ public class MenuFragment extends NamedFragment { } } - public void addGroup(String group) { - SettingsUtil.addGroup(requireContext(), group); - groupListAdapter.add(group); + public void addGroup(String groupName) { + String id = UUID.randomUUID().toString(); + SettingsUtil.addGroup(requireContext(), id, groupName); + groupListAdapter.add(id); } public void removeGroup(String group) { @@ -69,6 +95,11 @@ public class MenuFragment extends NamedFragment { groupListAdapter.remove(group); } + public void renameGroup(String group, String newName) { + SettingsUtil.setGroupName(requireContext(), group, newName); + groupListAdapter.update(group); + } + @Override public void onDestroyView() { super.onDestroyView(); diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/grouplist/GroupListAdapter.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/grouplist/GroupListAdapter.java index c727d08..3fa3dde 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/grouplist/GroupListAdapter.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/grouplist/GroupListAdapter.java @@ -10,9 +10,8 @@ import androidx.annotation.NonNull; 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 com.cringe_studios.cringe_authenticator.util.SettingsUtil; import java.util.ArrayList; import java.util.List; @@ -29,12 +28,12 @@ public class GroupListAdapter extends RecyclerView.Adapter { private Consumer navigateToGroup; - private Consumer removeGroup; + private Consumer showMenuCallback; - public GroupListAdapter(Context context, Consumer navigateToGroup, Consumer removeGroup) { + public GroupListAdapter(Context context, Consumer navigateToGroup, Consumer showMenuCallback) { this.context = context; this.navigateToGroup = navigateToGroup; - this.removeGroup = removeGroup; + this.showMenuCallback = showMenuCallback; this.inflater = LayoutInflater.from(context); this.items = new ArrayList<>(); this.handler = new Handler(Looper.getMainLooper()); @@ -51,17 +50,11 @@ public class GroupListAdapter extends RecyclerView.Adapter { public void onBindViewHolder(@NonNull GroupListItem holder, int position) { String group = items.get(position); - holder.getBinding().button.setText(group); + holder.getBinding().button.setText(SettingsUtil.getGroupName(context, group)); holder.getBinding().button.setOnClickListener(view -> navigateToGroup.accept(group)); holder.getBinding().button.setOnLongClickListener(view -> { - new StyledDialogBuilder(context) - .setTitle(R.string.group_delete_title) - .setMessage(R.string.group_delete_message) - .setPositiveButton(R.string.yes, (dialog, which) -> removeGroup.accept(group)) - .setNegativeButton(R.string.no, (dialog, which) -> {}) - .show(); - // TODO: better method? + showMenuCallback.accept(group); return true; }); } @@ -83,4 +76,10 @@ public class GroupListAdapter extends RecyclerView.Adapter { notifyItemRemoved(index); } + public void update(String group) { + int index = items.indexOf(group); + if(index == -1) return; + notifyItemChanged(index); + } + } diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/OTPData.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/model/OTPData.java similarity index 98% rename from app/src/main/java/com/cringe_studios/cringe_authenticator/OTPData.java rename to app/src/main/java/com/cringe_studios/cringe_authenticator/model/OTPData.java index d321911..37e2dec 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/OTPData.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/model/OTPData.java @@ -1,4 +1,4 @@ -package com.cringe_studios.cringe_authenticator; +package com.cringe_studios.cringe_authenticator.model; import androidx.annotation.NonNull; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java index 08339ec..65c49c4 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java @@ -12,9 +12,9 @@ import androidx.annotation.NonNull; import androidx.core.util.Consumer; import androidx.recyclerview.widget.RecyclerView; -import com.cringe_studios.cringe_authenticator.OTPData; import com.cringe_studios.cringe_authenticator.R; import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding; +import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator_library.OTPException; import com.cringe_studios.cringe_authenticator_library.OTPType; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java index c40f722..d02b3ba 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java @@ -3,8 +3,8 @@ package com.cringe_studios.cringe_authenticator.otplist; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import com.cringe_studios.cringe_authenticator.OTPData; import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding; +import com.cringe_studios.cringe_authenticator.model.OTPData; public class OTPListItem extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerActivity.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerActivity.java index 3029b16..e5ccfb4 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerActivity.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerActivity.java @@ -27,8 +27,8 @@ import androidx.camera.core.SurfaceOrientedMeteringPointFactory; import androidx.camera.lifecycle.ProcessCameraProvider; import androidx.core.content.ContextCompat; -import com.cringe_studios.cringe_authenticator.OTPData; import com.cringe_studios.cringe_authenticator.databinding.ActivityQrScannerBinding; +import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator.util.OTPParser; import com.google.common.util.concurrent.ListenableFuture; import com.google.mlkit.vision.barcode.BarcodeScanner; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerContract.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerContract.java index d161c7a..f0ecf39 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerContract.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/QRScannerContract.java @@ -8,7 +8,7 @@ import androidx.activity.result.contract.ActivityResultContract; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.cringe_studios.cringe_authenticator.OTPData; +import com.cringe_studios.cringe_authenticator.model.OTPData; public class QRScannerContract extends ActivityResultContract { diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/ScannerResult.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/ScannerResult.java index 3e1de5c..1daf160 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/ScannerResult.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/scanner/ScannerResult.java @@ -3,7 +3,7 @@ package com.cringe_studios.cringe_authenticator.scanner; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.cringe_studios.cringe_authenticator.OTPData; +import com.cringe_studios.cringe_authenticator.model.OTPData; public class ScannerResult { 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 3e2bee3..9e02249 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 @@ -8,8 +8,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; 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.model.OTPData; import com.cringe_studios.cringe_authenticator.util.OTPParser; import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/BiConsumer.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/BiConsumer.java new file mode 100644 index 0000000..f04f8d9 --- /dev/null +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/BiConsumer.java @@ -0,0 +1,7 @@ +package com.cringe_studios.cringe_authenticator.util; + +public interface BiConsumer { + + public void accept(T t, U u); + +} diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/DialogUtil.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/DialogUtil.java index a670823..239affa 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/DialogUtil.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/DialogUtil.java @@ -10,10 +10,11 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.core.util.Consumer; -import com.cringe_studios.cringe_authenticator.OTPData; import com.cringe_studios.cringe_authenticator.R; +import com.cringe_studios.cringe_authenticator.databinding.DialogCreateGroupBinding; import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeHotpBinding; import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeTotpBinding; +import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm; import com.cringe_studios.cringe_authenticator_library.OTPType; @@ -169,4 +170,34 @@ public class DialogUtil { case TOTP: showTOTPDialog(inflater, initialData, callback, back, false); break; } } + + public static void showCreateGroupDialog(LayoutInflater inflater, String initialName, Consumer callback) { + Context context = inflater.getContext(); + + DialogCreateGroupBinding binding = DialogCreateGroupBinding.inflate(inflater); + binding.createGroupName.setText(initialName); + + AlertDialog dialog = new StyledDialogBuilder(context) + .setTitle(R.string.action_new_group) + .setView(binding.getRoot()) + .setPositiveButton(R.string.add, (view, which) -> {}) + .setNegativeButton(R.string.cancel, (view, which) -> {}) + .create(); + + dialog.setOnShowListener(d -> { + Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); + okButton.setOnClickListener(v -> { + if(binding.createGroupName.getText().length() == 0) { + DialogUtil.showErrorDialog(context, context.getString(R.string.new_group_missing_title)); + return; + } + + dialog.dismiss(); + callback.accept(binding.createGroupName.getText().toString()); + }); + }); + + dialog.show(); + } + } diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/OTPParser.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/OTPParser.java index 392213a..8916394 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/OTPParser.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/OTPParser.java @@ -2,7 +2,7 @@ package com.cringe_studios.cringe_authenticator.util; import android.net.Uri; -import com.cringe_studios.cringe_authenticator.OTPData; +import com.cringe_studios.cringe_authenticator.model.OTPData; import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm; import com.cringe_studios.cringe_authenticator_library.OTPType; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java index f4648f1..afdd207 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java @@ -5,8 +5,8 @@ import android.content.SharedPreferences; import androidx.annotation.NonNull; -import com.cringe_studios.cringe_authenticator.OTPData; import com.cringe_studios.cringe_authenticator.R; +import com.cringe_studios.cringe_authenticator.model.OTPData; import com.google.gson.Gson; import java.util.ArrayList; @@ -44,12 +44,14 @@ public class SettingsUtil { return Arrays.asList(GSON.fromJson(prefs.getString("groups", "[]"), String[].class)); } - public static void addGroup(Context ctx, String group) { + public static void addGroup(Context ctx, String group, String groupName) { List groups = new ArrayList<>(getGroups(ctx)); groups.add(group); SharedPreferences prefs = ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE); prefs.edit().putString("groups", GSON.toJson(groups)).apply(); + + setGroupName(ctx, group, groupName); } public static void removeGroup(Context ctx, String group) { @@ -59,32 +61,45 @@ public class SettingsUtil { SharedPreferences prefs = ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE); prefs.edit().putString("groups", GSON.toJson(groups)).apply(); - deleteOTPs(ctx, group); + deleteGroupData(ctx, group); } public static List getOTPs(Context ctx, String group) { - String currentOTPs = ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).getString("group." + group, "[]"); + String currentOTPs = ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).getString("group." + group + ".otps", "[]"); return Arrays.asList(GSON.fromJson(currentOTPs, OTPData[].class)); } public static void addOTP(Context ctx, String group, @NonNull OTPData data) { + // TODO: check for code with same name + List otps = new ArrayList<>(getOTPs(ctx, group)); otps.add(data); ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).edit() - .putString("group." + group, GSON.toJson(otps.toArray(new OTPData[0]))) + .putString("group." + group + ".otps", GSON.toJson(otps.toArray(new OTPData[0]))) .apply(); } public static void updateOTPs(Context ctx, String group, List otps) { ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).edit() - .putString("group." + group, GSON.toJson(otps.toArray(new OTPData[0]))) + .putString("group." + group + ".otps", GSON.toJson(otps.toArray(new OTPData[0]))) .apply(); } - private static void deleteOTPs(Context ctx, String group) { + public static String getGroupName(Context ctx, String group) { + return ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).getString("group." + group + ".name", group); + } + + public static void setGroupName(Context ctx, String group, String name) { ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).edit() - .remove("group." + group) + .putString("group." + group + ".name", name) + .apply(); + } + + private static void deleteGroupData(Context ctx, String group) { + ctx.getSharedPreferences(GROUPS_PREFS_NAME, Context.MODE_PRIVATE).edit() + .remove("group." + group + ".otps") + .remove("group." + group + ".name") .apply(); } diff --git a/app/src/main/res/layout/dialog_create_group.xml b/app/src/main/res/layout/dialog_create_group.xml new file mode 100644 index 0000000..2ce7f09 --- /dev/null +++ b/app/src/main/res/layout/dialog_create_group.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 1c5242e..d4a5572 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -31,6 +31,9 @@ Aktion fehlgeschlagen Ungültige Zahl Zurück + Löschen? + OTP löschen? + Gruppe bearbeiten Anzeigen Bearbeiten diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 60178d9..e7f76ba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,6 +71,9 @@ Action failed Invalid number entered Back + Delete? + Delete this? + Edit Group View Edit